/* 
Script Created by: Larry Daughenbaugh [ www.systemsynapse.com ] for Travel Sentry [ www.travelsentry.org ]
*/													
/* =================================================================================================================== Validate Login Form */
function validateLogin(CurrentForm) {
	 if (CurrentForm.strUserName.value == '') {
	  	alert("Please enter your Username.");
    CurrentForm.strUserName.focus();
		return false;
	 }
  if (CurrentForm.strUserName.value.length < 8) {
	  	alert("Your Username must be at least eight characters long.");
    CurrentForm.strUserName.focus();
  return false;
  }
  if (CurrentForm.strPassword.value == '') {
	  	alert("Please enter your Password.");
    CurrentForm.strPassword.focus();
  return false;
  }
  if (CurrentForm.strPassword.value.length < 8) {
	  	alert("Your password must be at least eight characters long.");
    CurrentForm.strPassword.focus();
  return false;
  }
return true;	
}
/* =================================================================================================================== Validate General Help Form */
function validateHelp(CurrentForm) {
	 if (CurrentForm.tbEmail.value == '') {
	  	alert("Please enter your Email Address.");
    CurrentForm.tbEmail.focus();
		return false;
	 }
	 sEmail = CurrentForm.tbEmail.value;
  if(sEmail != "" && sEmail.search(/^[\w-_.]*[\w-_.]@[\w].+[\w]+[\w]$/) == -1){
	  	alert("Please enter a VALID Email Address.");
    CurrentForm.tbEmail.focus();
		return false;
	 }
		invalidChars = " /:,;";
  for (i=0; i<invalidChars.length; i++) {
    badChar = invalidChars.charAt(i);
    if (sEmail.indexOf(badChar,0) > -1) {
	    	alert("Please enter a VALID Email Address.");
      CurrentForm.tbEmail.focus();
      return false;
				}
  }
  if (CurrentForm.tbName.value == '') {
	  	alert("Please enter your Name.");
    CurrentForm.tbName.focus();
  return false;
  }
  if (CurrentForm.tbHelp.value == '') {
	  	alert("Please specify How We Can Help?");
    CurrentForm.tbHelp.focus();
  return false;
  }
return true;	
}
/* =================================================================================================================== Validate Request Info Form */
function validateRequestInfo(CurrentForm) {
	 if (CurrentForm.tbEmail.value == '') {
	  	alert("Please enter your Email Address.");
    CurrentForm.tbEmail.focus();
		return false;
	 }
	 sEmail = CurrentForm.tbEmail.value;
  if(sEmail != "" && sEmail.search(/^[\w-_.]*[\w-_.]@[\w].+[\w]+[\w]$/) == -1){
	  	alert("Please enter a VALID Email Address.");
    CurrentForm.tbEmail.focus();
		return false;
	 }
		invalidChars = " /:,;";
  for (i=0; i<invalidChars.length; i++) {
    badChar = invalidChars.charAt(i);
    if (sEmail.indexOf(badChar,0) > -1) {
	    	alert("Please enter a VALID Email Address.");
      CurrentForm.tbEmail.focus();
      return false;
				}
  }
  if (CurrentForm.ddQuestion.value == '') {
	  	alert("Please select a Security Question.");
  return false;
  }
  if (CurrentForm.tbQuestionAnswer.value == '') {
	  	alert("Please enter your Security Question Answer.");
    CurrentForm.tbQuestionAnswer.focus();
  return false;
  }
return true;	
}
/* =================================================================================================================== Count Form Field Characters */
function txtCounter(field,countfield,maxlimit) {
  if (field.value.length > maxlimit) {
    field.value = field.value.substring(0, maxlimit);
  } else {
    countfield.value = field.value.length;
		}
}
/* =================================================================================================================== Validate Create Industry Account Form */
function validateIndustryAccount(CurrentForm) {
	 if (CurrentForm.tbFirstName.value == '') {
	  	alert("Please enter your First Name.");
    CurrentForm.tbFirstName.focus();
		return false;
	 }
	 if (CurrentForm.tbLastName.value == '') {
	  	alert("Please enter your Last Name.");
    CurrentForm.tbLastName.focus();
		return false;
  }
	 if (CurrentForm.tbEmail.value == '') {
	  	alert("Please enter your Email Address.");
    CurrentForm.tbEmail.focus();
		return false;
  }
  sEmail = CurrentForm.tbEmail.value;
  if(sEmail != "" && sEmail.search(/^[\w-_.]*[\w-_.]@[\w].+[\w]+[\w]$/) == -1){
	  	alert("Please enter a VALID Email Address.");
    CurrentForm.tbEmail.focus();
		return false;
	 }
		invalidChars = " /:,;";
  for (i=0; i<invalidChars.length; i++) {
    badChar = invalidChars.charAt(i);
    if (sEmail.indexOf(badChar,0) > -1) {
	    	alert("Please enter a VALID Email Address.");
      CurrentForm.tbEmail.focus();
      return false;
				}
  }
	 if (CurrentForm.tbEmailVerify.value == '') {
	  	alert("Please enter your Email Address in the Verify Email Field.");
    CurrentForm.tbEmailVerify.focus();
		return false;
  }
  sEmail = CurrentForm.tbEmailVerify.value;
  if(sEmail != "" && sEmail.search(/^[\w-_.]*[\w-_.]@[\w].+[\w]+[\w]$/) == -1){
	  	alert("Please enter a VALID Email Address in the Verify Email Field.");
    CurrentForm.tbEmailVerify.focus();
		return false;
	 }
		invalidChars = " /:,;";
  for (i=0; i<invalidChars.length; i++) {
    badChar = invalidChars.charAt(i);
    if (sEmail.indexOf(badChar,0) > -1) {
	    	alert("Please enter a VALID Email Address in the Verify Email Field.");
      CurrentForm.tbEmailVerify.focus();
      return false;
				}
  }
  if (CurrentForm.tbEmail.value != CurrentForm.tbEmailVerify.value) {
	  	alert("Your Emails do not match. Please correct and try again.");
    CurrentForm.tbEmailVerify.value = "";
    CurrentForm.tbEmail.focus();
  return false;
  }
	 if (CurrentForm.tbUserName.value == '') {
	  	alert("Please specify an account Username.");
    CurrentForm.tbUserName.focus();
		return false;
  }
  if (CurrentForm.tbUserName.value.length < 8) {
	  	alert("Your Username must be at least eight characters long.");
    CurrentForm.tbUserName.focus();
  return false;
  }
	 if (CurrentForm.tbPassword.value == '') {
	  	alert("Please specify an account Password.");
    CurrentForm.tbPassword.focus();
		return false;
  }
  if (CurrentForm.tbPassword.value.length < 8) {
	  	alert("Your password must be at least eight characters long.");
    CurrentForm.tbPassword.focus();
  return false;
  }
	 if (CurrentForm.tbPasswordVerify.value == '') {
	  	alert("Please verify your Password.");
    CurrentForm.tbPasswordVerify.focus();
		return false;
  }
  if (CurrentForm.tbPasswordVerify.value.length < 8) {
	  	alert("The verify Password field must be at least eight characters long.");
    CurrentForm.tbPasswordVerify.focus();
  return false;
  }
  if (CurrentForm.tbPassword.value != CurrentForm.tbPasswordVerify.value) {
	  	alert("Your Passwords do not match. Please correct and try again.");
    CurrentForm.tbPassword.value = "";
    CurrentForm.tbPasswordVerify.value = "";
    CurrentForm.tbPassword.focus();
  return false;
  }
		dropdownChoice = CurrentForm.ddQuestion.selectedIndex
		if (CurrentForm.ddQuestion.options[dropdownChoice].value == "") {
	  	alert("Please select a Security Question.");
		return false;
		}
	 if (CurrentForm.tbQuestionAnswer.value == '') {
	  	alert("Please enter your Answer to your Security Question.");
    CurrentForm.tbQuestionAnswer.focus();
		return false;
  }
	 if (CurrentForm.tbCompanyName.value == '') {
	  	alert("Please enter your Company Name.");
    CurrentForm.tbCompanyName.focus();
		return false;
  }
		dropdownChoice2 = CurrentForm.ddCompanyType.selectedIndex
		if (CurrentForm.ddCompanyType.options[dropdownChoice2].value == "") {
	  	alert("Please select your Company Type.");
		return false;
		}
	 if (CurrentForm.tbAddress.value == '') {
	  	alert("Please enter your Address.");
    CurrentForm.tbAddress.focus();
		return false;
  }
	 if (CurrentForm.tbCity.value == '') {
	  	alert("Please enter your City.");
    CurrentForm.tbCity.focus();
		return false;
  }
		dropdownChoice3 = CurrentForm.ddCountry.selectedIndex
		if (CurrentForm.ddCountry.options[dropdownChoice3].value == "") {
	  	alert("Please select your Country.");
		return false;
		}
	 if (CurrentForm.tbWebsite.value == '') {
	  	alert("Please enter your Company Website.");
    CurrentForm.tbWebsite.focus();
		return false;
  }
  /*
  var websiteURL = CurrentForm.tbWebsite.value;
  var matchURL = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{2}/
  if (matchURL.test(websiteURL)) {
    return true;
  } else {
	  	alert("The Company Website you entered is invalid. Make sure it begins with 'http://'. Revise and try again. \n\n [ Example: http://www.yourwebsite.com ]");
    CurrentForm.tbWebsite.focus();
    return false; 
  }*/
return true;	
}

/* =================================================================================================================== Validate Create Security Account Form */
function validateSecurityAccount(CurrentForm) {
	 if (CurrentForm.tbFirstName.value == '') {
	  	alert("Please enter your First Name.");
    CurrentForm.tbFirstName.focus();
		return false;
	 }
	 if (CurrentForm.tbLastName.value == '') {
	  	alert("Please enter your Last Name.");
    CurrentForm.tbLastName.focus();
		return false;
  }
	 if (CurrentForm.tbEmail.value == '') {
	  	alert("Please enter your Email Address.");
    CurrentForm.tbEmail.focus();
		return false;
  }
  sEmail = CurrentForm.tbEmail.value;
  if(sEmail != "" && sEmail.search(/^[\w-_.]*[\w-_.]@[\w].+[\w]+[\w]$/) == -1){
	  	alert("Please enter a VALID Email Address.");
    CurrentForm.tbEmail.focus();
		return false;
	 }
		invalidChars = " /:,;";
  for (i=0; i<invalidChars.length; i++) {
    badChar = invalidChars.charAt(i);
    if (sEmail.indexOf(badChar,0) > -1) {
	    	alert("Please enter a VALID Email Address.");
      CurrentForm.tbEmail.focus();
      return false;
				}
  }
	 if (CurrentForm.tbEmailVerify.value == '') {
	  	alert("Please enter your Email Address in the Verify Email Field.");
    CurrentForm.tbEmailVerify.focus();
		return false;
  }
  sEmail = CurrentForm.tbEmailVerify.value;
  if(sEmail != "" && sEmail.search(/^[\w-_.]*[\w-_.]@[\w].+[\w]+[\w]$/) == -1){
	  	alert("Please enter a VALID Email Address in the Verify Email Field.");
    CurrentForm.tbEmailVerify.focus();
		return false;
	 }
		invalidChars = " /:,;";
  for (i=0; i<invalidChars.length; i++) {
    badChar = invalidChars.charAt(i);
    if (sEmail.indexOf(badChar,0) > -1) {
	    	alert("Please enter a VALID Email Address in the Verify Email Field.");
      CurrentForm.tbEmailVerify.focus();
      return false;
				}
  }
  if (CurrentForm.tbEmail.value != CurrentForm.tbEmailVerify.value) {
	  	alert("Your Emails do not match. Please correct and try again.");
    CurrentForm.tbEmailVerify.value = "";
    CurrentForm.tbEmail.focus();
  return false;
  }
	 if (CurrentForm.tbUserName.value == '') {
	  	alert("Please specify an account Username.");
    CurrentForm.tbUserName.focus();
		return false;
  }
  if (CurrentForm.tbUserName.value.length < 8) {
	  	alert("Your Username must be at least eight characters long.");
    CurrentForm.tbUserName.focus();
  return false;
  }
	 if (CurrentForm.tbPassword.value == '') {
	  	alert("Please specify an account Password.");
    CurrentForm.tbPassword.focus();
		return false;
  }
  if (CurrentForm.tbPassword.value.length < 8) {
	  	alert("Your password must be at least eight characters long.");
    CurrentForm.tbPassword.focus();
  return false;
  }
	 if (CurrentForm.tbPasswordVerify.value == '') {
	  	alert("Please verify your Password.");
    CurrentForm.tbPasswordVerify.focus();
		return false;
  }
  if (CurrentForm.tbPasswordVerify.value.length < 8) {
	  	alert("The verify Password field must be at least eight characters long.");
    CurrentForm.tbPasswordVerify.focus();
  return false;
  }
  if (CurrentForm.tbPassword.value != CurrentForm.tbPasswordVerify.value) {
	  	alert("Your Passwords do not match. Please correct and try again.");
    CurrentForm.tbPassword.value = "";
    CurrentForm.tbPasswordVerify.value = "";
    CurrentForm.tbPassword.focus();
  return false;
  }
		dropdownChoice = CurrentForm.ddQuestion.selectedIndex
		if (CurrentForm.ddQuestion.options[dropdownChoice].value == "") {
	  	alert("Please select a Security Question.");
		return false;
		}
	 if (CurrentForm.tbQuestionAnswer.value == '') {
	  	alert("Please enter your Answer to your Security Question.");
    CurrentForm.tbQuestionAnswer.focus();
		return false;
  }
	 if (CurrentForm.tbAirportCode.value == '') {
	  	alert("Please enter your Airport Code.");
    CurrentForm.tbAirportCode.focus();
		return false;
  }
		dropdownChoice2 = CurrentForm.ddUserType.selectedIndex
  var APOValue = CurrentForm.ddUserType.options[dropdownChoice2].value

 if (CurrentForm.ddUserType.options[dropdownChoice2].value == "") {
	  	alert("Please select your User Type.");
		return false;
		}
		dropdownChoice3 = CurrentForm.ddOrganization.selectedIndex
		if (CurrentForm.ddOrganization.options[dropdownChoice3].value == "") {
	  	alert("Please select your Organization.");
		return false;
		}
	 if (CurrentForm.tbTitle.value == '') {
	  	alert("Please enter your Title.");
    CurrentForm.tbTitle.focus();
		return false;
  }
		// If APO-Accredited Property Officer is selected, check additional fields
  if (APOValue == "APO-Accredited Property Officer") {
    if (CurrentForm.tbAddress.value == '') {
      alert("Please enter your Address.");
      CurrentForm.tbAddress.focus();
    return false;
    }
    if (CurrentForm.tbCity.value == '') {
      alert("Please enter your City.");
      CurrentForm.tbCity.focus();
    return false;
    }
    dropdownChoice4 = CurrentForm.ddState.selectedIndex
    if (CurrentForm.ddState.options[dropdownChoice4].value == "") {
      alert("Please select your State/Province.");
    return false;
    }
    if (CurrentForm.tbPostalCode.value == '') {
      alert("Please enter your Postal Code.");
      CurrentForm.tbPostalCode.focus();
    return false;
    }
    dropdownChoice5 = CurrentForm.ddCountry.selectedIndex
    if (CurrentForm.ddCountry.options[dropdownChoice5].value == "") {
      alert("Please select your Country.");
      return false;
    }
    if (CurrentForm.tbPhone.value == '') {
      alert("Please enter your Office Phone Number.");
      CurrentForm.tbPhone.focus();
    return false;
    }
		}
  dropdownChoice6 = CurrentForm.ddHub.selectedIndex
  if (CurrentForm.ddHub.options[dropdownChoice6].value == "1" && CurrentForm.tbSpoke01.value == '') {
    alert("You have indicated you are a HUB airport. Please enter at least one airport code for your Spoke airports.");
    CurrentForm.tbSpoke01.focus();
  return false;
  }
	 var APCode = CurrentForm.tbAirportCode.value
		
		if (APCode == CurrentForm.tbSpoke01.value || APCode == CurrentForm.tbSpoke02.value || APCode == CurrentForm.tbSpoke03.value || APCode == CurrentForm.tbSpoke04.value || APCode == CurrentForm.tbSpoke05.value || APCode == CurrentForm.tbSpoke06.value || APCode == CurrentForm.tbSpoke07.value || APCode == CurrentForm.tbSpoke08.value || APCode == CurrentForm.tbSpoke09.value || APCode == CurrentForm.tbSpoke10.value) {
	  	alert("Please do not enter your HUB airport code for any of the SPOKE airport codes.");
		return false;
  }
return true;	
}
/* =================================================================================================================== Validate Account Authentication Form */
function validateAuthenticate(CurrentForm) {
	 if (CurrentForm.tbID.value == '') {
	  	alert("Please enter your Authentication ID.");
    CurrentForm.tbFirstName.focus();
		return false;
	 }
	 if (CurrentForm.tbUserName.value == '') {
	  	alert("Please enter your Account Username.");
    CurrentForm.tbUserName.focus();
		return false;
  }
	 if (CurrentForm.tbPassword.value == '') {
	  	alert("Please enter your Account Password.");
    CurrentForm.tbPassword.focus();
		return false;
  }
return true;	
}