/**
This is a javascript function library.
@author Travis Mangum
@copyright Travis Mangum 2007
@created 2008.2.12
@version 2008.2.12

*/


function Calendar_Thumbnail(arg_Link) {
	/**
	* Creates a popup window called "calendar" where the user can select a date.<b> 
	* @version 1.0
	* @author Travis Mangum
	*/

	calendar = window.open(arg_Link, "_blank", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=200, height=200");
	calendar.focus();
}



function Element_Position3(obj) {
	/**
	* Returns the exact onscreen coordinates of the given element.
	* @version 1.0
	* @author Travis Mangum 
	*/


	var curleft = 0;
	var curtop = 0;
	
	if (obj.offsetParent) {
	
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		/*
		alert("Tag: " + obj.nodeName + 
		"\nStarting Cords: " + curleft + ", " + curtop);
		*/
		
		while (obj = obj.offsetParent) {
					
			tempx = curleft;
			tempy = curtop;
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			
			/*
			alert("Tag: " + obj.nodeName + 
			"\nOld Cords: " + tempx + ", " + tempy + 
			"\nNew Cords: " + curleft + ", " + curtop +
			"\nChange: " + (curleft - tempx) + ", " + (curtop - tempy));
			*/
			
		}
	}
	
	/*
	alert("Returning Cords: " + curleft + ", " + curtop);
	*/
	
	return [curleft,curtop];

}


function Form_ChangeValue (arg_Field, arg_Value) {
	/**
	* Changes the value of a field to the given value.
	* @version 1.0
 	* @author Travis Mangum 
	*/
	
	document.getElementById(arg_Field).value=arg_Value;
}



function Form_DisableFieldsOnValue (arg_MatchField, arg_MatchValue, arg_DisableField) {

	/**
	* This function disables a field when it contains a matching values.
	* @author Travis Mangum
	* @created 2008.2.12
	* @version 2008.2.12
	*/

	var FormValue = document.getElementById(arg_MatchField).value;
	var FieldNames = arg_DisableField.split(":");
	var Counter = 0;
	var Fields = FieldNames.length;
	
	 
	if (FormValue == arg_MatchValue)
	 	{	
		
			while (Counter < Fields)
			{
				document.getElementById(FieldNames[Counter]).value="";
				document.getElementById(FieldNames[Counter]).disabled=true;
				document.getElementById(FieldNames[Counter]).style.visibility="hidden";
				document.getElementById(FieldNames[Counter] + "_Row").style.visibility="hidden";
				//document.getElementById(FieldNames[Counter] + "_Required").style.visibility="hidden";
				Counter++;
			}
		}
	else
		{
			while (Counter < Fields)
			{		
				document.getElementById(FieldNames[Counter]).value="";
				document.getElementById(FieldNames[Counter]).disabled=false;
				document.getElementById(FieldNames[Counter]).style.visibility="visible";
				document.getElementById(FieldNames[Counter] + "_Row").style.visibility="visible";
				//document.getElementById(FieldNames[Counter] + "_Required").style.visibility="visible";
				Counter++;
			}
		}

}

function Form_SendValueToParent(Field, Value) {
	/**
	* Sends a field from a child window to its parent window, then closes the child window.
	* @author Travis Mangum
	* @version 1.0: 10/16/2007 
	*/
	
	opener.document.getElementById(Field).value = Value;
	window.close();
}


function Image_ChangeSource(ID, Source)
	{
		/**
		* This function changes the source of an image with the given id.
		* @author Travis Mangum
		* @created 2008.2.12
		* @version 2008.2.12
		*/
	
		document.getElementById(ID).src = Source;
		
	}
	

function Menu_Hide(element) {
	/**
	* This function sets the visibility of the menu to hidden, so that it no long diplays on the browser.
	* @version: 1.0: 10/16/2007
	* @author Travis Mangum
	*/
	
	document.getElementById(element).style.visibility = "hidden";
}
	


function Menu_Show_Right(element, parentElement) {
	/**
	* Positions the pop up menu to the right of the given object
	* @created 2008.2.20
	* @version 2008.2.20
	* @author Travis Mangum
	*/

	var parentElement = document.getElementById(parentElement);
	var elementPosition = Element_Position3(parentElement);
	var offsetHeight = elementPosition[1];
	var offsetWidth = parentElement.offsetWidth + elementPosition[0];
	var element = document.getElementById(element);
	
	element.style.left = offsetWidth - 2 + "px"; 
	element.style.top = offsetHeight + "px";
	element.style.visibility = "visible";	
	//alert("new position setting is: " + element.style.position);
	
}


function Menu_Show2(elmnt, parentelement) {
	/**
	Positions the menu under the given parent element, then sets its visibility to visible to the browser.
	@version 2.0:  10/16/2007
	@author Travis Mangum
	*/

	var parentelem = document.getElementById(parentelement);
	var elementposition = Element_Position3(parentelem);
	var offsetHeight = parentelem.offsetHeight + elementposition[1];
	var element = document.getElementById(elmnt);
	
	//element.style.position="absolute";
	//alert("current position setting is: " + element.style.position + "\nCurrent visibility is: " + element.style.visibility);
	element.style.left=elementposition[0] + "px"; 
	element.style.top=offsetHeight - 5 + "px";
	//element.style.position="fixed";
	element.style.visibility="visible";
	//element.style.position="fixed";
	//element.style.visibility="hidden";
	//element.style.visibility="visible";
	
	//alert("new position setting is: " + element.style.position);
	
}
