var digits = "0123456789";

var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"

var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

var whitespace = " \t\n\r";

var validDateChars = digits + "/"

var validSSNChars = digits + "-"

var validMoneyChars = digits + "."

var illegalChars = "/\:\"?*<>'|"


function alertCharsInBag (objField, bag) {   
		var i;
    var returnString = "";
    var bAlert = false;
    var s = objField.value;

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) {
        	bAlert = true;
        }
    }

    if (bAlert) {
    	alert("You cannot use the following characters: " + bag);
    	objField.focus();
    	return(false);
    } else {
    	return(true);
    }
}

function formatAlphaChars(objField){
	
	var strValue = objField.value;
	strValue = stripCharsNotInBag (strValue, lowercaseLetters + uppercaseLetters + whitespace);
	objField.value = strValue;
}

function formatNumeric(objField){
	
	var strValue = objField.value;
	strValue = stripCharsNotInBag (strValue, digits);
	objField.value = strValue;
}

function formatMoney(objMoneyField){
	var intLength;
	var i = 1;
	var strMoney = objMoneyField.value;
	strMoney = stripCharsNotInBag (strMoney, validMoneyChars);
	intLength = strMoney.length;
	strMoney = strMoney.substr(0, 20)
	if (intLength > 0){
		while (i < intLength && strMoney.charAt(i) != "."){
			i++;
		}
		
		if ((intLength - i) > 2 ){
			strMoney = strMoney.substr(0, i+3)
		}
		
		if ((intLength - i) == 2){
			strMoney = strMoney + "0";
		}
		
		if ((strMoney.charAt(i) == ".") && ((intLength - i) == 1)){
			strMoney = strMoney + "00";
		}
		
		if (strMoney.charAt(i) != "."){
			strMoney = strMoney + ".00";
		}
					
	}
	
	objMoneyField.value = strMoney;
	
}


function formatSSN(objSSNField){
	
	var strSSNNum = objSSNField.value;
	
	strSSNNum = stripCharsNotInBag (strSSNNum, digits);
	strSSNNum = strSSNNum.substr(0, 9)
	if (strSSNNum.length > 0){
		strSSNNum = reformat(strSSNNum, "", 3, "-", 2, "-", 5);
	}
	
	objSSNField.value = strSSNNum;
}

function formatZipCode(objZipField){
	
	var strZip = objZipField.value;
	strZip = stripCharsNotInBag (strZip, digits);
	strZip = strZip.substr(0, 9)
	if (strZip.length > 0 && strZip.length > 5){
		strZip = reformat(strZip, "", 5, "-", 4);
	}
			
	objZipField.value = strZip;
}


function formatDate(objDateField){

	var strDate = objDateField.value;
	strDate = stripCharsNotInBag (strDate, digits);
	strDate = strDate.substr(0, 8)
	if (strDate.length > 0){
		strDate = reformat(strDate, "", 2, "/", 2, "/", 4);
	}
	
	objDateField.value = strDate;
}

function formatPhone(objPhoneField){

	
	var strPhone = objPhoneField.value;
	if (!isEmpty(strPhone)){
		strPhone = stripCharsNotInBag (strPhone, digits);
		strPhone = strPhone.substr(0,10)
		if (strPhone.length > 0){
			strPhone = reformat(strPhone, "(", 3, ") ", 3, "-", 4);
		}

		objPhoneField.value = strPhone;
	}
}

function formatCCDate(objDateField){

	var strDate = objDateField.value;
	strDate = stripCharsNotInBag (strDate, digits);
	strDate = strDate.substr(0, 7)
	if (strDate.length > 0){
		strDate = reformat(strDate, "", 2, "/", 4);
	}
	
	objDateField.value = strDate;

}

function checkRequiredOption(objField, strName){
	if (objField.selectedIndex == 0){
		alert( strName + " does not have a valid selection. Please select an option from the list below");
		objField.focus();
		return (false);
	}
	else{
		return (true);
	}
	
}

function checkCCDate(objField, strName, intMaxLength, bRequired){

	var strValue = objField.value;
	
	if (isEmpty(strValue)){
		if (bRequired){
			alert (strName + " is required. You must fill this in before you can continue");
			objField.focus();
			return (false);
		}
		else{
			return (true);
		}
	
	}
	else{
		strValue = stripCharsNotInBag(strValue, digits);
		if (strValue.length != 6){
			alert( strName + " is not a valid date. Please use mm/yyyy or just type in all the numbers");
			objField.focus();
			return (false);
		}
		else{
			formatCCDate(objField);
			return (true);
		}
	}	
}



function checkField(objField, strName, intMaxLength, bRequired){

	var strValue = trim(objField.value);
	
	if (strValue.length > intMaxLength){
		alert("The text for " + strName + " is to long. Only " + intMaxLength + " characters are allowed");
		objField.focus();
		return(false);
	}
	
	if (isEmpty(strValue) && bRequired){
		alert(strName + " is required. Please fill this in before you continue.");
		objField.focus();
		return(false);
	}

	
	return(true);
} 

function checkNumeric(objField, strName, intMaxLength, intMinLength, bRequired){
	
	var strValue = objField.value;	
	
	if (strValue.length > 0 && (strValue.length > intMaxLength || strValue.length < intMinLength)){
		if (intMaxLength == intMinLength){
			alert(strName + " must be " + intMaxLength + " digits long.");
		}
		else {
			alert(strName + " must be between " + intMinLength + " and " + intMaxLength + " digits long.");
		}
		objField.focus();
		return(false);
	}
	
	if (isEmpty(strValue) && bRequired){
		alert(strName + " is required. Please fill this in before you continue.");
		objField.focus();
		return(false);
	}
	
	formatNumeric(objField);
	return(true);
} 

function checkEmail(objField, strName, intMaxLength, bRequired){

	var strValue;
	var intLength;
	strValue = objField.value;
	intLength = strValue.length
	var i = 1;
	
	if (isEmpty(strValue)){
		if (bRequired){
			alert (strName + " is required. You must fill this in before you can continue");
			objField.focus();
			return (false);
		}
		else{
			return (true);
		}
		
	}

	else{
		
		
		
		while((i < intLength) && (strValue.charAt(i) != "@")){
			i++
		}
		
		if ((i >=intLength) || (strValue.charAt(i) !="@")){
			alert("This email is not valid please use the format 'userid@domain.com'");
			objField.focus();
			return(false);
		}
		
		while((i < intLength) && (strValue.charAt(i) !=".")){
			i++;
		}
		
		if ((i >= intLength - 1) || (strValue.charAt(i) !=".")){
			alert("This email is not valid please use the format 'userid@domain.com'");
			objField.focus();
			return(false);
		}
			
	}
}

function checkPhone(objField, strName, intMaxLength, bRequired){

	var strValue = objField.value;
	
	if (isEmpty(strValue)){
		if (bRequired){
			alert (strName + " is required. You must fill this in before you can continue");
			objField.focus();
			return (false);
		}
		else{
			return (true);
		}
	
	}
	else{
		strValue = stripCharsNotInBag(strValue, digits);
		if (strValue.length != 10){
			alert( strName + " is not a valid phone number. Pease use (888) 555-5555 or just type in all the numbers");
			objField.focus();
			return (false);
		}
		else{
			formatPhone(objField);
			return (true);
		}
	}	
}

function checkZipCode(objField, strName, intMaxLength, bRequired){

	var strValue = objField.value;
	
	if (isEmpty(strValue)){
		if (bRequired){
			alert (strName + " is required. You must fill this in before you can continue");
			objField.focus();
			return (false);
		}
		else{
			return (true);
		}
	
	}
	else{
		strValue = stripCharsNotInBag(strValue, digits);
		if (strValue.length != 9 && strValue.length != 5){
			alert( strName + " is not a valid Zip Code. Pease use xxxxx-xxxx or just type in all the numbers");
			objField.focus();
			return (false);
		}
		else{
			formatZipCode(objField);
			return (true);
		}
	}	
}

function checkDate(objField, strName, intMaxLength, bRequired){

	var strValue = objField.value;
	
	if (isEmpty(strValue)){
		if (bRequired){
			alert (strName + " is required. You must fill this in before you can continue");
			objField.focus();
			return (false);
		}
		else{
			return (true);
		}
	
	}
	else{
		strValue = stripCharsNotInBag(strValue, digits);
		if (strValue.length != 8){
			alert( strName + " is not a valid date. Pease use mm/dd/yyyy or just type in all the numbers");
			objField.focus();
			return (false);
		}
		else{
			formatDate(objField);
			return (true);
		}
	}	
}

function checkSSN(objField, strName, intMaxLength, bRequired){

	var strValue = objField.value;
	
	if (isEmpty(strValue)){
		if (bRequired){
			alert (strName + " is required. You must fill this in before you can continue");
			objField.focus();
			return (false);
		}
		else{
			return (true);
		}
	
	}
	else{
		strValue = stripCharsNotInBag(strValue, digits);
		if (strValue.length != 9){
			alert( strName + " is not a valid social security number. Please input like xxx-xxx-xxxx or just type in all the numbers");
			objField.focus();
			return (false);
		}
		else{
			formatSSN(objField);
			return (true);
		}
	}	

}

function checkMoney(objField, strName, intMaxLength, bRequired){

	var strValue = objField.value;
	
	if (isEmpty(strValue)){
		if (bRequired){
			alert (strName + " is required. You must fill this in before you can continue");
			objField.focus();
			return (false);
		}
		else{
			return (true);
		}
	}
	else{
		formatMoney(objField);
		return (true);
	}	
}

function isCheckboxChecked(objChkbx){	
	
	if (objChkbx.checked == true){
		return (true);
		}
	else{
		return (false);
	}
	
}


function isCheckboxSelected(objChkbx, strName){	
	
	if (objChkbx.checked == true){
		return (true);
		}
	else{
		alert (strName + " is required. You must check this in order to submit the form.");
		objChkbx.focus();
		return (false);
	}
	
}


function isRadioChecked(objRadioBoxes, strName, numOfBoxes){
	var i;
	
	for (i=0; i < numOfBoxes; i++){

		if (objRadioBoxes[i].checked == true){
			return (true);
		}		
	}

	alert (strName + " option is required. You must select one of these options before you continue.");
	objRadioBoxes[0].focus();	
	return (false);
}

function checkOption (objOption){
	
	objOption.checked = true;
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}



function stripCharsNotInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }
	
    return returnString;
}


function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}





function reformat (s)

{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}



function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace)
}

function stripInitialWhitespace (s)

{   var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    
    return s.substring (i, s.length);
}



function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}



// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


/*---------------------------------------------
New functions added by js
---------------------------------------------*/
function trim(pString) {
 var value = pString;

	// trim off spaces at end by decreasing string by one every time a space is detected
	while (value.charAt(value.length-1) == " "){value = value.substring(0,value.length-1);}

	// trim off spaces at beginning by decreasing string by one every time a space is detected
	while(value.substring(0,1) ==" "){value = value.substring(1,value.length);} return value;

}




// function that make sure P.O. Box not allowed
function checkPO(pAddress) {
	// alert("I am here");
	var vAddress = pAddress.value;
	vAddress = trim(vAddress);

	// search either for variations of string at beginning of trimmed string or for
	// an exact match of P.O. Box within the string
	if ((vAddress.search(/P.?\s?O.?\s*Box/i)>-1)) {			
		alert("P.O. Boxes are not valid addresses for this field.");
		pAddress.value = "";
		pAddress.focus();
		return(false);
		// || (vAddress.search(/P.O.\sBox/i)>-1)) 
	} else {
		return(true);
	}
}


// function that compares two separate fields to see if they have the same value

function compareFields(pBase, pCompare) {
var vBase, vCompare
vBase = pBase.value;
vCompare = pCompare.value;

	if (vBase == vCompare) {
		alert("If the Home and Mailing Address are identical then there is no need to fill out the Mailing address section.");
		pCompare.value = "";
		document.AcctInfo.MailingCity.value = "";
		document.AcctInfo.MailingState.value = "";
		document.AcctInfo.MailingZip.value = "";
		pCompare.focus();
		return(false);
	} else {
		return(true);
	}
}

function compareSSNEIN(pBase, pCompare) {
var vBase, vCompare
vBase = pBase.value;
vBase = stripCharsInBag (vBase, "-")	
vCompare = pCompare.value;

	// alert (vBase +  " " + vCompare);
	if (vBase == vCompare) {
		alert("The Social Security and EIN number cannot be identical.");
		pCompare.value = "";
		pCompare.focus();
		return(false);
	} else {
		return(true);
	}
}



// checking for bogus sequence of numbers in a particular field
function checkSequence(pField, bRequired) {

var bBogus, vCharacters, vSSNvalue;

vSSNvalue = pField.value;
	
	
	bBogus = false;
	
	// check the obvious
	if (vSSNvalue == "123456789" || vSSNvalue == "123-45-6789" || vSSNvalue == "1234567890") {
		bBogus = true;
	} else {

		// check for dash characters
		var iLetterCount, sPrevLetter, sCurrLetter 

		iLetterCount = 0;
		sPrevLetter = "";

		// take out dashes for easier processing
		vCharacters = stripCharsInBag (vSSNvalue, "-")
		// alert(vCharacters);

		// check for repetitive sequence like 444444444
		if (bRequired) {
			if (vCharacters.length >= 9) {
				
				for (var i =0; i < vCharacters.length; i++) {
					sCurrLetter = vCharacters.charAt(i);
					if (sCurrLetter == sPrevLetter) {
						iLetterCount = iLetterCount + 1;
					}
					sPrevLetter = sCurrLetter;
				}	

				// alert(iLetterCount);
				// if counter is 8 or more then bogus
				if (iLetterCount >= 8) {
					bBogus = true;
				} else {
					return(true);
				}
			} else {
				bBogus = true;
			}
		} else {
			if (vCharacters != "") {
				if (vCharacters.length >= 9) {
					
					for (var i =0; i < vCharacters.length; i++) {
						sCurrLetter = vCharacters.charAt(i);
						if (sCurrLetter == sPrevLetter) {
							iLetterCount = iLetterCount + 1;
						}
						sPrevLetter = sCurrLetter;
					}	

					// alert(iLetterCount);
					// if counter is 8 or more then bogus
					if (iLetterCount >= 8) {
						bBogus = true;
					} else {
						return(true);
					}
				} else {
					bBogus = true;
				}
			}
		}		
	}

	if (bBogus == true) {
		alert("Please enter a valid Social Security Number.");
		pField.value = "";
		pField.focus();
		return(false);
	} else {
		return(true);
	}
}		


// checks if number in field is greater than number in parameter
function checkValue(objField, strName, intMinLength, bRequired){
	
	var strValue = objField.value;	
	
	if (strValue <= intMinLength) {
			alert(strName + " must be greater than " + intMinLength + ".");
			objField.focus();
			return(false);
	} else {	
		return(true);
	}
} 


function checkExpirationDate(objForm, pType) {
	
	var dExpDate;
	var dToday;
	var sInvalidExpDateAlertMsg;
	var sDate;
	
	sInvalidExpDateAlertMsg = new String("You have entered an expired date.");
	
	
	sDate = objForm.value;
 
	if (pType == "dl" || pType == "pp") {	
		if (parseValidate(objForm)) {
			dExpDate = new Date(sDate); 
			dToday = new Date();
			
			dExpDate.setHours(dToday.getHours() + 1);
			dExpDate.setMinutes(dToday.getMinutes());
			dExpDate.setSeconds(dToday.getSeconds());	
		
			
		
		
			// check if dob is today or in future
			if (dExpDate < dToday) {
				alert(sInvalidExpDateAlertMsg);
				objForm.focus();
				return (false);
			}
	
			return(true);
		} else {
			return(false);
		}
	} else if (pType == "cc") {
		
		var vMonth;
		var vYear;
		var vDay;
		var vDate;
		
		dToday = new Date();
		
		

		vDay = "/" + dToday.getDate() + "/"
		vMonth = "";
		vYear = "";

		sDate = objForm.value;
		
		// trim string
		sDate = trim(sDate);
		
		if (sDate.length == 0) {
			return(true);
		}
		
		// strip off first two digits for month
		for (i = 0; i <= 1; i++) {
			vMonth = vMonth + sDate.charAt(i);

		}
		
		// check if month is incorrect digit
		if (vMonth < 1 || vMonth > 12) {
			alert("The month must be a number from 1 to 12");
			objForm.focus();
			return(false);
		}
			
		// strip off last four digits for year
		for (i = 3; i <= 6; i++) {
			vYear = vYear + sDate.charAt(i);

		}

		
		vDate = vMonth + vDay + vYear
		dExpDate = new Date(vDate); 
		
		// set time to one hour from present time so user can enter current month and year for credit cards
		dExpDate.setHours(dToday.getHours() + 1);
		dExpDate.setMinutes(dToday.getMinutes());
		dExpDate.setSeconds(dToday.getSeconds());	
		
		// alert(dToday.getTime())
		// alert(dExpDate.getTime());
		// alert(dToday.getTime());
	
		// check if dob is today or in future
		if (dExpDate.getTime() < dToday.getTime()) {
			alert(sInvalidExpDateAlertMsg);
			objForm.focus();
			return (false);
		}

		return(true);

	}
}


//validates that the DOB is at least 18 if sType = 'Primary' -- returns true
//always makes sure that age is not in the future -- returns false if it is
function isValidAge(sType, objDOB) {

	var dDOB;
	var dToday;
	var sInvalidDOBAlertMsg;
	var sTooYoungAlertMsg;
	var sPrimary;
	var vType;
	
	sInvalidDOBAlertMsg = new String("You have entered an invalid date that is either today's date or a date in the future.");
	sTooYoungAlertMsg = new String("The age of this account holder is younger than 18 years old. This type of account holder is required to be at least 18 years of age.");
	
	if (parseValidate(objDOB)) {
	
		dDOB = new Date(objDOB.value); 
		dToday = new Date();
		
		sPrimary = "primary";
		
		vType = sType.toLowerCase();
		
		// check if dob is today or in future
		if (dToday <= dDOB) {
			alert(sInvalidDOBAlertMsg);
			objDOB.focus();
			return (false);
		}
		
	
		// alert((dDOB.getMonth() +1) + "/" + dDOB.getDate() + "/" + dDOB.getFullYear());
			
		// check if younger than 18
		// alert (dToday.getMonth() < dDOB.getMonth());
		if ((vType.indexOf(sPrimary) != -1) && (dToday.getFullYear() - dDOB.getFullYear() <= 18)) {
			// check if it year is 18 and check if month of birth date is in future
			if (dToday.getFullYear() - dDOB.getFullYear() == 18) {
				if (dToday.getMonth() < dDOB.getMonth()) {
					alert(sTooYoungAlertMsg);
					objDOB.focus();
					return (false);
				} else {
					// objDOB.value = (dDOB.getMonth() +1) + "/" + dDOB.getDate() + "/" + dDOB.getFullYear();
					return (true);
				}		
			} else {
				alert(sTooYoungAlertMsg);
				objDOB.focus();
				return (false);			
			}
		}
		
		// objDOB.value = (dDOB.getMonth() +1) + "/" + dDOB.getDate() + "/" + dDOB.getFullYear();
		return (true);
	} else {
		return(false);
	}
}


function checkIfPopulated(objAddress, objCity, objState, objZip) {
	var vAddress, vCity, vState, vZip;
	
	vAddress = "";
	vCity = "";
	vZip = "";

	vAddress = trim(objAddress.value);
	vCity = trim(objCity.value);
	vZip = trim(objZip.value);
	
	// alert(objState.value);
	if (vAddress.length == 0 && vCity.length == 0 && objState.value == "" && vZip.length == 0) {
		return(true);
	} else if (vAddress.length != 0 || vCity.length != 0 || objState.selectedIndex != 0 || vZip.length != 0) {
		// alert(vAddress + ", " + vCity + ", " + vState + ", " + vZip);
		
		// checkPO(objAddress, 'Address');
		// checkField(objAddress, 'Address', 120, true);
		// checkField(objCity, 'City', 120, true);
		// checkRequiredOption(objState, 'State');
		// checkZipCode(objZip, 'Zip Code', 10, true); 
		
		if (checkPO(objAddress, 'Address') == false || checkField(objAddress, 'Address', 120, true) == false  ||  checkField(objCity, 'City', 120, true) == false || checkRequiredOption(objState, 'State') == false || checkZipCode(objZip, 'Zip Code', 10, true) == false) {
			return(false); 
		} else {
			return(true);
		}
	} else {
		return(true);
	}
}



/*---------------------------------------------
Functions that check for valid dates
---------------------------------------------*/

var daysOfMonth = new Object();
daysOfMonth ['Jan'] = daysOfMonth ['January']   = daysOfMonth [1] = 31;
daysOfMonth ['Feb'] = daysOfMonth ['February']  = daysOfMonth [2] = 28;
daysOfMonth ['Mar'] = daysOfMonth ['March']     = daysOfMonth [3] = 31;
daysOfMonth ['Apr'] = daysOfMonth ['April']     = daysOfMonth [4] = 30;
daysOfMonth ['May'] = daysOfMonth ['May']       = daysOfMonth [5] = 31;
daysOfMonth ['Jun'] = daysOfMonth ['June']      = daysOfMonth [6] = 30;
daysOfMonth ['Jul'] = daysOfMonth ['July']      = daysOfMonth [7] = 31;
daysOfMonth ['Aug'] = daysOfMonth ['August']    = daysOfMonth [8] = 31;
daysOfMonth ['Sep'] = daysOfMonth ['September'] = daysOfMonth [9] = 30;
daysOfMonth ['Oct'] = daysOfMonth ['October']   = daysOfMonth [10] = 31;
daysOfMonth ['Nov'] = daysOfMonth ['November']  = daysOfMonth [11] = 30;
daysOfMonth ['Dec'] = daysOfMonth ['December']  = daysOfMonth [12] = 31;

// function to be called from another routine or event handler; 
// returns true or false depending on input returned from validDate()
function parseValidate(obj) {
	var vDate = obj.value
	vDate = vDate.split('/');
	var month = parseInt (vDate[0], 10);
	var day = parseInt (vDate[1], 10);
	var year = parseInt (vDate[2], 10);
	// alert(month + day + year);
	return validDate(month, day, year, obj);
}



function validDate(month, day, year, obj) {
  
	if (month < 1 || month > 12) {
		alert("The month field has an incorrect value. Please choose from 1 to 12.");
		obj.focus();
		return (false);
	} else if (day < 1) {
		alert("The day field has an incorrect value. Please choose a number greater than 0.");
		obj.focus();
		return (false);
	} else if (month == 2 && isLeapYear(year)) {
		var dayLimit = 29;
	} else {
		var dayLimit = daysOfMonth[month];
	}
	
	if (day > dayLimit) {
		alert("The day field has an incorrect value that exceeds the amount of days for the month you specified.");
		obj.focus();
		return (false);
	} else if (year < 1900) {
		alert("The date field has an incorrect value.");
		obj.focus();
		return (false);
	} else {
		return(true);
	}
}

function isLeapYear(y) {
	return (y % 4 == 0  && (y % 400 == 0 || y % 100 != 0))
}




function checkAsNumber(objField, strName, intMaxLength, intMinLength, bRequired){
	
	var strValue = objField.value;
	var i = 0;

	if (strValue.length > 0 && (strValue.length > intMaxLength || strValue.length < intMinLength)){
		if (intMaxLength == intMinLength){
			alert(strName + " must be " + intMaxLength + " digits long.");
		}
		else {
			alert(strName + " must be between " + intMinLength + " and " + intMaxLength + " digits long.");
		}
		objField.focus();
		return(false);
	}
	
	if (isEmpty(strValue) && bRequired){
		alert(strName + " is required. Please fill this in before you continue.");
		objField.focus();
		return(false);
	}


    	while (i < strValue.length) {
    		if (isNaN(parseInt(strValue.charAt(i)))) {
			alert(strName + " must be only numbers.");
			objField.focus();
    			return false; 
    			break;
    		}	
       	i++;
	}
	
	return true;

}


function checkRequiredSelect(objField, strName) {
	var bOk;
	bOk = false;

	for (var i = 0; i < objField.length; i++) {
		if (objField[i].selected == true && objField[i].value != "") {
			bOk = true;
		}	
	}	

	if (bOk == false){
		alert( strName + " does not have a valid selection. Please select an option from the list below");
		objField.focus();
		return (false);
	}
	else{
		return (true);
	}

	

}


/*---------------------------------------------
End of new functions added by js
---------------------------------------------*/
