function checkValid(frm)
{
	with(frm)
	{
		if(!checkValidNull(document.getElementById("teacher[title]") ," You must complete all of the required fields. Please enter : Title"))
			return false;
		if(document.getElementById("teacher[title]").value=='Other' && document.getElementById("titleother").value=="") 
		{
			alert("You must complete all of the required fields. Please enter : Title (if Other)");
			return false;	
		}
		if(!checkValidNull(document.getElementById("teacher[firstname]") ," You must complete all of the required fields. Please enter : First name"))	return false;
		if(!checkValidNull(document.getElementById("teacher[lastname]") ," You must complete all of the required fields. Please enter : Last name"))	return false;
		if(!checkValidNull(document.getElementById("teacher[email]")  ," You must complete all of the required fields. Please enter : E-mail address"))	return false;
		if(!checkValidNull(document.getElementById("teacher[telephone]")  ," You must complete all of the required fields. Please enter : Telephone number"))	return false;
		if(!checkValidNull(document.getElementById("teacher[job_title]")  ," You must complete all of the required fields. Please enter : Job title"))	return false;
		if(!checkValidNull(document.getElementById("teacher[taught]")  ," You must complete all of the required fields. Please enter : Subject(s) taught"))	return false;
		
		if((document.getElementById("teacher[age-5to7]").checked || document.getElementById("teacher[age-8to11]").checked || document.getElementById("teacher[age-11to14]").checked || document.getElementById("teacher[age-14to16]").checked)&&!document.getElementById("teacherage_rangecustom").checked)
		{
		}
		else if(document.getElementById("teacherage_rangecustom").checked)
		{
			if(!checkValidNull(document.getElementById("teacher[age-other]") ," You must complete all of the required fields. Please enter other : Age ranges you teach"))return false;
		}
		else
		{
			alert("You must complete all of the required fields. Please select at least one of the : Age ranges you teach");
			return false;
		}
		/*
		if(document.getElementById("teacher[job_type][Supply]").checked)
		{
		if(!checkValidNull(document.getElementById("school[building_no]")  ," You must complete all of the required fields. Please enter : Flat of house number"))	return false;
		if(!checkValidNull(document.getElementById("school[street_name]")  ," You must complete all of the required fields. Please enter : Street name"))	return false;
		if(!checkValidNull(document.getElementById("school[postcode]")  ," You must complete all of the required fields. Please enter : Post code"))	return false;
		if(!checkValidNull(document.getElementById("school[county]")  ," You must complete all of the required fields. Please enter : County for school"))	return false;
		
		}
		
		else */
			if(!document.getElementById("teacher[job_type][Permanent]").checked)
			{
				alert("You must complete all of the required fields. Please select any one of the : Job Type ");
				return false;			
			}
		
		if(document.getElementById("teacher[job_type][Permanent]").checked!=false)
		{
			/*if(!checkValidNull(document.getElementById("a[school_type]")  ," You must complete all of the required fields. Please enter : School Type"))	return false;*/
			if(!checkValidNull(document.getElementById("a[school_status]")  ," You must complete all of the required fields. Please enter : School Status"))	return false;
			if(!checkValidNull(document.getElementById("a[telephone]")  ," You must complete all of the required fields. Please enter : Switchboard number"))	return false;
			if(!checkValidNull(document.getElementById("a[county]")  ," You must complete all of the required fields. Please enter : County for school"))	return false;

		}
		if(document.getElementById("a[enrol-team-champ]").disabled==false && document.getElementById("a[enrol-team-champ]").checked==true){
		if(document.getElementById("agree_box").checked==false)
		{
			alert("You Must agree to The Times Spelling Bee terms and conditions");
			return false;
		}
	 }
		if(!checkValidNull(document.getElementById("teacher[password]") ," You must complete all of the required fields. Please enter : Password"))return false;
		
		else
		{ 
			tmpstr=new String();
			tmpstr=document.getElementById("teacher[password]").value;
			plen=tmpstr.length ;
			if(plen<6 || plen>20)
			{
				alert("Password must be 6 to 20 character long.");
				return false;
			}
			else if(document.getElementById("teacher[password]").value!=document.getElementById("password2").value)
			{
				alert("Confirm Password not match...");
				document.getElementById("password2").focus();
				return false;
				
				
			}
		}
		if(!(document.getElementById("teacher[times_periodicity][4]").checked||document.getElementById("teacher[times_periodicity][3]").checked||document.getElementById("teacher[times_periodicity][1]").checked||document.getElementById("teacher[times_periodicity][0]").checked))
		{
			alert("You must complete all of the required fields. Please select any one of the options : For question No.1 in Reading our Newspapers");
			return false;	
		}
		if(!(document.getElementById("teacher[sunday_periodicity][4]").checked || document.getElementById("teacher[sunday_periodicity][2]").checked || document.getElementById("teacher[sunday_periodicity][1]").checked || document.getElementById("teacher[sunday_periodicity][0]").checked))
		{
			alert("You must complete all of the required fields. Please select any one of the options : For question No.2 in Reading our Newspapers");
			return false;	
		}
		if(document.getElementById("teacher[job_type][Supply]").checked)
			if(!checkValidNull(document.getElementById("school[county]")  ," You must complete all of the required fields. Please enter : County for school"))	return false;
		else
			if(!checkValidNull(document.getElementById("a[county]")  ," You must complete all of the required fields. Please enter : County for school"))	return false;
		
		
	}
	return true;
}
function checkValidNull(objValue, msg)
{
	if(objValue)
	{	
		if(Trim(objValue.value)=="")
		{
			alert(msg);objValue.focus(); return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return true;
	}
}

function Trim(s)
{
	return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
