

	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 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 Delivery location.');document.onlinequote.location_from.focus(); return false;}
				if (document.onlinequote.location_to.value==0) { alert('Please choose a Collection location.'); document.onlinequote.location_to.focus(); return false;}
				if ((document.onlinequote.id1.selectedIndex==0) && (document.onlinequote.id2.selectedIndex==0) && (document.onlinequote.id3.selectedIndex==0) && (document.onlinequote.id4.selectedIndex==0)) { alert('Please choose a golf club.'); document.onlinequote.id1.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 (!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);
				if (nr_days==0) {nr_days=1;}
				if (strtime2 > strtime1) {alert('One day rental is 24h. In this case we have to charge one extra day.');nr_days=nr_days+1;}
				document.onlinequote.nrdays.value=nr_days;																										
												
				var CalculatePrice=0; extra= 0;	
				//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				
				//sistemul calc. Nr zile * valoarea PAX1- 1day,PAX2 - 2days,PAX3 - 3days * cantitatea QTY PENTRU 4 variabile - golf clubs
				//price for 1 day
				if (nr_days==1) {CalculatePrice=CalculatePrice+pax1[1]*qty[1]+pax1[2]*qty[2]+pax1[3]*qty[3]+pax1[4]*qty[4];}
				//price for 2 days
				if (nr_days==2) {CalculatePrice=CalculatePrice+pax2[1]*qty[1]+pax2[2]*qty[2]+pax2[3]*qty[3]+pax2[4]*qty[4];}
				//price for 3 days
				if (nr_days==3) {CalculatePrice=CalculatePrice+pax3[1]*qty[1]+pax3[2]*qty[2]+pax3[3]*qty[3]+pax3[4]*qty[4];}
				
				//price for 4 days
				if (nr_days==4) {CalculatePrice=CalculatePrice+pax6[1]*qty[1]+pax6[2]*qty[2]+pax6[3]*qty[3]+pax6[4]*qty[4];}
				
				//price for 7 days
				if ((nr_days>=5) && (nr_days<=7)) {CalculatePrice=CalculatePrice+pax4[1]*qty[1]+pax4[2]*qty[2]+pax4[3]*qty[3]+pax4[4]*qty[4];}
				//price for more then 7 days
				if (nr_days>7) {extra = nr_days-7; CalculatePrice=CalculatePrice+pax4[1]*qty[1]+pax4[2]*qty[2]+pax4[3]*qty[3]+pax4[4]*qty[4]+extra*pax5[1]*qty[1]+extra*pax5[2]*qty[2]+extra*pax5[3]*qty[3]+extra*pax5[4]*qty[4];}
			
				//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 + ')';
			document.onlinequote.totalprice.value = CalculatePrice;
			return true;
			
			}	
						