//==========================================================================
//==============NEWEST VERSION  - modified by Irina on 3 August 2010========
//=============we've added a new period - october - period 4============================
//===========================================================================
			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 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) {
			
		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 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];	
			yy = mmA[2];

			if(mm == 9 && yy == 2010)
			{
				//do nothing sept 2010 promo days===
			}
			else 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;}
		//alert(myGetHighSeasonDays);
		return myGetHighSeasonDays;	
	}

	function GetHighSeasonDaysMadeira(start_date, end_date, nr_days) {
		//high season
		//17.12.2010 - 04.01.2011 and 14.04.2010 - 26.04.2010
		
		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];	
			dd = mmA[1];
			yy = mmA[2];

			if  ((mm>=7) && (mm<=9)) {	myGetHighSeasonDays=myGetHighSeasonDays+1;	}
			
			//Irina - add new Christmas period 1
			if ((dd>=17) && (mm==12) && (yy==2010)  &&   (dd<=31) && (mm==12) && (yy==2010)) {	myGetHighSeasonDays=myGetHighSeasonDays+1;	}
			//Irina - add new Christmas period 2
			if ((dd>=1) && (mm==1) && (yy==2011)  &&   (dd<=4) && (mm==1) && (yy==2011)) {	myGetHighSeasonDays=myGetHighSeasonDays+1;	}						
			//Irina - add new Estear period 1
			if ((dd>=14) && (mm==4) && (yy==2011)  &&   (dd<=26) && (mm==4) && (yy==2011)) {	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 GetMidSeasonDaysMadeira(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];	
			dd = mmA[1];
			yy = mmA[2];			

			//Irina - add new Christmas period 1 and 2 and easter 1 and 2 - stay the same no of days - else add 
			var ok = 0;
			if  ( ((dd>=17) && (mm==12) && (yy==2010)  &&   (dd<=31) && (mm==12) && (yy==2010)) || 
				((dd>=1) && (mm==1) && (yy==2011)  &&   (dd<=4) && (mm==1) && (yy==2011)) || 
				((dd>=14) && (mm==4) && (yy==2011)  &&   (dd<=26) && (mm==4) && (yy==2011)) )
				{	
					myGetMidSeasonDays=myGetMidSeasonDays;	
					ok = 1;
				}
				else if ( (((mm>=4) && (mm<=6)) || ( (mm>=11) || (mm<=3) )) && ok == 0 ) {	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;}
		//alert("myGetMidSeasonDays = "+myGetMidSeasonDays);
		return myGetMidSeasonDays;	
	}

//==========added by Irina on 3 August 2010=================================
	function GetMidOctSeasonDaysMadeira(start_date, end_date, nr_days) {
		//Mid October Season Madeira season
				
		var myGetMidOctSeasonDaysMadeira = 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];	
			dd = mmA[1];
			yy = mmA[2];					
			if (mm == 10) 
			{	
				myGetMidOctSeasonDaysMadeira=myGetMidOctSeasonDaysMadeira+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 (myGetMidOctSeasonDaysMadeira<0)	{myGetMidOctSeasonDaysMadeira=0;}	
		return myGetMidOctSeasonDaysMadeira;	
	}	

	
	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];	
			dd = mmA[1];
			yy = mmA[2];
			
			//=====cod corect pana pe data de 13 nov 2009 - modificat de Irina==========
			//if ( ((mm>=4) && (mm<=6)) || (mm==10) ) {	myGetMidSeasonDays=myGetMidSeasonDays+1;	}
			if ((mm == 3 && dd >=27) || ((mm>=4) && (mm<=6)) || (((dd>=17) && (mm==12) && (yy==2010)  &&   (dd<=31) && (mm==12) && (yy==2010)) || ((dd>=1) && (mm==1) && (yy==2011)  &&   (dd<=4) && (mm==1) && (yy==2011))) ) {	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;}		
		//alert(myGetMidSeasonDays);
		return myGetMidSeasonDays;	
	}

//=================added by Irina on 3 August 2010=========================
	function GetMidOctSeasonDays(start_date, end_date, nr_days) {
		//October Mid Season Mainland
				
		var myGetMidOctSeasonDays=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];	
			dd = mmA[1];
			
			if (mm == 10) {	myGetMidOctSeasonDays=myGetMidOctSeasonDays+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 (myGetMidOctSeasonDays<0)	{myGetMidOctSeasonDays=0;}		
		//alert(myGetMidOctSeasonDays);
		return myGetMidOctSeasonDays;	
	}


//==========vor fi folosite pt. perioada de promotie sept 2010==============
//==========valabile pana la 1 oct 2010=====================================
	function GetPromoLowSeasonDays(start_date, end_date, nr_days) {
		//promo sept 2010 high season
				
		var myGetPromoLowSeasonDays=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];	
			yy = mmA[2];
			if((mm==9) && (yy == 2010)) {	myGetPromoLowSeasonDays=myGetPromoLowSeasonDays+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 (myGetPromoLowSeasonDays<0)	{myGetPromoLowSeasonDays=0;}					
		return myGetPromoLowSeasonDays;	
	}				
	
	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];	
			dd = mmA[1];
			yy = mmA[2];

			if(((dd>=17) && (mm==12) && (yy==2010)  &&   (dd<=31) && (mm==12) && (yy==2010)) || ((dd>=1) && (mm==1) && (yy==2011)  &&   (dd<=4) && (mm==1) && (yy==2011)))
			{
				//do nothing - these are the mid Christmas days
			}
			else if (((mm>=11) || (mm<=2)) || ((mm == 3) && (dd < 27))) {	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() {
			
				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));
				
				if  (strtime1<strtime2) 
						{  alert('The pick-up time is greater that the drop-off time resulting an extra day of payment.');
							var C = strdate2.split(/[\\\/]/); 
							C = [C[1],C[0],C[2]]; 
							var strdate1ss = C.join('/');
							var aux_date 	= dateAdd2("d", 1, strdate1ss);
							var aux_day 	= aux_date.getDate(); 
							var aux_month 	= aux_date.getMonth(); aux_month++; 
							var aux_year 	= aux_date.getFullYear();						
							strdate2  =  aux_day + "/"  + aux_month + "/" + aux_year;	
						}
				
				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 dd=A[1]; //day
				var mm=A[0]; //month
				var yy=A[2]; //year
				var dd2=B[1]; //day
				var mm2=B[0]; //month
				var yy2=B[2]; //year


				//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'))
				{
						ok = 0;
						if (((dd>=17) && (mm==12) && (yy==2010)  &&   (dd<=31) && (mm==12) && (yy==2010)) || 
							((dd>=1) && (mm==1) && (yy==2011)  &&   (dd<=4) && (mm==1) && (yy==2011)) || 
							((dd>=14) && (mm==4) && (yy==2011)  &&   (dd<=26) && (mm==4) && (yy==2011)))
						{  
							epoca = 3;
							ok = 1;
						} // high - new Christmas period 1 and 2 and easter 1 and 2 -added by Irina on 31 August 2010
								
						if (((mm>=7) && (mm<=9)) && ok == 0) 
						{  
							epoca = 3; 
						} //high
						if (((mm>=4) && (mm<=6)) && ok == 0)
						{  
							epoca = 2; 
						} //mid	
						if (((mm>=11) || (mm<=3)) && ok == 0) 	
						{  
							epoca = 2; 
						} //mid	
						if (mm==10  && ok == 0) 	
						{  
							epoca = 4; 
						} // october mid - added by Irina on 3 August 2010
						

						
						//se calculeaza numarul  de zile pt. Madeira
						var high_days = GetHighSeasonDaysMadeira(strdate1s, strdate2s, parseInt(nr_days));
						var mid_days = GetMidSeasonDaysMadeira(strdate1s, strdate2s, parseInt(nr_days));
						//==========added by Irina on 3 August 2010===============================
						var mid_oct_days = GetMidOctSeasonDaysMadeira(strdate1s, strdate2s, parseInt(nr_days));
						var low_days = 0;

						
				}
				else
				{	
					//se calc  epoca pt. Portugal continental

					//=====cod corect pana pe data de 13 nov 2009 - modificat de Irina==========
					//if ((mm>=11) || (mm<=3))		{  epoca =1; }		//start low
					if (((mm>=11) || (mm<=2)) || ((mm == 3) && (dd < 27))) {  epoca =1; }		//start low

										

					//=====cod corect pana pe data de 13 nov 2009 - modificat de Irina==========
					//if ( ((mm>=4) && (mm<=6)) || ((mm==10)) ) 	{  epoca =2; } //mid
					if ((mm == 3 && dd >=27) || ((mm>=4) && (mm<=6))){  epoca =2; }

					
					if ((mm>=7) && (mm<=9)) 		{  epoca =3; } //high
					if (mm == 10) 		{  epoca =4; } //october mid - added by Irina on 3 August 2010

					if (((dd>=17) && (mm==12) && (yy==2010)  &&   (dd<=31) && (mm==12) && (yy==2010)) || 
				((dd>=1) && (mm==1) && (yy==2011)  &&   (dd<=4) && (mm==1) && (yy==2011))){  epoca =2; }// mid - new Christmas period 1 and 2 and easter 1 and 2 -added by Irina on 31 August 2010

					//se calculeaza numarul  de zile pt. Portugal continental
					var high_days = GetHighSeasonDays(strdate1s, strdate2s, parseInt(nr_days));
					var mid_days = GetMidSeasonDays(strdate1s, strdate2s, parseInt(nr_days));
					//==========added by Irina on 3 August 2010===============================
					var mid_oct_days = GetMidOctSeasonDays(strdate1s, strdate2s, parseInt(nr_days));
					var low_days = GetLowSeasonDays(strdate1s, strdate2s, parseInt(nr_days));	
					var low_promo_days = GetPromoLowSeasonDays(strdate1s, strdate2s, parseInt(nr_days));
				}
				

				//=======added by Irina on 20 April 2010 - to differentiate the prices in Madeira from the prices in Mainland=========
				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'))
				{
					var car_price_mid = carpricemadeiramid[document.onlinequote.booking_car.value];
					//==========added by Irina on 3 August 2010===============================
					var car_price_oct_mid = carpricemadeiraoctmid[document.onlinequote.booking_car.value];
					var car_price_high= carpricemadeirahigh[document.onlinequote.booking_car.value];
				}
				else
				{
					var car_price_mid = carpricemid[document.onlinequote.booking_car.value];
					//==========added by Irina on 3 August 2010===============================
					var car_price_oct_mid = carpriceoctmid[document.onlinequote.booking_car.value];
					
					//se iau preturile pentru masini	
					//modified by Irina on 31 aug for sep 2010 promo
					if(low_promo_days)
					{
						//var car_price_low = carpricepromolow[document.onlinequote.booking_car.value];
						//low_days = low_promo_days;

						var car_price_high = carpricepromolow[document.onlinequote.booking_car.value];
						high_days = low_promo_days;
					}
					else
					{
						var car_price_high= carpricehigh[document.onlinequote.booking_car.value];
					}
					var car_price_low = carpricelow[document.onlinequote.booking_car.value];
				}
				//=======added by Irina on 20 April 2010 - to differentiate the prices in Madeira from the prices in Mainland=========
				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;
						//==========added by Irina on 3 August 2010===============================
						car_price_oct_mid = car_price_oct_mid * 1.1;
						car_price_high= car_price_high* 1.1;
					}

				//new insurance price - from 1 november 2010======
				if ((mm>=11) && (car_price_insurance==8.5)) {car_price_insurance = 9;}
				if ((mm>=11) && (car_price_insurance==10)) {car_price_insurance = 11;}

				//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;
				
				//==========modified by Irina on 3 August 2010===============================
				if ((low_days+mid_days+mid_oct_days+high_days)<7) {
					fator=6;
					//==========modified by Irina on 3 August 2010===============================
					if ((low_days+mid_days+mid_oct_days+high_days)<3) {

						if (low_days==2)  { low_days=3; }
						if (mid_days==2)  { mid_days=3; }
						//==========added by Irina on 3 August 2010===============================
						if (mid_oct_days==2)  { mid_oct_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;}
						//==========added by Irina on 3 August 2010===============================
						if ((mid_oct_days==1) && (high_days==1)) { mid_oct_days=2;}
						//==========added by Irina on 3 August 2010===============================
						if ((mid_oct_days==1) && (low_days==1)) { low_days=2;}
						if ((low_days==1) && (high_days==1)) { low_days=2;}

						//==========modified by Irina on 3 August 2010===============================
						if ((low_days==1) && (mid_days==0) && (mid_oct_days==0) && (high_days==0))  { low_days=3;}
						if ((low_days==0) && (mid_days==1) && (mid_oct_days==0) && (high_days==0))  { mid_days=3;}
						if ((low_days==0) && (mid_days==0) && (mid_oct_days==0) && (high_days==1))  { high_days=3;}
						if ((low_days==0) && (mid_days==0) && (mid_oct_days==0) && (high_days==1))  { high_days=3;}
						if ((low_days==0) && (mid_days==0) && (mid_oct_days==1) && (high_days==0))  { mid_oct_days=3;}
						//==========modified by Irina on 3 August 2010===============================

						}			
					}		
				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) ) 
				{
					//==========modified by Irina on 3 August 2010===============================
					if(mid_days > 0)
					{
						mid_days = mid_days  - (3 - low_days);
						low_days = 3;
					}
					else
					{
						mid_oct_days = mid_oct_days  - (3 - low_days);
						low_days = 3;
					}	
					//==========modified by Irina on 3 August 2010===============================
				}
				if ( (epoca == 2) && (mid_days<3) ) 
				{
					//==========modified by Irina on 3 August 2010===============================
					if(low_days > 0)
					{
						low_days = low_days  - (3 - mid_days);
					}
					else if(mid_oct_days > 0)
					{
						mid_oct_days = mid_oct_days  - (3 - mid_days);
					}
					else
					{
						high_days = high_days  - (3 - mid_days);
					}
					//==========modified by Irina on 3 August 2010===============================
					mid_days = 3;
				}

				if ( (epoca == 3) && (high_days<3) ) 
				{
					//==========modified by Irina on 3 August 2010===============================
					if(mid_days > 0)
					{
						mid_days = mid_days  - (3 - high_days);
						high_days = 3;
					}
					else
					{
						mid_oct_days = mid_oct_days  - (3 - high_days);
						high_days = 3;
					}
					//==========modified by Irina on 3 August 2010===============================
				}		

				if ( (epoca == 4) && (mid_oct_days<3) ) 
				{
					low_days = low_days  - (3 - mid_oct_days);
					mid_oct_days = 3;
				}	

				if(low_days < 0)
				{
					low_days = 0;
				}
				if(mid_days < 0)
				{
					mid_days = 0;
				}
				//==========added by Irina on 3 August 2010===============================
				if(mid_oct_days < 0)
				{
					mid_oct_days = 0;
				}
				if(high_days < 0)
				{
					high_days = 0;
				}
				//alert("valoarehigh = "+high_days+" - mid = "+mid_days+" - low = "+low_days+" epoca = "+epoca);
					
				//in caz ca sunt 7 zile atunci sa nu mai faca rotunjirea de pret
				if ( ((low_days % 7)==0) && (mid_days==0) && (mid_oct_days==0) && (high_days==0) )   { rotund=0;}
				if ( (low_days==0) && ((mid_days % 7)==0) && (mid_oct_days==0) && (high_days==0) )  { rotund=0;}		
				if ( (low_days==0) && (mid_days==0) && ((high_days % 7)==0) && (mid_oct_days==0) )  { rotund=0;}	
				//==========added by Irina on 3 August 2010===============================
				if ( (low_days==0) && (mid_days==0) && ((mid_oct_days % 7)==0) && (high_days==0) )  { rotund=0;}
				
				//alert("low = "+low_days+"mid = "+mid_days+"high = "+high_days);
				
				// 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) && (mid_oct_days==0) && (high_days==0) ) { var CalculatePrice =  (Math.round( (parseInt(car_price_low)   / 2)*100) )/100; halfweekprice = 1; }
			if ( (low_days==0) && (mid_days==3) && (mid_oct_days==0) && (high_days==0) ) { var CalculatePrice =  (Math.round( (parseInt(car_price_mid)   / 2)*100) )/100; halfweekprice = 1;}
			if ( (low_days==0) && (mid_days==0) && (mid_oct_days==0) && (high_days==3) ) { var CalculatePrice =  (Math.round( (parseInt(car_price_high)  / 2)*100) )/100; halfweekprice = 1;}	
			//==========added by Irina on 3 August 2010===============================
			if ( (low_days==0) && (mid_days==0) && (mid_oct_days==3) && (high_days==0) ) { var CalculatePrice =  (Math.round( (parseInt(car_price_oct_mid)  / 2)*100) )/100; halfweekprice = 1;}	

			
			
			//alert("car_price_low = "+car_price_low+" - car_price_mid = "+car_price_mid+" - car_price_high = "+car_price_high);
			
			if (halfweekprice!=1)
			{			
				var price_low1	= (Math.round( (parseInt(car_price_low)   / 6)*100) )/100;
				var price_mid1	= (Math.round( (parseInt(car_price_mid)   / 6)*100) )/100;
				var price_high1	= (Math.round( (parseInt(car_price_high)  / 6)*100) )/100;
				//==========added by Irina on 3 August 2010===============================
				var price_oct_mid1	= (Math.round( (parseInt(car_price_oct_mid)  / 6)*100) )/100;
		
				var price_low2	= (Math.round( (parseInt(car_price_low)   / 7)*100) )/100;
				var price_mid2	= (Math.round( (parseInt(car_price_mid)   / 7)*100) )/100;
				var price_high2	= (Math.round( (parseInt(car_price_high)  / 7)*100) )/100;
				//==========added by Irina on 3 August 2010===============================
				var price_oct_mid2	= (Math.round( (parseInt(car_price_oct_mid)  / 7)*100) )/100;

				//alert("price_low1 = "+price_low1+" - price_mid1 = "+price_mid1+" - price_high1 = "+price_high1+" - price_oct_mid1 = "+price_oct_mid1);
				//alert("price_low2 = "+price_low2+" - price_mid2 = "+price_mid2+" - price_high2 = "+price_high2+" - price_oct_mid2 = "+price_oct_mid2);
				
				
				// 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;
					//==========added by Irina on 3 August 2010===============================
					price_oct_mid= price_oct_mid1;
				}
				else
				{
					price_low = price_low2;
					price_mid = price_mid2;
					price_high= price_high2;
					//==========added by Irina on 3 August 2010===============================
					price_oct_mid= price_oct_mid2;
				}


				//alert("high = " + high_days + " - mid_days = "+mid_days+" - low_days = "+low_days+" - low_promo_days = "+low_promo_days);
				//alert("car_price_mid = " + price_mid + " - car_price_oct_mid = "+price_oct_mid+" - car_price_high = "+price_high+" - car_price_low = "+price_low);

				//alert("price_low = "+price_low+" - price_mid = "+price_mid+" - price_high = "+price_high);

				//alert("car_price_low = "+car_price_low+" - car_price_mid = "+car_price_mid+" - car_price_high = "+car_price_high);
				
				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'))
				{
					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 );
				//==========added by Irina on 3 August 2010===============================
				CalculatePrice = CalculatePrice + ((Math.floor(mid_oct_days / 7)) * car_price_oct_mid ) + ((mid_oct_days % 7) * price_oct_mid );	

			}

			//alert("high = "+high_days+" - mid = "+mid_days+" - low = "+low_days+" halfweekprice = "+halfweekprice);
			//excess insurance
			if (priceinsurance>0) CalculatePrice = CalculatePrice + priceinsurance;
			//total price
				
			
			//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 + ')';
			
			
			//alert(low_days+" - "+mid_days+" - "+high_days+" - "+document.onlinequote.totalprice.value+"  - "+document.onlinequote.nrdays.value);


			//for the commercial cars
			var car_type = cartype[document.onlinequote.booking_car.value];

			if(car_type == 3)
			{
				price_per_day = (Math.ceil( (parseInt(car_price_low) / 6)*100) )/100;
				extra_day_7 = (Math.ceil( (parseInt(car_price_low) / 7)*100) )/100;
				extra_day_6 = (Math.ceil((extra_day_7 + price_per_day) / 2) * 100) / 100;

				if(nr_days == 1)
				{
					total_price = price_per_day;
				}
				else if(nr_days == 2)
				{
					total_price = price_per_day * 2;
				}
				else if(nr_days == 3)
				{
					total_price = (Math.ceil( (car_price_low/2)*100) )/100;
				}
				else if((nr_days >= 4) && (nr_days < 7))
				{
					total_price = extra_day_6 * nr_days;
				}
				else
				{
					total_price = car_price_low + extra_day_7 * (nr_days - 7);
				}
				CalculatePrice = total_price;
			}
			
			CalculatePrice = (Math.round( (CalculatePrice)*100) )/100;
			document.onlinequote.totalprice.value = CalculatePrice;

			return true;
			
			}

			
			//--------------------------------------------
			//--- Added by George - 01.03.2011 -----------
			//--------------------------------------------

			function dateisNotPossible(day,month,year, mes) 
			{
				var datePoss = new Date().valueOf();
				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 calculate_price_check(err_car_id, 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 (isNaN(f.location_from.value) || (f.location_from.value==0)) 
				{ 
					alert(err_pick_up);
					f.location_from.focus(); 
					return false;
				}

				if (isNaN(f.location_to.value) || (f.location_to.value==0)) 
				{ 
					alert(err_drop_off);
					f.location_to.focus(); 
					return false;
				}

				if(isNaN(f.car_id.value) || (f.car_id.value == 0))
				{
					alert(err_car_id);
					f.car_id.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;}


				calculate_price();
				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 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 myonlinequote_check(err_car_id, 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, mes_valid_email,earliest_date_clients)
			{
				f = document.onlinequote;
				f.final_price.value = "yes";
				if(!calculate_price_check(err_car_id, 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, mes_valid_email,earliest_date_clients))
				{
					return false;
				}

				if (!emailck(f.email, mes_valid_email)) 
				{
					return false;
				}
				f.email_valid.value = 'yes';

				calculate_price();
				return true;
			}
