submitcount=0;
function carcalcvalidate(formobject) {

	var f = formobject || document.carcalc;
	var c,m,v;
	var daysout = 2; // days of lead time required (from today)
	var maxlength = 30; // days of max rental
    var startdaysout,enddaysout;

// form carcalc has these fields:

// <INPUT NAME="First" SIZE="10" TYPE="TEXT" MAXLENGTH="20">

	v = sval(c=f.First);
	if (v.length == 0) return abort(c,"Enter the driver's first name.");
    if (Check_Name_Field(c)) ; else return false;

// <INPUT NAME="Last" SIZE="15" TYPE="TEXT" MAXLENGTH="20">

	v = sval(c=f.Last);
	if (v.length == 0) return abort(c,"Enter the driver's last name.");
    if (Check_Name_Field(c)) ; else return false;

// <INPUT NAME="Age" SIZE="3" TYPE="TEXT" MAXLENGTH="3">

	v = sval(c=f.Age);
	if (v.length == 0) return abort(c,"Enter the driver's age.");
	if (v.match("^[1-9][0-9]+$")) ; // ok, continue
	else return abort(c,"The driver's age must be a whole number.");
	v = nval(c);
	if (v == NaN) return abort(c,"The driver's age must be a number.");
	if (v <21) return abort(c, "The driver must be 21 or older.");
	if (99 <v) return abort(c, "Please call if the driver is 100 or older!");

    v = sval(c=f.email);
    if (v.length == 0) return abort(c,"Enter your email address.");
    msg = "Your email address is not valid. Please re-enter it.";
    if (Check_EmailAddress_Field(c)) ; else return false;
    //if (0 == v.search(/\S+@\S+\.\S+/)) ; // ok, continue
    //else return abort(c, msg);

    v = sval(c=f.phone);
    if (v.length == 0) return abort(c,"Enter one or more phone numbers. Be sure to include your area code and country codes, as appropriate.");

// <SELECT NAME="CarLoc" onChange="GetCarCats(0)">

	v = sval(c=f.CarLoc);
	if (v == "XX") return abort(c,"Select Rental Location to pick up your rental car.");
       
// <SELECT NAME="CarCat"> (filled in dynamically)

	v = sval(c=f.CarCat);
	if (v == "XX") return abort(c,"Select Car Category (Compact, Intermediate...) of the car you wish to rent.");
       
    msg = "The car rental start date you have selected is not valid.";
	if (!CheckDate(f.date1)) return abort(f.date1,msg); 
    startdaysout = sval(f.date1);

// <SELECT NAME="Car_Start_Time">

	v = sval(c=f.Car_Start_Time);
	if (v == "XX") return abort(c,"Select the time of day you wish to pick up your rental car.");

    msg = "The car rental end date you have selected is not valid.";
	if (!CheckDate(f.date2)) return abort(f.date2,msg);
    enddaysout = sval(f.date2);

// <SELECT NAME="Car_End_Time">

	v = sval(c=f.Car_End_Time);
	if (v == "XX") return abort(c,"Select the time of day you wish to drop off your rental car.");
	if (enddaysout == startdaysout) { // same day, gotta check times
		var start24 = HHMM2min(sval(f.Car_Start_Time));
		if (start24 <0) return abort(c, "Please choose a valid car pickup time.");
		var end24 = HHMM2min(sval(f.Car_End_Time));
		if (end24 <0) return abort(c, "Please choose a valid car dropoff time.");
		if (end24 <= start24) return abort(c, "Car pickup time must be before car dropoff time when the pickup day is the same as the dropoff day. Please check the times.");
	}

// <INPUT NAME="CarClubNum" SIZE="16">

	v = (sval(c=f.CarClubNum));
	if (v.length == 0) ; // ok, optional, continue
	else if (v.match(/^\d{8}$/)) ; // ok, continue
	else return abort(c, "The Hertz Number One Club number must be all numeric and must be 8 digits long.");

// <INPUT TYPE="CHECKBOX" NAME="CarInfantSeat">
// <INPUT TYPE="CHECKBOX" NAME="CarToddlerSeat">

// <INPUT TYPE="SUBMIT" VALUE="Book Car Res" NAME="submit">
	c=f.submit;
// Check for double clicking of Submit button:
    if (submitcount > 0) {
        return abort(c, "We have received your booking request and are processing it. Please be patient. However, if you have gotten to this page through hitting your Back button, or if you suspect other malfunctions, please either reload this page or go back a page and then come back to this page and start again.");
    }
    ++submitcount;
    return true;
} // function carcalcvalidate
