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 refer = checkVar(theFormName,'howHear');

	if(firstName && suburb && postCode && email && mobilePhone && refer){
        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);

	if(firstName && address && suburb && postCode && email && mobilePhone){
        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);

	if(firstName && suburb && postCode && email && phone){
        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);

	if(firstName && suburb && postCode && email && phone){
        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 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 serviceInterval = checkVar(theFormName,'serviceInterval');

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

	if(firstName && lastName && suburb && postCode && email && phone && make && model && year && odometer && trans && reg && preferredDate && preferredTime && serviceInterval){
        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 make = checkVar(theFormName,'make');
	var model = checkVar(theFormName,'model');
	var year = checkNum(theFormName,'year',2);
	var reg = checkVar(theFormName,'reg');
	var partDescription = checkVar(theFormName,'partDescription');
	var partQty = checkVar(theFormName,'partQty');

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

function checkCON(){//contact enquiry form
	var theFormName = 'contactForm';
	var firstName = checkVar(theFormName,'firstName');
	var email = checkVarEmail(theFormName,'email');
	var phone = checkNum(theFormName,'phone',8);

	if(firstName && email && phone){
        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 checkEmailFriend(){//email alert
	var theFormName = 'emailFriend';
	var fullForm = document.forms[theFormName];
	var name = checkVar(theFormName,'name');
	var email = checkVarEmail(theFormName,'email');
	var friendName = checkVar(theFormName,'friendName');
	var friendEmail = checkVarEmail(theFormName,'friendEmail');

	if(name && email && friendName && friendEmail){
		var sendName = fullForm.elements['name'].value;
		var sendEmail = fullForm.elements['email'].value;
		var sendFriendName = fullForm.elements['friendName'].value;
		var sendFriendEmail = fullForm.elements['friendEmail'].value;
		var sendVEHID = fullForm.elements['vehID'].value;
		var sendvehType = fullForm.elements['vehType'].value;
		document.getElementById('emailWrapper').innerHTML = '<div class="loadingForm">&nbsp;</div>';
		dynamic('emailWrapper','inc/enquiry/email-friend.php','name='+sendName+'&email='+sendEmail+'&friendName='+sendFriendName+'&friendEmail='+sendFriendEmail+'vehID='+sendVEHID+'&vehType='+sendvehType);
    }
}

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; 
	enquiryForm = document.getElementById('howHear');
	var sldItem = enquiryForm.options[enquiryForm.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';}		
}
