// JavaScript Document
function check_search()
{
	if(document.book.country_id.value=="")
	{
		alert("Select Country.");
		document.book.country_id.focus();
		return false;
	}
	
	if(document.book.type_id[0].checked==false  && document.book.type_id[1].checked==false)
	{
		alert("Select Flight Type.");
		return false;
	}
	
	if(document.book.jid[0].checked==false  && document.book.jid[1].checked==false &&  document.book.jid[2].checked==false)
	{
		alert("Select Journey Type.");
		return false;
	}
	if(document.book.departure_id.value=="")
	{
		alert("Select Departure.");
		document.book.departure_id.focus();
		return false;
	}
	
		
	if(document.book.destination.value=="")
	{
		alert("Select Arrival.");
		return false;
	}
	if(document.book.class_id.value=="")
	{
		alert("Select Class .");
		document.book.class_id.focus();
		return false;
	}
	
	
	
	if(document.book.departure_date.value=="")
	{
		alert("Select Departure Date.");
		document.book.departure_date.focus();
		return false;
	}
	
	if(document.book.jid[1].checked==false)
	{
		
	if(document.book.destination_date.value=="")
	{
		alert("Select Arrival Date.");
		document.book.destination_date.focus();
		return false;
	}
	

	  
  var depart_date = document.book.departure_date.value;
  	var des_date = document.book.destination_date.value;

  /* var pd_temp=new Array();
   var sd_temp=new Array();
   pd_temp=depart_date.split("-");
   sd_temp=des_date.split("-");

		
	 if((pd_temp[2]>sd_temp[2]) )
      {
        alert("Departure Date is greater than the Arrival Date! Please enter proper dates");
        return false;
      }

    
	
	 if((pd_temp[2] == sd_temp[2]))
      {
        if((pd_temp[1]> sd_temp[1]))
        {
        alert("Departure Date is greater than the Arrival Date! Please enter proper dates");
          return false;
        }

        if((pd_temp[1]<= sd_temp[1]))
         {
         if((pd_temp[0]> sd_temp[0]))
         {
        alert("Departure Date is greater than the Arrival Date! Please enter proper dates");
           return false;
         }
        }

      }
	  
	}
*/
 var deadline1=new Array(); //destination adte
   deadline1=des_date.split("-");
   deadline1_year=deadline1[2];
   deadline1_month=deadline1[1];
   deadline1_day=deadline1[0];

   var deadline2=new Array(); //departuer date
   deadline2=depart_date.split("-");
   deadline2_year=deadline2[2];
   deadline2_month=deadline2[1];
   deadline2_day=deadline2[0];


   if((deadline2_year > deadline1_year))
   {
    alert("Departure Date is greater than Return Date!");
    return false;
   }

   if((deadline2_year == deadline1_year))
   {
    if((deadline2_month > deadline1_month))
     {
      alert("Departure Date is greater than Return Date!");
      return false;
     }
     
    if((deadline2_month >= deadline1_month))
    {
     if((deadline2_day > deadline1_day))
     {
      alert("Departure Date is greater than Return Date!");
      return false;
     }
    }

   }
 
 
	  


	  
	  
var adults = parseInt(document.book.adult.options[document.book.adult.selectedIndex].value);
var kids =  parseInt(document.book.child.options[document.book.child.selectedIndex].value);
var infants = parseInt(document.book.infant.options[document.book.infant.selectedIndex].value);
  if ((adults <= 0) && (kids <= 0)) {
    alert("\nYou must enter at least one passenger.\n")
    return false;
  }
  if (adults < infants) {
    alert("\nIf you wish to book a greater number of\nInfants than Adults, please contact our\nreservation center for possible arrangements.\n")
    return false;
  }
  if((adults == 0) && (kids > 0)) {
    alert("Children under 14 years MUST be accompanied by an adult aged 16 years or over.\nUnaccompanied children under 14 will not be permitted to board the aircraft.\nTo proceed please ensure that an adult is travelling with the child.\n\nUnaccompanied children aged between 14 and 15 years should \ncontact their local reservation centre to make a reservation.");
    return false;
  }
  if(adults+kids > 25) {
    alert("You have entered an invalid number of passengers.\nYou are allowed a maximum number of 25 passengers per booking.\n\nIf your party is larger than this, or you wish to \nbook a greater number of infants than adults, \nplease contact our reservation center for \npossible arrangements.\n");
    return false;
  }

}	
}







var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

function check_exist_member()
{
	if(document.member.email.value=="")
	{
	alert("Enter Email Address");
	document.member.email.focus();
	return false;
	}
	if(document.member.email.value!="")
	{
		if (filter.test(document.member.email.value))
		{
		}
		else
		{
			alert("Enter Valid Email Address");
			document.member.email.focus();
			return false;
		 
		}
	}
	
	if(document.member.Password2.value=="")
	{
	alert("Enter Password");
	document.member.Password.focus();
	return false;
	}
	
	
	}



var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard (cardnumber, cardname) {
     
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
  cards [0] = {name: "Visa", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "MasterCard", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "DinersClub", 
               length: "14,16", 
               prefixes: "300,301,302,303,304,305,36,38,55",
               checkdigit: true};
  cards [3] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [4] = {name: "AmEx", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [5] = {name: "Discover", 
               length: "16", 
               prefixes: "6011,650",
               checkdigit: true};
  cards [6] = {name: "JCB", 
               length: "15,16", 
               prefixes: "3,1800,2131",
               checkdigit: true};
  cards [7] = {name: "enRoute", 
               length: "15", 
               prefixes: "2014,2149",
               checkdigit: true};
  cards [8] = {name: "Solo", 
               length: "16,18,19", 
               prefixes: "6334, 6767",
               checkdigit: true};
  cards [9] = {name: "Switch", 
               length: "16,18,19", 
               prefixes: "4903,4905,4911,4936,564182,633110,6333,6759",
               checkdigit: true};
  cards [10] = {name: "Maestro", 
               length: "16,18", 
               prefixes: "5020,6",
               checkdigit: true};
  cards [11] = {name: "VisaElectron", 
               length: "16", 
               prefixes: "417500,4917,4913",
               checkdigit: true};
               
  // Establish card type
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardnumber = cardnumber.replace (/\s/g, "");
  
  // Check that the number is numeric
  var cardNo = cardnumber
  var cardexp = /^[0-9]{13,19}$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}
  

function check_new_member()
{

if(document.member.Title.value=="")
	{
	alert("Select Title ");
	document.member.Title.focus();
	return false;
	}
	
	if(document.member.First_Name.value=="")
	{
	alert("Enter First Name ");
	document.member.First_Name.focus();
	return false;
	}
	
	if(document.member.Last_Name.value=="")
	{
	alert("Enter Last Name ");
	document.member.Last_Name.focus();
	return false;
	}
	
  
   
	
	if(document.member.Address.value=="")
	{
	alert("Enter Address");
	document.member.Address.focus();
	return false;
	}

	if(document.member.Address2.value=="")
	{
	alert("Enter Address");
	document.member.Address2.focus();
	return false;
	}
/*if(document.member.Suburb.value=="")
	{
	alert("Enter Suburb");
	document.member.Suburb.focus();
	return false;
	}
	
if(document.member.State.value=="")
	{
	alert("Enter State");
	document.member.State.focus();
	return false;
	}*/

if(document.member.country_id.value=="")
	{
	alert("Enter Country");
	document.member.country_id.focus();
	return false;
	}
/*if(document.member.Post_Code.value=="")
	{
	alert("Enter Post Code ");
	document.member.Post_Code.focus();
	return false;
	}
	*/
	if(document.member.Email.value=="")
	{
	alert("Enter Email Address");
	document.member.Email.focus();
	return false;
	}
	if(document.member.Email.value!="")
	{
		if (filter.test(document.member.Email.value))
		{
		}
		else
		{
			alert("Enter Valid Email Address");
			document.member.Email.focus();
			return false;
		 
		}
	}
	
	if(document.member.Email.value!=document.member.Confirm_Email.value)
	{
	alert("Your Email Address and confirm Email Address does not match");
			document.member.Confirm_Email.focus();
			return false;
	}

	
	if(document.member.Password.value=="")
	{
	alert("Enter Password");
	document.member.Password.focus();
	return false;
	}
	
	
	if(document.member.Password.value!=document.member.Confirm_Password.value)
	{
	alert("Your Password and Confirm Password field does not match");
	document.member.Confirm_Password.focus();
	return false;
	}
	
	if(document.member.qid.value=="")
	{
	alert("Choose your question");
	document.member.qid.focus();
	return false;
	}
	
	if(document.member.answer.value=="")
	{
	alert("Enter Answer");
	document.member.answer.focus();
	return false;
	}

	if(document.member.Home_Phone.value=="")
	{
	alert("Enter Home Phone");
	document.member.Home_Phone.focus();
	return false;
	}
	/*
	if(document.member.Business_Phone.value=="")
	{
	alert("Enter Business Phone");
	document.member.Business_Phone.focus();
	return false;
	}*/
	if(document.member.Mobile.value=="")
	{
	alert("Enter Mobile");
	document.member.Mobile.focus();
	return false;
	}
	


	
}


  
  function check_rules()
{
 option_selected=0;
  resp_length=document.frmcon.elements['chk[]'].length;
  for(f=0; f<resp_length;f++)
  {  
  if(document.frmcon.elements['chk[]'][f].checked==false)
    {
      option_selected=1;
    }
   
  }
	  if(option_selected==1)
	  {
		alert("You have to agree with terms and conditons!");
		return false;
	  }
  }
  
  
  
  
  function  check_correct_data()
{
if(document.mul.departure_id1.value=='' && document.mul.departure_id2.value=='' && document.mul.departure_id3.value=='' && document.mul.departure_id4.value=='' && document.mul.departure_id5.value=='' && document.mul.departure_id6.value=='' )
{
alert("Select Departures and Destinations to get search results");
	return false;
}
	
departure_id1=document.mul.departure_id1.value;
destination_id1=document.mul.destination_id1.value;
departure_date1=document.mul.departure_date1.value;

departure_id2=document.mul.departure_id2.value;
destination_id2=document.mul.destination_id2.value;
departure_date2=document.mul.departure_date2.value;

departure_id3=document.mul.departure_id3.value;
destination_id3=document.mul.destination_id3.value;
departure_date3=document.mul.departure_date3.value;

departure_id4=document.mul.departure_id4.value;
destination_id4=document.mul.destination_id4.value;
departure_date4=document.mul.departure_date4.value;

departure_id5=document.mul.departure_id5.value;
destination_id5=document.mul.destination_id5.value;
departure_date5=document.mul.departure_date5.value;

departure_id6=document.mul.departure_id6.value;
destination_id6=document.mul.destination_id6.value;
departure_date6=document.mul.departure_date6.value;





if(departure_id1!='' && destination_id1=='')
	{
	alert("Select Destination");
	return false;
	}
	
	if(departure_id1=='' && destination_id1!='')
	{
	alert("Select Departure");
	return false;
	}
	
	deadline1=departure_date1;
  
   var date=new Date(); //to get todays date
   var d  = date.getDate();
   var day = (d < 10) ? '0' + d : d;
   var m = date.getMonth() + 1;
   var month = (m < 10) ? '0' + m : m;
   var yy = date.getYear();
   var year = (yy < 1000) ? yy + 1900 : yy;

   var todays_date=day + "-" + month + "-" + year
  
  if(deadline1!="")
  {

      var temp=new Array();
      temp=deadline1.split("-");

      if((temp[2]< year))
      {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
        return false;
      }


      if((temp[2] == year))
      {
        
        if((temp[1]< month))
        {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
        }
        
        if((temp[1]<= month))
        {
         if((temp[0]< day))
         {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
         }
        
        }
          
      }
   }
	
	
	
	if(departure_id2!='' && destination_id2=='')
	{
	alert("Select Destination");
	return false;
	}
	
	if(departure_id2=='' && destination_id2!='')
	{
	alert("Select Departure");
	return false;
	}
	
	deadline2=departure_date2;
  
   var date=new Date(); //to get todays date
   var d  = date.getDate();
   var day = (d < 10) ? '0' + d : d;
   var m = date.getMonth() + 1;
   var month = (m < 10) ? '0' + m : m;
   var yy = date.getYear();
   var year = (yy < 1000) ? yy + 1900 : yy;

   var todays_date=day + "-" + month + "-" + year
  
  if(deadline2!="")
  {

      var temp=new Array();
      temp=deadline2.split("-");

      if((temp[2]< year))
      {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
        return false;
      }


      if((temp[2] == year))
      {
        
        if((temp[1]< month))
        {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
        }
        
        if((temp[1]<= month))
        {
         if((temp[0]< day))
         {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
         }
        
        }
          
      }
   }
   
   
   
   if(departure_id3!='' && destination_id3=='')
	{
	alert("Select Destination");
	return false;
	}
	
	if(departure_id3=='' && destination_id3!='')
	{
	alert("Select Departure");
	return false;
	}
	
	deadline3=departure_date3;
  
   var date=new Date(); //to get todays date
   var d  = date.getDate();
   var day = (d < 10) ? '0' + d : d;
   var m = date.getMonth() + 1;
   var month = (m < 10) ? '0' + m : m;
   var yy = date.getYear();
   var year = (yy < 1000) ? yy + 1900 : yy;

   var todays_date=day + "-" + month + "-" + year
  
  if(deadline3!="")
  {

      var temp=new Array();
      temp=deadline3.split("-");

      if((temp[2]< year))
      {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
        return false;
      }


      if((temp[2] == year))
      {
        
        if((temp[1]< month))
        {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
        }
        
        if((temp[1]<= month))
        {
         if((temp[0]< day))
         {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
         }
        
        }
          
      }
   }
   
   
   
   
   if(departure_id4!='' && destination_id4=='')
	{
	alert("Select Destination");
	return false;
	}
	
	if(departure_id4=='' && destination_id4!='')
	{
	alert("Select Departure");
	return false;
	}
	
	deadline4=departure_date4;
  
   var date=new Date(); //to get todays date
   var d  = date.getDate();
   var day = (d < 10) ? '0' + d : d;
   var m = date.getMonth() + 1;
   var month = (m < 10) ? '0' + m : m;
   var yy = date.getYear();
   var year = (yy < 1000) ? yy + 1900 : yy;

   var todays_date=day + "-" + month + "-" + year
  
  if(deadline4!="")
  {

      var temp=new Array();
      temp=deadline4.split("-");

      if((temp[2]< year))
      {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
        return false;
      }


      if((temp[2] == year))
      {
        
        if((temp[1]< month))
        {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
        }
        
        if((temp[1]<= month))
        {
         if((temp[0]< day))
         {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
         }
        
        }
          
      }
   }
   
   
   
   if(departure_id5!='' && destination_id5=='')
	{
	alert("Select Destination");
	return false;
	}
	
	if(departure_id5=='' && destination_id5!='')
	{
	alert("Select Departure");
	return false;
	}
	
	deadline5=departure_date5;
  
   var date=new Date(); //to get todays date
   var d  = date.getDate();
   var day = (d < 10) ? '0' + d : d;
   var m = date.getMonth() + 1;
   var month = (m < 10) ? '0' + m : m;
   var yy = date.getYear();
   var year = (yy < 1000) ? yy + 1900 : yy;

   var todays_date=day + "-" + month + "-" + year
  
  if(deadline5!="")
  {

      var temp=new Array();
      temp=deadline5.split("-");

      if((temp[2]< year))
      {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
        return false;
      }


      if((temp[2] == year))
      {
        
        if((temp[1]< month))
        {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
        }
        
        if((temp[1]<= month))
        {
         if((temp[0]< day))
         {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
         }
        
        }
          
      }
   }
   if(departure_id6!='' && destination_id6=='')
	{
	alert("Select Destination");
	return false;
	}
	
	if(departure_id6=='' && destination_id6!='')
	{
	alert("Select Departure");
	return false;
	}
	
	deadline6=departure_date6;
  
   var date=new Date(); //to get todays date
   var d  = date.getDate();
   var day = (d < 10) ? '0' + d : d;
   var m = date.getMonth() + 1;
   var month = (m < 10) ? '0' + m : m;
   var yy = date.getYear();
   var year = (yy < 1000) ? yy + 1900 : yy;

   var todays_date=day + "-" + month + "-" + year
  
  if(deadline6!="")
  {

      var temp=new Array();
      temp=deadline6.split("-");

      if((temp[2]< year))
      {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
        return false;
      }


      if((temp[2] == year))
      {
        
        if((temp[1]< month))
        {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
        }
        
        if((temp[1]<= month))
        {
         if((temp[0]< day))
         {
        alert("Departure Date is less than todays date! Please enter proper Departure Date");
          return false;
         }
        
        }
          
      }
   }
	

}
