function validator() { this.inputName = new Array(); this.validationType = new Array(); this.formName = new Array(); this.errorMessage = new Array(); this.optionalFlag = new Array(); this.length = 0; this.emptyErrorMessage = "The required field is missing: "; this.showError = true; this.min_pass_length = 0; this.max_pass_length = 0; this.validate = validate; this.validateOne = validateOne; this.validateOneIndexed = validateOneIndexed; this.validateOneField = validateOneField; this.required = required; this.optional = optional; this.unrequired = unrequired; this.setpasswordsize = setpasswordsize; this.setvalidation = setvalidation; this.hasValue = hasValue; this.displayError = displayError; this.getIndex = getIndex; ////////////////////////////////////// // Validation Methods go here ///////////////////////////////////// // When adding new methods, be sure to the hasValue method if any "special" // handling is required (mainly if the element consists of more than one field). // this.isInputValid = isInputValid; this.isEmailValid = isEmailValid; this.isWysiwygValid = isWysiwygValid; this.isEitherValid = isEitherValid; this.isLengthValid = isLengthValid; this.isCCExpValid = isCCExpValid; this.isCCNumValid = isCCNumValid; this.isPasswordValid = isPasswordValid; this.isPhoneValid = isPhoneValid; this.isFaxValid = isPhoneValid; // Yes, this is intentional this.isZipValid = isZipValid; this.isCurrencyValid = isCurrencyValid; this.isFloatValid = isFloatValid; this.isIntegerValid = isIntegerValid; this.isUsernameValid = isUsernameValid; this.isURLValid = isURLValid; this.isEmailListValid = isEmailListValid; this.isDateValid = isDateValid; this.isTimeValid = isTimeValid; this.isMinChecked = isMinChecked; this.isFileValid = isFileValid; } function getFormObject(formNameTemp) { if(typeof formNameTemp == 'string') { formName = eval("document."+formNameTemp); }else{ formName = formNameTemp; } return formName; } function getInputObject(formNameTemp,inputNameTemp) { if ( (typeof formNameTemp == 'string') && (typeof inputNameTemp == 'string') ) { formName = eval("document."+formNameTemp); inputName = formName.elements[ inputNameTemp ]; } else if (typeof inputNameTemp == 'string') { formName = getFormObject(formNameTemp); inputName = formName[inputNameTemp]; } else { inputName = inputNameTemp; } return inputName; } function setpasswordsize( min, max ) { this.min_pass_length = min; this.max_pass_length = max; } function validateOne(validatedForm, validatedField) { var index = this.getIndex( validatedForm, validatedField ); if ( index < 0 ) { optionalFlag = true; validationType = "REGULAR"; } else { validationType = this.validationType[index]; optionalFlag = this.optionalFlag[index]; } return this.validateOneField(validatedForm, validatedField, validationType, optionalFlag, false); } function validateOneIndexed(i) { theForm = this.formName[i]; theField = this.inputName[i]; theValidation = this.validationType[i]; optionalFlag = this.optionalFlag[i]; return this.validateOneField(theForm, theField, theValidation, optionalFlag, true); } function validateOneField(theForm, theField, theValidation, optionalFlag, bMsg) { if ( optionalFlag && ! this.hasValue( theForm, theField, theValidation ) ) { return true; } if ( theValidation == null || theValidation == "REGULAR" ) { if ( ! this.isInputValid(theForm,theField,false,bMsg) ) { return false; } } else if ( theValidation == "WYSIWYG") { if ( ! this.isWysiwygValid(theForm,theField,bMsg) ) { return false; } } else if ( theValidation == "EMAIL") { if ( ! this.isEmailValid(theForm,theField,bMsg) ) { return false; } } else if ( theValidation == "CC_EXP") { if ( ! this.isCCExpValid(theForm,theField,bMsg) ) { return false; } } else if(theValidation == "CC_NUM") { if ( ! this.isCCNumValid(theForm, theField,bMsg) ) { return false; } } else if(theValidation == "EITHER") { if ( ! this.isEitherValid( theForm, theField,bMsg) ) { return false; } } else if(theValidation == "LENGTH") { if ( ! this.isLengthValid( theForm, theField,bMsg) ) { return false; } } else if(theValidation == "PASSWORD") { if ( ! this.isPasswordValid( theForm, theField, theField + "_VERIFY", bMsg) ) { return false; } } else if(theValidation == "MIN_CHECKED") { if ( ! this.isMinChecked(theForm,theField,bMsg)) { return false; } } else if ( theValidation == "FILE") { if ( ! this.isFileValid(theForm,theField,bMsg) ) { return false; } } else if(theValidation == "ZIP") { if ( ! this.isZipValid(theForm,theField,bMsg) ) { return false; } } else if ( theValidation == "PHONE") { if ( ! this.isPhoneValid(theForm,theField,bMsg) ) { return false; } } else if ( theValidation == "CURRENCY") { if ( ! this.isCurrencyValid(theForm,theField,bMsg) ) { return false; } } else if ( theValidation == "FLOAT") { if ( ! this.isFloatValid(theForm,theField,bMsg) ) { return false; } } else if ( theValidation == "INTEGER") { if ( ! this.isIntegerValid(theForm,theField,bMsg) ) { return false; } } else if ( theValidation == "USERNAME") { if ( ! this.isUsernameValid(theForm,theField,bMsg) ) { return false; } } else if ( theValidation == "URL") { if ( ! this.isURLValid(theForm,theField,bMsg) ) { return false; } } else if ( theValidation == "EMAIL_LIST") { if ( ! this.isEmailListValid(theForm,theField,bMsg) ) { return false; } } else if ( theValidation == "DATE") { if ( ! this.isDateValid(theForm,theField,bMsg)) { return false; } } else if ( theValidation == "TIME") { if ( ! this.isTimeValid(theForm,theField,bMsg)) { return false; } } return true; } function validate(validatedForm) { for( var i = 0; i < this.length; i++ ) { if (!this.validateOneIndexed(i)) return false; } return true; } function getIndex( formName, inputName ) { for ( var i = 0; i < this.length; ++i ) { if ( this.formName[i] == formName && this.inputName[i] == inputName ) { return i; } } return -1; } function optional(formName,inputName,message,validationType) { this.setvalidation(formName, inputName, message, validationType, true) } function required(formName, inputName, message, validationType) { this.setvalidation(formName, inputName, message, validationType, false) } function setvalidation(formName,inputName,message,validationType,optionalFlag) { var index = this.getIndex( formName, inputName ); if ( index < 0 ) { this.formName[this.length] = formName; this.inputName[this.length] = inputName; this.validationType[this.length] = validationType; this.errorMessage[this.length] = message; this.optionalFlag[this.length] = optionalFlag; this.length++; } else { this.optionalFlag[ index ] = optionalFlag; this.validationType[ index ] = validationType; } } function unrequired(formName,inputName,validationType) { var index = this.getIndex( formName, inputName ); if ( index >= 0 ) { this.validationType[ index ] = "NONE"; } } function hasValue( theForm, theField, theValidation ) { // Need to handle the special cases ( multiple fields ) separately if ( theValidation == "CC_EXP" ) { MonthField = getInputObject(theForm,theField + "_MONTH"); YearField = getInputObject(theForm,theField + "_YEAR"); MonthVal = getValue( MonthField ); YearVal = getValue( YearField ); return ( ! isEmpty( MonthVal ) || ! isEmpty( YearVal ) ); } else if ( theValidation == "EITHER" || theValidation == "FILE" ) { // There's nothing to do here. return true; } else if ( theValidation == "PASSWORD" ) { pwdField = getInputObject(theForm,theField ); verifyField = getInputObject(theForm,theField + "_VERIFY"); pwdVal = getValue( pwdField ); verifyVal = getValue( verifyField ); return ( ! isEmpty( pwdVal ) || ! isEmpty( verifyVal ) ); } else if ( theValidation == "MIN_CHECKED" ) { args = theField.replace(/ /g,"").split("&"); for ( j = 1; j < args.length; j++ ) { fieldName = args[j]; objField = getInputObject(formName,fieldName ); if ( objField.checked ) { return true; } } return false; } else if ( theValidation == "DATE" ) { MonthField = getInputObject(theForm,theField + "_MONTH"); DayField = getInputObject(theForm,theField + "_DAY"); YearField = getInputObject(theForm,theField + "_YEAR"); MonthVal = getValue( MonthField ); DayVal = getValue( DayField ); YearVal = getValue( YearField ); return ( !isEmpty( MonthVal ) || !isEmpty( DayVal ) || !isEmpty( YearVal ) ); } else if ( theValidation == "TIME" ) { HourField = getInputObject(theForm,theField + "_HOUR"); MinuteField = getInputObject(theForm,theField + "_MINUTE"); AMPMField = getInputObject(theForm,theField + "_AMPM"); HourVal = getValue( HourField ); MinuteVal = getValue( MinuteField ); AMPMVal = getValue( AMPMField ); return ( !isEmpty( HourVal ) || !isEmpty( MinuteVal ) || !isEmpty( AMPMVal ) ); } else { objField = getInputObject(theForm,theField); theVal = getValue( objField ); return ( ! isEmpty( theVal ) ); } } function displayError(formName,inputName,errorType) { if(this.showError==false) return; var index = this.getIndex( formName,inputName ); if ( index >= 0 ) { if ( this.errorMessage[ index ] != null ) { alert( this.errorMessage[index] ); return; } } if(errorType=="EMPTY") { alert(this.emptyErrorMessage+' '+inputName); } } function isInputValid(formNameTmp,inputName,suppressError,bMsg) { elementName = getInputObject(formNameTmp,inputName); if ( ! elementName ) { alert( "Error getting Element: " + inputName ); return false; } if ( (elementName.type == "text") || (elementName.type == "textarea") || (elementName.type == "hidden") || (elementName.type == "file") || elementName.type == "password" ) { if(elementName.value=='') { if ( suppressError != true ) { if (bMsg) this.displayError(formNameTmp,elementName.name,"EMPTY"); if (bMsg && elementName.type != "hidden") elementName.focus(); } return false; } } else if(elementName.type=='select-one'|| elementName.type=='select') { var index=elementName.selectedIndex; if(index==-1 || elementName.options[index].value == "") { if ( suppressError != true ) { if (bMsg) this.displayError(formNameTmp,elementName.name,"EMPTY"); if (bMsg) elementName.focus(); } return false; } } else if(elementName.type=='checkbox') { if(elementName.checked==false) { if ( suppressError != true ) { if (bMsg) this.displayError(formNameTmp,inputName,"EMPTY"); } return false; } } else if(elementName.type=='radio') { if (elementName.checked) { return true; } if ( suppressError != true ) { if (bMsg) this.displayError(formNameTmp,inputName,"EMPTY"); } return false; } else if(elementName[0].type=='radio') { var r; for ( r = 0; r < elementName.length; ++r ) { if(elementName[r].checked == true ) { return true; } } if ( suppressError != true ) { if (bMsg) this.displayError(formNameTmp,inputName,"EMPTY"); } return false; } else if ( elementName.type == null ) { radioLength=elementName.length; if ( ! (radioLength > 0 ) ) { return false; } for ( j = 0; j < radioLength; j++) { if( elementName[j].checked == true) { return true; } } if ( suppressError != true ) { if (bMsg) this.displayError(formNameTmp,inputName,"EMPTY"); } return false; } else { if(elementName.value=='') { if ( suppressError != true ) { if (bMsg) this.displayError(formNameTmp,elementName.name,"EMPTY"); if (bMsg) elementName.focus(); } return false; } } return true; } function isWysiwygValid( formName, wysiwygTemp, bMsg ) { wysiwygfield = getInputObject( formName, wysiwygTemp ); if ( isEmptyWysiwyg( wysiwygfield ) ) { if (bMsg) this.displayError(formName,wysiwygTemp,"EMPTY"); return false; } return true; } function isEmailValid( formName, emailTemp, bMsg ) { emailField = getInputObject( formName, emailTemp ); if ( ! isEmail( emailField ) ) { if (bMsg) emailField.focus(); if (bMsg) this.displayError(formName,emailTemp,"EMPTY"); return false; } return true; } function isCCNumValid( formName, fieldName, bMsg ) { cc_number = getInputObject(formName, fieldName ); if ( ! isCreditCardNumber( cc_number ) ) { if (bMsg) cc_number.focus(); if (bMsg) this.displayError(formName,fieldName,"EMPTY"); return false; } return true; } function isCCExpValid( formName, fieldName, bMsg ) { monField = getInputObject(formName, fieldName + "_MONTH" ); yearField = getInputObject(formName, fieldName + "_YEAR" ); idx = monField.selectedIndex; cc_month = monField.options[idx].value; idx = yearField.selectedIndex; cc_year = yearField.options[idx].value; if ( ! cc_year || ! cc_month ) { if (bMsg) this.displayError(formName,fieldName,"EMPTY"); return false; } thismonth = 4; thisyear = 2024; if ( cc_year > thisyear ) { return true; } else if ( cc_year < thisyear ) { if (bMsg) yearField.focus(); if (bMsg) this.displayError(formName,fieldName,"EMPTY"); return false; } if ( cc_month < thismonth ) { if (bMsg) monField.focus(); if (bMsg) this.displayError(formName,fieldName,"EMPTY"); return false; } return true; } function isEitherValid(formName,fieldnames, bMsg) { vals = fieldnames.replace(/ /g,"").split("&"); for ( j = 0; j < vals.length; j++ ) { if ( isInputValid(formName,vals[j],true,true) ) { return true; } } field1 = getInputObject(formName,vals[0]); if (bMsg) field1.focus(); if (bMsg) this.displayError(formName,fieldnames,"EMPTY"); return false; } function isLengthValid(formName,fieldname, bMsg) { params = fieldname.replace(/ /g,"").split("&"); minlength = parseInt( params[1], 10 ); maxlength = parseInt(params[2], 10 ); elementObj = getInputObject(formName,params[0]); strlength = elementObj.value.length; if ( strlength > maxlength ) { if (bMsg) elementObj.focus(); if (bMsg) this.displayError(formName,fieldname,"EMPTY"); return false; } if ( minlength > 0 && strlength < minlength ) { if (bMsg) elementObj.focus(); if (bMsg) this.displayError(formName,fieldname,"EMPTY"); return false; } return true; } function isPasswordValid( formName, pwd1Temp, pwd2Temp, bMsg ) { pwd1 = getInputObject( formName, pwd1Temp ); pwd2 = getInputObject( formName, pwd2Temp); if ( pwd1.value != pwd2.value ) { if (bMsg) pwd1.focus(); if (bMsg) alert("The password you provided does not match the confirmation password. Please try again!"); return false; } if ( this.min_pass_length > 0 ) { if(pwd1.value.length < this.min_pass_length ) { if (bMsg) pwd1.focus(); if (bMsg) alert("Passwords must be at least " + this.min_pass_length + " characters long. Please try again!"); return false; } } if ( this.max_pass_length > 0 ) { if ( pwd1.value.length > this.max_pass_length ) { if (bMsg) pwd1.focus(); if (bMsg) alert("Passwords cannot be longer than " + this.max_pass_length + " characters long. Please try again!"); return false; } } return true; } function isMinChecked( formName, orig_field_name, bMsg ) { var j; var args = orig_field_name.replace(/ /g,"").split("&"); min = args[0]; num_checked = 0; for ( j = 1; j < args.length; j++ ) { fieldName = args[j]; theField = getInputObject(formName,fieldName ); if ( theField.checked ) { num_checked++; } } if ( num_checked < min ) { if (bMsg) theField.focus(); if (bMsg) this.displayError(formName, orig_field_name ); return false; } return true; } // Requires 2 fields, a text field containing existing filename and // a file upload field, which has the same name as the text field with // "_file" appended to it function isFileValid(formName,fieldName, bMsg) { fileName_exist = getInputObject(formName,fieldName); fileName_upload = getInputObject(formName,fieldName + "_file" ); if ( fileName_exist.value == '' && fileName_upload.value == '' ) { if (bMsg) fileName_upload.focus(); if (bMsg) this.displayError(formName,fieldName,"EMPTY"); return false; } return true; } function isZipValid(formName,zipTemp, bMsg) { zipCode = getInputObject(formName,zipTemp); if ( ! isZip( zipCode ) ) { if (bMsg) this.displayError(formName, zipTemp ); if (bMsg) zipCode.focus(); return false; } return true; } function isPhoneValid(formName,phoneTemp, bMsg) { phoneNumber = getInputObject(formName,phoneTemp); if ( ! isPhone( phoneNumber ) ) { if (bMsg) phoneNumber.focus(); if (bMsg) this.displayError(formName, phoneTemp ); return false; } return true; } function isCurrencyValid( FormName, FieldName, bMsg ) { theField = getInputObject( FormName, FieldName ); if ( ! isCurrency( theField ) ) { if (bMsg) this.displayError(FormName, FieldName ); if (bMsg) theField.focus(); return false; } return true; } function isFloatValid( FormName, FieldName, bMsg ) { theField = getInputObject( FormName, FieldName ); if ( ! isFloat( theField ) ) { if (bMsg) this.displayError(FormName, FieldName ); if (bMsg) theField.focus(); return false; } return true; } function isIntegerValid( FormName, FieldName, bMsg ) { theField = getInputObject( FormName, FieldName ); if ( ! isInteger( theField ) ) { if (bMsg) this.displayError(FormName, FieldName ); if (bMsg) theField.focus(); return false; } return true; } function isUsernameValid( FormName, FieldName, bMsg ) { theField = getInputObject( FormName, FieldName ); if ( ! isUserName( theField ) ) { if (bMsg) this.displayError(FormName, FieldName ); if (bMsg) theField.focus(); return false; } return true; } function isURLValid( FormName, FieldName, bMsg ) { theField = getInputObject( FormName, FieldName ); if ( ! isURL( theField ) ) { if (bMsg) this.displayError(FormName, FieldName ); if (bMsg) theField.focus(); return false; } return true; } function isEmailListValid( FormName, FieldName, bMsg ) { theField = getInputObject( FormName, FieldName ); if ( ! isEmailList( theField ) ) { if (bMsg) this.displayError(FormName, FieldName ); if (bMsg) theField.focus(); return false; } return true; } function isDateValid( FormName, FieldName, bMsg ) { MonthField = getInputObject( FormName, FieldName + "_MONTH" ); DayField = getInputObject( FormName, FieldName + "_DAY" ); YearField = getInputObject( FormName, FieldName + "_YEAR" ); idx = MonthField.selectedIndex; MonthValue = MonthField.options[ idx ].value; DayValue = DayField.value; idx = YearField.selectedIndex; YearValue = YearField.options[ idx ].value; if ( ! CheckDate( MonthValue, DayValue, YearValue ) ) { if (bMsg) this.displayError(FormName, FieldName ); if (bMsg) MonthField.focus(); return false; } return true; } function isTimeValid( FormName, FieldName, bMsg ) { HourField = getInputObject( FormName, FieldName + "_HOUR" ); MinuteField = getInputObject( FormName, FieldName + "_MINUTE" ); AMPMField = getInputObject( FormName, FieldName + "_AMPM" ); HourVal = getValue( HourField ); MinuteVal = getValue( MinuteField ); AMPMVal = getValue( AMPMField ); if (isEmpty( HourVal ) || isEmpty( MinuteVal ) || isEmpty( AMPMVal )) { if (bMsg) this.displayError(FormName, FieldName ); if (bMsg) HourField.focus(); return false; } return true; } // ********************************************************************************* // // Public functions // function isCurrency(Field) { strValue = Field.value; regexp = /^(([0-9]{1,3}(\,[0-9]{3})*)|([0-9]{0,3}))(\.[0-9]{2})?$/ if (isEmpty(strValue)) { return false; } return regexp.test(strValue); } function isFloat(Field) { strValue = Field.value; regexp = /^(\+|\-)?([0-9]+)(((\.|\,)?([0-9]+))?)$/ if (isEmpty(strValue)) { return false; } return regexp.test(strValue); } function isInteger(Field) { strValue = getValue(Field); regexp = /^(\+|\-)?([0-9]+)$/ if (isEmpty(strValue)) { return false; } return regexp.test(strValue); } function isUserName(Field) { strValue = getValue(Field); regexp = /^([^$@\\ ]+)$/ if (isEmpty(strValue)) { return false; } return regexp.test(strValue); } function isCreditCardNumber(Field) { var iChkSum=0; var ccnum = getValue(Field); ccnum = ccnum.replace( /\D/g, "" ); // check for correct card number length if (ccnum.length<13) return false; // make an array and fill it with the individual digits of the cc number ccnumchk=new Array; for (iLoop=0; iLoop < ccnum.length; iLoop++) { ccnumchk[ccnum.length-1-iLoop] = ccnum.substring(iLoop, iLoop+1); } // perform the weird mathematical method (some base 10 stuff) to // convert the number to a two digit number // for those of you who aren't as familiar with the js operators // i'll comment some of the math lines...well, really just one var skemp=0; for (iLoop=0; iLoop < ccnum.length; iLoop++) { // if splits is an even number... if (iLoop %2 != 0) { ccnumchk[iLoop]=ccnumchk[iLoop]*2; if (ccnumchk[iLoop] >= 10) ccnumchk[iLoop]=ccnumchk[iLoop]-9; } // switch ccnumchk[splits] to a number ccnumchk[iLoop]++; ccnumchk[iLoop]--; iChkSum = iChkSum + ccnumchk[iLoop].valueOf(); } if (iChkSum%10 != 0) { return false; } // The result isn't base 10 return true; } function isEmail(Field) { strValue = getValue(Field); regexp = /^[A-Za-z0-9]+[A-Za-z0-9\_\-\.]*\@([A-Za-z0-9\-]+\.)+[A-Za-z]{2,5}$/ if (isEmpty(strValue)) { return false; } return regexp.test(strValue); } function isEmptyWysiwyg(Field) { strValue = getValue(Field); // delete all default tags rexp = / /gi; strValue = strValue.replace(rexp, ''); rexp = /

<\/p>/gi; strValue = strValue.replace(rexp, ''); rexp = /

 <\/p>/gi; strValue = strValue.replace(rexp, ''); if (isEmpty(strValue)) { return true; } return false; } function isURL(Field) { strValue = getValue(Field); regexp = /^http(s?):\/\/([^$@\\ ]+)$/i if (isEmpty(strValue)) { return false; } return regexp.test(strValue); } function isEmailList(Field) { strValue = getValue(Field); // delete all spaces near comma rexp = /, /gi; strValue = strValue.replace(rexp, ','); rexp = / ,/gi; strValue = strValue.replace(rexp, ','); strArray = strValue.split(","); regexp = /^[A-Za-z0-9]+[A-Za-z0-9\_\-\.]*\@([A-Za-z0-9\-]+\.)+[A-Za-z]{2,5}$/ for (var i=0; i < strArray.length; i++) { if (isEmpty(strArray[i])) return false; if (!regexp.test(strArray[i])) return false; } // set new field value (with removed spaces between comma and addresses) Field.value = strValue; return true; } function isZip(Field) { strValue = getValue(Field); if (isEmpty(strValue)) { return false; } if (strValue.indexOf('-') >=0 ) { regexp = /^\d{5}-\d{4}$/ } else { regexp = /^\d{5}$/ } return regexp.test(strValue); } function isPhone(Field) { strValue = getValue(Field); regexp = /^1{0,1} *(-| ){0,1} *[\(]*[0-9]{0,3}[\)]* *(-| ){0,1} *[0-9]{3} *(-| ){0,1} *[0-9]{4}$/; if (isEmpty(strValue)) { return false; } return regexp.test(strValue); } function isFax(Field) { strValue = getValue(Field); regexp = /^\d{3}-\d{3}-\d{4}$/ if (isEmpty(strValue)) { return false; } return regexp.test(strValue); } function isEmpty(s) { if (s == null || trim(s) == '') { return true; } else { return false; } } function isText(f) { return !isEmptyField(f); } function CheckDate(m,d,y) { Months = "31/!/28/!/31/!/30/!/31/!/30/!/31/!/31/!/30/!/31/!/30/!/31"; MonthArray = Months.split("/!/"); if (isNaN(parseInt(m,10))) return false; if (isNaN(parseInt(d,10))) return false; if (isNaN(parseInt(y,10))) return false; d = parseInt(d,10); y = parseInt(y,10); m = parseInt(m,10); y = convertYear(y); if (y <= 1900 ) return false; if (m < 1 || m > 12 ) return false; if ( isLeapYear(y)) MonthArray[1] = eval(eval(MonthArray[1]) + 1); if (d<1 || MonthArray[m-1] < d ) return false; return true; } function convertYear(y) { var borderYEAR = 40; yearvalue = parseInt(y,10); if (isNaN(yearvalue)) return y; if (yearvalue - borderYEAR <= 0) { yearvalue = yearvalue + 2000 } else if (yearvalue - 100 < 0) { yearvalue = yearvalue + 1900 } return yearvalue; } function isLeapYear(Year) { if(Math.round(Year/4) == Year/4){ if(Math.round(Year/100) == Year/100){ if(Math.round(Year/400) == Year/400) return true; else return false; }else return true; } return false; } function getValue(Field) { fieldType = Field.type; if (fieldType == "text") { return getTextValue(Field); } else if (fieldType == "hidden") { return getTextValue(Field); } else if (fieldType == "select-one") { return getListValue(Field); } else if (fieldType == "textarea") { return getTextValue(Field); } else if (fieldType == "file") { return getTextValue(Field); } else if (fieldType == "password") { return getTextValue(Field); } else if (fieldType == "checkbox") { return getCheckboxValue(Field); } else if (isNaN(fieldType)) { return getRadioValue(Field); } else { return getTextValue(Field); } } function getListValue(Field) { return Field[Field.selectedIndex].value; } function getTextValue(Field) { return Field.value; } function getCheckboxValue(Field) { if (Field.checked) return Field.value; return ''; } function getRadioValue(Field) { found = false; if(isNaN(Field.length)) { return Field.value; } for(var i=0; i< Field.length; i++) { if ( Field[i].checked ) { return Field[i].value; break; } } return !found; } function trim(str) { while (str.substring(0,1) == " ") { str = str.substring(1,str.length); } while (str.substring(str.length-1,str.length) == " ") { str = str.substring(0,str.length-1); } return str; } function PutDate(iMonth, iDay, iYear, sMonthCtrlName, sDayCtrlName, sYearCtrlName) { var sMonth, sDay, sYear; var iTmp; sMonth = 'opener.' + sMonthCtrlName; sDay = 'opener.' + sDayCtrlName; sYear = 'opener.' + sYearCtrlName; iTmp = eval(sYear + '[1].value'); if (typeof(opener.document) != 'object') { window.close(); return; } if (opener.document == null) { window.close(); return; } // SET THE VALUE OF THE FIELD THAT WAS PASSED TO THE CALENDAR if (typeof(eval(sMonth)) == "object") eval(sMonth + '.selectedIndex = ' + iMonth); if (typeof(eval(sDay)) == "object") eval(sDay + '.value = ' + iDay); if (typeof(eval(sYear)) == "object") eval(sYear + '.selectedIndex = ' + (iYear-iTmp+1)); // GIVE FOCUS BACK TO THE DATE FIELD if (typeof(eval(sMonth)) == "object") eval(sMonth + '.focus()'); window.close(); } function PickDate(iMonth, iDay, iYear, sMonthCtrlName, sDayCtrlName, sYearCtrlName) { var sURL; sURL = '/includes/datepicker.asp?MONTH=' + iMonth + '&DAY=' + iDay + '&YEAR=' + iYear + '&M_NAME=' + sMonthCtrlName + '&D_NAME=' + sDayCtrlName + '&Y_NAME=' + sYearCtrlName; var newwin = window.open(sURL, 'calendar', 'TOP=150,LEFT=300,WIDTH=170,HEIGHT=220,RESIZABLE=yes,SCROLLBARS=no,STATUS=0'); if (newwin != null) { if (newwin.opener == null) newwin.opener = self; } } function isEmptyList(Field) { return isEmpty(Field[Field.selectedIndex].value); } function isEmptyText(Field) { return isEmpty(Field.value) } function isEmptyCheckbox(Field) { return !Field.checked; } function isEmptyField(Field) { fieldType = Field.type; if (fieldType == "text") { return isEmptyText(Field); } else if (fieldType == "hidden") { return isEmptyText(Field); } else if (fieldType == "file") { return isEmptyText(Field); } else if (fieldType == "select-one") { return isEmptyList(Field); } else if (fieldType == "textarea") { return isEmptyText(Field); } else if (fieldType == "password") { return isEmptyText(Field); } else if (fieldType == "checkbox") { return isEmptyCheckbox(Field) } else if (isNaN(fieldType)) { return isEmptyRadio(Field) } else { return isEmptyText(Field); } } function isDefined(obj) { if(typeof(obj) == "undefined") { return false; } else { return true; } } function isEmptyRadio(Field) { found = false; if(isNaN(Field.length)) { return !Field.checked; } for(var i=0; i< Field.length; i++) { if ( Field[i].checked ) { found = true; break; } } return !found; } function formatCurrency(num, bPrintDollarSign) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); if (bPrintDollarSign) { return (((sign)?'':'-') + '$' + num + '.' + cents); } else { return (((sign)?'':'-') + '' + num + '.' + cents); } } oValidator = new validator();