function formValidator(thisform)
{
	
	var lname = document.voteform.lname;
	var fname = document.voteform.fname;
	var email = document.voteform.email;
	var cpnum = document.voteform.cpnum;
	var txtans = document.voteform.txtans;

	with (thisform)
	{
		if (validate_required(lname,"Last Name must filled out!")==false)
  			{lname.focus();return false;}
		if (isAlphabet(lname,"Please enter a valid Last Name!")==false)
  			{lname.focus();return false;}
		if (validate_required(fname,"First Name must be filled out!")==false)
			{fname.focus();return false;}
		if (isAlphabet(fname,"Please enter a valid First Name!")==false)		
  			{fname.focus();return false;}
		if (validate_required(email,"Email Address must be filled out!")==false)
			{email.focus();return false;}
		if (emailValidator(email,"Please put a valid email address!")==false)
			{email.focus();return false}	
		if (validate_required(cpnum,"Cell Number must be filled out!")==false)
  			{cpnum.focus();return false;}
		if (isNumeric(cpnum,"Please enter a valid Cellphone Number!")==false)
  			{cpnum.focus();return false;}
		if (lengthRestriction(txtans,"Answer must be filled out!")==false)
  			{txtans.focus();return false;}
	}

}

function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null||value=="")
  			{alert(alerttxt);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\s.\-_']+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	var min = 1;
	var max = 500;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +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;
	}
}


