function formValidator(){

	// Make quick references to our fields

	var name = document.getElementById('name');
	
	var email = document.getElementById('email');

	var enquiry = document.getElementById('enquiry');
	

	// Check each input in the order that it appears in the form!

	if(isAlphabet(name, "Please enter your first name")){
		
			if(emailValidator(email, "Please enter a valid email address")){

					if(IsEmpty(enquiry, "Please enter your enquiry")){

									if (jcap()){
												return true;
											}
							
									}


							}

						}

	return false;

	

}



function isAccept(elem, helperMsg){

if (!document.getElementById('agreement').checked )
    {

        alert (helperMSg);
		elem.focus();
		return false;

    }
  
	return true;

}

function correctPostcode(elem,helperMsg){



if((elem.value.toUpperCase().match(/GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW]) [0-9][ABD-HJLNP-UW-Z]{2}/))){return true;}else{alert (helperMsg); elem.focus();	return false;}



}



function isNumeric(elem, helperMsg){

	var numericExpression = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;

	if(elem.value.match(numericExpression)){

		return true;

	}else{

		alert(helperMsg);

		elem.focus();

		return false;

	}

}


function IsEmpty(elem, helperMsg) {
   if ((elem.value.length==0) ||
   (elem.value==null)) {
 		alert(helperMsg);
		elem.focus();
		return false;
   }
 return true;
}

function isAlphabet(elem, helperMsg){

	var alphaExp = /^[a-zA-Z]|\s[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\s]+$/;

	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("Password: min " +min+  " characters");

		elem.focus();

		return false;

	}

}



function lengthRestriction2(elem, min, max){

	var uInput = elem.value;

	if(uInput.length >= min && uInput.length <= max){

		return true;

	}else{

		alert("Advert title should not be empty or more than " +max+  " characters");

		elem.focus();

		return false;

	}

}





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;

	}

	

	

}


