// JavaScript Document

var OneWay = false



function CheckForm(RegForm) 
{
	//checks the form listed online
	var valid = true
	
	if (RegForm.Passengers.value =="0") {
			alert('Please select the number of passenger.');
			RegForm.Passengers.focus();
			return false //valid = 0
		}
		
	if (RegForm.First_Name.value == "") {
			alert('Please enter First Name');
			RegForm.First_Name.focus();
			return false //valid = 0
		}
		
	if (RegForm.Last_Name.value == "") {
			alert('Please enter your Last Name');
			RegForm.Last_Name.focus();
			return false //valid = 0
		}
		
	if (RegForm.Departing_From.value == "-") {
			alert('Please select a Departing Location from the list.');
			RegForm.Departing_From.focus();
			return false //valid = 0
		}
		
	if (RegForm.Arriving_To.value == "-") {
			alert('Please select a Destination Location from the list');
			RegForm.Arriving_To.focus();
			return false //valid = 0
		}
	
	if (RegForm.Departing_From.value == RegForm.Arriving_To.value) {
			alert('Please select a different Arriving To location (not same as Departing From)');
			RegForm.Arriving_To.focus();
			return false //valid = 0
	}
	
	if (RegForm.Returning_From.value == "-") {
			alert('Please select a Returning Location, if One Way trip, please select One Way from the list');
			RegForm.Returning_From.focus();
			return false //valid = 0
		}
	else if (RegForm.Returning_From.value == "One Way")
		{
			if (RegForm.Returning_To.value != "One Way") 
			{
				alert('Please select "One Way" from the Returing To list');
				RegForm.Returning_To.focus();
				return false //valid = 0
			}
			else if (RegForm.Returning_To.value == "One Way") 
			{
				RegForm.Returning_To.value = "One Way";
				OneWay = true;
			}
		}
	
	if (RegForm.Returning_To.value == "-") {
			alert('Please select a Returning To Location, if One Way trip, please select One Way from the list');
			RegForm.Returning_To.focus();
			return false //valid = 0
		}
	
	if (OneWay = false) 
	{
		if (RegForm.Returning_From.value == RegForm.Returning_To.value) 
		{
			alert('Please select a different Returning To location (not same as Returning From)');
			RegForm.Returning_To.focus();
			return false //valid = 0
		}
	}
	
	if (RegForm.Booking_Class.value =="-") {
			alert('Please select a Booking Class from the list');
			RegForm.Booking_Class.focus();
			return false //valid = 0
		}
	
	
	if (RegForm.Depart_Day.value =="-") {
			alert('Please select a Departure Day');
			RegForm.Depart_Day.focus();
			return false //valid = 0
		}
	if (RegForm.Depart_Month.value =="-") {
			alert('Please select a Departure Month');
			RegForm.Depart_Month.focus();
			return false //valid = 0
		}
	if (RegForm.Depart_Year.value =="-") {
			alert('Please select a Departure Year');
			RegForm.Depart_Year.focus();
			return false //valid = 0
		}
		
	
	if (OneWay == false)
	{
		if (RegForm.Return_Day .value =="-") {
				alert('Please select a Returning Day');
				RegForm.Return_Day .focus();
				return false //valid = 0
			}
		if (RegForm.Return_Month.value =="-") {
				alert('Please select a Returning Month');
				RegForm.Return_Month.focus();
				return false //valid = 0
			}
		if (RegForm.Return_Year.value =="-") {
				alert('Please select a Returning Year');
				RegForm.Booking_Class.focus();
				return false //valid = 0
			}
	}
	
	//Country_Code ""
	//Area_Code
	//Phone_Number 
	
	//telephone
	if(RegForm.Country_Code.value==""){ 
			alert('Please enter Telephone Number');
			RegForm.Country_Code.focus();
			return false //valid = 0
	}
	else if (!IsNumeric(RegForm.Country_Code.value)){
			alert('Please enter Numeric Country Code');
			RegForm.Country_Code.focus();
			return false //valid = 0
	}
	
	//area_code
	if(RegForm.Area_Code.value==""){ 
			alert('Please enter Telephone Number');
			RegForm.Country_Code.focus();
			return false //valid = 0
	}
	else if (!CheckPhoneNumber(RegForm.Area_Code.value,2)){
			alert('Please enter Numeric and/or 3 digit Area Code');
			RegForm.Area_Code.focus();
			return false //valid = 0
	}
	
	//Phone_Number
	if(RegForm.Phone_Number.value==""){ 
			alert('Please enter Telephone Number');
			RegForm.Phone_Number.focus();
			return false //valid = 0
	}
	else if (!CheckPhoneNumber(RegForm.Phone_Number.value,6)) {
			alert("Please enter a Numeric and/or 7 digit Telephone number");
			RegForm.Phone_Number.focus();
			return false //valid = 0
		}
	
	
	
	//email address
	if(RegForm.Email_Address.value==""){ 
			alert('Please enter an Email Address');
			RegForm.Email_Address.focus();
			return false //valid = 0
	}
	else if (!EmailCheck(RegForm.Email_Address.value)) {
			RegForm.Email_Address.focus();
			return false //valid = 0
	}
	
	//address
		
	if (RegForm.Street_Address.value == "") {
			alert('Please enter Street Address');
			RegForm.Street_Address.focus();
			return false //valid = 0
		}
	if (RegForm.City.value == "") {
			alert('Please enter City');
			RegForm.City.focus();
			return false //valid = 0
		}
	if (RegForm.Province.value == "") {
			alert('Please enter State/Province');
			RegForm.Province.focus();
			return false //valid = 0
		}
	
	if (RegForm.Postal_Code.value == "") {
			alert('Please enter Zip/Postal Code');
			RegForm.Postal_Code.focus();
			return false //valid = 0
		}
	else if(!IsNumeric(RegForm.Postal_Code.value)){
			alert('Please enter NUMERIC Zip/Postal Code');
			RegForm.Postal_Code.focus();
			return false //valid = 0
	}
	
	if (RegForm.Country.value == "") {
			alert('Please enter Country');
			RegForm.Country.focus();
			return false //valid = 0
		}
	


	return valid
}


function CheckPhoneNumber(TheNumber,LMax) {
	var valid = true;
	var GoodChars = "0123456789-";
	var i = 0;

	if( (TheNumber.length-1)== LMax )
		{valid =true;}
	else
		{valid = false;}
		
	for (i =0; i <= TheNumber.length -1; i++) {
		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
		// Note: Remove the comments from the following line to see this
		// for loop in action.
		
		valid = false;
		} // End if statement
	} // End for loop
		
	return valid;
}

/*
function CheckPhoneNumber(TheNumber,TypePhone) {
var valid = true
var GoodChars = "0123456789-+."
var i = 0

for (i =0; i <= TheNumber.length -1; i++) {
if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
valid = false
} // End if statement
	} // End for loop
if (valid == false)
	alert("Please enter a correct or NUMERIC " + TypePhone +" number");
	
return valid
}
*/
function IsNumeric(s){
		var i;
		for (i = 0; i < s.length; i++){   
						// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9")))
			{ 
				return false;
			}
		}
					
		// All characters are numbers.
		return true;
}
					
function EmailCheck (emailStr) {
 
var emailPat=/^(.+)@(.+)$/ 
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/ 
var atom=validChars + '+'
 
var word="(" + atom + "|" + quotedUser + ")"
 
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
 
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {

	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]
 
// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    return false
}
 
/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return false
}
 
// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

 
/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}
 
// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}
 
// If we've gotten this far, everything's valid!
return true
}

// end hiding contents from old browsers  -->

