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 submitEnq(){//enquiry
	var theFormName = 'enq';
	var firstName = checkVar(theFormName,'firstName');
	var email = checkVarEmail(theFormName,'email');
	var phone = checkNum(theFormName,'phone',8);
	var postCode = checkNum(theFormName,'postCode',4);

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