	// FORM VALIDATION
	function checkEmail(_email) {
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(_email)) return true; //alert('YES! Correct email address');
		else return false; //alert('NO! Incorrect email address');
	}
	function checkPhone(_phone, _checktype) { 
		_phone = _phone.replace(/\./g,"");
		_phone = _phone.replace(/-/g,"");
		_phone = _phone.replace(/\(/g,"");
		_phone = _phone.replace(/\)/g,"");
		_phone = _phone.replace(/ /g,"");
		switch (_checktype) {
			case "a" :
				//standard US 10
				if (_phone.match(/^\d{3}\d{3}\d{4}$/)) return true;
				break;
			
			case "b" :
				// standard US 7
				if (_phone.match(/^\d{3}\d{4}$/)) return true;
				break;
				
			case "c" :
				// digits only
				if (/^[0-9]+$/m.test(_phone)) return true;
	  			else return false; 			
				break
				
			default :
					// standard US 7 or 10 digit
					if (_phone.match(/^\d{3}\d{3}\d{4}$/)) return true;
					else if (_phone.match(/^\d{3}\d{4}$/)) return true;
					else return false;
					break;
		}

	}
	function checkZip(_zip) {
		filter = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
		if (!filter.test(_zip)) {
			return false;
		} else {
			return true;
		}
	}
	function checkCredit(cardNumber, cardType) {
	  var isValid = false;
	  var ccCheckRegExp = /[^\d ]/;
	  isValid = !ccCheckRegExp.test(cardNumber);
	
	  if (isValid)
	  {
	    var cardNumbersOnly = cardNumber.replace(/ /g,"");cardNumbersOnly = cardNumbersOnly.replace(/-/g,"");
	    var cardNumberLength = cardNumbersOnly.length;
	    var lengthIsValid = false;
	    var prefixIsValid = false;
	    var prefixRegExp;
	
	    switch(cardType)
	    {
	      case "mastercard":
	        lengthIsValid = (cardNumberLength == 16);
	        prefixRegExp = /^5[1-5]/;
	        break;
	
	      case "visa":
	        lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
	        prefixRegExp = /^4/;
	        break;
	
	      case "amex":
	        lengthIsValid = (cardNumberLength == 15);
	        prefixRegExp = /^3(4|7)/;
	        break;
	
		  case "discover":
	        lengthIsValid = (cardNumberLength == 16);
	        prefixRegExp = /^6011/;
	        break;
				   
	      default:
	        prefixRegExp = /^$/;
	        //alert("Card type not found");
			return false;
	    }
	
	    prefixIsValid = prefixRegExp.test(cardNumbersOnly);
	    isValid = prefixIsValid && lengthIsValid;
	  }
	
	  if (isValid)
	  {
	    var numberProduct;
	    var numberProductDigitIndex;
	    var checkSumTotal = 0;
	
	    for (digitCounter = cardNumberLength - 1; 
	      digitCounter >= 0; 
	      digitCounter--)
	    {
	      checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
	      digitCounter--;
	      numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
	      for (var productDigitCounter = 0;
	        productDigitCounter < numberProduct.length; 
	        productDigitCounter++)
	      {
	        checkSumTotal += 
	          parseInt(numberProduct.charAt(productDigitCounter));
	      }
	    }
	
	    isValid = (checkSumTotal % 10 == 0);
	  }
	
	  return isValid;
	}
	function validateRadioButtons(_name) {
		var flag = -1;

		if (_name.length >= 1) {
			for (var i=0; i<=_name.length-1; i++) {
				if (_name[i].checked) flag = 1
			}			 
			 
		} else {
			if (_name.checked) flag = 1
		}

		if (flag > -1) return false
		else return true;
	}
   
	function getRadioValue(_name) {
		var val = "";
		frm = document.forms[0]
		ele = frm.elements[_name]
		if (ele.length >= 1) {
			for (var i=0; i<=ele.length-1; i++) {
				if (ele[i].checked) val = ele[i].value
			}			 
		}
		return val
	}
	
	function IsNumeric(sText) {
		var ValidChars = "0123456789.-";
		var IsNumber=true;
		var Char;
		for (i = 0; i < sText.length && IsNumber == true; i++) 
			{ 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
				{
				IsNumber = false;
				}
			}
		return IsNumber;
   }
   
   	function stripBracketChars(_string) {
		_string = _string.replace(/\</g,"");
		_string = _string.replace(/\>/g,"");
		return _string
	}
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

  function formAction(_frmID,_action,_messdiv) {
		if(validateFields(_frmID,_messdiv)) {
			document.getElementById(_frmID).action = _action
			document.getElementById(_frmID).submit();
			return true;		
		} else {
			return false;
		}	
	}
  function formSubmit(_frmID,_action,_field,_value) {
  		if (_field) document.getElementById(_field).value = _value
		document.getElementById(_frmID).action = _action
		document.getElementById(_frmID).submit();
		return true;		
	}
	
  function formActionCharter_novalidate(_frmID,_action) {
	// skip validation for testing
	document.getElementById(_frmID).action = _action
	doGoogle(_frmID);
	document.getElementById(_frmID).submit();
	return true;
  
  }
  function formActionCharter(_frmID,_action,_messdiv) {
		PaxValid = false;

		inpPaxVal1 = document.getElementById("Number_of_Passengers")
		// clean up pax value
		inpPaxVal1.value = stripClean(inpPaxVal1.value)
		// if zero is leading digit, revalue as invalid
		if (inpPaxVal1.value.substring(0,1).indexOf("0") > -1) inpPaxVal1.value = "0";
		
		// check charter_type ... if lux then skip complex passenger count validation -- bit check for null value
		if (getRadioValue("Charter_Type") == "Luxury") {
		
				if ( (IsNumeric(inpPaxVal1.value)) && (inpPaxVal1.value != "") && (inpPaxVal1.value != "0") ) {
				
						if(validateFields(_frmID,_messdiv)) {
							document.getElementById(_frmID).action = _action
							doGoogle(_frmID);
							document.getElementById(_frmID).submit();
							return true;		
						} else {
							return false;
						}	
						
				} else {
			
						PaxValid = false;
						paxMsg = "Invalid Passenger Count";
						
						mrDiv = document.getElementById("msgRequiredDiv");
						mrDiv.innerHTML = paxMsg;
						
						paxMsg = "Please specify the number of expected passengers.";
						alert(paxMsg);
						return false
				}
									
									
		} else {
		
	
			if ( (IsNumeric(inpPaxVal1.value)) && (inpPaxVal1.value != "") && (inpPaxVal1.value != "0") ) {
				
				
				if (inpPaxVal1.value < 50) {
					PaxValid = false;
					paxMsg = "Invalid Passenger Count";
					
					mrDiv = document.getElementById("msgRequiredDiv");
					mrDiv.innerHTML = paxMsg;
					
					paxMsg = "You have entered a passenger count of " + inpPaxVal1.value + "\nOur minimum cabin configuration is 196 seats.";
					alert(paxMsg);
					return false
					
				} else {
					
					
					if (inpPaxVal1.value >= 150) PaxValid = true;
					else PaxValid = false;
					paxMsg = "You have entered a passenger count of " + inpPaxVal1.value + "\nOur minimum cabin configuration is 196 seats.  Do you wish to continue?"
				
						if (PaxValid) {
									if(validateFields(_frmID,_messdiv)) {
										document.getElementById(_frmID).action = _action
										doGoogle(_frmID);
										document.getElementById(_frmID).submit();
										return true;		
									} else {
										return false;
									}	
									
						} else {
							
							if (confirm(paxMsg)) {
							
							
									if(validateFields(_frmID,_messdiv)) {
										document.getElementById(_frmID).action = _action
										doGoogle(_frmID);
										document.getElementById(_frmID).submit();
										return true;		
									} else {
										return false;
									}	
							

							} else {
								return false
							}

						}
		
					} // < 50
				
			} else {
				PaxValid = false;
				paxMsg = "Invalid Passenger Count"
				
				mrDiv = document.getElementById("msgRequiredDiv")
				mrDiv.innerHTML = paxMsg;
				return false
			}
			
		} // if charter_type
			
		

	}
	
	function trim(strText) { 
		   // this will get rid of leading spaces 
		while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

		// this will get rid of trailing spaces 
		while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

		return strText;
	} 
	function resetBckgr(_this, _messdiv) {
		_this.className="winXp"
		if ((_messdiv > "") && (_messdiv != undefined)) _messdiv = "msgRequiredDiv" + _messdiv
		else _messdiv = "msgRequiredDiv"
		mrDiv = document.getElementById(_messdiv)
		mrDiv.innerHTML = "";
	}
	function validateFields(_frmID,_messdiv) {
		msgRequired = ""
		msgInvalid = ""
		msgDiv = ""
		frm = document.getElementById(_frmID)
		var SepChar = ""
		for (i=0;i<frm.length;i++) {
			frmElement = frm.elements[i]
			eleName = frmElement.getAttribute('name')
			eleRequired = frmElement.getAttribute('required')
			eleValidate = frmElement.getAttribute('validate')
			eleErrortext = frmElement.getAttribute('errortext')
			canBeValidated = true
			
			frmElement.value = stripBracketChars(frmElement.value);
			frmElement.value = trim(frmElement.value);
			
			//REQUIRE
			if (eleRequired == "true") {
				if (frmElement.value == "") {
					msgRequired += SepChar + eleErrortext;
					var SepChar = ", "
					canBeValidated = false
				} else {
					canBeValidated = true
				}
			}
			
			// VALIDATE 
			if ((eleValidate == "true") && (canBeValidated == true)) {
			
					//email address
					if (frmElement.id.indexOf("email") > -1) {
					
						if (document.getElementById("email2")) {
							// There is a second (confirm email box)
							if (frmElement.value == trim(document.getElementById("email2").value)) {
								//confirm email address match
								if(!checkEmail(frmElement.value)) {
									if (msgInvalid > "") msgInvalid += "and Invalid Email Address  "
									else msgInvalid = "\nInvalid Email Address  "
								}
							} else {
									if (msgInvalid > "") msgInvalid += "and Email Addresses do not match "
									else msgInvalid = "\nEmail Addresses do not match  "
									document.getElementById("email2").className = "valXp"
							}
						} else {
							// Only one email (no comapre)
								if(!checkEmail(frmElement.value)) {
									if (msgInvalid > "") msgInvalid += "and Invalid Email Address  "
									else msgInvalid = "\nInvalid Email Address  "
								}
						
						}
					} 
					// new password
					if (frmElement.name == "newpassword") {
							if (frmElement.value != document.getElementById("newpassword2").value) {
								//passwords do not match
									if (msgInvalid > "") msgInvalid += "and New Passwords do not match "
									else msgInvalid = "\nNew Passwords do not match  "
									frmElement.className = "valXp"
									document.getElementById("newpassword2").className = "valXp"
							}
					} 
					//phone number
					if (frmElement.id.toLowerCase().indexOf("phone") > -1) {
							if(!checkPhone(frmElement.value,"c")) {
								if (msgInvalid > "") msgInvalid += "and Invalid Phone Number  ";
								else msgInvalid = "\nInvalid Phone Number ";
								_phone = ""
							}
							else {
								_phone = frmElement.value
							}
					}	
					//fax number
					if (frmElement.id.toLowerCase().indexOf("fax") > -1) {
							if(!checkPhone(frmElement.value,"c")) {
								if (msgInvalid > "") msgInvalid += "and Invalid Fax Number  ";
								else msgInvalid = "\nInvalid Fax Number ";
								_phone = ""
							}
							else {
								_phone = frmElement.value
							}
					}	
					// credit card
					if (frmElement.id == "Payment_CardType") {
						_cardType = frmElement.value;
					}
					//cardNumber
					if ((frmElement.id == "Payment_CardNumber") && (_cardType != "")) {
							if(!checkCredit(frmElement.value, _cardType)) {
								msgInvalid = "Invalid Credit Card Number "
								frmElement.className = "valXp"
							}
					} 
					//cardexpmo
					if (frmElement.id == "Payment_ExpirationMonth")  { 
							var nowDate = new Date()
							var nowMonth = nowDate.getMonth()+1
							var nowYear = nowDate.getYear()
							if(nowYear<1000) nowYear+=1900
							if (document.getElementById("Payment_ExpirationYear").value > nowYear) { }
							else {
								if (frmElement.value.indexOf("0") == 0) {
									selMonth = frmElement.value.substring(1)
									if (selMonth < nowMonth) {
											if (msgInvalid > "") msgInvalid += "and Invalid Expiration Date  ";
											else msgInvalid = "\n Invalid Expiration Date  ";
									}
								}
							}
					}	
					
					
			
			}
		}
	
		if((msgRequired > "") || (msgInvalid > "")){
		// alert("Please correct the following:" + msgRequired);
			if (msgRequired > "") {
				if (msgRequired.indexOf(",") > 0) msgDiv = msgRequired + " are required.<br>";
				else msgDiv = msgRequired + " is required.<br>";
			} else {
				//msgDiv = "<br>"
			}
			
			if (msgInvalid > "") msgDiv += msgInvalid;
			//else msgDiv += "<br>"
			// alert(msgDiv)
			if ((_messdiv > "") && (_messdiv != undefined)) _messdiv = "msgRequiredDiv" + _messdiv
			else _messdiv = "msgRequiredDiv"
			mrDiv = document.getElementById(_messdiv)
			mrDiv.innerHTML = msgDiv;
			return false
		} else {
			//replace with reformatted phone number
			//document.getElementById("phone1").value = formatPhone(_phone);
			//if (document.getElementById("phone2").value > "" ) document.getElementById("phone2").value = formatPhone(document.getElementById("phone2").value);
			//if (document.getElementById("phone3").value > "" ) document.getElementById("phone3").value = formatPhone(document.getElementById("phone3").value);
			//alert(document.getElementById("phone1").value)
			//submit the form
			return true;
		}
	}
	
