
// SITE URL ///////////////////////////////////////////////
var site_url = 'http://www.choicetransfers.com/';
///////////////////////////////////////////////////////////



	$(function() {
		$("#arrdate").datepicker({ dateFormat: 'dd/M/yy',  minDate: 0, maxDate: "+12M +10D"  });
		$("#arrdate").datepicker();
		

		$("#depdate").datepicker({ dateFormat: 'dd/M/yy', minDate: 3, maxDate: "+12M +10D"  });
		$("#depdate").datepicker();
		
		var roundtrip = document.getElementById('status');
		if(roundtrip.value=='No') { 
			document.getElementById('depdate').disabled = true; 
			document.getElementById('dephour').disabled = true; 
			document.getElementById('depmin').disabled = true; 
		}
		
		
	});
	
	function roundstatus(val) { 
		if(val=='Yes') {
		document.getElementById('depdate').disabled = false; 
		document.getElementById('dephour').disabled = false; 
		document.getElementById('depmin').disabled = false; 
		}
		else {
			document.getElementById('depdate').disabled = true; 
			document.getElementById('dephour').disabled = true; 
			document.getElementById('depmin').disabled = true;
		}
	}



function check_contacts() {
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if(document.getElementById("name_box").value=='') { alert ('Please provide your name to continue'); return false ; }
	else if(document.getElementById("email_box").value=='') { alert ('Please provide your e-mail to continue'); return false ; }
	else if (document.getElementById("email_box").value.search(emailRegEx) == -1) {
          alert("Please enter a valid email address."); return false ; }
	
	else if(document.getElementById("message_box").value=='') { alert ('Please write a message to continue'); return false ; }
	
}

function check_search() {
	if(document.getElementById("destination_box").value=='') { alert ('Please select a country'); return false ; }
	if(document.getElementById("from_box").value=='') { alert ('Please Select a destination'); return false ; }
	else if(document.getElementById("to_box").value=='') { alert ('Please select the resort area'); return false ; }
}

function check_agreement() {
if(document.getElementById("checkagree").checked=='') { 
alert ('You need to accept the terms of service and confirm your booking to continue'); return false ; }	
}

function check_bookform() {
	
	var currentTime = new Date()
	var month = currentTime.getMonth() + 1
	var day = currentTime.getDate()
	var year = currentTime.getFullYear()
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	
	
	if(document.getElementById("name_box").value=='') { alert ('Please write your name to continue'); return false ; }
	else if(document.getElementById("phone_box").value=='') { alert ('Please write your contact Phone'); return false ; }
	else if(document.getElementById("email_box").value=='') { alert ('Please write your e-mail to continue'); return false ; }
	else if (document.getElementById("email_box").value.search(emailRegEx) == -1) {
          alert("Please enter a valid email address."); return false ;
  	}
	
	else if(document.getElementById("email2_box").value=='') { alert ('Please confirm your e-mail'); return false ; }
	else if (document.getElementById("email2_box").value.search(emailRegEx) == -1) {
          alert("Please enter a valid email address."); return false ;
  	}
	
	else if(document.getElementById("email_box").value!= document.getElementById("email2_box").value) 
	{ alert ('Your e-mail does not match please confirm'); return false ; }
	
	else if(document.getElementById("from_airport").value=='') { 
	alert ('Booking error, please go back and try again!'); return false ; }
	else if(document.getElementById("resort_box").value=='') { 
	alert ('Booking error, please go back and try again!'); return false ; }
	else if(document.getElementById("exact_box").value=='') { 
	alert ('Please write the hotel name where you will be staying in the selected Resort area!'); return false ; }
	else if(document.getElementById("service_box").value=='') { 
	alert ('Booking error, please go back and try again!'); return false ; }
	else if(document.getElementById("pax_box").value=='') { 
	alert ('Booking error, please go back and try again!'); return false ; }
	else if(document.getElementById("journey_box").value=='') { 
	alert ('Booking error, please go back and try again!'); return false ; }
	
	//Arrival
	else if(document.getElementById("arrival_date").value=='') { 
	alert ('Booking error, please go back and try again!'); return false ; }
	else if(document.getElementById("arrival_airline").value=='') { 
	alert ('Please specify the Arrival Airline Name!'); return false ; }
	else if(document.getElementById("arrival_flight").value=='') { 
	alert ('Please write your Arrival Flight Number!'); return false ; }
	
	
	
	if(document.getElementById("journey_box").value=='Yes') { 
	  if(document.getElementById("departure_date").value=='') { alert ('Please select your Departure Date!'); 
	  return false ; }
	  if(document.getElementById("departure_airline").value=='') { alert ('Please specify your departure Airline Name!'); 
	  return false ; }
	  if(document.getElementById("departure_flight").value=='') { alert ('Please write your departure flight number!'); 
	  return false ; }
	}
	
	
	// CREDIT CARD
	
	if(document.getElementById("cardname").value=='') { alert ('Please write your name on card!'); return false ; }
	else if (!isNaN(document.getElementById("cardname").value)) { 
	alert('Card name can not contain numeric values'); return false ; }	
	
	if (!checkCreditCard (document.getElementById('CardNumber').value,document.getElementById('CardType').value)) {
    alert (ccErrors[ccErrorNo]); return false ;
  	}

	if(document.getElementById("valid_month").value<=month && document.getElementById("valid_year").value<=year) { 
	alert ('Credit card expiration date has expired, please use other or contact us'); return false ; }
	
	
	if(document.getElementById("card_code").value=='') { alert ('Please type your Card security code'); return false ; }
	
	if(document.getElementById("CardType").value=='Visa' || document.getElementById("CardType").value=='MasterCard' ) { 
		if (isNaN(document.getElementById("card_code").value)) { 
		alert('Card security code can only be in numeric values'); return false ; } 
		else {
			var str=document.getElementById("card_code").value;
			if(str.length>3 || str.length<3) { alert('Invalid Card Security Code'); return false ; } 
		}
	} // fim de check visa & Mastercard
	
	else if(document.getElementById("CardType").value=='AmEx') { 
		if (isNaN(document.getElementById("Card_code").value)) { 
		alert('Card security code can only be in numeric values'); return false ; } 
		else {
			var str=document.getElementById("Card_code").value;
			if(str.length>4 || str.length<4) { alert('Invalid Card Security Code'); return false ; } 
		}
	} // fim de check American Express
	
	if(document.getElementById("checkagree").checked=='') { 
	alert ('You need to accept the terms of service and confirm your booking to continue'); return false ; }
	
	
}
//////////// AIRPORTS //////////////////////////////////

var ajax = new Array();

function getdest(sel)
{
	var countryCode = sel.options[sel.selectedIndex].value;
	//alert(countryCode);
	document.getElementById('from_box').options.length = 0;	// Empty city select box
	document.getElementById('to_box').options.length = 0;
	if(countryCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = site_url+'getair.php?countryCode='+countryCode;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createair(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function createair(index)
{
	var obj = document.getElementById('from_box');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}




	/////////////////////////////7 CITIES //////////////7
var ajax = new Array();

function getCityList(sel)
{
	var countryCode = sel.options[sel.selectedIndex].value;
	//alert (countryCode);
	document.getElementById('to_box').options.length = 0;	// Empty city select box
	if(countryCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = site_url+'getcities.php?countryCode='+countryCode;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createCities(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function createCities(index)
{
	var obj = document.getElementById('to_box');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}






