function emailck(objToCheck) {
				spedia_re= /[^A-Za-z0-9_.@\-]/g;
				var array1 = objToCheck.value.match(spedia_re);									
				
				if ( ( array1 == null && (objToCheck.value.indexOf("@") == -1 || objToCheck.value.indexOf(".") == -1))){
		      	alert('Please enter a valid email.');
      			objToCheck.focus();
		        return false;
			   }
			   return true;
			   
			}

function isDate(dtStr){
				var myRegex = new RegExp("^([0-2][0-9]|[3][0-1])\/([0][0-9]|[1][0-2])\/[0-9]{4}$");
				var myRegex2 = new RegExp("^([0-2][0-9]|[3][0-1])\.([0][0-9]|[1][0-2])\.[0-9]{4}$");
				if ( (dtStr.match(myRegex)) || (dtStr.match(myRegex2)) )
					{//valid date format, check for valid date dd/mm/yyyy
					var theDay = Math.round(dtStr.substr(0,2));
					var theMonth = Math.round(dtStr.substr(3,2));
					var theYear = Math.round(dtStr.substr(6,4));
					
					if (theYear< 2005) {
						alert ("The year has to be greater then 2004.");
						return false;
						}
					else if ((theYear%4 == 0) && (theDay > 29) && (theMonth == 2)) {
						alert ("Not a valid date (dd/mm/yyyy).");
						return false;
						}
					else if ((theYear%4 != 0) && (theDay > 28) && (theMonth == 2)) {
						alert ("Not a valid date (dd/mm/yyyy).");
						return false;
						}
					else if ((theDay > 30) && ((theMonth == 0) || (theMonth == 4) || (theMonth == 6) || (theMonth == 9) || (theMonth == 11) )) {
						alert ("Not a valid date (dd/mm/yyyy).");
						return false;
						}
					else {
						return true;
						}
					}
				else
					{
					alert ("Date not in correct dd/mm/yyyy format.");
					return false;
					}
				
			
			}	
	
function checkmyDates(day1,day2,month1,month2,year1,year2) 
{
			
		if (parseFloat(year1) > parseFloat(year2)) 
		{
			alert("First date is later than second date. Please correct that.");
			return false;
		}
		if (parseFloat(year1) == parseFloat(year2)) 
		{
			if (parseFloat(month1) > parseFloat(month2)) 
			{
				alert("First date is later than second date. Please correct that.");
 				return false;
			}
			if (parseFloat(month1) == parseFloat(month2)) 
			{
				if (parseFloat(day1) > parseFloat(day2)) 
				{
					alert("First date is later than second date. Please correct that.");
					return false;
				}
				/*if (parseFloat(day1) == parseFloat(day2)) 
				{
					alert("First date can't be equal with second date. Please correct that.");
					return false;
				}*/
			}
		}
		return true;
}

function dateisNotPossible(day,month,year) {
	var datePoss = new Date().valueOf() + 86400000;
	var dateReal = new Date();
	dateReal.setMonth(month - 1);
	dateReal.setYear(parseInt(year));
	dateReal.setDate(parseInt(day));
	if (dateReal.valueOf() < datePoss) {
		alert("Earliest possible date of service is 1 day from now. You specify the date: "+day+"-"+month+"-"+year);
		return false;
	}
	return true;
}


function compare_dates(day1,month1,year1,day2,month2,year2) 
{
	var dateReal_1 = new Date();
	var dateReal_2 = new Date();

	dateReal_1.setMonth(month1 - 1);
	dateReal_1.setYear(parseInt(year1));
	dateReal_1.setDate(parseInt(day1));

	
	dateReal_2.setMonth(month2 - 1);
	dateReal_2.setYear(parseInt(year2));
	dateReal_2.setDate(parseInt(day2));

	if (dateReal_2.valueOf() < dateReal_1.valueOf())
	{
		return -1;
	}
	else if (dateReal_2.valueOf() == dateReal_1.valueOf())
	{
		return 0;
	}
	else
	{
		return 1;
	}
	return true;
}


function valid() {

if (document.calctransfer.dest1.value==0) { 
	alert('Select the "Transfer to" location.');
	document.calctransfer.dest1.focus();return false;
	}
var date1String = document.calctransfer.transferdate1.value;
var day1    = date1String.substr(0,2);
var month1  = date1String.substr(3,2);
var year1   = date1String.substr(6,4);

document.calctransfer.checktwo2.value==1;
	
if ((date1String=='dd/mm/yyyy') || (date1String=='')) 
			{
			alert('Select a pick up date please');
			document.calctransfer.transferdate1.value='';
			document.calctransfer.transferdate1.focus();
			return false;
			}
			
if (isDate(date1String)==false) { document.calctransfer.transferdate1.focus(); return false; }
			
if (dateisNotPossible(day1,month1,year1)==false) { document.calctransfer.transferdate1.focus(); return false; }			
			
if (document.calctransfer.checktwo[1].checked) 
  {
	document.calctransfer.checktwo2.value==2;
	if (document.calctransfer.depart2.value==0) {
		alert('Select the "Return from" location.');
		document.calctransfer.depart2.focus();return false;
	}
	
	if (document.calctransfer.dest2.value==0) { 
		alert('Select the return "Transfer to" location.');
		document.calctransfer.dest2.focus();return false;
		
	}	
	
	if ((document.calctransfer.transferdate2.value=='dd/mm/yyyy') || (document.calctransfer.transferdate2.value=='')) 
			{
			alert('Select a return date up date please');
			document.calctransfer.transferdate2.value='';
			document.calctransfer.transferdate2.focus();
			return false;
			}	
	
	if (isDate(document.calctransfer.transferdate2.value)==false) {
			document.calctransfer.transferdate2.focus(); return false;
			}
  }
  
  if (document.calctransfer.email.value=='') {
		alert('Fill the email field, please.');
		document.calctransfer.email.focus();return false;
  }
  
  if (emailck(document.calctransfer.email)==false) {
			document.calctransfer.email.focus(); return false;
			}
			
	document.calctransfer.dest1display.value = document.calctransfer.dest1.options[document.calctransfer.dest1.selectedIndex].text;
	document.calctransfer.depart1display.value = document.calctransfer.depart1.options[document.calctransfer.depart1.selectedIndex].text;
	
	document.calctransfer.dest2display.value = document.calctransfer.dest2.options[document.calctransfer.dest2.selectedIndex].text;
	document.calctransfer.depart2display.value = document.calctransfer.depart2.options[document.calctransfer.depart2.selectedIndex].text;
	
   
return true;

}

function calcpret(){
	var pricecalc = 0; //final price
	var mychecktwo = 0;
	if (document.calctransfer.checktwo[0].checked) { mychecktwo = 1; document.calctransfer.checktwo2.value=1; } //one way
	if (document.calctransfer.checktwo[1].checked) { mychecktwo = 2; document.calctransfer.checktwo2.value=2; } //two ways
	var pers = document.calctransfer.persnum.value;
	var addr1 = document.calctransfer.depart1.value; //id
	var addr2 = document.calctransfer.dest1.value; //id 
	var addr3 = document.calctransfer.depart2.value; //id
	var addr4 = document.calctransfer.dest2.value; //id
	var addr1txt = document.calctransfer.depart1.options[document.calctransfer.depart1.selectedIndex].text;
	var addr2txt = document.calctransfer.dest1.options[document.calctransfer.dest1.selectedIndex].text;
	var addr3txt = document.calctransfer.depart2.options[document.calctransfer.depart2.selectedIndex].text;
	var addr4txt = document.calctransfer.dest2.options[document.calctransfer.dest2.selectedIndex].text;
	
	if ((addr1txt!='Faro Airport') && (addr2==0)) {return false;}
	if (addr2==0) {document.calctransfer.result.value = 0; alert('Select first a "Transfer to" location.'); document.calctransfer.dest1.selectedIndex=0; document.calctransfer.dest1.focus(); return false;}
	if (addr1txt==addr2txt) {document.calctransfer.result.value = 0; document.calctransfer.dest1.selectedIndex=0; alert('You can not select the departure location to be the same as destination.'); return false;}
	if ((addr1txt!="Faro Airport") && (addr2txt!="Faro Airport")) {document.calctransfer.result.value = 0; alert('The price for this location will be specified into the confirmation of the transfer booking.'); return false;}
	
	if (mychecktwo == 2) {
			if ((addr3txt!='Faro Airport') && (addr4==0)) {return false;}
			if (addr4==0) {document.calctransfer.result.value = 0; alert('Select first a "Transfer to" location.'); document.calctransfer.dest2.selectedIndex=0; document.calctransfer.dest2.focus(); return false;}
			if (addr3txt==addr4txt) {document.calctransfer.result.value = 0; document.calctransfer.dest2.selectedIndex=0; alert('You can not select the departure location to be the same as destination.'); return false;}
			if ((addr3txt!="Faro Airport") && (addr4txt!="Faro Airport")) {document.calctransfer.result.value = 0; alert('The price for this location will be specified into the confirmation of the transfer booking.'); return false;}
			}
	
	if (pers<5)
		{  if ((addr2!=0) && (addr1txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc1[addr2]); } //faro airport to Alvor / ex
		   if ((addr1!=0) && (addr2txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc1[addr1]); } //Lagos to Faro airport / ex
		   if (mychecktwo == 2) {
		   			if ((addr4!=0) && (addr3txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc1[addr4]); } //faro airport to Alvor / ex
		   			if ((addr3!=0) && (addr4txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc1[addr3]); } //Lagos to Faro airport / ex
		   			}
		}
		
	if ((pers>=5) && (pers<=8))
		{  if ((addr2!=0) && (addr1txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc2[addr2]); } //faro airport to Alvor / ex
		   if ((addr1!=0) && (addr2txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc2[addr1]); } //Lagos to Faro airport / ex
		   if (mychecktwo == 2) {
		   			if ((addr4!=0) && (addr3txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc2[addr4]); } //faro airport to Alvor / ex
		   			if ((addr3!=0) && (addr4txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc2[addr3]); } //Lagos to Faro airport / ex
		   			}
		}
		
	if ((pers>=9) && (pers<=12))
		{  if ((addr2!=0) && (addr1txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc3[addr2]); } //faro airport to Alvor / ex
		   if ((addr1!=0) && (addr2txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc3[addr1]); } //Lagos to Faro airport / ex
		   if (mychecktwo == 2) {
		   			if ((addr4!=0) && (addr3txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc3[addr4]); } //faro airport to Alvor / ex
		   			if ((addr3!=0) && (addr4txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc3[addr3]); } //Lagos to Faro airport / ex
		   			}
		}
		
	if ((pers>=13) && (pers<=16))
		{  if ((addr2!=0) && (addr1txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc4[addr2]); } //faro airport to Alvor / ex
		   if ((addr1!=0) && (addr2txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc4[addr1]); } //Lagos to Faro airport / ex
		   if (mychecktwo == 2) {
		   			if ((addr4!=0) && (addr3txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc4[addr4]); } //faro airport to Alvor / ex
		   			if ((addr3!=0) && (addr4txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc4[addr3]); } //Lagos to Faro airport / ex
		   			}
		}
		
	if (pers>=17)
		{  if ((addr2!=0) && (addr1txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc5[addr2]); } //faro airport to Alvor / ex
		   if ((addr1!=0) && (addr2txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc5[addr1]); } //Lagos to Faro airport / ex
		   if (mychecktwo == 2) {
		   			if ((addr4!=0) && (addr3txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc5[addr4]); } //faro airport to Alvor / ex
		   			if ((addr3!=0) && (addr4txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc5[addr3]); } //Lagos to Faro airport / ex
		   			}
		}
		
	document.calctransfer.result.value = pricecalc;
}

function return_btn() {
if (document.calctransfer.checktwo[1].checked) { //two ways
	document.calctransfer.dest2.selectedIndex=document.calctransfer.depart1.selectedIndex+1;
    document.calctransfer.depart2.selectedIndex=document.calctransfer.dest1.selectedIndex; calcpret();
	}
	else
	{
	document.calctransfer.depart2.selectedIndex=0;document.calctransfer.dest2.selectedIndex=0;
	calcpret();
	}
}

function return_change() {

if (document.calctransfer.checktwo[1].checked==false) 
	{ 	alert('Please select first the "Round-trip" option if you want to book a return transfer.'); 
		document.calctransfer.depart2.selectedIndex=0;
		document.calctransfer.dest2.selectedIndex=0;
	}
calcpret();
}

function valid_book()
{
	f = document.book;

	if(f.client_id.value == "")
	{
		if (f.fname.value=='') 
		{ 
			alert('Complete the first name field, please.');
			f.fname.focus(); return false;
		}
		if (f.lname.value=='') 
		{ 
			alert('Complete the last name field, please.');
			f.lname.focus(); return false;
		}
		if (f.country.selectedIndex == 0) 
		{ 
			alert('Select the country field, please.');
			f.country.focus(); return false;
		}
		if (f.phone.value=='') 
		{ 
			alert('Complete the phone field, please.');
			f.phone.focus(); return false;
		}
		if (f.mobile.value=='') 
		{ 
			alert('Complete the mobile field, please.');
			f.mobile.focus(); return false;
		}
	}

	if(f.checktwo.value == 1)
	{
		var date1String = f.transferdate1.value;
		var day1    = date1String.substr(0,2);
		var month1  = date1String.substr(3,2);
		var year1   = date1String.substr(6,4);
	}
	else if(f.checktwo.value == 2)
	{
		var date1String = f.transferdate1.value;
		var day1    = date1String.substr(0,2);
		var month1  = date1String.substr(3,2);
		var year1   = date1String.substr(6,4);

		var date2String = f.transferdate2.value;
		var day2    = date2String.substr(0,2);
		var month2  = date2String.substr(3,2);
		var year2   = date2String.substr(6,4);
	
	}
	else
	{
		var date2String = f.transferdate2.value;
		var day2    = date2String.substr(0,2);
		var month2  = date2String.substr(3,2);
		var year2   = date2String.substr(6,4);
	
	}
	


	if(f.checktwo.value == 1 || f.checktwo.value == 2)
	{
		if ((date1String=='dd/mm/yyyy') || (date1String=='')) 
		{
			alert('Select a pick up date please');
			f.transferdate1.value='';
			f.transferdate1.focus();
			return false;
		}

		if (isDate(date1String)==false) { f.transferdate1.focus(); return false; }
		if (dateisNotPossible(day1,month1,year1)==false) { f.transferdate1.focus(); return false; }	
	}

	if(f.checktwo.value == 2 || f.checktwo.value == 3)
	{
		if ((date2String=='dd/mm/yyyy') || (date2String=='')) 
		{
			alert('Select a drop off date please');
			f.transferdate2.value='';
			f.transferdate2.focus();
			return false;
		}

		if (isDate(date2String)==false) { f.transferdate2.focus(); return false; }
		if (dateisNotPossible(day2,month2,year2)==false) { f.transferdate2.focus(); return false; }
		
		if(f.checktwo.value == 2)
		{
			if (!checkmyDates(day1,day2,month1,month2,year1,year2)) {return false;}
			if(date1String == date2String)
			{
				if((f.dep1hour.value > f.dep2hour.value) || (f.dep2hour.value - f.dep1hour.value <= 1))
				{
					alert("The drop off hour must be at least one hour later than the pick up hour");
					f.dep2hour.focus();
					return false;
				}
			}
		}
	}
	
	if(f.address.value == "")
	{
		alert("Please fill in the exact address in "+ f.city_name.value);
		f.address.focus();
		return false;
	}

	if(f.comments.value.length > 500)
	{
		alert(" Maximum 500 characters for the comments.Now you have " + f.comments.value.length + " characters.");
		return false;
	}

	return true;
}
