/*
	www.ppdocs.com 2000
*/


<!-- ************************************************ -->
function FlashItem(oField, errMsg) {
  SetFocus(oField);
	alert(errMsg);
}	

function VState(oField) {
	if(FldHasValue(oField)) {
		var inStr = oField.value;
		switch ( inStr.toUpperCase() ) {
			case "AK": case "AL": case "AR": case "AZ": case "CA": case "CO": case "CT": case "DC": case "DE": case "FM":
			case "FL": case "GA": case "GU": case "HI": case "IA": case "ID": case "IL": case "IN": case "KS": 
			case "KY": case "LA": case "MA": case "MD": case "ME": case "MH": case "MI": case "MN": case "MO": case "MS": 
			case "MT": case "NC": case "ND": case "MP": case "NE": case "NH": case "NJ": case "NM": case "NV": case "NY":
			case "OH": case "OK": case "OR": case "PW": case "PA": case "PR": case "RI": case "SC": case "SD": case "TN":
			case "TX": case "UT": case "VA": case "VI": case "VT": case "WA": case "WI": case "WV": case "WY":
			case "US": case "AE": case "AA": case "AP":
				oField.value = inStr.toUpperCase();
				return true;
				break;
			default:
				FlashItem (oField, "Please enter a valid state");
				return false;
		}
	}
	else {
		return true;
	}
}
// VState

function VPhone(oField) {
	if(FldHasValue(oField)) {
		var inStr = oField.value;
		inStr = NumOnly(inStr);
		inStr = stripSpaces(inStr);
		if (inStr.length != 10) {
			FlashItem (oField, "Please enter a valid 10-DIGIT phone number in the format (999) 999-9999");
			return false; }
		else {
			PhoneNo1 = inStr.substring(0, 3); // First part of PhoneNo
			PhoneNo2 = inStr.substring(3, 6); // Second part of PhoneNo
			PhoneNo3 = inStr.substring(6, 10); // Third part of PhoneNo
		} // Divide 10 digit into Area Code, Prefix and Suffix
		oField.value = "(" + PhoneNo1 + ") " + PhoneNo2 + "-" + PhoneNo3;
		return true;
	}
	else {
		return true;
	}
}

function VZip(oField) {
	if(FldHasValue(oField)) {
		inStr = oField.value;
		inLen = inStr.length;
		Msg = "Please enter a 5 digit zip in format NNNNN or 9 Digit, NNNNN-NNNN";

		if ((inLen != 5) && (inLen != 9) && (inLen != 10)) {
			FlashItem(oField, Msg);
			return false;
		}
		
		if (inLen == 5) {
		 	if (!ChkNumeric2( oField )) {
				FlashItem(oField, Msg);
				return false; 
			}
			else {
				return true;
			}
		}
			
		var dash = inStr.indexOf("-", 0);
		if (dash == -1)  {	//no dash in zip
			if(inLen == 10)	{ //10 digits
				FlashItem(oField, Msg);
				return false; 
			}
			inStr = stripSpaces(inStr);
			FirstFive = inStr.substring(0, 5) // first 5 digits of zip code
			LastFour = inStr.substring(5, inStr.length) // last 4 digits of zip code
			for(var i=0; i < inLen; i++) {
				var ch = inStr.substring(i,i+1)
				if (ch < "0" || ch > "9") {
					FlashItem(oField, Msg);
					return false;
				}
			}
			oField.value = FirstFive + "-" + LastFour;
			return true;			
		}
		if (dash != 5) {
			FlashItem(oField, Msg);
			return false;
		}
		
		//otherwise validate in 99999-9999 format
		for(var i=0; i < inLen; i++) {
			var ch = inStr.substring(i,i+1)
			if (ch < "0" || ch > "9") {
				if (ch != "-") {
					FlashItem(oField, Msg);
					return false;
				}
			}
		}
	}
	else {
		return true;
	}

}	//VZip

function VEmail(oField) {
	//** Requires stripSpaces function **//
	if(FldHasValue( oField ))	{
		var inStr = oField.value;

		inStr = stripSpaces(inStr);
		if ( inStr.length == 0 ) return false;
		//Slash1 = inStr.indexOf("@");
		var AtSign = inStr.indexOf("@");
		if ( AtSign < 1 )	{
			FlashItem(oField, "Please enter a valid Email address");
			return false; 
		}
		var Period2 = inStr.indexOf(".", AtSign+1);
		var inStrlength = inStr.length
		if (Period2 < AtSign+2 || inStr.length - 2 <= Period2) {
			FlashItem(oField, "Please enter a valid Email address");
			return false;
		}
		return true;
	}
	else {
		return true;
	}
}
// VEmail


function VNum( oField ) {
	var ValueSent = oField.value;
	var ch;
	for (var i = 0; i < ValueSent.length; ++i) {
		ch = ValueSent.substring(i,i + 1);
		if (ch < "0" || "9" < ch) {
			FlashItem(oField, "Please enter a valid number, decimals and other punctuation are not allowed");
			return false;
		}
	}
	return true;
}



function NumOnly( oField ) {
// by Brett W for PPDocs.com, 02 Aug 2000
	var ValueSent = oField;
	var Vlen = oField.length
	x = "";
	for (var i = 0; i < Vlen; ++i) {
		var ch = ValueSent.substring(i,i + 1);
		if ("0" <= ch && ch <= "9") x = x + ch
	}
	return x;
}// NumOnly

function ChkNumeric2( oField ) {
	var ValueSent = oField;
	for (var i = 0; i < oField.length; ++i) {
		var ch = ValueSent.substring(i,i + 1);
		if (ch < "0" || "9" < ch) return false;
	}
	return true;
}// ChkNumeric2

function SetFocus( oField ) {
	try {	
		oField.focus();
		oField.select();
	}
	catch(e) {}
}// SetFocus

function FldHasValue( oField ) {
	if ((oField.value == "") || (oField.value == "undefined" )) return false;
	else return true;
}	//FldHasValue

function stripSpaces(stg) {
	//** Trim leading and trailing spaces off string value **
	x = stg + "";
	while (x.substring(0,1) == ' ') x = x.substring(1);
	while (x.substring(x.length-1,x.length) == ' ') x = x.substring(0,x.length-1);
	return x;
}//stripSpaces

function outputComma(number) {
	//** accounts for Negative values **
	var neg = "";
	number = '' + number
	if (number.charAt(0) == "-"){
		neg = "-";
		number = number.substring(1,number.length)
	}
	if (number.length > 6) {
		var mod = number.length%3;
		var output = (mod > 0 ? (number.substring(0,mod)) : '');
		for (i=0 ; i < Math.floor(number.length/3) ; i++) {
			if (((mod ==0) && (i ==0)) || ( output.length > number.length-3 ))
				output+= number.substring(mod+3*i,mod+3*i+3);
			else 
				output+= ',' + number.substring(mod+3*i,mod+3*i+3); 
		}
		return (neg + output);
	}
	else return neg + number;
}

function stripSpaces(stg) {
	//** Trim leading and trailing spaces off string value **
	x = stg + "";
	while (x.substring(0,1) == ' ') x = x.substring(1);
	while (x.substring(x.length-1,x.length) == ' ') x = x.substring(0,x.length-1);
	return x;
}

function stripDblSpaces(stg) {
	//** replate double spaces with a single **
	var x = stg + "";
	while (x.indexOf('  ') != -1) x = x.replace('  ',' ');
	return x;
}//stripDblSpaces

function stripCommas(ValueSent) {
	// ** Clean , and $ sign from number/string values **
	var Vlen = ValueSent.length;
	var ch;
	var nval = "";
	for (var i = 0; i < Vlen; ++i) {
		ch = ValueSent.substring(i,i + 1);
		if(ch != "," && ch != "$")
			nval = nval + ch;
	}
	return nval;
}

function formatCent(amount) {
	amount -= 0;
	return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function VCurr( oField ) {
	if(FldHasValue( oField )) {
		var ValueSent = oField.value;
		var RevisedValue = "";
		var ch = "";
		//strip out dollar signs and commas
		for (var i = 0; i < ValueSent.length; ++i) {
			ch = ValueSent.charAt(i);
			if ((ch != ",") && (ch != "$") )
				RevisedValue = RevisedValue + ch;
		}
		//check for more than one decimal point
		var FieldLength = RevisedValue.length;
		var DecimalPt = RevisedValue.indexOf(".", 0);
		if (DecimalPt != -1) {
			if (DecimalPt < FieldLength - 3) {
				FlashItem (oField, "Please enter a valid monetary amount");
				return false; 
			}
			var DecimalPt2 = RevisedValue.indexOf(".", DecimalPt + 1);
			if (DecimalPt2 != -1) {
				currencyError = true;
				FlashItem (oField, "Please enter a valid monetary amount");
				return false; 
			}
		}
		for (var i = 0; i < RevisedValue.length; ++i) {
			ch = RevisedValue.charAt(i);
			if ((ch < "0" || "9" < ch) && ch != '.' && ch != '$') {
				FlashItem (oField, "Please enter a valid monetary amount");
				return false; 
			}
		}
		oField.value = outputComma(formatCent(RevisedValue));
		return true;
	}
	else {
		return true;
	}
} // VCurr

function VCurr2( oField ) {
	if(FldHasValue( oField )) {
		var ValueSent = oField.value;
		var RevisedValue = "";
		var ch = "";
		var IsNeg = ValueSent.charAt(0) == "-"
		//strip out dollar signs and commas
		for (var i = 0; i < ValueSent.length; ++i) {
			ch = ValueSent.charAt(i);
			if ((ch != ",") && (ch != "$") && (ch != "-") )
				RevisedValue = RevisedValue + ch;
		}
		//check for more than one decimal point
		var FieldLength = RevisedValue.length;
		var DecimalPt = RevisedValue.indexOf(".", 0);
		if (DecimalPt != -1) {
			if (DecimalPt < FieldLength - 3) {
				FlashItem (oField, "Please enter a valid monetary amount");
				return false; 
			}
			var DecimalPt2 = RevisedValue.indexOf(".", DecimalPt + 1);
			if (DecimalPt2 != -1) {
				currencyError = true;
				FlashItem (oField, "Please enter a valid monetary amount");
				return false; 
			}
		}
		for (var i = 0; i < RevisedValue.length; ++i) {
			ch = RevisedValue.charAt(i);
			if ((ch < "0" || "9" < ch) && ch != '.' && ch != '$') {
				FlashItem (oField, "Please enter a valid monetary amount");
				return false; 
			}
		}
		
		if (IsNeg)
  		oField.value = "-" + outputComma(formatCent(RevisedValue));
		else
  		oField.value = outputComma(formatCent(RevisedValue));
		return true;
	}
	else {
		return true;
	}
} // VCurr

function VDate( oField ) {
	//** Requires stripSpaces function **//
	if(FldHasValue( oField )) {
		var inStr = oField.value;
		var myinStr = "";
		var TodaysDate = new Date();
		inStr = stripSpaces(inStr);
		if ( inStr.length == 0 ) return false;
		if (inStr.length > 10 || inStr.length < 6) {
			FlashItem (oField, "Please enter a valid date in the format MM/DD/YYYY");
			return false; }
		var Slash0 = inStr.indexOf("/");
		if (Slash0 == -1) {
			myinStr = inStr.substring(0,2) + "/" + inStr.substring(2,4) + "/" + inStr.substring(4, inStr.length);
			inStr = myinStr; }
		var Slash1 = inStr.indexOf("/");
		if (Slash1 < 1 || Slash1 > 2) {
			FlashItem (oField, "The date must be entered in the format MM/DD/YYYY");
			return false; }
		var Slash2 = inStr.indexOf("/", Slash1+1);
		if (Slash2 < 3 || Slash2 > 5) {
			FlashItem (oField, "The date must be entered in the format MM/DD/YYYY");
			return false; }
		Month = inStr.substring(0, Slash1) // month
		Day = inStr.substring(Slash1 + 1, Slash2) // day
		Year = inStr.substring(Slash2 + 1, inStr.length) // year
		var YLen = Year.length;

		if (!ChkNumeric2(Month) || !ChkNumeric2(Year) || !ChkNumeric2(Day) || 
		   (Year > 2100) || (Month < 1) || (Month > 12) || (Day < 1) || (Day > 31)) {
			FlashItem (oField, "Please enter a valid date in the format MM/DD/YYYY");
			return false 
		}
		if (YLen == 2) {
			if (Year < 0 || Year > 99) {
				FlashItem (oField, "Please enter a valid value for the year in the format MM/DD/YYYY");
				return false;
			}
			if (Year > 75 && Year < 100) Year = "19" + Year;
			else Year = "20" + Year;
			if (Day.length < 2) Day = "0" + Day;
			if (Month.length < 2) Month = "0" + Month;
			oField.value = Month + "/" + Day + "/" + Year;
		}
		else {
			if (YLen != 4 || (!ChkNumeric2(Year))) {
				FlashItem (oField, "Please enter a valid value for the year in the format MM/DD/YYYY");
				return false; }
			if (Year < 1880) {
				FlashItem (oField, "Please Enter a valid year in in the format MM/DD/YYYY");
				return false }
		}
		if (Month == 4 || Month == 6 || Month == 9 || Month == 11) {
			if (Day == 31) {
				FlashItem (oField, "Please enter a valid value for the day - Month selected has 30 days or less");
				return false; 
			}
		}
		if (Month == 2){
			var g=parseInt(Year/4)
			if (isNaN(g)) {
				FlashItem (oField, "Please enter a valid value for the date");
				return false; 
			}
			if (Day > 29) {
				FlashItem (oField, "Please enter a valid value for the date");
				return false; 
			}
			if (Day == 29 && ((Year/4)!=parseInt(Year/4))) {
				FlashItem (oField, "Please enter a valid value for the date");
				return false; 
			}
		}
		if (Day.length < 2) Day = "0" + Day;
		if (Month.length < 2) Month = "0" + Month;
		oField.value = Month + "/" + Day + "/" + Year;
		return true;
	}
	else {
		return true;
	}
} // VDate

function VYear(oField) {
	//** Requires stripSpaces function **//
	if(FldHasValue( oField )) {
		var inStr = oField.value + "";
		var Slash1;
		var Slash2;
		var TodaysDate = new Date();
		inStr = stripSpaces(inStr);
		if ( inStr.length == 0 )
			return false;
		if (inStr.length > 4 || inStr.length < 2) {
			FlashItem (oField, "Please enter a valid year in the format YYYY");
			return false;
		}
		Year = oField.value // year
		var YLen = Year.length;
		if(!ChkNumeric2(Year)) {
			FlashItem (oField, "Please Enter a valid year in in the format YYYY");
			return false
		}
		if (Year > 2100) {
			FlashItem (oField, "Please Enter a valid year in in the format YYYY");
			return false
		}
		if (YLen == 2) {
			if (Year < 0 || Year > 99) {
				FlashItem (oField, "Please enter a valid value for the year in the format YYYY");
				return false;
			}
			if (Year > 75 && Year < 100)
				Year = "19" + Year;
			else
				Year = "20" + Year;
			oField.value = Year;
		}
		else {
			if (YLen != 4 || (!ChkNumeric2(Year))) {
				FlashItem (oField, "Please enter a valid value for the year in the format YYYY");
				return false; }
			if (Year < 1880) {
				FlashItem (oField, "Please Enter a valid year in in the format YYYY");
				return false
			}
		}
		oField.value = Year;
		return true;
	}
	else {
		return true;
	}
} // VYear


function VMERSMin(oField) {
//** Requires stripSpaces function **//
	if(FldHasValue( oField )) {
		var inStr = oField.value + "";
		var Slash1;
		var Slash2;
		inStr = stripSpaces(inStr);
		if (inStr.length > 20 || inStr.length < 18) {
			FlashItem (oField, "Please enter a valid MERS Number in the format 9999999-9999999999-9");
			return false;
		}
//** MERSMin field is too little or too many characters and/or not in the proper format
		if (inStr.length = 18) Slash1 = 7;
		else Slash1 = inStr.indexOf("-");
		//Location of first SLASH(-)
		if (Slash1 !== 7) {
			FlashItem (oField, "The MERS Number must be entered in the format 9999999-9999999999-9");
			return false;
		}
		//** The first hyphen is not in the proper place
		if (inStr.length = 18) Slash2 = 18;
		else Slash2 = inStr.indexOf("-", Slash1+1);
		//Location of second SLASH(-)
		if (Slash2 !== 18) {
			FlashItem (oField, "The MERS Number must be entered in the format 9999999-9999999999-9");
			return false;
		}
		//** The second hyphen is not in the proper place
		if (inStr.length == 18) {
			MERSMin1 = inStr.substring(0, 7); // First part of MERSMin
			MERSMin2 = inStr.substring(7, 17); // Second part of MERSMin
			MERSMin3 = inStr.substring(17, 18); // Third part of MERSMin
		} // Set variable if MERSMin is only digits and no hyphens
		else {
			MERSMin1 = inStr.substring(0, Slash1); // First part of MERSMin
			MERSMin2 = inStr.substring(Slash1 + 1, Slash2); // Second part of MERSMin
			MERSMin3 = inStr.substring(Slash2 + 1, inStr.length); // Third part of MERSMin
		} // Set variables if MERSMin includes hyphens
		if(!ChkNumeric2(MERSMin1)) {
			FlashItem (oField, "Please enter a valid MERS Number in the format 9999999-9999999999-9");
			return false;
		}
		if(!ChkNumeric2(MERSMin2)) {
			FlashItem (oField, "Please enter a valid MERS Number in the format 9999999-9999999999-9");
			return false;
		}
		if(!ChkNumeric2(MERSMin3)) {
			FlashItem (oField, "Please enter a valid MERS Number in the format 9999999-9999999999-9");
			return false;
		}
		oField.value = MERSMin1 + "-" + MERSMin2 + "-" + MERSMin3;
		return true;
	}
	else {
		return true;
	}
}
// VMERSMin

function VPC(oField) {
	if(FldHasValue( oField )) {	
		var instr = oField.value;
		var instrlen = instr.length;
		var ch = "";
		var newValue = "";
		var p = 0;
		//strip out percent sign
		for (var x=0; x<instrlen; x++){
			ch = instr.substring(x,x+1);
			if (ch != "%") newValue += ch;
			else ++p;
		}
		instrlen -= p;
		//check for more than one decimal point
		var DecimalPt = newValue.indexOf(".", 0);
		var DecimalPt2 = newValue.indexOf(".", DecimalPt + 1);
		if (DecimalPt2 != -1){
			FlashItem(oField, "Please Enter A Numeric Value (1.234)");
			return false;
		}
		instrlen = newValue.length;
		for (var i = 0; i < instrlen ; ++i) {
			var ch = newValue.substring(i,i + 1);
			if ((ch < "0" || "9" < ch) && ch != '.') {
				FlashItem(oField, "Please Enter A Numeric Value (1.234)");
				return false;
			}
		}
		// no more than 3 decimal places
		var places = newValue.substring(DecimalPt+1);
		if ( places.length > 3 ){
			FlashItem(oField, "No more than 3 decimal places are required. (1.234)");
			return false;
		}
		// returns the X.999 format
		newValue -= 0;
		if (newValue == Math.floor(newValue)) newValue += ".000";
		else if (newValue*10 == Math.floor(newValue*10)) newValue += "00";
		else if (newValue*100 == Math.floor(newValue*100)) newValue += "0";
		oField.value = newValue;
		return true;
	}
	else {
		return true;
	}
}

function VCase( oField ) {
		return true;
} // VCase

function VReq( oField ) {
	if (FldHasValue(oField)) {
		return true;
	}
}


