// Generated by xSynthesis LLC (c) Application Generator v.0.5
// xSynthesis LLC (c) 2002
// SYSTEM FUNCTIONS - DO NOT MODIFY!

//Hide Script for Older Browsers
<!-- //Hide script from older browsers
// xWebForm: Select Option by Value Instead of Index
function fnSelectOptionByValue(ctrSelect,varValue){
	for (var i=0; i < ctrSelect.options.length; i++) {
		if (ctrSelect.options[i].value == varValue) {
			//alert('selecting with index ' + i + ' but value ' + varValue);
			ctrSelect.options[i].selected = true;
		}
	}
}

// xWebForm: Select Radio by Value Instead of Index
function fnSelectOptionRadioByValue(ctrSelectRadio,varValue){
	for (var i=0; i < ctrSelectRadio.length; i++) {
		if (ctrSelectRadio[i].value == varValue) {
			ctrSelectRadio[i].checked = true;
		}
	}
}

// Validate Text and Number Fields
function fnValidateCtr (pFld, pLengthLow, pLengthHigh, pCtrType, pNumMin, pNumMax, pRegExp, pFocus, pErrorMsg){
	
	//pFld=field object; 
	//pLengthLow/ pLengthHigh = integers for lenght(pLengthLow to 1 to not allow blank entry);
	//pCtrType = "text", "int", "real"
	//pNumMin/ pNumMax = the min and max value of integers;
	//pRegExp = validate against this regular expression (null = skip regexp validation);
	//pFocus = 0 to not focus on the field if error (any other value do focus);
	//pErrorMsg= error message text; 
	//returns 0 (false) for error, 1 (true) for success;
	
	if ((pFld.value.length <= pLengthLow) && (pLengthLow == 0)) {
		return 1;
	}
	
	if ((pFld.value.length < pLengthLow) && (pLengthHigh == 1)) {
		alert ("The "+pErrorMsg+" May Not Be Left Blank.  \nPlease Enter "+pErrorMsg);
		if (pFocus!=0) {pFld.focus();}
		return 0;
	}
	
	if ((pFld.value.length < pLengthLow) && (pCtrType != "int") && (pCtrType != "float")){
		alert ("The "+pErrorMsg+" is Shorter Than Allowed. \nPlease Use At Least "+pLengthLow+" Character(s).");
		if (pFocus!=0) {pFld.focus();}
		return 0;
	}
	if ((pFld.value.length > pLengthHigh) && (pCtrType != "int") && (pCtrType != "float")) {
		alert ("The "+pErrorMsg+" Cannot Be Longer Than " + pLengthHigh + " Character(s).");
		if (pFocus!=0) {pFld.focus();}
		return 0;
	}
	
	// More detailed number (int and float) validation;
	if ((pCtrType == "int") || (pCtrType == "float")) {
		re =/,/gi; //Browsers 4.0 and above only
		pFld.value=pFld.value.replace(re,""); //Browsers 4.0 and above only
		if (pCtrType == "int") {
			numValue=parseInt(pFld.value);
			pNumMin = parseInt(pNumMin);
			pNumMax = parseInt(pNumMax);
			}
			else{
			numValue=parseFloat(pFld.value);
			pNumMin = parseFloat(pNumMin);
			pNumMax = parseFloat(pNumMax);
			}
		if ( (isNaN(numValue)) && (pFld.value!="") ) {
			pFld.value = "";
			alert ("Please Enter " + pErrorMsg + " in Numbers Only");
			if (pFocus!=0) {pFld.focus();}
			return 0;
		}
		if ((pFld.value=="") &&  (pFld.value.length < pLengthLow) && (pNumMin != 0 )){
			alert ("The "+pErrorMsg+" May Not Be Left Blank.  \nPlease Enter "+pErrorMsg);
			if (pFocus!=0) {pFld.focus();}
			return 0;
		}
		if (pFld.value > pNumMax) {
			alert ("The "+pErrorMsg+" is Larger Than Allowed. \nPlease Use a Smaller Number Than "+pNumMax+".");
			if (pFocus!=0) {pFld.focus();}
			return 0;
		}
		if (pFld.value < pNumMin) {
			alert ("The "+pErrorMsg+" is Smaller Than Allowed. \nPlease Use a Larger Number Than "+pNumMin+".");
			if (pFocus!=0) {pFld.focus();}
			return 0;
		}
		if (pCtrType == "int") {
			pFld.value=parseInt(pFld.value);}
			else{
			pFld.value=parseFloat(pFld.value);}
	}
	
	//Use pRegExp for phone, email, web address patterns match (even dates?)
	if ((pRegExp !="") && (window.RegExp)) { // second part prevents execution for browsers that don't support RegExp
		var cRegExp = pRegExp;
		// var cRegExp = "^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$"; //another one
		// var cRegExp = "^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$"; //another one
		// /^(file|http):\/\/\S+\/\S+\.(gif|jpg)$/i //verify URL
		var reg1 = new RegExp (cRegExp);
		//alert ("Reg1: " + reg1);
		//alert("RegExp Result: " + (reg1.test(pFld.value)));
		if (!reg1.test(pFld.value)) {
			alert ("The "+pErrorMsg+" is not valid. \nPlease use a valid type of "+pErrorMsg+".");
			if (pFocus!=0) {pFld.focus();}
			return 0;
		}
		// for older browsers
		// if(str.indexOf("@") >= 0);
    		//  return true;
	}
	//re=/"/gi;
	//pFld.value=pFld.value.replace(re,"'");
	//re=/','/gi;
	//pFld.value=pFld.value.replace(re,"', '");
	//re =/"/gi;
	//fld.value=fld.value.replace(re,"'");
	//fld.value = fnStringReplace(fld.value, "\"", "'" )
	
	return 1;
}

function fnValidateSelectCtr (pFld, pSelectType, pReqNumSelect, pErrorMsg){
	//pFld=field object; 
	//pErrorMsg= error message text; 
	//returns 0 (false) for error, 1 (true) for success;
	
	if (pReqNumSelect != "0") {
		if (pSelectType == "listbox") {
			//alert("Listbox " + pFld.name & " Selected Index: " + pFld.options.selectedIndex);
			if (pFld.options.selectedIndex == -1) { 
				alert ("You Must Select a " + pErrorMsg);
				pFld.focus();
				return 0;
			} else {
			//alert ("(" + pFld.options[pFld.options.selectedIndex].value + ")");
				if (pFld.options[pFld.options.selectedIndex].value == "") {
					alert ("You Must Select a " + pErrorMsg);
					pFld.focus();
					return 0;
				}
			}
		}
	}
	
	if (pReqNumSelect != "0") {
		if (pSelectType == "radio") {
			//alert ("Length: " + pFld.length);
			for (var i =0; i< pFld.length; i++) {
				//alert (pFld[i].checked); 
				if (pFld[i].checked == true) {
					return 1; // One checked, return success;
				}
			}
			alert ("You Must Select a " + pErrorMsg);
			pFld[0].focus();
			return 0; // It was radio, but none were checked;
		}
	}
	return 1;
}
// TO BE CLEANED UP!!
function fnStringReplace( origStr, findTxt, replaceTxt ) {
	var pos = 0;
	var len = findTxt.length;
	pos = origStr.indexOf(findTxt);
	while (pos != -1) {
		preStr = origStr.substring(0, pos);
		postStr = origStr.substring(pos+len, origStr.length);
		origStr = preStr + replaceTxt + postStr;
		pos = origStr.indexOf(findTxt);
	}
	return origStr;
}

function fnPage (pRowFirst, pCtr, pForm) {
	pCtr.value = pRowFirst;
	pForm.submit();
}

function fnValidateStateCountry(pCountry, pState, pStateErrorMsg) {
	if (pCountry.value == "USA") {
		if (fnValidateSelectCtr (pState,"listbox","1",pStateErrorMsg) ==0) {return 0;}
	} else {
		if (pState.options.selectedIndex != -1) { 
		//alert ("(" + pState.options[pState.options.selectedIndex].value + ")");
			if (pState.options[pState.options.selectedIndex].value != "") {
				alert ("You Must Not Select a " + pStateErrorMsg + " When Not Within the US");
				pState.focus();
				return 0;
			}
		}
	}
	return 1;
}

// End Hiding Script -->