function takeYear(theDate) {
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}
var today = new Date();
Year = takeYear(today);
function validateSignUp () {
	$("custmessages").innerHTML = "";
	$("vehiclemessages").innerHTML = "";
	$("originmessages").innerHTML = "";
	$("destinmessages").innerHTML = "";
	$("tosmessages").innerHTML = "";
	
	error = false;
	re = /^[0-9a-zA-Z\-_ ]*$/;
	re_phone = /^[0-9\-_ ]*$/;
	re_number = /^[0-9]*$/;

// Customer Information //
	customersname  = $("customersname");
	quotedamount  = $("quotedamount");
	address  = $("address");
	city  = $("city");
	state  = $("state");
	zip  = $("zip");
	homephone  = $("homephone");
	cellphone  = $("cellphone");
	fax  = $("fax");
	email  = $("email");

	if (customersname.value.length < 1) {
		custError("Please enter the customers name.");
		error = true;	
	} if (quotedamount.value.length < 1) {
		custError("Please enter a quoted amount.");
		error = true;
	} if (address.value.length < 6) {
		custError("Your address is too short.");
		error = true;
	} if (city.value.length < 1) {
		custError("Please enter the city.");
		error = true;
	} if (state.value.length < 1) {
		custError("Please enter the state.");
		error = true;
	} if (zip.value.length != 5) {
		custError("Please enter a five digit zip code.");
		error = true;
	} if (homephone.value.length < 6) {
		custError("The home phone number entered is not valid.");
		error = true;
	} if (cellphone.value.length > 0 && cellphone.value.length < 6) {
		custError("The cell phone number entered is not valid.");
		error = true;
	} 
/* Vehicle Information */
	vehicleyear  = parseInt($("vehicleyear").value);
	if(isNaN(vehicleyear)){ vehicleyear = "string"}
	make  = $("make");
	model  = $("model");
	color  = $("color");
	availabledate  = $("availabledate");
	licenseplate  = $("licenseplate");
	vinnumber  = $("vinnumber");
	if (typeof vehicleyear != "number" || vehicleyear < 1900 || vehicleyear > Year) {
		vehicleError("Please enter a valid vehicle year. (ex:1963)");
		error = true;
	} if (make.value.length < 1) {
		vehicleError("Enter a Vehicle Make.");
		error = true;
	} if (model.value.length < 1) {
		vehicleError("Enter a Vehicle Model.");
		error = true;
	} if (color.value.length < 1) {
		vehicleError("Enter a Vehicle Color.");
		error = true;
	} if (availabledate.value.length < 1) {
		vehicleError("Please fill out the Availability Date.");
		error = true;
	} if (licenseplate.value.length < 1) {
		vehicleError("Please enter a license plate number.");
		error = true;
	} if (vinnumber.value.length < 1) {
		vehicleError("Please enter a vin number.");
		error = true;
	}
/* Origin Information */
	originname  = $("originname");
	originaddress  = $("originaddress");
	origincity  = $("origincity");
	originstate  = $("originstate");
	originzip  = $("originzip");
	originphone1  = $("originphone1");
	originphone2  = $("originphone2");
	originphone3  = $("originphone3");

	if (originname.value.length < 1) {
		originError("Please enter a Name.");
		error = true;
	} if (originaddress.value.length < 1) {
		originError("Please enter an Address.");
		error = true;
	} if (origincity.value.length < 1) {
		originError("Please enter a City.");
		error = true;
	} if (originstate.value.length < 1) {
		originError("Please enter a State.");
		error = true;
	} if (originzip.value.length < 1) {
		originError("Please enter a Zip Code.");
		error = true;
	} if (originphone1.value.length < 1) {
		originError("The Contact Phone number entered is not valid.");
		error = true;
	} if (originphone2.value.length > 0 && originphone2.value.length < 6) {
		originError("The Second Contact Phone number entered is not valid.");
		error = true;
	} if (originphone3.value.length > 0 && originphone3.value.length < 6) {
		originError("The Third Contact Phone number entered is not valid.");
		error = true;
	}
/* Destination Information */
	destinationname  = $("destinationname");
	destinationaddress  = $("destinationaddress");
	destinationcity  = $("destinationcity");
	destinationstate  = $("destinationstate");
	destinationzip  = $("destinationzip");
	destinationphone1  = $("destinationphone1");
	destinationphone2  = $("destinationphone2");
	destinationphone3  = $("destinationphone3");
	comments  = $("comments");
	if (destinationname.value.length < 1) {
		destinError("Please enter a Name.");
		error = true;
	} if (destinationaddress.value.length < 1) {
		destinError("Please enter an Address.");
		error = true;
	} if (destinationaddress.value.length < 1) {
		destinError("Please enter an Address.");
		error = true;
	} if (destinationcity.value.length < 1) {
		destinError("Please enter a City.");
		error = true;
	} if (destinationstate.value.length < 1) {
		destinError("Please enter a State.");
		error = true;
	} if (destinationzip.value.length < 1) {
		destinError("Please enter a Zip.");
		error = true;
	} if (destinationphone1.value.length < 1) {
		destinError("The Contact Phone number entered is not valid.");
		error = true;
	} if (destinationphone2.value.length > 0 && destinationphone2.value.length < 6) {
		destinError("The Second Contact Phone number entered is not valid.");
		error = true;
	} if (destinationphone3.value.length > 0 && destinationphone3.value.length < 6) {
		destinError("The Third Contact Phone number entered is not valid.");
		error = true;
	}
/* Email Validation */
	var at="@";
	var dot=".";
	var lat=email.value.indexOf(at);
	var lstr=email.value.length;
	var ldot=email.value.indexOf(dot);
	var emailerror = false;
	if (email.value.indexOf(at)==-1){ emailerror = true; emailmsg="1";	}
	if (email.value.indexOf(at)==-1 || email.value.indexOf(at)==0 || email.value.indexOf(at)==lstr){ emailerror = true; emailmsg="2"; }
	if (email.value.indexOf(dot)==-1 || email.value.indexOf(dot)==0 || email.value.indexOf(dot)==lstr){ emailerror = true; emailmsg="3"; }
	if (email.value.indexOf(at,(lat+1))!=-1){ emailerror = true; emailmsg="4"; }
	if (email.value.substring(lat-1,lat)==dot || email.value.substring(lat+1,lat+2)==dot){ emailerror = true; emailmsg="5"; }
	if (email.value.indexOf(dot,(lat+2))==-1){ emailerror = true; emailmsg="6"; }
	if (email.value.indexOf(" ")!=-1){ emailerror = true; emailmsg="7"; }
	if (emailerror==true){custError("Invalid email."/* + emailmsg*/); error = true; }




	if (!$('tos').checked) {
		tosError("You must agree to the Terms of Service.");
		error = true;
	}

	if (error){return false;}
	
}

function custError(text) {
	new Element('h3').setProperty('class', 'incorrect').appendText(text).setOpacity(0).injectInside('custmessages').effect('opacity').start(0,1);
	document.getElementById('customersname').focus();
}
function vehicleError(text) {
	new Element('h3').setProperty('class', 'incorrect').appendText(text).setOpacity(0).injectInside('vehiclemessages').effect('opacity').start(0,1);
	document.getElementById('customersname').focus();
}
function originError(text) {
	new Element('h3').setProperty('class', 'incorrect').appendText(text).setOpacity(0).injectInside('originmessages').effect('opacity').start(0,1);
	document.getElementById('customersname').focus();
}
function destinError(text) {
	new Element('h3').setProperty('class', 'incorrect').appendText(text).setOpacity(0).injectInside('destinmessages').effect('opacity').start(0,1);
	document.getElementById('customersname').focus();
}
function tosError(text) {
	new Element('h3').setProperty('class', 'incorrect').appendText(text).setOpacity(0).injectInside('tosmessages').effect('opacity').start(0,1);
}
