<!-- 
/* Same as left function in vbscript*/
function Left(str, n){
	if(n<=0) return "";/*Invalid bound, return blank string*/
	else if(n>String(str).length)return str;/* Invalid bound, return whole string*/
	else return String(str).substring(0,n); // Valid bound, return appropriate substring
}
/* Same as right function in vbscript*/
function Right(str, n){
	var l=String(str).length;
	if(n<0) return "";/*Invalid bound, return blank string*/
	else if(n>String(str).length)return str;/* Invalid bound, return whole string*/
	else return String(str).substring(l-n,l); // Valid bound, return appropriate substring
}
/* Trim any spaces on the left side of a field */
function LTrim(str){ 
	for (var k=0; k<str.length&&str.charAt(k)<=" " ; k++) ;
		return str.substring(k,str.length);
}
/* Trim any spaces on the right side of a field */
function RTrim(str){
	for(var j=str.length-1;j>=0&&str.charAt(j)<=" ";j--);
		return str.substring(0,j+1);
}
/* Trim any spaces on both ends of a field */
function Trim(str){return LTrim(RTrim(str));}
/* Check if a field is empty. Required Parameters: tField - a valid field on the form, tName - the description of the field. */
function CheckEmpty(tField,tName){
	if(Trim(tField.value)==""){alert("Please enter a value in the \""+tName+"\" field.");tField.focus();return(false);}
	else{return (true);}
}
/* Check if a field contains a date in the format mm/dd/yy Required Parameter: tField - a valid date field on the form */
function CheckDate(tField){
	with(tField.value){
		if(charAt(2)!='/'||charAt(5)!='/'||charAt(0)=='/'||charAt(1)=='/'||charAt(3)=='/'||charAt(4)=='/'||charAt(6)=='/'||charAt(7)=='/'){
			alert("Please enter the date in the format mm/dd/yy");tField.focus();return (false);
		}
		else{
			if(charAt(0)=='m'||charAt(1)=='m'||charAt(3)=='d'||charAt(4)=='d'||charAt(6)=='y'||charAt(7)=='y'){
				alert("Please enter a valid date");tField.focus();return (false);
			}
			return (true);
		}
	}
}
/* Check dates, should be used both onkeyup and at pre-submission validation. required parameter is the date field. */
function valiDate(d){
	var substrings=d.value.split('/');
	if(parseInt(d.value.substring(0,2))>12&&parseInt(d.value.substring(0,2))!=99){alert('You have entered an invalid month');return(false);}
	if(d.value.length==2&&substrings.length-1<1){d.value=d.value+'/';}
	if(parseInt(d.value.substring(3,5))>31&&parseInt(d.value.substring(3,5))<99){alert('You have entered an invalid day');return(false);}
	if(d.value.length==5&&substrings.length - 1 < 2){d.value=d.value+'/';}
	if(d.value.length==8&&(d.value.charAt(2)!='/'||d.value.charAt(5)!='/')){alert('This date is not properly formatted. Please use the format mm/dd/yy');d.focus();return(false);}
	return(true);
}
/* For use with print setups. Initially just stock images... only allow 22 chars for secondary field. */
function CheckRadioEmpty(tField,tField1, tName,tName1){
	if(tField.checked==true&&tField1.value.length>22){ 
		alert("Because you are using "+tName+", please enter at most 22 characters in the "+tName1+" field .");tField.focus();return (false);
	}
	else{return(true);}
}
/****************************************************************
 Check if a field is numeric(0-9), and optionally, if the number exceeds an upper or lower limit.
 Required Parameters:
	tField - a valid field on the form
	tName - the description of the field
	numtype - set what type of number we are checking for
		(1)currency, 0-9 includes period and dash
		(2)zipcode, 0-9 includes dash
		(3)number, 0-9
		(4)for laser checks checking account number, 0-9 / - Xx
		(5)for decimals, 0-9 includes period
		any other value will default to number
	Optional Parameters: lowerlimit - the lower limit of the field, upperlimit - the upper limit of the field *** BOTH are required to use either
*******************************************************************/
function CheckNumeric(tField,tName,numtype,lowerlimit,upperlimit){
	switch(numtype) {
		case 1:
			var a=tField.value // Check for multiple decimal points
			var substrings=a.split(".");
			if(substrings.length>2){alert("The "+tName+" field has too many decimals");tField.focus();return(false);}
			var checkOK="-0123456789.";
			break;
		case 2:var checkOK="-0123456789";break;
		case 3:var checkOK="0123456789";break;
		case 4:var checkOK="-/0123456789Xx";break;
		case 5:var checkOK="0123456789.";break;
		case 6:var checkOK="/0123456789";break;
		case 7:var checkOK=" -0123456789";break;
		case 8:var checkOK="-/0123456789Xx ";break;
		default:var checkOK="0123456789";break;
	}
	var checkStr=tField.value;
	var allValid=true;
	var validGroups=true;
	var decPoints=0;
	var allNum="";
	var numalerttext="Invalid characters in the \""+tName+"\" field. Valid characters are "+checkOK;
	for (i=0;i<checkStr.length;i++){
		var ch=checkStr.charAt(i);
		for (j=0;j<checkOK.length;j++)
			if(ch==checkOK.charAt(j))
				break;
		if(j==checkOK.length){allValid=false;break;}
		if(ch!=","){allNum+=ch;}
	}
	if(!allValid){alert(numalerttext);tField.focus();return (false);}
	else{
		if(!(typeof upperlimit=='undefined'||typeof lowerlimit=='undefined')){
			var chkVal=allNum;
			var prsVal=parseInt(allNum,10);
			var rangealerttext="Please enter a value greater than or equal to "+lowerlimit+" and less than or equal to "+upperlimit+" in the \""+tName+"\" field.";
			if(chkVal!=""&&!(prsVal>=lowerlimit&&prsVal<=upperlimit)){alert(rangealerttext);tField.focus();return (false);}
			else
				return (true);
		}
		else
			return (true);
	}
}
function AddZero(tField){if(tField.value.length==1){tField.value="0"+tField.value;}}
/* Check if beginning payment number is less than the ending payment number. CheckNumeric function should be run first.
	Required Parameters: startnum - a valid starting payment number form field, endnum - a valid ending payment number form field. */
function BeginEndValid(startnum,endnum){
	if(parseInt(startnum.value)>parseInt(endnum.value)){alert("Ending Payment Number must be greater than Starting Payment Number.");startnum.focus();return(false);}
	else{return(true);}
}
/* If there is more than one value in a dropdown, check if anything has been selected.
	Required Parameters:tField - a valid dropdown field on the form, tName - the description of the field*/
function CheckDDSelected(tField,tName){
	if((tField.length>1)&&(tField.selectedIndex<1)){alert("Please make a selection in the \""+tName+"\" field.");tField.focus();return(false);}
	else{return(true);}
}
/* Check if the email contains an @ sign and a period. Required Parameters: tField - an email address from form, tName - the description of the field */
function CheckEmail(tField,tName){
	if(Trim(tField.value)==""){alert("Please enter a value in the \""+tName+"\" field.");tField.focus();return(false);}
	if(tField.value.indexOf("@")==-1){alert("The \"@\" symbol is required in the \""+tName+"\" field");tField.focus();return(false);}
 	if(tField.value.indexOf(".")==-1){alert("Please include a period in the \""+tName+"\" field.");tField.focus();return(false);}
 	if(tField.value.indexOf(",")!=-1){alert("Please do not use commas in the \""+tName+"\" field.");tField.focus();return(false);}
 	else{return(true);}
}
/* Check any 2 fields to make sure they match each other, primarily for changing passwords */
function Check2Fields(tField1, tField2, tName){
	if(tField1.value!=tField2.value){alert("Please make sure the \""+tName+"\" fields match each other.");tField2.focus();return(false);}
	else{return(true);}
}
/** Check if one of two dropdown fields have been selected. Required Parameters: tFields - valid fields on the form, tName - the description of the fields */
function CheckEmptyTwo(tField,tField1,tName){
	if((tField.value=="")&&(tField1.value=="")){alert("At lease one of the \""+tName+"\" fields needs to be filled.");tField.focus();return (false);}
	else
		return (true);
}
/* Check field for special characters */
function CheckSpecial (tField, tName){
	var checkOK="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@-_,.' &//()";
	var checkStr=tField.value;
	var allValid=true;
	var allNum="";
	var numalerttext="Special characters are not allowed in the \""+tName+"\" field.";
	for (i=0; i < checkStr.length; i++)
	{
		ch=checkStr.charAt(i);
		for (j=0; j < checkOK.length; j++)
			if(ch==checkOK.charAt(j))
				break;
		if(j==checkOK.length){allValid=false;break;}
		if(ch!=",")
			allNum += ch;
	}
	if(!allValid){alert(numalerttext);tField.focus();return(false);}
	else{return(true);}
}
/* Check field for quotes */
function CheckQuotes (tField, tName){
	var checkStr=tField.value;
	var allValid=true;
	for (i=0;i<checkStr.length;i++){ch=checkStr.charAt(i);if(ch=='"'){allValid=false;break;}}
	if(!allValid){alert("Quotes are not allowed in the \""+tName+"\" field.");tField.focus();return (false);}
	else
		return (true);
}
/* Check 3 fields for numeric and lengths of 3, 3 and 4 */ 
function CheckPhone(num1, num2, num3){
	if(!(CheckNumeric(num1,"Phone1",3))||!(CheckNumeric(num2,"Phone2",3))||!(CheckNumeric(num3,"Phone3",3))) return (false);
	else
	{
		if(num1.value.length!=3||num2.value.length!=3||num3.value.length!=4)
		{
			alert("The phone number you entered appears invalid. Please try again.");num1.focus();return (false);
		}
		else
			return (true);
	}
}
/* Make sure field equals exact length specified */
function LengthEquals(tField,length,tName){
	if(!(tField.value.length==parseInt(length,10))){alert("The \""+tName+"\" field must be exactly "+length+" characters long.");tField.focus();return (false);}
	else
		return (true);
}
/* Check if a field is the right length. Required Parameters: tField - a valid form field, size - required size of the field, tName - description of the field */
function MinLength(tField,size,tName){
	if(!(CheckEmpty(tField,tName))) return (false);
	else
	{
		if(tField.value.length < parseInt(size))
		{
			alert("Please enter a value in the \""+tName+"\" field that is at least "+size+" characters.");tField.focus();return (false);
		}
		else
			return (true);
	}
}
/* Validate a credit card number using the Luhn Algorithm */
function CheckCC(tField){
	if(!(MinLength(tField,15,"Credit Card Number"))) return (false);
	else if(!(CheckNumeric(tField,"Credit Card Number",7))) return (false);
	else{
		var sCardNumber = tField.value;
		var bDoubleDigit = false;
		var iSum=0,iNum;
		for(var i=sCardNumber.length-1;i>=0;i--) {
			iNum=parseInt(sCardNumber.charAt(i));
			if(bDoubleDigit) { iSum+=(iNum>4)?(iNum*2-9):(iNum*2); }
			else { iSum+=iNum; }
			bDoubleDigit=!bDoubleDigit;
		}
		if((iSum%10)==0) return(true);
		else{
			alert("This credit card number does not appear to be valid.\nPlease check it again and/or call 1-800-445-3913 for assistance");
			tField.focus();return(false);
		}
	}
}
/* Check if a field is the right length. Required Parameters: tField - a valid form field, size - the required size, tName - the description of the field. */
function MaxLength(tField,size,tName){
	if(tField.value.length>parseInt(size,10)){alert("Please enter a value in the \""+tName+"\" field that is less than "+size+" characters.");tField.focus();return (false);}
	else{return (true);}
}
/* Check if a field value is higher than required minimum. Required Parameters:tField - a valid field, minval - minimum value, tName - description of field */
function MinValue(tField,minval,tName){
	if(parseInt(tField.value,10)<parseInt(minval,10)){alert("The \""+tName+"\" field must not be less than "+minval+".");tField.focus;return(false);}
	else{return (true);}
}
/* Check if a field value is lower than required maximum. Required Parameters: tField - a valid field, maxval - maximum value, tName - description of the field */
function MaxValue(tField,maxval,tName){
	if(parseInt(tField.value,10)>parseInt(maxval,10)){alert("The \""+tName+"\" field must be less than "+maxval+".");tField.focus;return(false);}
	else{return (true);}
}
/* Check if one of two dropdown fields have been selected. Required Parameters: tField,tField1 - valid dropdown form fields, tName - description of fields */
function CheckEitherDDSelected(tField,tField1,tName){
	if((tField.selectedIndex==0)&&(tField1.selectedIndex==0)){alert("Please make a selection in the \""+tName+"\" field.");tField.focus();return(false);}
	else{return (true);}
}
/* Check for empty, numeric, 5 or 10 digits, make sure a '-' is included in 10 digit zip */
function ZipCheck(zip){
	if(!(CheckNumeric(zip,"Zip Code",2))) return(false);
	if(zip.value.length!=5&&zip.value.length!=10){alert("Please enter the Zip Code as either a 5 or 10 position value.");zip.focus();return (false);}
	if(zip.value.length>5&&zip.value.charAt(5)!="-"){alert("When using a Zip+4 zipcode, the 6th character must be \"-\".");zip.focus();return (false);}
	return (true);
}
/* Checks 2 digit state field against a verified list of options - does nothing if field is empty! */
function StateCheck(state){
	statearray=new Array(55);
	statearray[0]="PR";
	statearray[1]="AK";
	statearray[2]="AL";
	statearray[3]="AR";
	statearray[4]="AZ";
	statearray[5]="CA";
	statearray[6]="CO";
	statearray[7]="CT";
	statearray[8]="DC";
	statearray[9]="DE";
	statearray[10]="FL";
	statearray[11]="GA";
	statearray[12]="HI";
	statearray[13]="IA";
	statearray[14]="ID";
	statearray[15]="IL";
	statearray[16]="IN";
	statearray[17]="KS";
	statearray[18]="KY";
	statearray[19]="LA";
	statearray[20]="MA";
	statearray[21]="MD";
	statearray[22]="ME";
	statearray[23]="MI";
	statearray[24]="MN";
	statearray[25]="MO";
	statearray[26]="MS";
	statearray[27]="MT";
	statearray[28]="NC";
	statearray[29]="ND";
	statearray[30]="NE";
	statearray[31]="NH";
	statearray[32]="NJ";
	statearray[33]="NM";
	statearray[34]="NV";
	statearray[35]="NY";
	statearray[36]="OH";
	statearray[37]="OK";
	statearray[38]="OR";
	statearray[39]="PA";
	statearray[40]="RI";
	statearray[41]="SC";
	statearray[42]="SD";
	statearray[43]="TN";
	statearray[44]="TX";
	statearray[45]="UT";
	statearray[46]="VA";
	statearray[47]="VT";
	statearray[48]="WA";
	statearray[49]="WI";
	statearray[50]="WV";
	statearray[51]="WY";
	statearray[52]="--"
	statearray[53]="AE";
	statearray[54]="AA";
	statearray[55]="AP";
	if(state.value!="")	{
		var stateValid=false;
		var statestring=state.value;
		for(i=0;i<55;i++){
			if(statearray[i]==statestring.toUpperCase()){ 
				if(i<53){stateValid=true;break;} 
				else{
					ArmedCheck=window.confirm("Your entry in the \"State\" field is an Armed Forces designation. Click \"OK\" if that is correct.");
					if(ArmedCheck==false){stateValid=true;state.focus();return (false);break;}
					else{stateValid=true;return (true);break;}
				}
			}
		}
		if(!stateValid){alert("The state abbreviation you entered is not valid. Please re-enter.");state.focus();return (false);}
	}
	return(true)
}
function ValidDecimal(num,tName){
	if(num.value!=""){
		var Pay=parseFloat(num.value);		
		var pennies=Pay*100; 
		pennies=Math.round(pennies); 
		var strValidPay=new String (pennies);
		var len=strValidPay.length;
		num.value=strValidPay.substring(0,len-2)+"."+strValidPay.substring(len - 2, len);
		if(num.value!=strValidPay.substring(0,len-2)+"."+strValidPay.substring(len - 2, len)){
			alert("Please only have 2 numbers after the decimal point in the \""+tName+"\" field.");num.focus();return (false);
		}
		return(true);
	}
	return(true);
}
function BothRequired(field1,text1,field2,text2)
/* Use this function when 2 fields are required if either is used */
{
	if((field1.value==""&&field2.value!="")||(field1.value!=""&&field2.value=="")){
		alert("The \""+text1+"\" field and the \""+text2+"\" field are BOTH required if using either.");field2.focus();return (false);
	}
	return(true);
 }
function ThisBiggerThanThat(bignum,bigtext,littlenum,littletext)
/* Use this function when one field must have a smaller number than another */
{
	var prsMax=bignum.value;
	var prsMin=littlenum.value;
	while(prsMax.charAt(0)=="0"){prsMax=prsMax.substring(1,prsMax.length);bignum.value=prsMax}
	while(prsMin.charAt(0)=="0"){prsMin=prsMin.substring(1,prsMin.length);littlenum.value=prsMin}
	if(parseInt(prsMin)>parseInt(prsMax)){alert("The \""+bigtext+"\" field must be greater than the \""+littletext+"\" field.");bignum.focus();return (false);}
	return(true);
}
// -->