function book(classtype){
var valid;
valid = calculate();
if(valid==false){
	return false;
}
if(document.CalculatePrices.CDW.checked){
	document.CalculatePrices.CDWaiver.value = "YES";
}else{
	document.CalculatePrices.CDWaiver.value = "NO";
}
var drivers = document.CalculatePrices.Drivers.options[document.CalculatePrices.Drivers.selectedIndex].value;
document.CalculatePrices.adddrivers.value = drivers - 1;

if(classtype=='A'){
	document.CalculatePrices.euros.value = document.CalculatePrices.classAeu.value;
	document.CalculatePrices.classtype.value ="A";
	document.CalculatePrices.cartype.value = "Fiat Seicento - 3 door";
}else if(classtype=='B'){
	document.CalculatePrices.euros.value = document.CalculatePrices.classBeu.value;
	document.CalculatePrices.classtype.value ="B";
	document.CalculatePrices.cartype.value = "Fiat Punto - 5 door";
}else if(classtype=='C'){
	document.CalculatePrices.euros.value = document.CalculatePrices.classCeu.value;
	document.CalculatePrices.classtype.value ="C";
	document.CalculatePrices.cartype.value = "Rover 25/45 - 4/5 door";
}else if(classtype=='D'){
	document.CalculatePrices.euros.value = document.CalculatePrices.classDeu.value;
	document.CalculatePrices.classtype.value ="D";
	document.CalculatePrices.cartype.value = "Rover 45 Saloon - 4 door";
}else if(classtype=='E'){
	document.CalculatePrices.euros.value = document.CalculatePrices.classEeu.value;
	document.CalculatePrices.classtype.value ="E";
	document.CalculatePrices.cartype.value = "Fiat Punto Automatic - 5 door";
}else if(classtype=='F'){
	document.CalculatePrices.euros.value = document.CalculatePrices.classFeu.value;
	document.CalculatePrices.classtype.value ="F";
	document.CalculatePrices.cartype.value = "Rover 45 Automatic - 4 door";
}else if(classtype=='G'){
	document.CalculatePrices.euros.value = document.CalculatePrices.classGeu.value;
	document.CalculatePrices.classtype.value ="G";
	document.CalculatePrices.cartype.value = "Rover 75 Automatic - 4 door";
}else if(classtype=='H'){
	document.CalculatePrices.euros.value = document.CalculatePrices.classHeu.value;
	document.CalculatePrices.classtype.value ="H";
	document.CalculatePrices.cartype.value = "Land Rover Freelander - 4 door";

}else if(classtype=='I'){
	document.CalculatePrices.euros.value = document.CalculatePrices.classIeu.value;
	document.CalculatePrices.classtype.value ="I";
	document.CalculatePrices.cartype.value = "Land Rover Discovery";
}else if(classtype=='J'){
	document.CalculatePrices.euros.value = document.CalculatePrices.classJeu.value;
	document.CalculatePrices.classtype.value ="J";
	document.CalculatePrices.cartype.value = "Range Rover";
}else if(classtype=='K'){
	document.CalculatePrices.euros.value = document.CalculatePrices.classKeu.value;
	document.CalculatePrices.classtype.value ="K";
	document.CalculatePrices.cartype.value = "Rover 75 Luxury";
}
if (Validate()) document.CalculatePrices.submit(); 
}

function calculate(){
	var startday;
	var startmonth;
	var startyear;
	var season = "low";
	var validate1;
	var validate2;
	
	startday = document.CalculatePrices.ArrDay.options[document.CalculatePrices.ArrDay.selectedIndex].value;
	startmonth = document.CalculatePrices.ArrMonth.options[document.CalculatePrices.ArrMonth.selectedIndex].value;
	startyear = document.CalculatePrices.ArrYear.options[document.CalculatePrices.ArrYear.selectedIndex].value;
	starttime = document.CalculatePrices.TimeArrival.options[document.CalculatePrices.TimeArrival.selectedIndex].value;
	
	startdate = startday+"/"+startmonth+"/"+startyear;
	document.CalculatePrices.startdate.value = startdate;
	document.CalculatePrices.starttime.value = starttime + ":00";
		
	endday = document.CalculatePrices.DepartDay.options[document.CalculatePrices.DepartDay.selectedIndex].value;
	endmonth = document.CalculatePrices.DepartMonth.options[document.CalculatePrices.DepartMonth.selectedIndex].value;
	endyear = document.CalculatePrices.DepartYear.options[document.CalculatePrices.DepartYear.selectedIndex].value;
	endtime = document.CalculatePrices.TimeDeparture.options[document.CalculatePrices.TimeDeparture.selectedIndex].value;
	enddate = endday+"/"+endmonth+"/"+endyear;
	document.CalculatePrices.enddate.value = enddate;
	document.CalculatePrices.endtime.value = endtime + ":00";
	
	validate1 = checkstartdate(document.CalculatePrices.startdate);
	if(validate1 == false){
		return false;
	}
	validate2 = checkenddate(document.CalculatePrices.enddate);
	if(validate2 == false){
		return false;
	}
	
	if(document.CalculatePrices.TimeArrival.options[document.CalculatePrices.TimeArrival.selectedIndex].value == ""){
		alert("You must select a Pickup Time");
		document.CalculatePrices.TimeArrival.focus();
		return false;
	}
	if(document.CalculatePrices.TimeDeparture.options[document.CalculatePrices.TimeDeparture.selectedIndex].value == ""){
		alert("You must select a Drop Off Time");
		document.CalculatePrices.TimeDeparture.focus();
		return false;
	}
	
	if(endmonth >= 7 && endmonth < 9){
		season = "high";
	}
	if((endmonth == 12 && endday >=11) || (endmonth == 1 && endday <=6)){
		season = "high";
	}
	if(startmonth >= 7 && startmonth < 9){
		season = "high";
	}
	if((startmonth == 12 && startday >=11) || (startmonth == 1 && startday <=6)){
		season = "high";
	}
	
	
	if (Date.parse(document.CalculatePrices.startdate.value) > Date.parse(document.CalculatePrices.enddate.value)) {
		alert("Drop Off Date must be later than Pickup date!!!");
		return false;
	}
	
	// The number of milliseconds in one day
    var HOURS = 1000 * 60 * 60

    // Convert both dates to milliseconds
    var date1_ms = Date.parse(document.CalculatePrices.startdate.value +" "+starttime+":00:00")
    var date2_ms = Date.parse(document.CalculatePrices.enddate.value +" "+endtime+":00:00")

	// Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)
    var tothours = difference_ms/HOURS;
    // Convert back to hours and return
	
	
	if(!tothours>0){
		alert("Drop Off Time must be later than Pickup Time!!!");
		return false;
	}
	
	var diffhours = tothours % 24;
	var fulldays = (tothours - diffhours)/24
	
	var totaldays = fulldays;
	if(diffhours>=2 && fulldays>0){
		totaldays = totaldays + 2;
	}
	if(fulldays == 0){
		totaldays = 1;
	}
	
	var drivers = document.CalculatePrices.Drivers.options[document.CalculatePrices.Drivers.selectedIndex].value;
	var driverprice= (drivers - 1)*totaldays;
	var CDWins;
	
	if(document.CalculatePrices.CDW.checked){
	CDWins = totaldays * 1;
	}else{
	CDWins = totaldays * 0;
	}
	
	document.CalculatePrices.classAeu.value = round_decimals((priceit(season,0,totaldays)+(driverprice*8)+(CDWins * 7)),2);
	document.CalculatePrices.classBeu.value = round_decimals((priceit(season,1,totaldays)+(driverprice*8)+(CDWins * 7)),2);
	document.CalculatePrices.classCeu.value = round_decimals((priceit(season,2,totaldays)+(driverprice*8)+(CDWins * 9)),2);
	document.CalculatePrices.classDeu.value = round_decimals((priceit(season,3,totaldays)+(driverprice*8)+(CDWins * 9)),2);
	document.CalculatePrices.classEeu.value = round_decimals((priceit(season,4,totaldays)+(driverprice*8)+(CDWins * 9)),2);
	document.CalculatePrices.classFeu.value = round_decimals((priceit(season,5,totaldays)+(driverprice*8)+(CDWins * 9)),2);
	document.CalculatePrices.classGeu.value = round_decimals((priceit(season,6,totaldays)+(driverprice*8)+(CDWins * 15)),2);
	document.CalculatePrices.classHeu.value = round_decimals((priceit(season,7,totaldays)+(driverprice*8)+(CDWins * 15)),2);
	document.CalculatePrices.classIeu.value = round_decimals((priceit(season,8,totaldays)+(driverprice*15)+(CDWins * 25)),2);
document.CalculatePrices.classJeu.value = round_decimals((priceit(season,9,totaldays)+(driverprice*15)+(CDWins * 25)),2);
document.CalculatePrices.classKeu.value = round_decimals((priceit(season,10,totaldays)+(driverprice*15)+(CDWins * 25)),2);

		
	return true;
}

function priceit(season,classtype,days){

var lowseason1 = [22.00,25.00,35.00,40.00,44.00,50.00,69.00,63.00,101.00,210.00,82.00];
var lowseason2 = [17.00,21.00,29.00,36.00,39.00,40.00,58.00,57.00,88.00,180.00,69.00];
var highseason1 = [38.00,43.00,50.00,57.00,53.00,63.00,76.00,82.00,120.00,210.00,107.00];
var highseason2 = [34.00,38.00,45.00,53.00,48.00,57.00,69.00,78.00,101.00,180.00,95.00];

var amount;

if(season=="low" && days<7){
	amount = lowseason1[classtype]*days;
	return amount;
}
if(season=="low" && days>6){
	amount = lowseason2[classtype]*days;
	return amount;
}
if(season=="high" && days<7){
	amount = highseason1[classtype]*days;
	return amount;
}
if(season=="high" && days>6){
	amount = highseason2[classtype]*days;
	return amount;
}


}



function checkstartdate(objName) {
var datefield = objName;
	if (chkdate(objName) == false) {
		//datefield.select();
		alert("You have entered an incorrect Pickup date.  Please try again.");
		//datefield.focus();
		return false;
	}
	else {
		return true;
		
   }
}
function checkenddate(objName) {
var datefield = objName;
	if (chkdate(objName) == false) {
		//datefield.select();
		alert("You have entered an incorrect Drop Off date.  Please try again.");
		//datefield.focus();
		return false;
	}
	else {
		return true;
   }
}


function chkdate(objName) {
//var strDatestyle = "US"; //United States date style
var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
strDate = datefield.value;
	if (strDate.length < 1) {
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
   		}
	}
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
   		}
	}
	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}

// US style
	if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}

intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
   			}
		}
	if (isNaN(intMonth)) {
		err = 3;
		return false;
   	}
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {
datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
}
else {
datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}


function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

//  End -->

