var ns6 = document.getElementById&&!document.all?1:0
var head = "display:''"
var folder = ''

function ClearSearchField() {
	var searchValue;

	searchValue = document.forms['search'].elements['f_keywords'];

	if (searchValue.value == 'Enter Keyword(s)') {
		searchValue.value = '';
	}
}

function OpenPopup(sURL, sWindowName, iWidth, iHeight, sScrollYesNo, sResizableYesNo) {
	var fLeftPosition, fTopPosition;
	var sSettings;

	fLeftPosition = (screen.width) ? (screen.width-iWidth)/2 : 0;
	fTopPosition = (screen.height) ? (screen.height-iHeight)/2 : 0;

	sSettings = 'height='+ iHeight +',width='+ iWidth +',top='+ fTopPosition +',left='+ fLeftPosition +',scrollbars='+ sScrollYesNo +',resizable=' + sResizableYesNo
	window.open(sURL, sWindowName, sSettings)
}

function MarkCheckboxes(sFieldName, sAction) {
	for (i = 0; i < document.main[sFieldName].length; i++) {
        document.main[sFieldName][i].checked = sAction;
    }
}

function expandit(obj, objid) {
    folder = document.getElementById('SPAN' + objid).style;
    img = document.getElementById('IMG' + objid);

    if (folder.display == "none") {
        folder.display = "block";
        img.src = img.src.replace(/plus/i, "minus");
    }
    else {
        folder.display = "none";
        img.src = img.src.replace(/minus/i, "plus");
    }
}

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.isErrorValid = isErrorValid;
	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 validateOne(validatedForm, validatedField) {
	var index = this.getIndex(validatedForm, validatedField);

	if (index < 0) {
		optionalFlag = true;
		validationType = "TEXT";
	}
	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 == "TEXT") {
		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 == "ERROR") {
		if (!this.isErrorValid(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 isErrorValid(formName, fieldName, bMsg) {
	oField = getInputObject(formName, fieldName);

	if (bMsg) oField.focus();
	if (bMsg) this.displayError(formName, fieldName, "EMPTY");
	return false;
}

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 = 12;
	thisyear = 2099;

	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 isMinChecked(formName, orig_field_name, bMsg) {
	var oField = document.forms[formName].elements[orig_field_name];
	var iCount = 0;

    for (i = 0; i < oField.length; i++) {
        if (oField[i].checked) {
			++iCount;
		}
    }

    if (iCount < 1) {
		if (bMsg) this.displayError(formName, orig_field_name);
		return false;
	}

	return true;
}

/*
function isMinChecked(formName, orig_field_name, bMsg) {
	var j;
	alert(orig_field_name);
	var args = orig_field_name.replace(/ /g,"").split("&");

	min = args[0];
	num_checked = 0;

	alert(formName + ': min = ' + min + ' / num_checked = ' + num_checked + ' / length = ' + args.length);

	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 IsPhoneUS(v, o) {
	var n = (''+Num(v.R(/x.*$/i, ''))).R(/^\+?1/, ''), x = v.R(/^.*x/i, ''), b = Match(n, /[2-9][\d]{2}[2-9][\d]{6}/);
	if (o && b) Set(o, n.R(/^([\d]{3})([\d]{3})([\d]{4})/, '$1-$2-$3') + (x != v ? ' ext. '+Num(x) : ''));
	return b;
}

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) {
	min_username_len = 3;
	max_username_len = 25;

	theField = getInputObject(FormName, FieldName);
	iFieldLen = getValue(theField).length;

	if (iFieldLen < min_username_len) {
		if (bMsg) alert("Usernames must be at least " + min_username_len + " characters long. Please try again!");
		if (bMsg) theField.focus();
		return false;
	}

	if (iFieldLen > max_username_len) {
		if (bMsg) alert("Usernames cannot be longer than " + max_username_len + " characters long. Please try again!");
		if (bMsg) theField.focus();
		return false;
	}

	if (!isUserName(theField)) {
		if (bMsg) this.displayError(FormName, FieldName);
		if (bMsg) theField.focus();
		return false;
	}
	return true;
}

function isPasswordValid(formName, pwd1Temp, pwd2Temp, bMsg) {
	pwd1 = getInputObject(formName, pwd1Temp);
	pwd2 = getInputObject(formName, pwd2Temp);

	if (isEmptyField(pwd1)) {
		if (bMsg) alert("Field value for 'Password' is invalid.");
   		if (bMsg) pwd1.focus();
		return false;
	}

	if (isEmptyField(pwd2)) {
		if (bMsg) alert("Field value for 'Verify Password' is invalid.");
   		if (bMsg) pwd2.focus();
		return false;
	}

	if (pwd1.value != pwd2.value) {
		if (bMsg) alert("The password you provided does not match the confirmation password. Please try again!");
   		if (bMsg) pwd1.focus();
		return false;
	}

	if (this.min_pass_length > 0) {
		if(pwd1.value.length < this.min_pass_length) {
			if (bMsg) alert("Passwords must be at least " + this.min_pass_length + " characters long. Please try again!");
			if (bMsg) pwd1.focus();
			return false;
		}
	}

	if (this.max_pass_length > 0) {
		if (pwd1.value.length > this.max_pass_length) {
			if (bMsg) alert("Passwords cannot be longer than " + this.max_pass_length + " characters long. Please try again!");
			if (bMsg) pwd1.focus();
			return false;
		}
	}

	return true;
}

function setpasswordsize(min, max) {
	this.min_pass_length = min;
	this.max_pass_length = max;
}

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 = /&nbsp;/gi;
	strValue = strValue.replace(rexp, '');
	rexp = /<p><\/p>/gi;
	strValue = strValue.replace(rexp, '');
	rexp = /<p>&nbsp;<\/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(Phone) {
	return Phone.value.replace(/[^0-9]/g, '').length == 10;
}

function isPhoneOld(Field) {
	strValue = getValue(Field);

	regexp = /^(0|1){0,1} *(-| ){0,1} *[\(]*[0-9]{0,3}[\)]* *(-| ){0,1} *[0-9]{3} *(-| ){0,1} *[0-9]{3,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.php?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) {
	if (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);
		}
	}
	else {
		return true;
	}
}

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);
  	}
}


function CheckAllItems(sForm, sField, sAction) {
	var i = 0;

	if (document.getElementById) {
		var fItems = document.records[sField];

		if (isNaN(fItems.length)) {
			fItems.checked = sAction;
		}
		else {
			for (i = 0; i < fItems.length; i++) {
				fItems[i].checked = sAction;
			}
		}
	}
}

function BreakFrames() {
  	if (top.location != location) {
		top.location.href = document.location.href;
  	}
}

function ToggleProfile(i) {
	var sDisplay = 'none';
	var i2;

	if (document.getElementById) {
		for (i2 = 1; i2 <= 4; ++i2) {
			sDisplay = (i == i2 ? 'block' : 'none');

			document.getElementById('profile_profile_nav' + i2).style.display = sDisplay;
			document.getElementById('profile_profile_box' + i2).style.display = sDisplay;
		}
	}

	return false;
}

function ToggleSpotlights(i) {
	var sDisplay = 'none';
	var i2;

	if (document.getElementById) {
		for (i2 = 0; i2 <= 2; ++i2) {
			sDisplay = (i == i2 ? 'block' : 'none');

			document.getElementById('spotlight' + i2).style.display = sDisplay;
		}
	}

	return false;
}

function UpdateSearchProducts() {
	var sProduct = document.header_search.search_product.value;
	var sProductHTML = '<input type="checkbox" name="f_products[]" value="' + sProduct + '" id="product_' + sProduct + '" checked="checked" class="checkbox" /> <label for="product_' + sProduct + '">' + sProduct + '</label><br />';
	document.getElementById("search_products2_list_html").innerHTML = sProductHTML + document.getElementById('search_products2_list_html').innerHTML;
	document.header_search.search_product.value = '';
}

function preview_coupon(event, special_id) {
	if (browser.isIE) {
	    x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
	    y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	if (browser.isNS) {
	    x = event.clientX + window.scrollX;
	    y = event.clientY + window.scrollY;
	}


	new Ajax.Request (
		'/salons/special.php',
		{queue: {position: 'end', scope: 'command'},
			method: 'post',
			postBody: 'special_id=' + special_id + '&ajax=true',
			onComplete: function(response) {
			   document.getElementById('coupon_div').innerHTML=response.responseText;
			   document.getElementById('coupon_div').style.left=(x - (700 / 2))  + 'px';
			   document.getElementById('coupon_div').style.top=(y - (432 / 2))  + 'px';
			   document.getElementById('coupon_div').style.display='block';
			}
		}
	);
}

function Browser() {
	var ua, s, i;

  	this.isIE    = false;
  	this.isNS    = false;
  	this.version = null;

  	ua = navigator.userAgent;

  	s = "MSIE";
  	if ((i = ua.indexOf(s)) >= 0) {
    	this.isIE = true;
    	this.version = parseFloat(ua.substr(i + s.length));
    	return;
  	}

  	s = "Netscape6/";
  	if ((i = ua.indexOf(s)) >= 0) {
    	this.isNS = true;
    	this.version = parseFloat(ua.substr(i + s.length));
    	return;
  	}

  	// Treat any other "Gecko" browser as NS 6.1.

  	s = "Gecko";
  	if ((i = ua.indexOf(s)) >= 0) {
    	this.isNS = true;
    	this.version = 6.1;
    	return;
  	}
}

function getcities(state, city) {
	if (state !== "") {
		document.getElementById("citymenu").style.display = "block";

		new Ajax.Request (
			'/includes/getcities.php', {
				queue: {position: 'end', scope: 'command'},
				method: 'post',
				postBody: 'state='+state+'&ajax=true',
				onComplete: function(response) {
					document.getElementById('citymenu').options.length = 0;
					cityarray = response.responseText.split("~|~");
					document.getElementById('citymenu').options[0] = new Option('- Select City -', '');

					for (i = 0; i < cityarray.length; i++) {
						if (cityarray[i] !== "") {
							document.getElementById('citymenu').options[i + 1] = new Option(cityarray[i], cityarray[i]);
							if (city == cityarray[i]) document.getElementById('citymenu').options[i + 1].selected = 1;
						}
					}
				}
			}
		);
	}
}

function ChangeHeaderImage(i) {
	if (document.getElementById) {
		for (iCount = 0; iCount <= 6; ++iCount) {
			document.getElementById("homepage_image" + (iCount)).style.display = "none";
			document.getElementById("hit" + (iCount)).style.display = "none";
			document.getElementById("hit_bg" + (iCount)).style.display = "none";
		}
		document.getElementById("homepage_image" + (i)).style.display = "block";
		document.getElementById("hit" + (i)).style.display = "block";
		document.getElementById("hit_bg" + (i)).style.display = "block";
	}
}

function DisplayCallout(i) {
	if (document.getElementById) {
		for (iCount = 1; iCount <= 3; ++iCount) {
			document.getElementById("callout" + (iCount)).style.display = "none";
		}

		document.getElementById("callout" + (i)).style.display = "block";
	}
}


var browser = new Browser();
oValidator = new validator();