/**************************************************************/ function checkOptionalPhoneDigitsFormat(thisForm, val, length, digitsFormatMeg, requiredDigitLength ) { curVal = trim(thisForm.elements[val].value); if ( curVal != "" ) { if ( !isNaN(curVal) ==0 ) { alert(digitsFormatMeg); thisForm.elements[val].value = ""; thisForm.elements[val].focus(); return false; } else if ( curVal.length != length ) { alert( length + " " + requiredDigitLength ); thisForm.elements[val].focus(); return false; } else return true; } else return true; } function checkOptionalField(thisForm, val1, val2, val3, fillAllMeg ) { curVal1 = trim(thisForm.elements[val1].value); curVal2 = trim(thisForm.elements[val2].value); curVal3 = trim(thisForm.elements[val3].value); if ( curVal1 == "" && curVal2 =="" && curVal3 =="" ) { return true; } else if ( curVal1.length == "" ) { alert( fillAllMeg ); thisForm.elements[val1].focus(); return false; } else if ( curVal2.length == "" ) { alert( fillAllMeg ); thisForm.elements[val2].focus(); return false; } else if ( curVal3.length == "" ) { alert( fillAllMeg ); thisForm.elements[val3].focus(); return false; } else return true; } function checkInputAndDigitsFormat(thisForm, val, length, requiredFieldMeg, digitsFormatMeg, requiredDigitLength) { curVal = trim(thisForm.elements[val].value); if ( curVal == "" ) { alert(requiredFieldMeg); thisForm.elements[val].focus(); return false; } else if (!isNaN(curVal) ==0 ) { alert(digitsFormatMeg); curVal = ""; thisForm.elements[val].focus(); return false; } else if ( curVal.length != length ) { alert( length + " " + requiredDigitLength ); thisForm.elements[val].focus(); return false; } else { return true; } } // getSelectedRadioItem is to get index of radio buttons. // It returns the index. function getSelectedRadioItem(radioGroup) { for ( var i = 0; i < radioGroup.length; i++ ) { if ( radioGroup[i].checked) return i; } return 0 ; } /**************************************************************/ // getValue is to get code and description. // It runs true. function getValue ( InString ) { strLength = InString.length; charPos = InString.indexOf("!"); code = InString.substring (0, charPos); InString = InString.substring(charPos+1, strLength); descripton = InString; return true; } /**************************************************************/ /**************************************************************/ function checkPostalZip( postalZipVal, countryCode, errorMsgCanada, errorMsgUSA ) { // not mandatory fields if (postalZipVal == "") return true; // united states if ( countryCode == 209 ) { re1 = /^\d{5}-\d{4}$/; re2 = /^\d{5}$/; if ( postalZipVal.search(re1)==-1 && postalZipVal.search(re2)==-1 ) { alert(errorMsgUSA); return false; } else { return true; } } // canada if (countryCode == 57 ) { re1 = /^[A-Za-z][0-9][A-Za-z][ ]*([0-9][A-Za-z][0-9])?$/; if ( postalZipVal.search(re1)==-1 ) { alert(errorMsgCanada); return false; } else { return true; } } // others (always true) return true; } /**************************************************************/ /**************************************************************/ function getCheckedServices(hiddenField, checkboxField) { hiddenField.value = ""; for (i = 0; i < checkboxField.length; i++) { if (checkboxField[i].checked == true) { if (hiddenField.value == "") { hiddenField.value = checkboxField[i].value; }else { hiddenField.value += "|" + checkboxField[i].value; } } } } /**************************************************************/ /**************************************************************/ function checkPostalCodeWOCountry( obj ) { curVal = obj.value; if (curVal.length > 0) { re1 = /^\d{5}-\d{4}$/; re2 = /^\d{5}$/; if ( curVal.search(re1)==-1 && curVal.search(re2)==-1 ) { re1 = /^[A-Za-z][0-9][A-Za-z][ ]*([0-9][A-Za-z][0-9])?$/; if ( curVal.search(re1)==-1 ) { return false; } } } return true; } /**************************************************************/ /**************************************************************/ function validateSelection(radioBoxField) { if ((typeof (radioBoxField.length)) == "undefined") { return true; } for (i = 0; i < radioBoxField.length; i++) { if (radioBoxField[i].checked) { return true; } } return false; } /**************************************************************/ /**************************************************************/ function validateEmailFormat( obj ) { myVar = obj.value; if (myVar.length > 0) { re1 = /^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$/; if ( myVar.search(re1)==-1 ) { return false; } } return true; } /**************************************************************/ /**************************************************************/ function validateContactNumber( obj1, obj2, obj3 ) { if (!isNaN(obj1.value) ==0) { obj1.value = ""; obj1.focus(); return false; } if (!isNaN(obj2.value) ==0) { obj2.value = ""; obj2.focus(); return false; } if (!isNaN(obj3.value) ==0) { obj3.value = ""; obj3.focus(); return false; } if ((obj1.value.length) < 3) { obj1.value = ""; obj1.focus(); return false; } if ((obj2.value.length) < 3) { obj2.value = ""; obj2.focus(); return false; } if ((obj3.value.length) < 4) { obj3.value = ""; obj3.focus(); return false; } return true; } /**************************************************************/ /**************************************************************/ function validatePhoneLength( obj1, obj2, obj3, isMandatory ) { obj1.value = trim (obj1.value); obj2.value = trim (obj2.value ); obj3.value = trim (obj3.value ); if ( isMandatory == 0 && obj1.value.length == 0 && obj2.value.length == 0 && obj3.value.length == 0) return true; if ((obj1.value.length) != 3) { obj1.focus(); return false; } if ((obj2.value.length) != 3) { obj2.focus(); return false; } if ((obj3.value.length) != 4) { obj3.focus(); return false; } return true; }