// JavaScript Document
var researchIs_NS = navigator.appName=="Netscape";
var researchIs_Ver = parseInt(navigator.appVersion);
var researchIs_NS4 = researchIs_NS&&researchIs_Ver>=4&&researchIs_Ver<5;
var researchIs_NS5up = researchIs_NS&&researchIs_Ver>=5;

//A general function designed to check if an input field has a value
function checkInput(id)
{
	element = document.getElementById(id);
	
	switch(element.type)
	{
		case 'radio':
			return checkInputForRadioButton(element.form.name, element.name);
		case 'text':
			return checkInputForTextField(element);
		case 'textarea':
			return checkInputForTextArea(element);
		case 'select-one':
			return checkInputForComboBox(element);
	}
}



//Checks a radioButtonArray to make sure one of them is checked
//Returns the selected value, if one is selected, otherwise null;
function checkInputForRadioButton(formName, elementName)
{
	radioButtonArray = document.forms[formName].elements[elementName];
	selectedValue = null;
	
	for (i = 0; i < radioButtonArray.length; i++)
	{
		if (radioButtonArray[i].checked)
		{
			selectedValue = radioButtonArray[i].value;
		}
	}
	
	return selectedValue;
}

//Checks a text field to make sure it isn't empty
//Returns true if the it is empty, false otherwise
function checkInputForTextField(element)
{
	value = element.value.replace(/^\s+|\s+$/g,"");
	if ( value != '' )
	{
		return value;
	}
	else
	{
		return null;
	}
}

//Checks a text field to make sure it isn't empty
//Returns true if the it is empty, false otherwise
function checkInputForTextArea(element)
{
	value = element.value.replace(/^\s+|\s+$/g,"");
	if ( value != '' )
	{
		return value;
	}
	else
	{
		return null;
	}
}

//Check is an item has been selected in a combo box
//Returns true/false
function checkInputForComboBox(element)
{
	if ( element.selectedIndex != null && element.options[element.selectedIndex].value != '' )
	{
		return element.options[element.selectedIndex].value;
	}
	else
	{
		return null;
	}
}

//show OR hide funtion depends on if element is shown or hidden
/*sample code:
	<h4><img src="/graphics/redarrow.jpg" name="imgfirst" border="0" ><a href="javascript:shoh('first');" style="color:#434343" ><strong>Titile</strong></a></h4>
	<div id="first" style="display:none" >

		CONTENT
	
	</div>
*/

imgout=new Image(9,9);
imgin=new Image(9,9);

on = false;
/////////////////BEGIN USER EDITABLE///////////////////////////////
	imgout.src="/graphics/redarrow.jpg";
	imgin.src="/graphics/reddownarrow.jpg";
///////////////END USER EDITABLE///////////////////////////////////

//this switches expand collapse icons
function filter(imagename,objectsrc){
	if (document.images){
		document.images[imagename].src=eval(objectsrc+".src");
	}
}

function shoh(id) { 
	
	if (document.getElementById) { // DOM3 = IE5, NS6
		if (document.getElementById(id).style.display == "none"){
			document.getElementById(id).style.display = 'block';
			filter(("img"+id),'imgin');			
		} else { 
			filter(("img"+id),'imgout');
			document.getElementById(id).style.display = 'none';			
		}	
	} else { 
		if (document.layers) {	
			if (document.id.display == "none"){
				document.id.display = 'block';
				filter(("img"+id),'imgin');
			} else {
				filter(("img"+id),'imgout');	
				document.id.display = 'none';
			}
		} else {
			if (document.all.id.style.visibility == "none"){
				document.all.id.style.display = 'block';
			} else {
				filter(("img"+id),'imgout');
				document.all.id.style.display = 'none';
			}
		}
	}
}

function findRealPositionLeft(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft
		while (obj = obj.offsetParent)
			curleft += obj.offsetLeft
	}
	return curleft;
}

function findRealPositionTop(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
			curtop += obj.offsetTop
	}
	return curtop;
}

function findRealPositionRight(obj)
{
	return findRealPositionLeft(obj) + obj.offsetWidth;
}

function findRealPositionBottom(obj)
{
	return findRealPositionTop(obj) + obj.offsetHeight;
}

function getPageHeight()
{
	if ( researchIs_NS5up == true ) //window.innerHeight && window.scrollMaxY ) // Firefox 
	{
		if ( window.innerHTML && window.scrollMaxY )
		{
			pageHeight = window.innerHeight + window.scrollMaxY;
		}
		else
		{
			pageHeight = findRealPositionBottom(document.body) + 'px';
		}
	}
	else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
	{
		pageHeight = document.body.scrollHeight;
	}
	else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
	{
		pageHeight = document.body.offsetHeight + document.body.offsetTop;
	}
	
	return pageHeight;
}
