<!--
var charexp = /[a-zA-Z0-9]/
var inputexp = /./
var zipexp = /^\d{5}$|^\d{5}[\-\s]?\d{4}$|^\d{3}[\-\s]\d{4}$/
var emailexp = /^[-a-zA-Z_0-9\.]+@[-a-zA-Z_0-9\.]+\.[a-zA-Z]{2,4}$/i
var fieldCheck = true;		// Set validation to always pass by default.
var fieldsNeeded = "";

function isValid(pattern, str) {
	return pattern.test(str)
}

	 

function validateForm(input, formName) {
    var validationPasssed
	fieldCheck = true;
	fieldsNeeded = "There was in error in the following field(s):\n\n";

	if (formName == "checkout_Pymt" && input.PayType.value != "SKIP" && input.rdoPayPO.checked == true) {
		if (!(input.rdoHardCopy1.checked == true || input.rdoHardCopy2.checked == true)){
			fieldsNeeded += "Indicate if you are sending a Hard Copy of the PO.\n";
			fieldCheck = false;
		}
	}
	// First check to see if the fields in the requiredFields array were left blank.
    for(var fieldNum=0; fieldNum < requiredFields.length; fieldNum++) {
		if (!hasChar(input.elements[requiredFields[fieldNum]].value)) {
            fieldsNeeded += fieldNames[fieldNum] + " field is missing or invalid.\n";
            fieldCheck = false;
		} else {
			validateFieldSize(input,formName,requiredFields[fieldNum],fieldNames[fieldNum]);
		}  
	}
	
	if((optionalFields[0].toUpperCase()) != "N/A") //by swathi(5/17/2002)
	{
	   for(fieldNum=0; fieldNum < optionalFields.length; fieldNum++) {
			if (hasInput(input.elements[optionalFields[fieldNum]].value)) {
				validateFieldSize(input,formName,optionalFields[fieldNum],oFieldNames[fieldNum]);
			}  
	  }
	}

    // All required fields have been check pass back if the validation succeeded.
    if (fieldCheck == true) {
       	return true;
	} else {
		fieldsNeeded += "\nYou can not submit this information until all errors have been corrected."
        alert(fieldsNeeded);
        return false;
	}
}	// End validateForms
//-----------------------------------------j
function validateFieldSize(input,formName,fieldID,fieldName) {
	var i;
  // Check to see if the field are of correct size according to database.
	for(i = 0; i < allFields.length; i++) {
		if (allFields[i] == fieldID) {
		    var s = new String(input.elements[fieldID].value);
		    if((s.length) <= sizeFields[i]) {
				validateField(input,formName,fieldID,fieldName);
			} else  { 
				fieldsNeeded += fieldName + " field Size is "+ s.length + " but,can only be of maximum size " + sizeFields[i]+ " \n ";
				fieldCheck = false;
			 }
		}//if
	}//for
}//function
//---------------------------------y
function validateField(input,formName,fieldID,fieldName) {
	var i;
	var bPassed = true;
	// Check to see if the field needs an e-mail vailidation check.
	for(i = 0; i < emailFields.length; i++) {
		if (emailFields[i] == fieldID) {
			if (!isValid(emailexp,input.elements[fieldID].value)) {
				fieldsNeeded += fieldName + " field does not contain a valid e-mail address.\n";
				fieldCheck = false;
			}
		}
	}

	// Check to see if the field needs a Zip code vailidation check.
	for(i = 0; i < zipFields.length; i++) {
		if (zipFields[i] == fieldID) {
			if (!isValid(zipexp,input.elements[fieldID].value)) {
				fieldsNeeded += fieldName + " field is not in the proper zip code format (i.e. 74146 or 74146-1234).\n";
				fieldCheck = false;
			}
		}
	}		
					
	// Check to see if the field needs a numeric code vailidation check.
	for(i = 0; i < numericFields.length; i++) {
		if (numericFields[i] == fieldID) {
			bPassed = allNumeric(input.elements[fieldID].value)
			if (bPassed == false) {
				fieldsNeeded += fieldName + " field must contain all numeric values (i.e. 0 - 9).\n";
				fieldCheck = false;
			}
		}
	}		

	// Check to see if the field needs a phone number vailidation check.
	for(i = 0; i < phoneFields.length; i++) {
		if (phoneFields[i] == fieldID) {
			// Perform the numeric code vailidation check.
			bPassed = isPhone(input.elements[fieldID].value)
			if (bPassed == "false") {
				fieldsNeeded += fieldName + " field is not a valid phone number (example format: 918-8675309 or 9188675309).\n";
				fieldCheck = false;
			} else {
				input.Phone.value = bPassed;
			}
		}
	}		

	// Check to see if the field needs a credit card vailidation check.
	for(i = 0; i < creditcardFields.length; i++) {
		if (creditcardFields[i] == fieldID) {
			// Perform the numeric code vailidation check.
			bPassed = isCreditCard(input.elements[fieldID].value)
			if (bPassed == false) {
				fieldsNeeded += fieldName + " field does not contain a valid credit card number (example format: 1111222233334444 or 1111-2222-3333-4444).\n";
				fieldCheck = false;
			} else {
				input.elements[fieldID].value = bPassed;
			}
		// Call this function to make sure that the expiration date hasn't already expired.
			bPassed = checkExpDate(formName);
			if (bPassed == false) {
				fieldsNeeded += "The expiration date you have selected has already expired.  Please double check your selections.\n";
				fieldCheck = false;
			}		 
		}
	}
} // End validateField


function allNumeric(str) {
	var pattern = /[^0-9]/
	return !pattern.test(str)
}

function allAlpha(checkString) {
	var sChr;
	var bAlpha = false;		// Set to false in case white space characters are found
	var i;

    // Loop through the string character by character.
    for (i = 0; i < checkString.length; i++) {
        sChr = checkString.substring(i, i+1);

        // ENSURE CHARACTER IS AN ALPHA CHARACTER
        if ((sChr >= "a" && sChr <= "z") || (sChr >= "A" && sChr <= "Z" ) ||
			(sChr >= "0" && sChr <= "9"))
		{
            bAlpha = true;		// A character or number was found.
            break;
		}
	}
    return bAlpha;
}



// This function determines if the string passed in is a valid US ten digit phone number.  
//If the string is valid, it returns the string formated (###) ###-####, else returns false.
function isPhone(strPhone) {
	var s = new String(stripNonDigits(strPhone));
	if (s.length != 10) {
		// inappropriate length
		return "false";
	}
	s = "(" + s.substring(0,3)+ ") " +s.substring(3,6)+ "-" +s.substring(6,10)
	return s;	
}

// This function determines if the string passed in is a valid credit
// card number.  It accepts only numeric values between 13-16 digits. If the
// string is valid, it returns card number, else false.
function isCreditCard(strCC) {
	var s = new String(stripNonDigits(strCC));
	var iSum = 0;
	var iMulti = 0;
	var iProd = 0;
	var iRet;
	var sChr;
		
	if (s.length < 13 || s.length > 16) {
		// inappropriate length
		return false;
	}
    // Always set card number to an even length string to make this work correctly.
    iRet = (s.length % 2);
    if (iRet == 1) s = "0" + s;

	// Run valid credit card check.
	for (var i = s.length-1; i > '-1'; i--) {
		sChr = s.charAt(i);
		iRet = ((i + 1) % 2);		// Add one to i to offset for zero based length.
		if (iRet == 1) {
			iProd = parseInt(sChr) * 2;
			// If the digit double is 10 or more then the amount to add to the sum is 1+ digit mod 10
			if (iProd > 9) {
				iSum += (iProd - 9);
			} else 	{
				iSum += iProd;
			}
		} else {
		iSum += parseInt(sChr);
		}
	}
	iRet = (iSum % 10);
	if (iRet != 0) return false;		// Invalid card number.
	return s;	
}
 

// Verify that the expiration date choosen has not expired.
function checkExpDate(input) {
	var dDate;
	var dToday = new Date();	
	var iMonth = getOPTValue(input.listmonth);
	var iYear = getOPTValue(input.listyear);

	// Make sure that the values aren't empty.
	if (iMonth == ' ' || iMonth == '') return false;
	if (iYear == ' ' || iYear == '') return false;
	if (iMonth == '12') {
		iMonth = '0';
		iYear = parseInt(iYear) + 1;
		iYear = '0' + iYear;
	}
	iYear = '20' + iYear;
	dDate = new Date(iYear,iMonth,01);
	if (dDate < dToday) {
		return false;	
	}
	return true;
}

// This function returns that value of the currently selection 
// dropdown list option.  The value return updates the state textbox object.
function getOPTValue(input) {
	var listValue = "";
	// Read the current value of the drop down list object and return its value.
	if (input.selectedIndex != -1) {
	   listValue = input.options[input.selectedIndex].value;
	}
	return listValue;
}

// Rounding Function
function roundOff(value, precision) {
	value = "" + value //convert value to string
	precision = parseInt(precision);

	var whole = "" + Math.round(value * Math.pow(10, precision));

	var decPoint = whole.length - precision;

	if(decPoint != 0) {
		result = whole.substring(0, decPoint);
		result += ".";
		result += whole.substring(decPoint, whole.length);
	} else {
		result = whole;
	}
	return result;
}

// This function sets the default value for a drop down list box based
// on the parameter passed to the function.  The first parameter is the default
// value and the second is the form name.
function setOPTValue(input, listObj) {	
	for (var i = 0; i < listObj.length; i++) {
		if (listObj.options[i].value == input) {
			listObj.options[i].selected = true;
			return true;
		}	
	}
}

function hasChar(str) {
	return charexp.test(str)
}

function hasInput(str) {
	return inputexp.test(str)
}

function stripNonDigits(str) {
	return str.replace(/[^0-9]/g,"")
}

// This function sets the default value for a drop down list box based
// on the parameter passed to the function.  The first parameter is the default
// value and the second is the form name.
function getState(input, listObj)
{	
	for (var i = 0; i < listObj.length; i++)
	{
		if (listObj.options[i].value == input)
		{
			listObj.options[i].selected = true;
			return true;
		}	
	}
}
//-->

