function doValidation(theForm)
{
	var valid, make, model, make1;
	valid = true;
	
	make = theForm.make.value
	model = theForm.model.value;
	
	for(i=0; i<theForm.length; i++){
		if (theForm.elements[i].type.toLowerCase() != "hidden"){//eleminate javascript error when trying to set focus to a field that is hidden
			switch(theForm.elements[i].name.toLowerCase())
			{
				case "makenotrim1":
					if ( theForm.elements[i].value == null || theForm.elements[i].value == "" ) {
						alert( "Please select a make" );
						valid = false;
					}
					else if ( theForm.elements[i].value == make ) {
						alert( "You have already requested a quote for a " + make + ". Please select another make for another quote." );
						valid = false;
					}
					
					if ( valid == false ) {
						theForm.elements[i].focus();
					}
					else {
						make1 = theForm.elements[i].value;
					}
					
					break;
					
				case "modelnotrim1":
					if ( theForm.elements[i].value == null || theForm.elements[i].value == "" ) {
						alert( "Please select a model" );
						theForm.elements[i].focus();
						valid = false;
					}
					break;
					
				case "makenotrim2":
					if ( theForm.elements[i].value == null || theForm.elements[i].value == "" ) {
						alert( "Please select a make" );
						valid = false;
					}
					else if ( theForm.elements[i].value == make ) {
						alert( "You have already requested a quote for a " + make + ". Please select another make for another quote." );
						valid = false;
					}
					else if ( theForm.elements[i].value == make1 ) {
						alert( "You have already requested a quote for a " + make1 + ". Please select another make for another quote." );
						valid = false;
					}
					
					if ( valid == false ) {
						theForm.elements[i].focus();
					}
					
					break;
					
				case "modelnotrim2":
					if ( theForm.elements[i].value == null || theForm.elements[i].value == "" ) {
						alert( "Please select a model" );
						theForm.elements[i].focus();
						valid = false;
					}
					break;

				case "make1":
					if ( theForm.elements[i].value == null || theForm.elements[i].value == "" ) {
						alert( "Please select a make" );
						valid = false;
					}
					else if ( theForm.elements[i].value == make ) {
						alert( "You have already requested a quote for a " + make + ". Please select another make for another quote." );
						valid = false;
					}
					
					if ( valid == false ) {
						theForm.elements[i].focus();
					}
					else {
						make1 = theForm.elements[i].value;
					}
					
					break;
					
				case "model1":
					if ( theForm.elements[i].value == null || theForm.elements[i].value == "" ) {
						alert( "Please select a model" );
						theForm.elements[i].focus();
						valid = false;
					}
					break;

				case "autoid1":
					if ( theForm.elements[i].value == null || theForm.elements[i].value == "" ) {
						alert( "Please select a trim" );
						theForm.elements[i].focus();
						valid = false;
					}
					break;
					
				case "make2":
					if ( theForm.elements[i].value == null || theForm.elements[i].value == "" ) {
						alert( "Please select a make" );
						valid = false;
					}
					else if ( theForm.elements[i].value == make ) {
						alert( "You have already requested a quote for a " + make + ". Please select another make for another quote." );
						valid = false;
					}
					else if ( theForm.elements[i].value == make1 ) {
						alert( "You have already requested a quote for a " + make1 + ". Please select another make for another quote." );
						valid = false;
					}
					
					if ( valid == false ) {
						theForm.elements[i].focus();
					}
					
					break;
					
				case "model2":
					if ( theForm.elements[i].value == null || theForm.elements[i].value == "" ) {
						alert( "Please select a model" );
						theForm.elements[i].focus();
						valid = false;
					}
					break;

				case "autoid2":
					if ( theForm.elements[i].value == null || theForm.elements[i].value == "" ) {
						alert( "Please select a trim" );
						theForm.elements[i].focus();
						valid = false;
					}
					break;
					
			}	// end switch
		}
		
		if (!valid)
			break;	
	}	// end for loop
	
	return valid;
}


function doValidationForm2(theForm)
{
	var filledOut = true;

	filledOut = checkEmptyField (theForm.firstname, "Please enter a valid first name.");
	if (!filledOut) {
		return false;
	}

	filledOut = checkEmptyField (theForm.lastname, "Please enter a valid last name.");
	if (!filledOut) {
		return false;
	}
	
	filledOut = checkEmptyField (theForm.address, "Please enter a valid address.");
	if (!filledOut) {
		return false;
	}

	filledOut = checkEmptyField (theForm.city, "Please enter a valid city.");
	if (!filledOut) {
		return false;
	}

	/*  Allows only valid State*/
	var checkStr = theForm.state.options[theForm.state.options.selectedIndex].value;
	if (checkStr == null || checkStr == "")	{
		alert("Please select a state.");
		theForm.state.focus();
		filledOut=false;
		return (false);
	}

	/*Allows only valid Zip*/
	filledOut = checkZip (theForm);
	if (!filledOut) {
		return false;
	}

	/*  Allows only valid Email address.*/

	checkStr=theForm.email.value;
	if(checkStr=="" || checkStr.lastIndexOf("@")==-1 || checkStr.lastIndexOf(".")==-1) {
		alert("Please enter a valid Email address");
		theForm.email.focus();
		filledOut=false;
		return false;
	}
	
	var emailArr=checkStr.split("@");
	var user = new String( emailArr[0] );
	var domainAddress = new String( emailArr[1] );
	var domainAddressArr = domainAddress.split(".");
	var domain = new String( domainAddressArr[0] );
	var net = new String( domainAddressArr[1] );
		
	if ((user.length==0) || (domain.length==0) || (net.length==0)) {
		alert("Please enter a valid Email address.");
		theForm.email.focus();
		filledOut=false;
		return false;	
	}
	
	checkStr = theForm.payment.options[theForm.payment.options.selectedIndex].value;
	if (checkStr == null || checkStr == "")	{
		alert("Please select a Payment.");
		theForm.payment.focus();
		filledOut=false;
		return (false);
	}
	
	/* Allows only valid HomeAreaCode(only numeric values) */
	checkStr=theForm.areacode1.value;
	var objRegExp = /(^\d{3}$)/;
	if (!objRegExp.test(checkStr)) {
		alert("Please enter valid AreaCode (Numeric only)");
		theForm.areacode1.focus();
		filledOut=false;
		return(false);
	}

	/* Allows only valid HomePrefix(only numeric values)*/
   	checkStr=theForm.prefix1.value;
   	var objRegExp = /(^\d{3}$)/;
	if (!objRegExp.test(checkStr)) {
		alert("Please enter valid HomePrefix(Numeric only)");
		theForm.prefix1.focus();
		filledOut=false;
		return(false);
	}
	
	/* Allows only valid HomeNumber(only numeric values) */
	checkStr=theForm.phone1.value;
	var objRegExp = /(^\d{4}$)/;
	if (!objRegExp.test(checkStr)) {
		alert("Please enter valid HomeNumber (Numeric only)");
		theForm.phone1.focus();		
		filledOut=false;
		return(false);
	}

	return true;
}

function doValidationForm1(theForm)
{
	var filledOut = true;

	filledOut = checkEmptyField (theForm.make, "Please select a make.");
	if (!filledOut) {
		return false;
	}

	filledOut = checkEmptyField (theForm.model, "Please select a model.");
	if (!filledOut) {
		return false;
	}

	filledOut = checkEmptyField (theForm.autoid, "Please select a trim.");
	if (!filledOut) {
		return false;
	}

	/*Allows only valid Zip*/
	filledOut = checkZip (theForm);
	if (!filledOut) {
		return false;
	}

	return (true);
}

function doValidationFormNoTrim(theForm)
{
	var filledOut = true;

	filledOut = checkEmptyField (theForm.make, "Please select a make.");
	if (!filledOut) {
		return false;
	}

	filledOut = checkEmptyField (theForm.model, "Please select a model.");
	if (!filledOut) {
		return false;
	}
	
	/*if (theForm.make2.value != "")
	{
		filledOut = checkEmptyField (theForm.model2, "Please select a model.");
		if (!filledOut) {
			theForm.model2.focus();
			return false;
		}
	}

	if(theForm.make.value==theForm.make2.value) {
		alert("You have already selected a " + theForm.make.value + " for a quote.  Please select another make for another quote.");
		theForm.make2.focus();
		return (false);
	}*/
	
	/*Allows only valid Zip*/
	filledOut = checkZip (theForm);
	if (!filledOut) {
		return false;
	}

	return (true);
}

function doValidationFormNoTrim2(theForm)
{
	var filledOut = true;

	filledOut = checkEmptyField (theForm.make2, "Please select a make.");
	if (!filledOut) {
		return false;
	}

	filledOut = checkEmptyField (theForm.model2, "Please select a model.");
	if (!filledOut) {
		return false;
	}

	/*Allows only valid Zip*/
	filledOut = checkZip (theForm);
	if (!filledOut) {
		return false;
	}

	return (true);
}

function checkEmptyField (fieldObj, message)
{
	var checkStr=fieldObj.value;

	if(checkStr == null || checkStr == "") {
		alert(message);
		fieldObj.focus();
		return false;
	}

	return true;
}

function checkZip (theForm)
{
	var objRegExp = /(^\d{5}$)/;

	//check for valid US Zipcode
	if (!objRegExp.test(theForm.zip.value)) {
		alert("Please enter a valid zip.");
		theForm.zip.focus();
		return false;
	}

	return true;
}

function checkZip2 (theForm)
{
	var objRegExp = /(^\d{5}$)/;

	//check for valid US Zipcode
	if (!objRegExp.test(theForm.zip2.value)) {
		alert("Please enter a valid zip.");
		theForm.zip2.focus();
		return false;
	}

	return true;
}



function doValidationFormNoTrim3(theForm)
{
	var filledOut = true;

	filledOut = checkEmptyField (theForm.make, "Please select a make.");
	if (!filledOut) {
		return false;
	}

	filledOut = checkEmptyField (theForm.model, "Please select a model.");
	if (!filledOut) {
		return false;
	}
	
	/*Allows only valid Zip*/
	filledOut = checkZip (theForm);
	if (!filledOut) {
		return false;
	}

	return (true);
}

function doValidationFormNoTrim4(theForm)
{
	var filledOut = true;

	filledOut = checkEmptyField (theForm.make, "Please select a make.");
	if (!filledOut) {
		return false;
	}

	filledOut = checkEmptyField (theForm.model, "Please select a model.");
	if (!filledOut) {
		return false;
	}
	
	if (theForm.make2.value != "")
	{
		filledOut = checkEmptyField (theForm.model2, "Please select a model.");
		if (!filledOut) {
			theForm.model2.focus();
			return false;
		}
	}

	if(theForm.make.value==theForm.make2.value) {
		alert("You have already selected a " + theForm.make.value + " for a quote.  Please select another make for another quote.");
		theForm.make2.focus();
		return (false);
	}
	
	/*Allows only valid Zip*/
	filledOut = checkZip (theForm);
	if (!filledOut) {
		return false;
	}
	
	return (true);
}

function doValidationFormNoTrim5(theForm)
{
	var filledOut = true;

	filledOut = checkEmptyField (theForm.make, "Please select a make.");
	if (!filledOut) {
		return false;
	}

	filledOut = checkEmptyField (theForm.model, "Please select a model.");
	if (!filledOut) {
		return false;
	}
	
	if (theForm.make2.value != "")
	{
		filledOut = checkEmptyField (theForm.model2, "Please select a model.");
		if (!filledOut) {
			theForm.model2.focus();
			return false;
		}
	}

	if(theForm.make.value==theForm.make2.value) {
		alert("You have already selected a " + theForm.make.value + " for a quote.  Please select another make for another quote.");
		theForm.make2.focus();
		return (false);
	}
	
	/*Allows only valid Zip*/
	if (document.getElementById("LightBoxZipBox").style.display == "block") 
	{		
		filledOut = checkZip2 (theForm);
		if (!filledOut) {
			return false;
		}
	}
	else
	{
		filledOut = checkZip (theForm);
		if (!filledOut) {
			return false;
		}
	}
	
	return (true);
}

function doValidationForm3(theForm)
{
	var filledOut = true;

	filledOut = checkEmptyField (theForm.make1, "Please select a make.");
	if (!filledOut) {
		return false;
	}

	if(theForm.make1.value==theForm.make.value) {
		alert("You have already requested a quote for a " + theForm.make.value + ".  Please select another make for another quote.");
		theForm.make1.focus();
		return (false);
	}

	if(theForm.make2.value==theForm.make.value) {
		alert("You have already requested a quote for a " + theForm.make.value + ".  Please select another make for another quote.");
		theForm.make2.focus();
		return (false);
	}

	if(theForm.make1.value==theForm.make2.value) {
		alert("You have already selected a " + theForm.make1.value + " for a quote.  Please select another make for another quote.");
		theForm.make2.focus();
		return (false);
	}

	filledOut = checkEmptyField (theForm.model1, "Please select a model.");
	if (!filledOut) {
		return false;
	}

	return (true);
}

function doValidationForm4(theForm)
{
	var valid;
	valid = true;
	for(i=0;i<theForm.length;i++){
		if (theForm.elements[i].type.toLowerCase() != "hidden"){//eleminate javascript error when trying to set focus to a field that is hidden
			switch(theForm.elements[i].name.toLowerCase())
			{
				case "firstname":				
					valid = valid && CheckText(theForm.elements[i], false, "First Name") 
					break;
				case "lastname":
					valid = valid && CheckText(theForm.elements[i], false, "Last Name") 
					break;
				case "email":
					valid = valid && CheckEmail(theForm.elements[i], false, "Email") 
					break;
				case "address":
					valid = valid && CheckText(theForm.elements[i], false, "Address") 
					break;
				case "city":
					valid = valid && CheckText(theForm.elements[i], false, "City") 
					break;
				case "zip":
					valid = valid && CheckZip(theForm.elements[i], false, "ZIP Code") 		
					break;
				case "state":
					valid = valid && CheckSelect(theForm.elements[i], false, "State") 
					break;
				case "areacode1":
					valid = valid && CheckUnsignedInteger(theForm.elements[i], false, "Preferred Phone Area Code", 3) 
					break;
				case "prefix1":
					valid = valid && CheckUnsignedInteger(theForm.elements[i], false, "Preferred Phone Prefix", 3) 
					break;
				case "phone1":
					valid = valid && CheckUnsignedInteger(theForm.elements[i], false, "Preferred Phone Number", 4) 
					break;
				case "homeareacode": case "homephone1":
					valid = valid && CheckUnsignedInteger(theForm.elements[i], false, "Home Phone Area Code", 3) 
					break;
				case "homeprefix": case "homephone2":
					valid = valid && CheckUnsignedInteger(theForm.elements[i], false, "Home Phone Prefix", 3) 
					break;
				case "homenumber": case "homephone3":
					valid = valid && CheckUnsignedInteger(theForm.elements[i], false, "Home Phone Number", 4) 
					break;
				case "eveareacode": case "workphone1": case "areacode2":
					valid = valid && CheckUnsignedInteger(theForm.elements[i], false, "Work Phone Area Code", 3) 
					break;
				case "eveprefix": case "workphone2": case "prefix2":
					valid = valid && CheckUnsignedInteger(theForm.elements[i], false, "Work Phone Prefix", 3) 
					break;
				case "evenumber": case "workphone3": case "phone2":
					valid = valid && CheckUnsignedInteger(theForm.elements[i], false, "Work Phone Number", 4) 
					break;
				case "make":
					valid = valid && CheckSelect(theForm.elements[i], false, "Make")
					break;
				case "model":
					valid = valid && CheckSelect(theForm.elements[i], false, "Model")
					break;
				case "autoid":
					valid = valid && CheckSelect(theForm.elements[i], false, "Trim")
					break;
				case "payment":
					valid = valid && CheckSelect(theForm.elements[i], false, "Payment") 	
					break;			
			}	// end switch
		}
		if (!valid)
			break;	
	}	// end for loop
	return valid;
}// end function

function doDealerValidation(theForm)
{
	var valid;
	valid = true;
	
	for(i=0; i<theForm.length; i++){
		if (theForm.elements[i].type.toLowerCase() != "hidden"){//eleminate javascript error when trying to set focus to a field that is hidden
			switch(theForm.elements[i].name.toLowerCase())
			{					
				case "dealer1":
					if ( theForm.Dealer1.checked == false) {
						valid = false;
					}
					else
					{
						valid = true;
					}
					break;

				case "dealer2":
					if ( theForm.Dealer2.checked == true) {
						valid = true;
					}
					break;
					
				case "dealer3":
					if ( theForm.Dealer3.checked == true) {
						valid = true;
					}
					break;

				case "dealer4":
					if ( theForm.Dealer4.checked == true) {
						valid = true;
					}
					break;
								
			}	// end switch
		}
		
	}	// end for loop
	
	if (!valid)
	{
			alert("Please select a Dealer");
	}
	
	return valid;
}

