<!--
function all_ON(form, name){
	len = form.elements.length;
	var undefined;
	if (eval('form.' + name + '0').checked == false){
	for (i = 1; i < len; i++){
	element = eval('form.' + name + i);
	if (element != undefined && element.type == "checkbox")
	eval('form.' + name + i).checked=false;}}
	else{
	for (i = 1; i < len; i++){
	element = eval('form.' + name + i);
	if (element != undefined && element.type == "checkbox")
	eval('form.' + name + i).checked=true;}}}

function all_OFF(form, name){
	eval('form.' + name + '0').checked=false;}

function getObjValue (form, objnm, commaconv, grabtxt){
	var intype = form.elements[objnm].type;
	var val = "";
	if (intype == "select-one" ){
	if (grabtxt){
	val = form.elements[objnm].options[form.elements[objnm].selectedIndex].text;}
	else{
	val = form.elements[objnm].options[form.elements[objnm].selectedIndex].value;}}
	else if (intype == "select-multiple" ){
	sobj = form.elements[objnm];
	for(inum=0; inum < sobj.options.length; inum++){
	var tval = sobj.options[inum].value;
	val = val+tval+"#";}}
	else if ((intype == "text")||(intype == "textarea")||(intype == "hidden")||(intype == "password")){
	val = form.elements[objnm].value;}
	else if (intype == "checkbox" ){
	if (form.elements[objnm].checked){
	val = form.elements[objnm].value;}}
	else{
	if (typeof(form.elements[objnm][0]) == "object"){
	if (form.elements[objnm][0].type == "radio"){
	for (inum = 0; inum < form.elements[objnm].length; inum++){
	if (form.elements[objnm][inum].checked){
	val = form.elements[objnm][inum].value;
	break;}}}
	else if (form.elements[objnm][0].type == "checkbox"){
	for (inum = 0; inum < form.elements[objnm].length; inum++){
	if (form.elements[objnm][inum].checked){
	val = val + form.elements[objnm][inum].value + "#";}}}
	else{
	alert ("Undefined object type encountered");}}
	else if (form.elements[objnm].type == "radio"){
	if (form.elements[objnm].checked){
	val = form.elements[objnm].value;}}
	else{
	alert ("Undefined object type encountered");}}
	if (commaconv){
	while (val.indexOf(",") >= 0){
	val = val.substring(0, val.indexOf(","))+"##"+val.substring(val.indexOf(",")+1,val.length);}}
	return (val);}

function gotAllRequired(sform, fields){
	var go_on = true;
	var end = gotAllRequired.arguments.length;
	for (i = 1; (i < end)&&(go_on == true); i++){
	var inname = sform.elements[gotAllRequired.arguments[i]].name;
	go_on = checkfldForNull (sform, inname);
	if (go_on == false){}}
	return(go_on);}

function checkfldForNull (form, fieldnm){
	var retval = true;
	var fldval = getObjValue (form, fieldnm, false, false);
	if (fldval == ""){
	retval = false;}
	return(retval);}

/*
'====================================================================================================
'	NAME:	       verifyNoAnswer
'	DESCRIPTION:   Removes the No Answer checked value if something else is checked or removes any checked if no answer is selected
'====================================================================================================
*/
function verifyNoAnswer(oCheckBox)
{

    if( (!isIE && !isNetscape) || isNetscape) return;
    var strName = oCheckBox.name ;
    var strItemName = oCheckBox.parentNode.innerText.toLowerCase();
    var strFormName = oCheckBox.form.name;
    var strValue = oCheckBox.value;
	var oForm = eval("document." + strFormName);
	var isNoAnswer;
	var i = 0;

     if (strItemName.indexOf("no answer") <= -1){
        //Something other than no answer was selected, so remove the check box from no answer.
        isNoAnswer = false;
     } else if(strItemName.indexOf("no answer") > -1) {
        isNoAnswer = true;
     }

	for(i = 0; i < oForm.length; i++){

	    if (oForm[i].name == strName){
	     //   alert("match " + oForm[i].parentElement.innerText.toLowerCase());
            if(isNoAnswer && oForm[i].value != strValue ){
                oForm[i].checked = false;
            }else if (!isNoAnswer && oForm[i].parentElement.innerText.toLowerCase().indexOf("no answer") > -1){
                oForm[i].checked = false;
            }

	    }
	}
}

function getDisplayNameForInput(form, input) {
		var result = null;
 		if(input.getAttribute("displayname") != undefined) {
			result = input.getAttribute("displayname");
		} else if (input.name != undefined) {
			if(findValueForInput(form, input.name, "DispName")!=null) {
				result = findValueForInput(form, input.name, "DispName")
			} else {
				result = input.name;
			}
		}
		return result;


}
function findValueForInput(form, inputName, valueType) {
	var foundValue = null;

	var reqTypeInputName =  inputName + valueType;
	if(typeof(form[reqTypeInputName])!="undefined") {
		foundValue = form[reqTypeInputName].value;
	}

	return foundValue;


}
/*
'====================================================================================================
'	NAME:		   checkForm
'	DESCRIPTION:   Checks a form based on attributes set on the form tags
'	HTML Attributes:	Required="true" - Checks to see if the field is blank
'						Required="text" -  Checks to see if the text field is empty
'						Required="number" -  Checks to see if the field is a number
'						Required="checkbox" -  Checks to see if the field has a selected check box
'						Required="email" -  Checks to see if the field is a email address
'
'	[DISPLAYNAME]:	displayname="Something" - Optional, uses this value as the name of the field for alerts.
'====================================================================================================
*/

function checkForm(oForm)
// KPS - Generic check form function. Pass in the form and it checks for a required attribute.
// KPS - if required attribute is found and value is empty it prompts the user and returns false.
{
	var undefined;
	for (var i = 0; i <= oForm.length -1; i++) {

		// modifications made to check for hidden inputs describing validation needs
		var reqType = String(oForm[i].getAttribute("required")).toLowerCase();
		if(typeof(reqType)!="undefined") {
			var inputName  = oForm[i].name;
			if(findValueForInput(oForm, inputName, "ReqType")!=null) {
				reqType =findValueForInput(oForm, inputName, "ReqType");
			}
		}

		switch(reqType)
		{
			case undefined:
				break;

			case 'true':
				if(!checkTextField(oForm, oForm[i]))
				{
					return false;
				}
				break;

			case 'text':
				if(!checkTextField(oForm, oForm[i]))
				{
					return false;
				}
				break;

			case 'number':
				if(!checkNumber(oForm, oForm[i]))
				{
					return false;
				}
				break;

			case 'email':
				if(!checkEmail(oForm, oForm[i]))
				{
					return false;
				}
				break;

			case 'checkbox':
				if( !checkCheckBox(oForm[i],oForm) )
				{
					return false;
				}
				break;
			case 'fullyear':
				if( !checkFullYear(oForm, oForm[i]) )
				{
					return false;
				}
				break;
		}
	}

	return true;
}

/*
'====================================================================================================
'	NAME:		   checkTextField
'	DESCRIPTION:   Checks to see if a text field has just text in it
'
'	This could be expanded to check for alpha's ect....
'====================================================================================================
*/

function checkTextField(form, oText) {
// KPS - Generic function that checks to see if a text field is blank, returns a Boolean value
	var isValid = true;

	if (oText.value.trim() == "" || oText.value.trim() == "?")	{
		if(oText.type != "hidden") {
			oText.focus();
		}
		var dispName = getDisplayNameForInput(form, oText);
		if(dispName!=null) {

		    alert("Please enter a value for " +dispName + ".");
		} else {
		    alert("Please enter a value for the current field.");
		}
		isValid = false;
	}
	return isValid;
}

/*
'====================================================================================================
'	NAME:		   checkNumber
'	DESCRIPTION:   Checks to see if a text field has just numbers in it
'====================================================================================================
*/

function checkNumber(form, oText)  {
// KPS - Generic function that checks to see if a text field has only numbers, returns a Boolean value
	var isValid = true;
	var strValue = oText.value.trim()
	if ( strValue == "" || isNaN(strValue))
	{
		if(oText.type != "hidden") {
			oText.focus();
		}

		var dispName = getDisplayNameForInput(form, oText);
		if(dispName!=null) {
		  alert("Please enter a valid number for " + dispName+ ".");

		} else{
		   alert("Please enter a valid number for the current field.");
		}
		isValid = false;
	}

	return isValid;
}

/*
'====================================================================================================
'	NAME:		   checkEmail
'	DESCRIPTION:   Checks to see if a text field has a vaild email
'====================================================================================================
*/

function checkEmail(form, oText) {
// KPS - Generic function that checks to see if a text field has only numbers, returns a Boolean value
	var isValid = true;
	var strValue = oText.value.trim()

    //Expression 1
    var emailPattern1 = /^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/
    //Expression 2
    var emailPattern2 = /^(([-\w \.]+)|(""[-\w \.]+"") )?<([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))>$/

	//if ( strValue == "" || strValue.indexOf("@") == -1 || strValue.indexOf(".") == -1 )
	if ( !emailPattern1.test(strValue) && !emailPattern2.test(strValue) )
	{
		if(oText.type != "hidden") {
			oText.focus();
		}

		var dispName = getDisplayNameForInput(form, oText);
		if(dispName!=null) {
		  	alert("Please enter a valid email for " + dispName + ".");

		} else{
		   alert("Please enter a valid email for the current field.");
		}
		isValid = false;
	}

	return isValid;
}

/*
'====================================================================================================
'	NAME:		   checkCheckBox
'	DESCRIPTION:   Checks to see if a check box field has been checked
'====================================================================================================
*/

function checkCheckBox(oCheckBox, oForm)

{

    var strName = oCheckBox.name ;
//	var oCB = eval("oForm." + strName);
	var oCB = document.getElementsByName(strName);
	var bCheckedFlag = false;
	var i = 0;

    for(i = 0; i < oCB.length ; i++){
         if (oCB(i).checked){
          bCheckedFlag = true;
          break;
         }
    }

//kps - Add check to make sure field is not disabled before focus
    if (!bCheckedFlag){
        if(oCB(0).type != "hidden" && !oCB(0).disabled && !oCB(0).readOnly){
			//oCB(0).focus();
		}

        var dispName = getDisplayNameForInput(oForm, oCheckBox);
        if(dispName !=null) {
            alert("Please select a " +dispName + ".");

        } else {
           alert("Please select the current field.");
        }

		return false;
    } else {
        return true;
    }

	return false;
}

/*
'====================================================================================================
'	NAME:		   checkFullYear
'	DESCRIPTION:   Checks to see if a text field has 4 digit year
'
'====================================================================================================
*/

function checkFullYear(form, oText)
// KPS - Generic function that checks to see if a text field is a full 4 digit year, returns a Boolean value
{
	if (oText.value.trim() == "" || oText.value.length < 4)
	{
		if(oText.type != "hidden") {
			oText.focus();
		}
		var dispName = getDisplayNameForInput(form, oText);
		if(dispName!=null) {
		   alert("Please enter a full year for " + dispName+ ".");
		} else {
		    alert("Please enter a full year for the current field.");
		}

		return false;
	}
	return true;
}
/*
'====================================================================================================
'	NAME:		   addInputField
'	DESCRIPTION:   Adds a input into the form DOM
'====================================================================================================
*/
function addSingleInputField(oForm, sName, sValue, sType){
    if(!isIE && !isNetscape) return;

	var oInput;
	var parent;

	try{
		parent = oForm.ownerDocument;

		oInput = parent.createElement("input");


		oInput.type = sType;
		oInput.name = sName;
		oInput.value = sValue;

		oForm.appendChild(oInput);

	}catch(e){

		alert("addSingleInputField() " + e.description);

	}


}

/*
'====================================================================================================
'	NAME:		   addAllInputFields
'	DESCRIPTION:   Adds a input into the form DOM
'====================================================================================================
*/
function addAllInputFields(oForm, sName, oElements, sType){
    if(!isIE && !isNetscape) return;

	var oInput;
	var parent;

	try{
		parentDocument = oForm.ownerDocument;

		if(inForm(oForm, sName)){
			deleteInputField(oForm, sName);
		}


		for(var i=0; i< oElements.length; i++){

			oInput = parentDocument.createElement("input");
			oInput.type = sType;
			oInput.name = sName;
			oInput.value = oElements.item(i).value;

			oForm.appendChild(oInput);
		}

	}catch(e){

		alert("addAllInputFields()" + e.description);

	}


}

/*
'====================================================================================================
'	NAME:		   inForm
'	DESCRIPTION:   Adds a input into the form DOM
'====================================================================================================
*/
function inForm(oForm, sName){
    if(!isIE && !isNetscape) return;
	var result = false;

	try{

		for(var i = 0; i < oForm.length; i++){
			if (oForm.elements[i].name.toLowerCase() == sName.toLowerCase()){
				result = true;
				break
			}
		}

	}catch(e){
		result = false;
		alert("inForm()" + e.description);

	}

	return result;

}

/*
'====================================================================================================
'	NAME:		   deleteInputField
'	DESCRIPTION:   Adds a input into the form DOM
'====================================================================================================
*/
function deleteInputField(oForm, sName){
    if(!isIE && !isNetscape) return;
	var result = false;

	try{

	var i = 0

	while(i < oForm.length){

		if(oForm.elements[i].name == sName){
			oForm.elements.item(i).removeNode();
		} else {
			i++;
		}

		if (i > 10000){

			break;
		}

	}

		result = true;
	}catch(e){
		result = false;
		alert("deleteInputField() " + e.description);

	}

	return result;

}

/*
'====================================================================================================
'	NAME:		   clearValues
'	DESCRIPTION:
'====================================================================================================
*/
function clearValues(){
   // if(!isIE && !isNetscape) return;
	var oUsername;
	var oPassword;

	try{
		oUsername = document.getElementsByName("username").item(0)
		oPassword = document.getElementsByName("password").item(0)

		if(oUsername.value == "enter e-mail"){
			oUsername.value = "";
		}

		if(oPassword.value == "enter passw."){
			oPassword.value = "";
		}

	}catch(e){

		alert("clearValues() " + e.description);

	}


}



/*
'====================================================================================================
'	NAME:		   selectNoAnswer
'	DESCRIPTION:
'====================================================================================================
*/

	function selectNoAnswer(oForm){
		var element
		var option
		var displayName = "";

		if(oForm == null){
			return;
		}

		for(var i = 0; i < oForm.length; i++){
			element = oForm.elements[i];


			//alert(element.nodeName);

			switch(element.nodeName.toLowerCase()){

				case "select":
						//alert("length = " + element.options.length)

						for(var j = 0; j < element.options.length; j++){
							option = element.options[j];

							//alert(option.innerHTML);
							if(option.innerHTML.fullTrim().toLowerCase() == "no answer"){
								element.selectedIndex = j;
								break;
							}

						}


						break;

				case "input":
						if(element.type == "checkbox" || element.type == "radio"){

							displayName = element.getAttribute("displayName");
							if(displayName == "" || displayName == null){
								//kps - try to get name from the value;
								displayName = element.value;
							}
							//alert("Input - Type = " + element.type + " '" + displayName.trim() + "'");
							if( displayName.fullTrim().toLowerCase() == "no answer"){
								try{
									element.checked = true;
									verifyNoAnswer(element);
								}catch(e){

								}
							}
						}
						break;


			}
		}

	}

/*
'====================================================================================================
'	NAME:		   autoZipTab
'	DESCRIPTION:    checks user input for a zip code format, then sets focus to a button
'====================================================================================================
*/
function autoZipTab(oInput, sButtonName){

	try{
		var bIsNum = false;
		var sTrimmedValue = "";
		oButton = document.getElementsByName(sButtonName).item(0)

		if(typeof(oButton) != "object" || oButton == null){

			return;
		}

		bIsNum = isNumeric(oInput.value);
		sTrimmedValue = oInput.value.replace(" ", "");

		if( bIsNum && sTrimmedValue.length >= 5){

			oButton.focus();
			return;
		}else if(!bIsNum && sTrimmedValue.length >=6){
			oButton.focus();
			return;
		}

	}catch(e){

		alert("Error in autoZipTab():\n\n" + e.description);

	}
}

/*
'====================================================================================================
'	NAME:		   autoPhoneTab
'	DESCRIPTION:    checks user input for a zip code format, then sets focus to a button
'====================================================================================================
*/
function autoPhoneTab(input, len, e)
{

	//kps - we need to rewrite this!
	
	//var isNN = (navigator.appName.indexOf("Netscape") != -1);
	var isNN = false;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    var keyCode = (isNN) ? e.which : e.keyCode;
    if (input.value.length >= len && !containsElement(filter,keyCode))
    {
        if(input.form[getIndex(input)+1]) {
            input.form[getIndex(input)+1].focus();
            input.form[getIndex(input)+1].select();
        }
    }
    function containsElement(arr, ele)
    {
      for(var i = 0;i < arr.length;i++)
      {
        if(arr[i] == ele)
            return true;
      }
      return false;
    }
    function getIndex(input)
    {
      for(var i = 0;i < input.form.length;i++)
      {
        if(input.form[i] == input)
            return i;
      }
      return -1;
    }
}

/*
'====================================================================================================
'	NAME:		   autoDateTab
'	DESCRIPTION:   automaticly tabs between multiple data fields
'====================================================================================================
*/
function autoDateTab(input, len, e)
{
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if (input.value.length >= len && !containsElement(filter,keyCode))
    {
        if(input.form[getIndex(input)+1])
            input.form[getIndex(input)+1].focus();
    }
    function containsElement(arr, ele)
    {
      for(var i = 0;i < arr.length;i++)
      {
        if(arr[i] == ele)
            return true;
      }
      return false;
    }
    function getIndex(input)
    {
      for(var i = 0;i < input.form.length;i++)
      {
        if(input.form[i] == input)
            return i;
      }
      return -1;
    }
}

/*
'====================================================================================================
'	NAME:		   submitCountry
'	DESCRIPTION:    submits form with country code selected
'====================================================================================================
*/
function submitCountry(oSelect, oForm){

	try{
	//var sCountryCode = "";

	//sCountryCode = oSelect.options[oSelect.selectedIndex];

	//if (sCountryCode.length > 0){
		oForm.buttonPicked.value = "Check Country Code";
		oForm.submit();
	//}

	}catch(e){

		alert("Error in submitCountry():\n\n" + e.description);

	}
}

/*
'====================================================================================================
'	NAME:		   checkCharacters
'	DESCRIPTION:    checks text objects for invalid character codes
'====================================================================================================
*/

	function checkCharacters(oText){
		var text = oText.value
		var countInvalid = 0;
		var aErrors = new Array();
		var oCharCode
		var bHasChanged = false;
		var bump = 0;

		//kps - search all characters in string for invalid ones
		for (var i=0; i < text.length;i++){

			if(text.charCodeAt(i) > 128 || text.charCodeAt(i) < 0){
				oCharError = new CharError(text.charCodeAt(i), i);
				aErrors.push(oCharError)
			}
		}

		var sError =  ""
/*
		if(aErrors.length > 0 && aErrors.length < 10){
			sError = "The text you have entered contains "+ aErrors.length + " invalid character(s), which cannot be sent via email.\n\nInvalid characters found:\n\n";
			var sBadCharacters = "";
				for(var i=0; i < aErrors.length; i++){
					oCharError = aErrors[i];
				//	sBadCharacters += " " + oCharError.char;
				sBadCharacters += " " + oCharError;
				}
				sError += sBadCharacters;

		} else {
			sError = "The text you have entered contains "+ aErrors.length + " invalid character(s), which cannot be sent via email.\n\nPlease correct before saving!";
		}
		alert(sError);
*/

		if(aErrors.length > 0){
			var sError =  "The text you have entered contains "+ aErrors.length + " invalid character(s), which cannot be sent via email.\n\nClick OK to find and replace these characters\nClick Cancel to manually fix the document";
			var sReplacement = "";
			var bReplace = confirm(sError);

			if(bReplace){
				for(var i=0; i < aErrors.length; i++){
					oCharError = aErrors[i];
						//sReplacement = prompt("Please enter a new value for:\n " + oCharError.char + " ");
						sReplacement = prompt("Please enter a new value for:\n " + oCharError + " ");

						if(sReplacement != "" && sReplacement != null){
							bHasChanged = true;

							text = text.substring(0, ( (oCharError.position+ bump) )) + sReplacement + text.substring((oCharError.position+ bump) +1);
							bump = bump + (sReplacement.length - 1)

						}

				}
			} else{
				bHasChanged = false;
				sError = "Invalid characters found:\n\n";
				var sBadCharacters = "";
					for(var i=0; i < aErrors.length; i++){
						oCharError = aErrors[i];
					//	sBadCharacters += " " + oCharError.char;
					sBadCharacters += " " + oCharError;

					}
					sError += sBadCharacters;
					alert(sError)
			}
		} else {
			return true;
		}


		if (bHasChanged){
			oText.value = text;
			return true;
		} else {
			return false;
		}

	}

/*
'====================================================================================================
'	NAME:		   CharError
'	DESCRIPTION:    Character code error object.  Used with checkCharacters()
'====================================================================================================
*/
	function CharError(code, pos){
		this.charCode = code;
		this.position = pos;
	//	this.char = String.fromCharCode(this.charCode);
	}

/*
'====================================================================================================
'	NAME:		   isValidDate
'	DESCRIPTION:    returns true if an input is a valid date
'====================================================================================================
*/
	function isValidDate(sValue, vAllowFutureDates){
		var testDate;
		var bAllowFuture = true;
		var now = new Date();

		if(vAllowFutureDates == "false" || vAllowFutureDates == false){
			bAllowFuture = false;
		}

		try{
			testDate = new Date(sValue)

			//alert(testDate.getFullYear());

			if (!isNaN(testDate.getFullYear()) && bAllowFuture){
				return true;
			} else if (!isNaN(testDate.getFullYear()) && !bAllowFuture){
				if (testDate.getTime() < now.getTime()){
					return true;
				} else {
					return false;
				}

			}else{
				return false;
			}
		}catch(e){
			return false;
		}
	}

/*
'====================================================================================================
'	NAME:		   convertMultipleDateToSingle
'	DESCRIPTION:    converts MM DD YYYY fields to a single hidden field
'====================================================================================================
*/
	function convertMultipleDateToSingle( sFieldName){
		try{

			var dateField = document.getElementsByName(sFieldName).item(0);
			var undefined;

			if(dateField == null || dateField == undefined){
				return ;
			}

			var mmField = document.getElementsByName(sFieldName+"1").item(0)
			var ddField = document.getElementsByName(sFieldName+"2").item(0)
			var yyyyField = document.getElementsByName(sFieldName+"3").item(0)

			if(mmField.value.length > 0 && ddField.value.length > 0 && yyyyField.value.length > 0){
			    dateField.value = mmField.value +"/"+ ddField.value +"/"+ yyyyField.value;
			   }
			//alert(dateField.value);
		}catch(e){
			return false;
		}
	}

/*
'====================================================================================================
'	NAME:		   setPhoneValue
'	DESCRIPTION:    If split phone elements exist then join them to the field passed in
'====================================================================================================
*/
	function setPhoneValue(name, form){
		try{
		var oField1 = eval("form."+name+"1");
		var oField2 = eval("form."+name+"2");
		var oField3 = eval("form."+name+"3");
		var oField = eval("form."+name);


		if(typeof(oField1) == "object" && typeof(oField2)  == "object"&& typeof(oField3) == "object"){
			if(typeof(oField) == "object"){
                oField.value = oField1.value + oField2.value + oField3.value;
            } else {
                alert("Destination field is not an object");
            }
        }

		}catch(e){
			errHandler(setPhoneValue, e, "Error joining phone fields")
			return;
		}
	}
// -->