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, mes1, mes2, mes3)
{
	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}$");
	// || (dtStr.match(myRegex2))
	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 (mes1);
			return false;
			}
		else if ((theYear%4 == 0) && (theDay > 29) && (theMonth == 2)) {
			alert (mes2);
			return false;
			}
		else if ((theYear%4 != 0) && (theDay > 28) && (theMonth == 2)) {
			alert (mes2);
			return false;
			}
		else if ((theDay > 30) && ((theMonth == 0) || (theMonth == 4) || (theMonth == 6) || (theMonth == 9) || (theMonth == 11) )) {
			alert (mes2);
			return false;
			}
		else {
			return true;
			}
		}
	else
		{
		alert (mes3);
		return false;
		}
	

}	

function dateisNotPossible(day,month,year, mes) 
{
	//var datePoss = new Date().valueOf();

	var datePoss = new Date();
	//datePoss.setTime(datePoss.getTime() + 2*(1000*3600*24));
	var dateReal = new Date();

	dateReal.setMonth(Number(month) - 1);
	dateReal.setYear(parseInt(year));
	dateReal.setDate(Number(day));

	if (dateReal.valueOf() < datePoss) {
		alert(mes+day+"-"+month+"-"+year);
		return false;
	}
	return true;
}

function dateisNotPossible_clients(day,month,year, mes) 
{
	//var datePoss = new Date().valueOf();

	var datePoss = new Date();
	datePoss.setDate(datePoss.getDate()+2);
	//datePoss.setTime(datePoss.getTime() + 2*(1000*3600*24));
	var dateReal = new Date();
	

	dateReal.setMonth(Number(month) - 1);
	dateReal.setYear(parseInt(year));
	dateReal.setDate(Number(day));

	
	if (dateReal.valueOf() < datePoss) {
		alert(mes+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 isDate2(dtStr){
				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 ("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 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) {
		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+"  "+dateReal);	return false; }
		return true;
	}
	
	function myisDate(dtStr){
				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 ("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 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 = dateAdd("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 = dateAdd("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 = dateAdd("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() {
			
				if (!emailck(document.onlinequote.myemail)) { return false; }
				if (!calculatemyprice()) { return false; }
				
				document.onlinequote.submit();
			
		}
	
	function  calculatemyprice() {
				var rotund = 1;
			
				if (document.onlinequote.location_from.value==0) { alert('Please choose a pick up location.');document.onlinequote.location_from.focus(); return false;}
				if (document.onlinequote.location_to.value==0) { alert('Please choose a drop off location.'); document.onlinequote.location_to.focus(); return false;}
				if (document.onlinequote.booking_car.value==0) { alert('Please choose a car.'); document.onlinequote.booking_car.focus(); return false;}
				var strdate1 = document.onlinequote.pickup.value;
				var strdate2 = document.onlinequote.dropoff.value;				
				if (myisDate(strdate1)==false) { document.onlinequote.pickup.focus();  return false;}
				if (myisDate(strdate2)==false) { document.onlinequote.dropoff.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])) {return false;}
				
				if (!checkmyDates(A[1],B[1],A[0],B[0],A[2],B[2])) {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));										
				
				//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 rotunzirea 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
	
			var price_low1	= (Math.floor( (parseInt(car_price_low)   / 6)*10) )/10;
			var price_mid1	= (Math.floor( (parseInt(car_price_mid)   / 6)*10) )/10;
			var price_high1	= (Math.floor( (parseInt(car_price_high)  / 6)*10) )/10;
	
			var price_low2	= (Math.ceil( (parseInt(car_price_low)   / 7)*10) )/10;
			var price_mid2	= (Math.ceil( (parseInt(car_price_mid)   / 7)*10) )/10;
			var price_high2	= (Math.ceil( (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
			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;}														
				
			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.ceil( (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;
			return true;
			
			}	

function onlinequote_check(err_pick_up, err_drop_off, err_pick_up_date, err_drop_off_date, err_diff_date, mes1, mes2, mes_date, mes_isdate_1, mes_isdate_2, mes_isdate_3, date_format,earliest_date_clients)
{
	f = document.onlinequote;

	cal_adv = f.cal_adv.value;
	
	//var error = $("company_id"); 
	if (f.location_from.value==0) 
	{ 
		alert(err_pick_up);
		f.location_from.focus(); 
		return false;
	}

	if (f.location_to.value==0) 
	{ 
		alert(err_drop_off);
		f.location_to.focus(); 
		return false;
	}
	var date1String = f.pickup.value;
	var day1    = date1String.substr(0,2);
	var month1  = date1String.substr(3,2);
	var year1   = date1String.substr(6,4);



	var date2String = f.dropoff.value;
	var day2    = date2String.substr(0,2);
	var month2  = date2String.substr(3,2);
	var year2   = date2String.substr(6,4);


	if ((date1String==date_format) || (date1String=='')) 
	{
		alert(err_pick_up_date);
		f.pickup.value='';
		f.pickup.focus();
		return false;
	}

	if (isDate(date1String, mes_isdate_1, mes_isdate_2, mes_isdate_3)==false) { f.pickup.focus(); return false; }

	if(cal_adv == 1)
	{
		if(dateisNotPossible(day1,month1,year1,mes_date)==false) 
		{ 
			f.pickup.focus(); return false; 
		}
	}
	else
	{
		if(dateisNotPossible_clients(day1,month1,year1,earliest_date_clients)==false) 
		{ 
			f.pickup.focus(); return false; 
		}
	}
		

	if ((date2String==date_format) || (date2String=='')) 
	{
		alert(err_drop_off_date);
		f.dropoff.value='';
		f.dropoff.focus();
		return false;
	}

	if (isDate(date2String, mes_isdate_1, mes_isdate_2, mes_isdate_3)==false) { f.dropoff.focus(); return false; }
	if (dateisNotPossible(day2,month2,year2,mes_date)==false) { f.dropoff.focus(); return false; }

	if(date1String == date2String)
	{
		alert(err_diff_date);
		f.dropoff.focus();
		return false;
	}


	if (!checkmyDates(day1,day2,month1,month2,year1,year2, mes1, mes2)) {return false;}
	
	f.submit();
	return true;

}
