///////////////////////////////////////////
////////////JavaScript/////////////////////
///////////////////////////////////////////

//function to make current window goTo a passed address

	function goToSite(siteName)
	{
		self.location=siteName
	}


//function to set the focus on the field passed to it.
	function betterSetFocus(formName,fieldName) 
	{
	var strFieldName = fieldName;
	var strFormName = formName;

	var formElement = document.forms[strFormName].elements[strFieldName];	
	formElement.focus();
	}

//function to submit a passed form
	function jsSubmit(frmName)
	{
	document.forms(frmName).submit();
	}

//function to set value of a form input
	//sets the value and then submits the form

	function setFormFieldValue(formName,fieldName,passedValue) 
	{
	var strFieldName = fieldName;
	var strFormName = formName;

	var formElement = document.forms[strFormName].elements[strFieldName];
	formElement.value = passedValue;
	document.forms[formName].submit();
	}

//function to set value of a form input
	//sets the value and then submits the form
	//*special version for orderIssueQueuePage*

	function setFormFieldValueOI(formName,fieldName1,fieldName2,passedValue1,passedValue2) 
	{
	var strFieldName = fieldName1;
	var strFormName = formName;

	var formElement = document.forms[strFormName].elements[strFieldName];
	formElement.value = passedValue1;
	var formElement = document.forms[strFormName].elements[fieldName2];
	formElement.value = passedValue2;

	document.forms[formName].submit();
	}

//function to validate fields

	//function requires three passed values:
	//formName - the name of the form containing the field to be validated
	//fieldName - the name of the element on the field to be validated
	//
	function isFieldPopulated(formName,fieldName,fieldDisplayName)
	{
		if (document.forms[formName].elements[fieldName].value=="") 
			{
			//alert (fieldDisplayName + " is a required value.");
			betterSetFocus(formName,fieldName);
			if (window.document.all)
			{
			document.all.alertSpan.innerText=fieldDisplayName + " is a required value.";

			} 
			else 
			{
			//span tags don't work the same in Mozilla/netscape so show alert instead
			alert(fieldDisplayName + " is a required value.");
			}

			return false
			}


//	if (document.forms[frmName].building.selectedIndex==0) 
//			{
//			alert("Building is a required value.")
//			betterSetFocus('building','add')
//			return false
//			}
		
		return true
		
	}
	
	
	function isNumeric(formName,fieldName,fieldDisplayName)
		
		{
		   var ValidChars = "0123456789.";
		   var IsNumber=true;
		   var Char;
		   var sText;
		   
		   sText = document.forms[formName].elements[fieldName].value
		
		 
		   for (i = 0; i < sText.length && IsNumber == true; i++) 
		      { 
		      	Char = sText.charAt(i); 
		      	if (ValidChars.indexOf(Char) == -1) 
		      	   {
		      	   	IsNumber = false;
		      	   }
		      }
		   if (IsNumber == false)
		   	{
		   		if (window.document.all)
						{
							document.all.alertSpan.innerText=fieldDisplayName + " must be numeric.";
						} 
					else 
						{
							//span tags don't work the same in Mozilla/netscape so show alert instead
						alert(fieldDisplayName + " must be numeric.");
						}
		   	}
		   //document.all.alertSpan.innerText=fieldDisplayName + " must be numeric."
		   return IsNumber
}

	function isSixteenChar(formName,fieldName,fieldDisplayName)
	
	{
		var sText;
		sText = document.forms[formName].elements[fieldName].value
		if (sText.length > 16)
			{
				if (window.document.all)
					{
						document.all.alertSpan.innerText=fieldDisplayName + " must be 16 characters or less.";
					} 
				else 
					{
					//span tags don't work the same in Mozilla/netscape so show alert instead
					alert(fieldDisplayName + " must be 16 characters or less.");
					}
				return false
			}
		return true
	}


//function to test field equality

	//function requires three passed values:
	
	//fieldNameOne - the name of the element on the form with the correct value
	//fieldNameTwo - the name of the element on the form to be tested against the correct value
	//
	function areFieldsEqual(formName,fieldNameOne,fieldNameTwo,fieldDisplayName)
	{
		
		if (document.forms[formName].elements[fieldNameOne].value != document.forms[formName].elements[fieldNameTwo].value) 
			{
			//alert (fieldDisplayName + " is a required value.");
			betterSetFocus(formName,fieldNameTwo);
			if (window.document.all)
			{
			document.all.alertSpan.innerText= "The " + fieldDisplayName + " you entered does not match.";
			//document.all.alertSpan.innerText= "The " + document.forms[formName].elements[fieldNameOne].value + " " + document.forms[formName].elements[fieldNameTwo].value;
			} 
			else 
			{
			//span tags don't work the same in Mozilla/netscape so show alert instead
			alert("The " + fieldDisplayName + " you entered does not match.");
			}

			return false
			}

	
		return true
		
	}



// don't forget this useful event: onBlur="validate();"

// note - mozilla and its spawn (firefox, camino, navigator) are very
// picky about using brackets when referring to the DOM (document object model)
// but IE isn't, this can cause some weird don't show up on IE, do show up on Mozilla
// bugs so always use: 
//		document.forms[someFormName].elements[someElementName]
// never:
//		document.forms(someFormName).elements(someElementName)




////////////////////////////////////////////////
////////////////////////////////////////////////	
////	javascript - addModality			////
////	function created by tony dellos		////
////	from inforge systems				////
////	contact: www.inforge.com			////
////////////////////////////////////////////////

function addModality(strFormName)
	{
	 	
	j=0 // placeholder for select element
	with (document.forms[strFormName].strModality)
		{
		i=options.length-1
		for (i;i>0;i--) options[i]=null;
		for (i=0;i<ary2d.length;i++) 
			{
			if (i>0) //test for first row so that we don't get a -1
				{			
				if(ary2d[i][1] !== ary2d[i-1][1])
					{
					options[j] = new Option (ary2d[i][1], ary2d[i][1]);
					j++;
					}	
				}
			else
				{
				options[j] = new Option ("-no selection-","");
				j++;
				options[j] = new Option (ary2d[0][1],ary2d[0][1]);
				j++;
				}
			}
		}
	with (document.forms[strFormName].strSystemType)
		{
		i=options.length-1
		for (i;i>0;i--) options[i]=null;
		}
	}//end function



////////////////////////////////////////////////
////////////////////////////////////////////////
////	javascript - addSystemType			////
////	function created by tony dellos		////
////	from inforge systems				////
////	contact: www.inforge.com			////
////////////////////////////////////////////////

	function addSystemType(strFormName)
	{
	j=0
	with (document.forms[strFormName].strSystemType) // with the select on the current form
		{
		i=options.length-1
		for (i;i>0;i--) options[i]=null;//wipe out any existing options
		for (i=0;i<ary2d.length;i++)
			{
			
			if(i>0) //test for first instance of loop
				{
				
					if(ary2d[i][1] == document.forms[strFormName].strModality.value)// if the description two column in the
																		// array for the current row
																		// equals the selected value in the
																		// description two dropdown
						{
						options[j] = new Option (ary2d[i][0],ary2d[i][0]);
						j++
						}
				}
			else
				{
				options[j] = new Option ("-no selection-","");
				j++;
				if(ary2d[i][1] == document.forms[strFormName].strModality.value) //see above
					{
					options[j] = new Option (ary2d[0][0],ary2d[0][0]);
					j++;
					}
				}
			}
		}
	}//end function



//function to validate fields

	//function requires three passed values:
	//formName - the name of the form containing the field to be validated
	//fieldName - the name of the element on the field to be validated
	//
	function isDropDownSelected(formName,fieldName,fieldDisplayName)
	{

		if (document.forms[formName].elements[fieldName].selectedIndex==0)
			{
			//alert (fieldDisplayName + " is a required value.");
			betterSetFocus(formName,fieldName);
				if (window.document.all)
				{
				document.all.alertSpan.innerText=fieldDisplayName + " is a required value.";

				} 
				else 
				{
				//span tags don't work the same in Mozilla/netscape so show alert instead
				alert(fieldDisplayName + " is a required value.");
				}

			return false
			}


 

		
		return true
		
	}


////////////////////////////////////////////////
////////////////////////////////////////////////	
////	javascript - jsValidateTime			////
////	function created by anthony dellos	////
////	from inforge systems				////
////	contact: www.inforge.com			////
////	updated: 12/6/2005					////
////////////////////////////////////////////////


	function jsValidateTime(formName,fieldName) 
	{

	var strFieldName = fieldName;
	var strFormName = formName;

	var o = document.forms[strFormName].elements[strFieldName];
	var t = o.value;
	var pieces = t.split(":");

	if (pieces.length < 2) 
	{
	betterSetFocus(formName,fieldName);
		jsGenericAlert("Please enter the time in HH:MM format!");
		o.value = '';
		return false;	
	}
	
	if (pieces.length > 2)
	{
		betterSetFocus(formName,fieldName);
		jsGenericAlert("Please enter the time in HH:MM format!");
		o.value = '';
		return false;
	}

	if (parseInt(pieces[0]) > 23) 
	{
		betterSetFocus(formName,fieldName);
		jsGenericAlert("Hours cannot exceed 23!");
		o.value = '';
		return false;
	}

	if (parseInt(pieces[1]) > 59) 
	{
		betterSetFocus(formName,fieldName);
		jsGenericAlert("Minutes cannot exceed 59!");
		o.value = '';
		return false;
	}
	

	if (parseInt(pieces[0]<10))
	{
	pieces[0] = "0" + pieces[0];
	alert("hoo");
	}
	
	if (parseInt(pieces[1]<10))
	{
	pieces[0] = "0" + pieces[1];
	}
	
	//pieces[0] = parseInt(pieces[0]) < 10 ? ("0" + pieces[0]) : pieces[0];
	//pieces[1] = parseInt(pieces[1]) < 10 ? ("0" + pieces[1]) : pieces[1];
	o.value = pieces[0] + ":" + pieces[1];

}



////////////////////////////////////////////////
////////////////////////////////////////////////
////	javascript - jsGenericAlert			////
////	function created by tony dellos		////
////	from inforge systems				////
////	contact: www.inforge.com			////
////	modified: 12/6/2005					////
////////////////////////////////////////////////


function jsGenericAlert(strAlertText)
{
	if (window.document.all)
			{
			document.all.alertSpan.innerText = strAlertText;

			} 
			else 
			{
			//span tags don't work the same in Mozilla/netscape so show alert instead
			alert(strAlertText);
			}
}
