function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
		return (false);
		}	
	} 
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);		
		} 
	}
}


function ifNum(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	 return true;
}

function checkVar(theForm,theVar){
	var theFormA = document.forms[theForm];
	if (theFormA.elements[theVar].value.replace(/\s+/i,"")==""){
         theFormA.elements[theVar].className = 'errorSelect';
        return false;
	}else{
        theFormA.elements[theVar].className = '';
        return true;
    }
}

function checkNum(theForm,theVar,theSize){
	var theFormN = document.forms[theForm];
	if (theFormN.elements[theVar].value.length < theSize){
         theFormN.elements[theVar].className = 'errorSelect';
        return false;
	}else{
        theFormN.elements[theVar].className = '';
        return true;
    }
}

function checkVarEmail(theForm,theVar){
	var theFormE = document.forms[theForm];
	if(!check_email(theFormE.elements[theVar].value)){
         theFormE.elements[theVar].className = 'errorSelect';
		 return false;
    }else{
        theFormE.elements[theVar].className = '';
        return true;
    }
}

function checkVE(){//vehicle enquiry
	var theFormName = 'enqForm';
	var firstName = checkVar(theFormName,'firstName');
	var address = checkVar(theFormName,'address');
	var suburb = checkVar(theFormName,'suburb');
	var postCode = checkNum(theFormName,'postCode',4);
	var email = checkVarEmail(theFormName,'email');
	var mobilePhone = checkNum(theFormName,'phone',8);
	var howHear = checkVar(theFormName,'howHear');

	if(firstName && address && suburb && postCode && email && mobilePhone && howHear){
        document.forms[theFormName].submit();
    }
}

function checkVFE(){//vehicle finance enquiry
	var theFormName = 'enqFinanceForm';
	var firstName = checkVar(theFormName,'firstName');
	var address = checkVar(theFormName,'address');
	var suburb = checkVar(theFormName,'suburb');
	var postCode = checkNum(theFormName,'postCode',4);
	var email = checkVarEmail(theFormName,'email');
	var mobilePhone = checkNum(theFormName,'phone',8);
	var howHear = checkVar(theFormName,'howHear');

	if(firstName && address && suburb && postCode && email && mobilePhone && howHear){
        document.forms[theFormName].submit();
    }
}

function checkFE(){//finance enquiry form
	var theFormName = 'financeForm';
	var firstName = checkVar(theFormName,'firstName');
	var suburb = checkVar(theFormName,'suburb');
	var postCode = checkNum(theFormName,'postCode',4);
	var email = checkVarEmail(theFormName,'email');
	var phone = checkNum(theFormName,'phone',8);
	var howHear = checkVar(theFormName,'howHear');

	if(firstName && suburb && postCode && email && phone && howHear){
        document.forms[theFormName].submit();
    }
}

function checkGIFT(){//internet gift form
	var theFormName = 'internetGift';
	var firstName = checkVar(theFormName,'firstName');
	var suburb = checkVar(theFormName,'suburb');
	var postCode = checkNum(theFormName,'postCode',4);
	var email = checkVarEmail(theFormName,'email');
	var phone = checkNum(theFormName,'phone',8);
	var howHear = checkVar(theFormName,'howHear');

	if(firstName && suburb && postCode && email && phone && howHear){
        document.forms[theFormName].submit();
    }
}

function checkFL(){//fleet enquiry form
	var theFormName = 'fleetForm';
	var firstName = checkVar(theFormName,'firstName');
	var suburb = checkVar(theFormName,'suburb');
	var postCode = checkNum(theFormName,'postCode',4);
	var email = checkVarEmail(theFormName,'email');
	var phone = checkNum(theFormName,'phone',8);
	var howHear = checkVar(theFormName,'howHear');

	if(firstName && suburb && postCode && email && phone && howHear){
        document.forms[theFormName].submit();
    }
}

function checkSER(){//service enquiry form
	var theFormName = 'serviceForm';
	var firstName = checkVar(theFormName,'firstName');
	var lastName = checkVar(theFormName,'surname');
	var suburb = checkVar(theFormName,'suburb');
	var postCode = checkNum(theFormName,'postCode',4);
	var email = checkVarEmail(theFormName,'email');
	var phone = false;
	var homePhone = checkNum(theFormName,'homePhone',8);
	var workPhone = checkNum(theFormName,'workPhone',8);
	var mobilePhone = checkNum(theFormName,'mobilePhone',8);
	var dealership = checkVar(theFormName,'selectDealership');
	var make = checkVar(theFormName,'make');
	var model = checkVar(theFormName,'model');
	var odometer = checkNum(theFormName,'odometer',2);
	var year = checkNum(theFormName,'year',2);
	var trans = checkVar(theFormName,'trans');
	var reg = checkVar(theFormName,'reg');
	var preferredDate = checkVar(theFormName,'preferredDate');
	var preferredTime = checkVar(theFormName,'preferredTime');
	var howHear = checkVar(theFormName,'howHear');

	if(homePhone || workPhone || mobilePhone){
		phone = true;
	}

	if(firstName && lastName && suburb && postCode && email && phone && dealership && make && model && year && odometer && trans && reg && preferredDate && preferredTime && howHear){
        document.forms[theFormName].submit();
    }
}

function checkSERsmall(){//mini service enquiry form
	var theFormName = 'serviceForm';
	var firstName = checkVar(theFormName,'firstName');
	var phone = checkNum(theFormName,'phone',8);
	var email = checkVarEmail(theFormName,'email');
	var make = checkVar(theFormName,'make');
	var model = checkVar(theFormName,'model');
	var year = checkNum(theFormName,'year',2);
	var odometer = checkNum(theFormName,'odometer',2);
	var preferredDate = checkVar(theFormName,'preferredDate');
	var preferredTime = checkVar(theFormName,'preferredTime');

	if(firstName && phone && email && make && model && year && odometer && preferredDate && preferredTime){
        document.forms[theFormName].submit();
    }
}

function checkPAR(){//parts enquiry form
	var theFormName = 'partsForm';
	var firstName = checkVar(theFormName,'firstName');
	var lastName = checkVar(theFormName,'surname');
	var suburb = checkVar(theFormName,'suburb');
	var postCode = checkNum(theFormName,'postCode',4);
	var email = checkVarEmail(theFormName,'email');
	var phone = false;
	var homePhone = checkNum(theFormName,'homePhone',8);
	var workPhone = checkNum(theFormName,'workPhone',8);
	var mobilePhone = checkNum(theFormName,'mobilePhone',8);
	var dealership = checkVar(theFormName,'selectDealership');
	var make = checkVar(theFormName,'make');
	var model = checkVar(theFormName,'model');
	var year = checkNum(theFormName,'year',2);
	var reg = checkVar(theFormName,'reg');
	var vin = checkVar(theFormName,'vin');
	var partDescription = checkVar(theFormName,'partDescription');
	var partQty = checkVar(theFormName,'partQty');
	var howHear = checkVar(theFormName,'howHear');

	if(homePhone || workPhone || mobilePhone){
		phone = true;
	}
	if(firstName && lastName && suburb && postCode && email && phone && dealership && make && model && year && reg && vin && partDescription && partQty && howHear){
        document.forms[theFormName].submit();
    }
}

function checkPARsmall(){//mini parts enquiry form
	var theFormName = 'partsForm';
	var firstName = checkVar(theFormName,'firstName');
	var phone = checkNum(theFormName,'phone',8);
	var email = checkVarEmail(theFormName,'email');
	var make = checkVar(theFormName,'make');
	var model = checkVar(theFormName,'model');
	var year = checkNum(theFormName,'year',2);
	var odometer = checkNum(theFormName,'odometer',2);
	var partDescription = checkVar(theFormName,'partDescription');
	var partQty = checkVar(theFormName,'partQty');

	if(firstName && phone && email && make && model && year && odometer && partDescription && partQty){
        document.forms[theFormName].submit();
    }
}

function checkCON(){//contact enquiry form
	var theFormName = 'contactForm';
	var firstName = checkVar(theFormName,'firstName');
	var lastName = checkVar(theFormName,'surname');
//	var suburb = checkVar(theFormName,'suburb');
	var postCode = checkNum(theFormName,'postCode',4);
	var email = checkVarEmail(theFormName,'email');
//	var phone = false;
	var phone = checkNum(theFormName,'phone',8);
//	var homePhone = checkNum(theFormName,'homePhone',8);
//	var workPhone = checkNum(theFormName,'workPhone',8);
//	var mobilePhone = checkNum(theFormName,'mobilePhone',8);
	var dealership = checkVar(theFormName,'selectDealership');
//	var howHear = checkVar(theFormName,'howHear');

//	if(homePhone || workPhone || mobilePhone){
//		phone = true;
//	}
//	if(firstName && lastName && suburb && postCode && email && phone && dealership && howHear){
	if(firstName && lastName && postCode && email && phone && dealership){
        document.forms[theFormName].submit();
    }
}

function checkSUA(){//alerts signup

	var theFormName = 'alertForm';
	var fullname = checkVar(theFormName,'fullname');
	var email = checkVarEmail(theFormName,'email');
	var make = checkVar(theFormName,'make');
	var model = checkVar(theFormName,'model');

	if(fullname && email && make && model){
        document.forms[theFormName].submit();
    }
}

function checkSUN(){//newsletter signup
	var theFormName = 'newsletterForm';
	var firstName = checkVar(theFormName,'firstName');
	var surname = checkVar(theFormName,'surname');
	var email = checkVarEmail(theFormName,'email');

	if(firstName && surname && email){
        document.forms[theFormName].submit();
    }
}

function checkItalk(dID){
	var theFormName = 'italk_connect';
	var phone2 = checkNum(theFormName,'phone2',8);
	var strUC;

	if(phone2){			
		strUC = 'pageID=37&dealerID=';
		strUC += dID;
		strUC += '&action=ITalk';
		userClick(strUC);
        document.forms[theFormName].submit();
    }
}

function checkVFEOther(){
	
	var sldItem = enqFinanceForm.howHear[enqFinanceForm.howHear.selectedIndex].value; 
	var howOther = document.getElementById('howOtherVFE');	

	if(sldItem == 'OTHER'){					
		howOther.style.display='';}	
	else{
		howOther.style.display='none';}		
	
}
function checkUVEOther(){
	
	var sldItem = enqForm.howHear[enqForm.howHear.selectedIndex].value; 
	var howOther = document.getElementById('howOtherUVE');	

	if(sldItem == 'OTHER'){					
		howOther.style.display='';}	
	else{
		howOther.style.display='none';}		
}

function checkHowOther(selBox){	
	
	var sldItem = selBox[selBox.selectedIndex].value; 
	var howOther = document.getElementById('howOther');	

	if(sldItem == 'OTHER'){					
		howOther.style.display='';}	
	else{
		howOther.style.display='none';}		
}
