function checkFormQuote() {
	if (document.formQuote.vehicleMake.selectedIndex == "0") {
		alert("You need to select a vehicle make."); 
		document.formQuote.vehicleMake.focus();
		return false;	
	} else if (document.formQuote.vehicleYear.selectedIndex == "0") {
		alert("You need to select a vehicle year."); 
		document.formQuote.vehicleYear.focus();
		return false;		
	} else if (document.formQuote.vehicleModel.value == "e.g. Commodore" || document.formQuote.vehicleModel.value == "") {
		alert("You need to enter a vehicle model."); 
		document.formQuote.vehicleModel.focus();
		return false;	
	} else if (document.formQuote.vehicleProblem.selectedIndex == "0") {
		alert("You need to select the type of problem for which you require assistance."); 
		document.formQuote.vehicleProblem.focus();
		return false;		
	} else if (document.formQuote.myName.value == "") {
		alert("We can't reply to you if we don't know your name."); 
		document.formQuote.myName.focus();
		return false;
	} else if (document.formQuote.myPhone.value == "") {
		alert("Without a phone number, we won't be able to call you, should you require us to."); 
		document.formQuote.myPhone.focus();	
		return false;
	} else if (document.formQuote.myEmail.value == "") {
		alert("Without an email address our reply will bounce around the cosmos forever."); 
		document.formQuote.myEmail.focus();
		return false;
	} else if(null == document.formQuote.myEmail.value.match(/[a-zA-Z0-9._]+@[a-zA-Z0-9.-_]+/)) {
		alert("How about a valid email address, otherwise you'll never hear from us."); 
		document.formQuote.myEmail.focus();
		return false;
	}
	return true;
}

function checkFormContact() {
	if (document.formContact.myName.value == "") {
		alert("We can't reply to you if we don't know your name."); 
		document.formContact.myName.focus();
		return false;
	} else if (document.formContact.myEmail.value == "") {
		alert("Without an email address our reply will bounce around the cosmos forever."); 
		document.formContact.myEmail.focus();
		return false;
	} else if(null == document.formContact.myEmail.value.match(/[a-zA-Z0-9._]+@[a-zA-Z0-9.-_]+/)) {
		alert("How about a valid email address, otherwise you'll never hear from us."); 
		document.formContact.myEmail.focus();
		return false;
	} else if (document.formContact.myPhone.value == "") {
		alert("Without a phone number, we won't be able to call you, should you require us to."); 
		document.formContact.myPhone.focus();	
		return false;
	} else if (document.formContact.myComments.value == "") {
		alert("Please enter a message."); 
		document.formContact.myComments.focus();
		return false;
	}
	return true;
}

function YY_confirm(msg) {
	document.MM_returnValue=(confirm(unescape(msg)));
}

function clearDefault (el) {
	if (el.defaultValue==el.value) el.value = ""
}

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

function formValidator(){
	
	var vName = document.getElementById('myName');
	var vEmail = document.getElementById('myEmail');	
	var vPhone = document.getElementById('myPhone');
	var vSubject = document.getElementById('mySubject');
	var vComments = document.getElementById('myComments');
	
	if(isAlphabet(vName, "Please enter only letters for your name")){
		if(emailValidator(vEmail, "Please enter a valid email address")){
			if(isNumeric(vPhone, "Please enter a valid phone number")){
				if(madeSelection(vSubject, "Please select a subject")){
					if(isEmpty(vComments, "Please enter a comment or make an enquiry")){
						return true;
					}
				}
			}
		}
	}
	
	return false;
	
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}else{
		return true;
	}
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "AAG Contact Us: No Subject"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}