			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];			
			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 GetHighSeasonDaysMadeira(start_date, end_date, nr_days) {
		//high season
		//17.12.2009 - 07.01.2010 and 27.03.2010 - 06.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;	}
			
			//Bogdan - add new Christmas period 1
			if ((dd>=17) && (mm==12) && (yy==2009)  &&   (dd<=31) && (mm==12) && (yy==2009)) {	myGetHighSeasonDays=myGetHighSeasonDays+1;	}
			//Bogdan - add new Christmas period 2
			if ((dd>=1) && (mm==1) && (yy==2010)  &&   (dd<=7) && (mm==1) && (yy==2010)) {	myGetHighSeasonDays=myGetHighSeasonDays+1;	}						
			//Bogdan - add new Estear period 1
			if ((dd>=27) && (mm==3) && (yy==2010)  &&   (dd<=31) && (mm==3) && (yy==2010)) {	myGetHighSeasonDays=myGetHighSeasonDays+1;	}
			//Bogdan - add new Estear period 1
			if ((dd>=1) && (mm==4) && (yy==2010)  &&   (dd<=6) && (mm==4) && (yy==2010)) {	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];			

			//Bogdan - add new Christmas period 1 and 2 and easter 1 and 2 - stay the same no of days - else add 
			if  ( ((dd>=17) && (mm==12) && (yy==2009)  &&   (dd<=31) && (mm==12) && (yy==2009)) || ((dd>=1) && (mm==1) && (yy==2010)  &&   (dd<=7) && (mm==1) && (yy==2010)) || ((dd>=27) && (mm==3) && (yy==2010)  &&   (dd<=31) && (mm==3) && (yy==2010)) || ((dd>=1) && (mm==4) && (yy==2010)  &&   (dd<=6) && (mm==4) && (yy==2010)) )
				{	myGetMidSeasonDays=myGetMidSeasonDays;	}
				else if ( ((mm>=4) && (mm<=6)) || (mm==10) || ( (mm>=11) || (mm<=3) ) ) {	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 GetLowSeasonDaysMadeira(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];					
			

			//Bogdan - add new Christmas period 1 and 2 and easter 1 and 2 - stay the same no of days - else add 
			if  ( ((dd>=17) && (mm==12) && (yy==2008)  &&   (dd<=31) && (mm==12) && (yy==2008)) || ((dd>=1) && (mm==1) && (yy==2009)  &&   (dd<=4) && (mm==1) && (yy==2009)) || ((dd>=29) && (mm==3) && (yy==2009)  &&   (dd<=31) && (mm==3) && (yy==2009)) || ((dd>=1) && (mm==4) && (yy==2009)  &&   (dd<=14) && (mm==4) && (yy==2009)) )
				{	myGetLowSeasonDays=myGetLowSeasonDays;	}
				else 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 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];
			
			//=====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)) || (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 GetPromoLowSeasonDays(start_date, end_date, nr_days) {
		//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>=1) && (mm<=3)) && (yy == 2009)) {	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];
			//=====cod corect pana pe data de 13 nov 2009 - modificat de Irina==========
			/*if(((mm>=1) && (mm<=3)) && (yy == 2009))
			{
				//do nothing - these are the promo days
			}
			else if (((mm>=11) || (mm<=3))) {	myGetLowSeasonDays=myGetLowSeasonDays+1; }*/

			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('Bitte, wählen Sie einen Standort für die Sammlung.');document.onlinequote.location_from.focus(); return false;}
				if (document.onlinequote.location_to.value==0) { alert('Bitte, wählen Sie einen Standort für die Lieferung.'); document.onlinequote.location_to.focus(); return false;}
				if (document.onlinequote.booking_car.value==0) { alert('Bitte, wählen Sie ein Auto.'); 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('Die Zeitpunkt der Sammlung ist größer als der Zeitpunkt der Lieferung, was einen zusätzlichen Tag der Zahlung.');
							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'))
				{
				
						//Bogdan - add new Christmas period 1 and 2 and easter 1 and 2 - stay the same no of days - else add 
						if  ( ((dd>=17) && (mm==12) && (yy==2009)  &&   (dd<=31) && (mm==12) && (yy==2009)) || ((dd>=1) && (mm==1) && (yy==2010)  &&   (dd<=7) && (mm==1) && (yy==2010)) || ((dd>=27) && (mm==3) && (yy==2010)  &&   (dd<=31) && (mm==3) && (yy==2010)) || ((dd>=1) && (mm==4) && (yy==2010)  &&   (dd<=6) && (mm==4) && (yy==2010)) )
							{	 epoca =3;	}
							else if ((mm>=7) && (mm<=9)) 		{  epoca =3; } //high
								else if ((mm>=4) && (mm<=6) || (mm==10)) {  epoca =2; } //mid	
										else if ((mm>=11) || (mm<=3)) 	{  epoca =2; } //mid	
								

						/*day_start = new Array();
						month_start = new Array();
						year_start = new Array();
						day_end = new Array();
						month_end = new Array();
						year_end = new Array();

						var num_special_periods = document.onlinequote.num.value;
						for(k = 1; k <= num_special_periods; k++)
						{
							day_start[k] = eval("document.onlinequote.day_start_"+k+".value");
							month_start[k] = eval("document.onlinequote.month_start_"+k+".value");
							year_start[k] = eval("document.onlinequote.year_start_"+k+".value");

							day_end[k] = eval("document.onlinequote.day_end_"+k+".value");
							month_end[k] = eval("document.onlinequote.month_end_"+k+".value");
							year_end[k] = eval("document.onlinequote.year_end_"+k+".value");



							if ((dd>=day_start[k]) && (mm==month_start[k]) && (yy==year_start[k])  &&   (dd2<=day_end[k]) && (mm2==month_end[k]) && (yy2==year_end[k])) { epoca =3; }
						}*/

						/*
						//Bogdan - add new Christmas period
						if ((dd>=19) && (mm==12) && (yy==2007)  &&   (dd2<=31) && (mm2==12) && (yy2==2007)) { epoca =3; }
						//Bogdan - add new Christmas period 2
						if ((dd>=19) && (mm==12) && (yy==2007)  &&   (dd2<=3) && (mm2==1) && (yy2==2008)) { epoca =3; }						
						//Bogdan - add new Estear period
						if ((dd>=9) && (mm==3) && (yy==2008)  &&   (dd2<=23) && (mm2==3) && (yy2==2008)) { epoca =3; }*/

						//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));
						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)) || (mm==10)){  epoca =2; }

					
					if ((mm>=7) && (mm<=9)) 		{  epoca =3; } //high

					//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));
					var low_days = GetLowSeasonDays(strdate1s, strdate2s, parseInt(nr_days));	
					var low_promo_days = GetPromoLowSeasonDays(strdate1s, strdate2s, parseInt(nr_days));
				}
				
				

				//se iau preturile pentru masini	
				if(low_promo_days)
				{
					var car_price_low = carpricepromolow[document.onlinequote.booking_car.value];
					low_days = low_promo_days;
				}
				else
				{
					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) ) 
					{
						if(low_days > 0)
						{
							low_days = low_days  - (3 - mid_days);
						}
						else
						{
							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;
					}	
				if(low_days < 0)
				{
					low_days = 0;
				}
				if(mid_days < 0)
				{
					mid_days = 0;
				}
				if(high_days < 0)
				{
					high_days = 0;
				}

					
				//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
	
			//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)*100) )/100; halfweekprice = 1; }
			if ( (low_days==0) && (mid_days==3) && (high_days==0) ) { var CalculatePrice =  (Math.round( (parseInt(car_price_mid)   / 2)*100) )/100; halfweekprice = 1;}
			if ( (low_days==0) && (mid_days==0) && (high_days==3) ) { var CalculatePrice =  (Math.round( (parseInt(car_price_high)  / 2)*100) )/100; halfweekprice = 1;}												
			
			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;
		
				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;

				
				
				// 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;
				}
				
				//alert("price_low = "+price_low+" - price_mid = "+price_mid+" - price_high = "+price_high);

				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 );		
			}
			//alert("high = "+high_days+" - mid = "+mid_days+" - low = "+low_days+" halfweekprice = "+halfweekprice);
			//excess insurance
			if (priceinsurance>0) CalculatePrice = CalculatePrice + priceinsurance;

			//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;
			}


			//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;
			return true;
			
			}	