/*********************************************************************
/ ordrfrm-valid.js - v1.4 - 012000 - wbd
/ This file contains functions that can be used by html pages needing to validate form
/ fields for blankness, number/letter presence and length (ie phone number prefix's
/ need 3 numbers) and for valid email addresses (only checks for presence of a "@"
/ and a "." in the submitted text
/
/********************************************************************/

//Enter this tag after head tag
//<script language="JavaScript" type="text/javascript" src="/scripts/ordrfrm-valid.js"></script>
//Enter these next lines after above tag then start function expressions...
//<script type="text/javascript">
//<!--
//function CheckForm(formObj){
//
//-->
//
//</script>


// Checks to make sure a Card Type was chosen
//if(checkListBoxSel(formObj.<fieldname>.value,"<fieldname>","<Appropriate Message>",formObj)) return false;
function checkListBoxSel(objListBoxType,objName,alertBox,formObj) {
	if (objListBoxType == "choose") {
		alert(alertBox)
		eval("formObj." + objName + ".focus()")
		return true
	}
	return false
}
// Checks the seminar radio button
function checkSeminar(objSeminar,objName,alertBox,formObj) {
	for (var i = 0; i<3; i++) {
		var checked = objSeminar[i].checked == "1"
		if (checked) break;
	}
 	if (!checked) {
		alert(alertBox)
		return true
	}
	return false
}
// Checks the card type to the first number of the cc number given
//if(checkCCFirstDigit(formObj.<Card Type Field Name>.value,formObj.<Card No Field Name>,"<Card Type Field Name>","<Appropriate Message",formObj)) return false;
function checkCCFirstDigit(txtCardType,ccNo,objName,alertBox,formObj) {
	var firstNo = txtCardType == "visa" ? 4 : 5
	var match = ccNo.value.charAt(0) == firstNo
	if (!match) {
		alert(alertBox)
		eval("formObj." + objName + ".focus()")
		return true
	}
	return false
}
// Check to see if the field is just blank
//if(fieldBlank(formObj.<fieldname>.value,"<fieldname>","Appropriate Message",formObj)) return false;
function fieldBlank(textObj, objName, alertBox, formObj) {
	if (textObj == "") return (makeAlertBox(alertBox, objName, formObj));
	return false;
}
// Check for a letter (upper or lower case) as the first character in the object
//if(checkLetter(formObj.<fieldname>.value,"<fieldname>","Appropriate Message",formObj)) return false;
function checkLetter(textObj, objName, alertBox, formObj) {
	if ((textObj != " ") && (textObj.charCodeAt(0) >= "65" && textObj.charCodeAt(0) <= "90") || (textObj.charCodeAt(0) >= "97" && textObj.charCodeAt(0) <= "122")) return false;
	else return (makeAlertBox(alertBox, objName, formObj));
}
// Check for valid phone number
// Use formObj.<fieldname>.value.length for firstLength to test the number when the length varies
//if(checkNumber(formObj.<fieldname>,<firstLength>,<secondLength>,"<fieldname>","<Appropriate Message>",formObj)) return false;
function checkNumber(numberObj,maxLength,maxLength2,objName,alertBox,formObj) {
	if (numberObj.value == "" || (numberObj.value.length != maxLength && numberObj.value.length != maxLength2)) return (makeAlertBox(alertBox, objName, formObj));
	else{
		var i = 0 
		var j = numberObj.value.length
		while (i < j) {
			if (numberObj.value.charAt(i) < "0" || numberObj.value.charAt(i) > "9") return (makeAlertBox(alertBox, objName, formObj));
			else i = i + 1;
		}
	}
	return false
}
// Check for valid international phone number
//if(checkIntlNumber(formObj.<fieldname>,"<fieldname>","<Appropriate Message>",formObj)) return false;
function checkIntlNumber(numberObj,objName,alertBox,formObj) {
	var i = 0 
	var j = numberObj.value.length
	if (j < 1) return (makeAlertBox(alertBox, objName, formObj));
	while (i < j) {
		if ((numberObj.value.charAt(i) < "0" || numberObj.value.charAt(i) > "9") && numberObj.value.charAt(i) != "-") return (makeAlertBox(alertBox, objName, formObj));
		else i = i + 1;
	}
return false
}
//Check number against range
//if(checkNumberRange(formObj.<fieldname>.value,<lownumber>,<highnumber>,"<fieldname>","Appropriate Message",formObj)) return false;
function checkNumberRange(intNumber,lowNo,highNo,objName,alertBox,formObj) {
	if (intNumber < lowNo || intNumber > highNo) {
		alert(alertBox)
		eval("formObj." + objName + ".focus()")
		return true
	}
	return false
}
// Check for email address: look for [@] and [.] 
//if(validEmail(formobj.<fieldname>,<fieldname>,"<Appropriate Message>",formObj)) return false;
function validEmail(emailObj, objName, alertBox, formObj) {
	if (emailObj.value.indexOf("@") + "" != "-1" && emailObj.value.indexOf(".") + "" != "-1" && emailObj.value.indexOf(",") + "" == "-1" && emailObj.value != "") return false;
	else return (makeAlertBox(alertBox, objName, formObj));
}
//Search Checkboxes to see if any are selected.
//if(scanCheckBoxes(<name of checkbox series>, <max no of check boxes>, <name of whatever the boxes repesent>, formObj)) return false;
function scanCheckBoxes(boxName, j, optionName, formObj){
	var count = 0
	j = Number(j) + 1
	for (i=1; i<j; i++){
		if (eval("formObj." + boxName + i + ".checked")) count = count + 1;
	}
	if (count == "0"){
		alert("Please choose at least one " + optionName + ".")
		eval("formObj." + boxName + "1.focus()")
		return true
	}else{
		return false
	}
}
//This function is used internally to generate the alert and focus on the field
function makeAlertBox(alertBox, objName, formObj) {
	alert(alertBox)
	eval("formObj." + objName + ".focus()")
	eval("formObj." + objName + ".select()")
	return true
}
