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 have 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 of the date specified does not exist.");
					return false;
					}
				
			
			}	

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 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;
	var transfer_date =  document.calctransfer.transferdate1.value;

	var date_end_promo=new Date();
	date_end_promo.setFullYear(2011,3,31);
	
	
	var day1    = transfer_date.substr(0,2);
	var month1  = transfer_date.substr(3,2);
	var year1   = transfer_date.substr(6,4);

	var transfer_date_object = new Date();
	transfer_date_object.setFullYear(year1,month1,day1);

	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 (date_end_promo > transfer_date_object)
	{
		myloc_a = myloc3;
		myloc_b = myloc4;
	}
	else
	{
		myloc_a = myloc1;
		myloc_b = myloc2;
	}
	
	if (pers<5)
	{  if ((addr2!=0) && (addr1txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc_a[addr2]); } //faro airport to Alvor / ex
	   if ((addr1!=0) && (addr2txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc_a[addr1]); } //Lagos to Faro airport / ex
	   if (mychecktwo == 2) 
	   {
				if ((addr4!=0) && (addr3txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc_a[addr4]); } //faro airport to Alvor / ex
				if ((addr3!=0) && (addr4txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc_a[addr3]); } //Lagos to Faro airport / ex
	   }
	}
		
	if (pers>=5)
	{  if ((addr2!=0) && (addr1txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc_b[addr2]); } //faro airport to Alvor / ex
	   if ((addr1!=0) && (addr2txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc_b[addr1]); } //Lagos to Faro airport / ex
	   if (mychecktwo == 2) 
	   {
				if ((addr4!=0) && (addr3txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc_b[addr4]); } //faro airport to Alvor / ex
				if ((addr3!=0) && (addr4txt=="Faro Airport")) { pricecalc = parseFloat(pricecalc) + parseFloat(myloc_b[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();
}
