			function emailck(objToCheck, message) {
				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(message);
      			objToCheck.focus();
		        return false;
			   }
			   return true;
			}
			
			
	function checkmyDates(day1,day2,month1,month2,year1,year2,mes1, mes2) {
			
		if (parseFloat(year1) > parseFloat(year2)) {
			alert(mes1);
			return false;
		}
		if (parseFloat(year1) == parseFloat(year2)) {
			if (parseFloat(month1) > parseFloat(month2)) {
				alert(mes1);
 				return false;
			}
			if (parseFloat(month1) == parseFloat(month2)) {
				if (parseFloat(day1) > parseFloat(day2)) {
					alert(mes1);
					return false;
				}
				if (parseFloat(day1) == parseFloat(day2)) {
					alert(mes2);
					return false;
				}
			}
		}
	return true;
	}		
	
	function mindatePossible(day,month,year, mes6) {
		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(mes6+": "+day+"-"+month+"-"+year);	
			return false; 
		}*/
		return true;
	}
	
	function myisDate(dtStr, mes3, mes4, mes5){
				var myRegex = new RegExp("^([0-2][0-9]|[3][0-1])\/([0][0-9]|[1][0-2])\/[0-9]{4}$");
				
				if ( (dtStr.match(myRegex)) )
					{//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 (mes3);
						return false;
						}
					else if ((theYear%4 == 0) && (theDay > 29) && (theMonth == 2)) {
						alert (mes4);
						return false;
						}
					else if ((theYear%4 != 0) && (theDay > 28) && (theMonth == 2)) {
						alert (mes4);
						return false;
						}
					else if ((theDay > 30) && ((theMonth == 0) || (theMonth == 4) || (theMonth == 6) || (theMonth == 9) || (theMonth == 11) )) {
						alert (mes4);
						return false;
						}
					else {
						return true;
						}
					}
				else
					{
					alert (mes5);
					return false;
					}
				
			
			}
	
	function GetHighSeasonDays(start_date, end_date, nr_days) {
		//high season
				
		var myGetHighSeasonDays=0;		
		if (nr_days<0)	{nr_days=0;}		
		var current_date=start_date;
		
		var n = 0; var current_date2;
		for (n=1; n<=nr_days; n++) {			
			var mmA = current_date.split(/[\\\/]/); 			
			mm = mmA[0];			
			if  ((mm>=7) && (mm<=9)) {	myGetHighSeasonDays=myGetHighSeasonDays+1;	}
			current_date2 = dateAdd2("d", 1, current_date);								
			var curr_date = current_date2.getDate(); var curr_month = current_date2.getMonth(); curr_month++; var curr_year = current_date2.getFullYear();						
			current_date  =  curr_month + "/" + curr_date + "/" + curr_year;			
		}
		if (myGetHighSeasonDays<0)	{myGetHighSeasonDays=0;}					
		return myGetHighSeasonDays;	
	}
	
	function GetMidSeasonDays(start_date, end_date, nr_days) {
		//high season
				
		var myGetMidSeasonDays=0;		
		if (nr_days<0)	{nr_days=0;}		
		var current_date=start_date;
		
		var n = 0; var current_date2;
		for (n=1; n<=nr_days; n++) {	

			var mmA = current_date.split(/[\\\/]/); 			
			mm = mmA[0];			
			if ( ((mm>=4) && (mm<=6)) || (mm==10) ) {	myGetMidSeasonDays=myGetMidSeasonDays+1;	}
			
			current_date2 = dateAdd2("d", 1, current_date);								
			var curr_date = current_date2.getDate(); var curr_month = current_date2.getMonth(); curr_month++; var curr_year = current_date2.getFullYear();						
			current_date  =  curr_month + "/" + curr_date + "/" + curr_year;			
		}
		if (myGetMidSeasonDays<0)	{myGetMidSeasonDays=0;}					
		return myGetMidSeasonDays;	
	}
	
	function GetLowSeasonDays(start_date, end_date, nr_days) {
		//high season
				
		var myGetLowSeasonDays=0;		
		if (nr_days<0)	{nr_days=0;}		
		var current_date=start_date;
		
		var n = 0; var current_date2;
		for (n=1; n<=nr_days; n++) {			
			var mmA = current_date.split(/[\\\/]/); 			
			mm = mmA[0];					
			if ((mm>=11) || (mm<=3)) {	myGetLowSeasonDays=myGetLowSeasonDays+1; }
			
			current_date2 = dateAdd2("d", 1, current_date);
			var curr_date = current_date2.getDate(); var curr_month = current_date2.getMonth(); curr_month++; var curr_year = current_date2.getFullYear();						
			current_date  =  curr_month + "/" + curr_date + "/" + curr_year;			
		}
		if (myGetLowSeasonDays<0)	{myGetLowSeasonDays=0;}					
		return myGetLowSeasonDays;	
	}				
		
		function booknow(err1, err2, err3, mes1, mes2, mes3, mes4, mes5, mes6, err_email, sess_language_id) {
			
				if (!emailck(document.onlinequote.myemail, err_email)) { return false; }
				if (!calculatemyprice(err1, err2, err3, mes1, mes2, mes3, mes4, mes5, mes6, sess_language_id)) { return false; }
			
				
				document.onlinequote.submit();
			
		}
	
	function calculatemyprice(err1, err2, err3, mes1, mes2, mes3, mes4, mes5, mes6, sess_language_id) {
				var rotund = 1;

				if(sess_language_id ==1)
				{
					document.getElementById("show_currency").innerHTML = '&euro;'; 
					document.onlinequote.current_currency.value = 'euro';
					document.onlinequote.currency.value = 'euro';
				}
			
				if (document.onlinequote.location_from.value==0) { alert(err1);document.onlinequote.location_from.focus(); return false;}
				if (document.onlinequote.location_to.value==0) { alert(err2); document.onlinequote.location_to.focus(); return false;}
				if (document.onlinequote.booking_car.value==0) { alert(err3); document.onlinequote.booking_car.focus(); return false;}

				
				var strdate1 = document.onlinequote.pickup.value;
				var strdate2 = document.onlinequote.dropoff.value;				
				if (myisDate(strdate1,mes3, mes4, mes5)==false) { document.onlinequote.pickup.focus();  return false;}
				if (myisDate(strdate2,mes3, mes4, mes5)==false) { document.onlinequote.dropoff.focus(); return false;}

				if(document.getElementById("div_message_pickup").style.display == "inline") 
				{ 
					var div_message_pickup = document.getElementById("div_message_pickup").innerHTML.replace("<br>", "\n"); 
					alert(div_message_pickup); 
					document.onlinequote.pickup_time.focus(); 
					return false;
				}


				var strtime1 = document.onlinequote.pickup_time.value;
				var strtime1 = parseFloat(strtime1.substr(0,2));
				var strtime2 = document.onlinequote.dropoff_time.value;	
				var strtime2 = parseFloat(strtime2.substr(0,2));
								
				
				var A = strdate1.split(/[\\\/]/); 
				A = [A[1],A[0],A[2]]; 
				strdate1s = A.join('/');
				
				var B = strdate2.split(/[\\\/]/); 
				B = [B[1],B[0],B[2]]; 
				strdate2s = B.join('/');														
				
				if (!mindatePossible(A[1],A[0],A[2],mes6)) {return false;}
				
				if (!checkmyDates(A[1],B[1],A[0],B[0],A[2],B[2], mes1, mes2)) {return false;}
					
				//nr de zile pt care trebuie calculat pretul
				var nr_days = DateDiff("d", strdate1s, strdate2s);
				document.onlinequote.nrdays.value=nr_days;
				
				// detectez din ce epoca/sezon se face rezervarea
				var epoca = 0;
				var mm=A[0];
				if ((mm>=11) || (mm<=3))		{  epoca =1; }		
				if ( ((mm>=4) && (mm<=6)) ) 	{  epoca =2; }
				if ((mm>=7) && (mm<=9)) 		{  epoca =3; }
				if ((mm==10)) 					{  epoca =4; }
				
				//daca rezervarea este pentru Madeira atunci sunt doar 2 epoci - MID si HIGH iar celelalte 2 se contopesc adica 1 sau 4 devine epoca 2
				if ((document.onlinequote.location_from.options[document.onlinequote.location_from.selectedIndex].text=='Madeira - Funchal Airport') || (document.onlinequote.location_from.options[document.onlinequote.location_from.selectedIndex].text=='Madeira - Funchal Office') || (document.onlinequote.location_from.options[document.onlinequote.location_from.selectedIndex].text=='Madeira - Porto Santo Airport'))
					{
						if ((epoca==1) || (epoca==4)) {epoca=2;}
					}
				
				
				var high_days = GetHighSeasonDays(strdate1s, strdate2s, parseInt(nr_days));
				var mid_days = GetMidSeasonDays(strdate1s, strdate2s, parseInt(nr_days));
				var low_days = GetLowSeasonDays(strdate1s, strdate2s, parseInt(nr_days));	
				
				//alert("low = "+low_days+" - mid = "+mid_days+" - high = "+high_days);
				
				//daca rezervarea este pentru Madeira atunci zilele din epoca de LOW sunt transferate in epoca MID
				if ((document.onlinequote.location_from.options[document.onlinequote.location_from.selectedIndex].text=='Madeira - Funchal Airport') || (document.onlinequote.location_from.options[document.onlinequote.location_from.selectedIndex].text=='Madeira - Funchal Office') || (document.onlinequote.location_from.options[document.onlinequote.location_from.selectedIndex].text=='Madeira - Porto Santo Airport'))
					{
						if (low_days!=0) {mid_days=mid_days+low_days; low_days=0;}
					}
					
					
				var car_price_low = carpricelow[document.onlinequote.booking_car.value];
				var car_price_mid = carpricemid[document.onlinequote.booking_car.value];
				var car_price_high= carpricehigh[document.onlinequote.booking_car.value];
				var car_price_insurance= carinsurance[document.onlinequote.booking_car.value];
				
				//daca rezervarea este pentru Porto Santo - Madeira pretul creste cu 10%
				if (document.onlinequote.location_from.options[document.onlinequote.location_from.selectedIndex].text=='Madeira - Porto Santo Airport')
					{
						car_price_low = car_price_low * 1.1;
						car_price_mid = car_price_mid * 1.1;
						car_price_high= car_price_high* 1.1;
					}

				//new insurance price
				if ((mm>=11) && (car_price_insurance==7.5)) {car_price_insurance = 8.5;}
				if ((mm>=11) && (car_price_insurance==14)) {car_price_insurance = 15;}
				if ((mm>=11) && (car_price_insurance==18)) {car_price_insurance = 20;}

				//calculez excess insurance
				
				if (document.onlinequote.EXCESS_INSURANCE.checked==true) {
					var priceinsurance = nr_days*parseFloat(car_price_insurance);
					document.onlinequote.mypriceinsurance.value=priceinsurance;
					
					}
					else
					{
						document.onlinequote.mypriceinsurance.value=''; 
					}
					
				var fator;
				
				if ((low_days+mid_days+high_days)<7) {
					fator=6;
					if ((low_days+mid_days+high_days)<3) {
						if (low_days==2)  { low_days=3; }
						if (mid_days==2)  { mid_days=3; }
						if (high_days==2) { high_days=3; }
						if ((low_days==1) && (mid_days==1)) { low_days=2;}
						if ((mid_days==1) && (high_days==1)) { mid_days=2;}
						if ((low_days==1) && (high_days==1)) { low_days=2;}
						if ((low_days==1) && (mid_days==0) && (high_days==0))  { low_days=3;}
						if ((low_days==0) && (mid_days==1) && (high_days==0))  { mid_days=3;}
						if ((low_days==0) && (mid_days==0) && (high_days==1))  { high_days=3;}
						}			
					}		
				else
					{ fator=7;	}	
					
				//reglez nr. de zile in caz ca rezervarea pica intre epoci - ex. 2zile in LS si 5 in MS atunci va fi 3zile in LS si 4zile in MS
				/*if ( (epoca == 1) && (low_days<3) ) {
						mid_days = mid_days  - (3 - low_days);
						low_days = 3;
					}
				if ( (epoca == 2) && (mid_days<3) ) {
						high_days = high_days  - (3 - mid_days);
						mid_days = 3;
					}
				if ( (epoca == 3) && (high_days<3) ) {
						mid_days = mid_days  - (3 - high_days);
						high_days = 3;
					}		
				if ( (epoca == 4) && (mid_days<3) ) {
						low_days = low_days  - (3 - mid_days);
						mid_days = 3;
					}	*/	
					
				//in caz ca sunt 7 zile atunci sa nu mai faca rotunjirea de pret
				if ( ((low_days % 7)==0) && (mid_days==0) && (high_days==0) )   { rotund=0;}
				if ( (low_days==0) && ((mid_days % 7)==0) && (high_days==0) )  { rotund=0;}		
				if ( (low_days==0) && (mid_days==0) && ((high_days % 7)==0) )  { rotund=0;}		
				
				// doua preturi diferite in functie de cate zile doreste rezervarea . ex. pt 4. zile pret1 iar pt. 8. zile pret 3

			//half of week price
			halfweekprice = 0;
			var CalculatePrice = 0;	

			if ( (low_days==3) && (mid_days==0) && (high_days==0) ) { var CalculatePrice =  (Math.round( (parseInt(car_price_low)   / 2)*10) )/10; halfweekprice = 1; }
			if ( (low_days==0) && (mid_days==3) && (high_days==0) ) { var CalculatePrice =  (Math.round( (parseInt(car_price_mid)   / 2)*10) )/10; halfweekprice = 1;}
			if ( (low_days==0) && (mid_days==0) && (high_days==3) ) { var CalculatePrice =  (Math.round( (parseInt(car_price_high)  / 2)*10) )/10; halfweekprice = 1;}	
			
			
			
			if (halfweekprice!=1)
			{		
		
				var price_low1	= (Math.round( (parseInt(car_price_low)   / 6)*10) )/10;
				var price_mid1	= (Math.round( (parseInt(car_price_mid)   / 6)*10) )/10;
				var price_high1	= (Math.round( (parseInt(car_price_high)  / 6)*10) )/10;
		
				var price_low2	= (Math.round( (parseInt(car_price_low)   / 7)*10) )/10;
				var price_mid2	= (Math.round( (parseInt(car_price_mid)   / 7)*10) )/10;
				var price_high2	= (Math.round( (parseInt(car_price_high)  / 7)*10) )/10;
				
				// decid care pret sa fie folosit (mic de 7 zile sau mare de 6 zile) in functie de numarul de zile			
				//metoda veche - pt teste
				/*if (low_days<7)  {price_low = price_low1; }  else {price_low = price_low2;}
				if (mid_days<7)  {price_mid = price_mid1; }  else {price_mid = price_mid2;}
				if (high_days<7) {price_high= price_high1; } else {price_high= price_high2;}*/

				// decid care pret sa fie folosit (mic de 7 zile sau mare de 6 zile) in functie de numarul de zile			
				//metoda actuala -cea corecta
				if(nr_days < 7)
				{
					price_low = price_low1;
					price_mid = price_mid1;
					price_high= price_high1;
				}
				else
				{
					price_low = price_low2;
					price_mid = price_mid2;
					price_high= price_high2;
				}													
																			
				if(((nr_days == 6) && (low_days==6) && (mid_days==0) && (high_days==0)) || ((nr_days == 6) && (low_days==0) && (mid_days==6) && (high_days==0)) || ((nr_days == 6) && (low_days==0) && (mid_days==0) && (high_days==6)))	
				{
					if(low_days==6)
					{
						var CalculatePrice = car_price_low;	
					}
					else if(mid_days==6)
					{
						var CalculatePrice = car_price_mid;	
					}
					else
					{
						var CalculatePrice = car_price_high;	
					}
					
				}
				else
				{
					var CalculatePrice = ((Math.floor(low_days / 7)) * car_price_low ) + ((low_days % 7) * price_low );	
					CalculatePrice = CalculatePrice + ((Math.floor(mid_days / 7)) * car_price_mid ) + ((mid_days % 7) * price_mid );	
					CalculatePrice = CalculatePrice + ((Math.floor(high_days / 7)) * car_price_high ) + ((high_days % 7) * price_high );
				}
					
			}
			//excess insurance
			if (priceinsurance>0) CalculatePrice = CalculatePrice + priceinsurance;
			//total price
			CalculatePrice = (Math.round( (CalculatePrice)*100) )/100;	
			
			//document.onlinequote.mycalcprice.value = '('+ (Math.floor(low_days / 7)) +' * ' + car_price_low + ' + ' + (low_days % 7) + ' * '+price_low+' ) + ('    +     (Math.floor(mid_days / 7)) +' * ' + car_price_mid + ' + ' + (mid_days % 7) + ' * '+price_mid+' ) + ('     +     (Math.floor(high_days / 7)) +' * ' + car_price_high + ' + ' + (high_days % 7) + ' * '+ price_high + ')';
			document.onlinequote.totalprice.value = CalculatePrice;
			document.onlinequote.totalprice_euro.value = document.onlinequote.totalprice.value;
			quote_ajax();
			return true;
			
			}	

function change_currency(rate)
{
	f = document.onlinequote;

	if(f.totalprice_euro.value > 0)
	{
		if(f.currency.value == 'gbp' && f.current_currency.value == 'euro')
		{
			f.totalprice.value = Math.round((f.totalprice_euro.value / rate) * 100) / 100;
			document.getElementById("show_currency").innerHTML = '&pound;'; 
		}

		if(f.currency.value == 'euro' && f.current_currency.value == 'gbp')
		{
			f.totalprice.value = f.totalprice_euro.value;
			document.getElementById("show_currency").innerHTML = '&euro;'; 
		}
		f.current_currency.value = f.currency.value;
	}
	else
	{
		if(f.currency.value == 'gbp')
		{
			f.currency.value = 'euro';
		}
	}
	return true;
}

//====================================================================================
var xmlHttp
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

var url_check = "include/get_check_hour.php?pickup_time="; 
function check_program_hours() 
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	var location_from = document.getElementById("location_from").value; 

	var location_to = document.getElementById("location_to").value;

	var pickup_time = document.getElementById("pickup_time").value; 

	var dropoff_time = document.getElementById("dropoff_time").value;

	//alert(url_check + pickup_time + "&dropoff_time=" + dropoff_time + "&location_from=" + location_from + "&location_to=" + location_to);
	xmlHttp.open("GET", url_check + pickup_time + "&dropoff_time=" + dropoff_time + "&location_from=" + location_from + "&location_to=" + location_to, true); 
	xmlHttp.onreadystatechange = handleHttpResponse_price; 
	xmlHttp.send(null);
}

function handleHttpResponse_price() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 		
		xmlDoc=xmlHttp.responseXML;
		var pickup_outside_program = xmlDoc.getElementsByTagName("pickup_outside_program")[0].childNodes[0].nodeValue;
		var dropoff_outside_program = xmlDoc.getElementsByTagName("dropoff_outside_program")[0].childNodes[0].nodeValue;

		var opening_hours = document.getElementById("opening_hours").value;
		var pickup_time_not_correct = document.getElementById("pickup_time_not_correct").value;
		var dropoff_time_not_correct = document.getElementById("dropoff_time_not_correct").value;


		if((pickup_outside_program == 1) || (dropoff_outside_program == 1))
		{
			document.getElementById("div_message_pickup").innerHTML = opening_hours;
			if(pickup_outside_program == 1)
			{
				document.getElementById("div_message_pickup").innerHTML = document.getElementById("div_message_pickup").innerHTML + "<br>" + pickup_time_not_correct;
				document.onlinequote.pickup_time.focus();
			}
			if(dropoff_outside_program == 1)
			{
				document.getElementById("div_message_pickup").innerHTML = document.getElementById("div_message_pickup").innerHTML + "<br>" + dropoff_time_not_correct;
				document.onlinequote.dropoff_time.focus();
			}
			document.getElementById("div_message_pickup").style.display = "inline";

		}
		else
		{
			document.getElementById("div_message_pickup").innerHTML = "";
			document.getElementById("div_message_pickup").style.display = "none";

		}
		
	} 
} 

