
window.onload = function() {
	contactSend();
	dealerSend();
}

/* -- checker function - checks to see if variables in each function exist -- */

function checkVars(e) {
	var x = e.split(",");
	var pass = true;
	checkerInvalid = new Array;

	for(i=0; i<x.length; i++) {
		
		if(!eval(x[i])) {
		pass = false; 
		checkerInvalid[checkerInvalid.length] = x[i];
		}
		
	}
	
	return pass;

}

/* -- validate contact form -- */

function valContactForm() {
	
	if(!checkVars('document.frmcontact.co_visitorname, document.frmcontact.co_street, document.frmcontact.co_city, document.frmcontact.co_state, document.frmcontact.co_zip, document.frmcontact.co_email')) {
		return;
	}
	
	var name_value = document.frmcontact.co_visitorname.value;
	var street_value = document.frmcontact.co_street.value;
	var city_value = document.frmcontact.co_city.value;
	var state_value = document.frmcontact.co_state.value;
	var zip_value = document.frmcontact.co_zip.value;
	var email_value = document.frmcontact.co_email.value;
	var errormsg = '';


	if (name_value == '') {
		errormsg = errormsg + '-You must input your Name\n';
	}
	
	if (street_value == '') {
		errormsg = errormsg + '-You must input your Street Address\n';
	}
	
	if (city_value == '') {
		errormsg = errormsg + '-You must input your City\n';
	}
	
	if (state_value == '') {
		errormsg = errormsg + '-You must input your State\n';
	}
	
	if (zip_value == '') {
		errormsg = errormsg + '-You must input your Zip Code\n';
	}
	
	if (email_value == '') {
		errormsg = errormsg + '-You must input your Email Address\n';
	}
	
	if (errormsg != '') {
		alert('The following errors were found:\n'+errormsg);
		return false;
	}
	
	else { 
		return true; 
	}

}

function contactSend() {
	
	
	if(!checkVars('document.getElementById("frmcontact")')) {
		return;
	}
	
	var form_name = document.getElementById("frmcontact");
	
	form_name.onsubmit = function() {
		return valContactForm();
	}
}
	
/* -- [ Validate the Dealer Locator Form ] -- */
	
function valDealerLoc() {
	
	if(!checkVars("document.frmlocatedealer.lo_de_zip")) {
		return;
	}
	
	var zip_value = document.frmlocatedealer.lo_de_zip.value;
	var dealer_error = "";
	
	if(zip_value == "") {
		dealer_error = dealer_error + "-You must input your Zip Code\n";
	}
	
	if(dealer_error != "") {
		alert("The following errors were found:\n"+dealer_error);
		return false;
	}
	

}


function dealerSend() {

	if(!checkVars('document.getElementById("frmlocatedealer")')) {
		return;
	}
	
	dealer_form = document.getElementById("frmlocatedealer");
	
	dealer_form.onsubmit = function() {
		return valDealerLoc();
	}
}