function validateForm(theForm) {

	var info = "";

	if(theForm.name=="entryform") {

		info += checkFilmName(theForm.filmname1.value);
			
		info += checkNameSurname(theForm.g_name.value);

		if(checkNameSurname(theForm.g_name.value)=="")
			info += checkNameSurname(theForm.l_name.value);

		info += checkEmail(theForm.email.value);	
		
		info += checkPhone(theForm.phone.value);
		
		info += checkSuburb(theForm.suburb.value);
		
		info+=checkPostcode(theForm.postcode.value); 
		
		info+=checkFilmedBy(theForm.filmmadeby.value); 
		
		if(theForm.filmmadeby.value=="individual")
			info += checkDOB(theForm.dd.value, theForm.mm.value, theForm.yyyy.value);
		else if(theForm.filmmadeby.value=="school")
			info += checkSchoolName(theForm.schoolname.value);
			
		info += checkFilmName(theForm.filmname2.value);
		
		info += checkFilmDuration(theForm.filmduration.value);
		
		info += checkFilmGenre(theForm.filmduration.value);
		
		info += checkSynopsis(theForm.synopsis.value);
		
		info += checkAspectRatio(theForm.aspectratio.value);
		
		info += checkSustainability(theForm.sustainability.value);
		
		info += checkPeople(theForm.otherpeople.value);
		
		if(theForm.otherpeople.value=="Yes")
			info+=checkPeopleRelease(theForm.peopleconsent.value);
		
		info += checkMusic(theForm.music.value);
		
		if(theForm.music.value=="Yes") {
			info+=checkMusicCreate(theForm.createmusic.value);
			info+=checkMusicPermission(theForm.permissionmusic.value);
		}

		if(theForm.guardianemail.value!="")
			info += checkEmail(theForm.guardianemail.value);
			
		if(theForm.guardiantelephone.value!="")
			info += checkPhone(theForm.guardiantelephone.value);
		
		if(!theForm.agreeterms.checked)
			info+="* You need to agree to Future Shots terms to be eligible for entry.";
		
		if(info!="") {
			alert(info);
			return false;
		}
		else if (!confirmInfo())
				return false;
		else
		{
			if(theForm.uploadfilm.value=="upload"){
				alert("You have chosen to upload your film.\n\nThe upload process may take several minutes depending on the file size and your internet speed.\n\nPlease be patient.\n\nDO NOT CLOSE YOUR BROWSER WINDOW UNTIL YOU SEE THE CONFIRMATION SCREEN.");
			}

			theForm.action="?entrysuccess";
			return true;
		}
	}
	else if (theForm.name=="judgingform") {
	
		info += checkName(theForm.judgename.value);
		
		if(theForm.category.value=="")
			info+="* Please select a category. \n\n";
		
		info+=checkScore(theForm.originality.name,theForm.originality.value,10);
		
		info+=checkScore(theForm.composition.name,theForm.composition.value,10);
		
		info+=checkScore(theForm.clarity.name,theForm.clarity.value,10);
		
		info+=checkScore(theForm.creative.name,theForm.creative.value,10);
		
		info+=checkScore(theForm.technical.name,theForm.technical.value,5);
		
		if(info!="") {
			alert(info);
			return false;
		}
		else if (!confirmInfo())
				return false;
		else
		{
			theForm.action="scorecomplete.php";
			return true;
		}
		
	}
	else if (theForm.name=="votingform") {
	
		info += checkEmail(theForm.voteremail.value);
		
		if(info!="") {
			alert(info);
			return false;
		}
		else
		{
			theForm.action="votecomplete.php";
			return true;
		}
		
	}

} 

function checkEmail(strng) {

	var error = "";

	var emailFilter=/^.+@.+\..{2,3}$/;

	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/

	 if (strng == "") {

	    error = "* Please enter your email address.\n\n";

	 }

	

	else if (!(emailFilter.test(strng))) { 

	       error = "* Please enter a valid email address.\n\n";

	}

	

	else if (strng.match(illegalChars)) {

	   error = "* The email address contains illegal characters.\n\n";

	

	}

return error;

}

function checkPhone(strng) {

	var error = "";

	

	if (strng == "") {

	    error = "* Please enter your telephone number.\n\n";

	 }

	else if (isNaN(parseInt(strng))) {

	   error = "* Phone number must be a number.\n\n";

	}

	else if (!(strng.length == 10)) {

		error = "* The phone number is the wrong length. Make sure you included an area code.\n\n";

	}

	return error;

}

function checkFilmName (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter your film name.\n\n";

	 }

  return error;  

}

function checkSuburb (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter your suburb name.\n\n";

	 }

  return error;  

}

function checkFilmedBy (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter whether this film was made by an individual or school or team.\n\n";

	 }

  return error;  

}

function checkSchoolName (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter your school name.\n\n";

	 }

  return error;  

}

function checkFilmDuration (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter your film duration.\n\n";

	 }

  return error;  

}

function checkFilmGenre (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter your film genre.\n\n";

	 }

  return error;  

}

function checkSynopsis (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter your film synopsis.\n\n";

	 }

  return error;  

}

function checkAspectRatio (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter your film aspect ratio.\n\n";

	 }

  return error;  

}

function checkSustainability (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter the sustainable practices you followed whilst making your film.\n\n";

	 }

  return error;  

}

function checkPeople (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please state whether people other than yourself appear in your film.\n\n";

	 }

  return error;  

}

function checkMusic (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please state whether you've used music in your film. \n\n";

	 }

  return error;  

}

function checkPeopleRelease(strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please state whether the people that feature in your film completed a release form. \n\n";

	 }

  return error;  

}

function checkMusicCreate(strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please state whether you created the music. \n\n";

	 }

  return error;  

}

function checkMusicPermission(strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please state whether you gained permission to use that music in your film by completing a release form. \n\n";

	 }

  return error;  

}


function checkNameSurname (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter both given name and surname.\n\n";

	 }

  return error;  

}

function checkName (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter your name.\n\n";

	 }

  return error;  

}

function checkPostcode (strng) {

 var error = "";

  if (strng == "") {

	    error = "* Please enter your postcode.\n\n";

	 }

	else if (isNaN(parseInt(strng))) {

	   error = "* Postcode must be a number.\n\n";

	} 

	else if (strng.length != 4) {

		error = "* The postcode must have 4 digits.\n\n";

	}

  return error;  

} 

function checkDOB(strng,strng2,strng3)

{

	var error = "";

	if (strng=="" || strng2=="" || strng3=="")
		return "* Please enter your date of birth.  \n\n";

	if(parseInt(strng2)%2==0 && parseInt(strng)>30 && parseInt(strng2)!=2 && parseInt(strng2)<=7)

	 	error="* Day cannot be more than 30 for the chosen month.\n\n";

	else if(parseInt(strng2)%2!=0 && parseInt(strng)>30 && parseInt(strng2)!=2 && parseInt(strng2)>7)

	 	error="* Day cannot be more than 30 for the chosen month.\n\n"; 	

	else if (parseInt(strng2)==2)

	{

		

		if(parseInt(strng)>=29)

		{

		    if(parseInt(strng3)%4!=0)

		        error="* Day cannot be more than 28 for the chosen month.\n\n";

		 	if(parseInt(strng3)%100==0)

		 	{

		 		if(parseInt(strng3)%400!=0)

		 			error="* Day cannot be more than 28 for the chosen month.\n\n";

		 		else if(parseInt(strng)>29)

	 				error="* Day cannot be more than 29 for the chosen month.\n\n";

	 		}

	 		else if(parseInt(strng)>29)

	 		{

		 		error="* Day cannot be more than 29 for the chosen month.\n\n";

	 		}	

		}

	}

	return error; 	 	

}





function confirmInfo()

{

	if (confirm("Are you sure you want to proceed?")==true)

		return true;

		

	return false;	

}

function chkfilmmade(ele) {
	if(ele.value=="individual"){
		document.entryform.dd.disabled=false;
		document.entryform.mm.disabled=false;
		document.entryform.yyyy.disabled=false;
		document.entryform.schoolname.disabled=true;
		document.entryform.schoollevel.disabled=true;
		document.entryform.yclass.disabled=true;
		document.entryform.mixedgrades.disabled=true;
		document.entryform.numstudents.disabled=true;
		document.entryform.numteammember.disabled=true;
		document.entryform.member1.disabled=true;
		document.entryform.member2.disabled=true;
		document.entryform.member3.disabled=true;
		document.entryform.member4.disabled=true;
		document.entryform.member5.disabled=true;
	}
	else if(ele.value=="school"){
		document.entryform.dd.disabled=true;
		document.entryform.mm.disabled=true;
		document.entryform.yyyy.disabled=true;
		document.entryform.schoolname.disabled=false;
		document.entryform.schoollevel.disabled=false;
		document.entryform.yclass.disabled=false;
		document.entryform.mixedgrades.disabled=false;
		document.entryform.numstudents.disabled=false;
		document.entryform.numteammember.disabled=true;
		document.entryform.member1.disabled=true;
		document.entryform.member2.disabled=true;
		document.entryform.member3.disabled=true;
		document.entryform.member4.disabled=true;
		document.entryform.member5.disabled=true;
	}
	else if(ele.value=="team"){
	    document.entryform.dd.disabled=true;
		document.entryform.mm.disabled=true;
		document.entryform.yyyy.disabled=true;
		document.entryform.schoolname.disabled=true;
		document.entryform.schoollevel.disabled=true;
		document.entryform.yclass.disabled=true;
		document.entryform.mixedgrades.disabled=true;
		document.entryform.numstudents.disabled=true;
		document.entryform.numteammember.disabled=false;
		document.entryform.member1.disabled=false;
		document.entryform.member2.disabled=false;
		document.entryform.member3.disabled=false;
		document.entryform.member4.disabled=false;
		document.entryform.member5.disabled=false;
	}
	else {
	    document.entryform.dd.disabled=true;
		document.entryform.mm.disabled=true;
		document.entryform.yyyy.disabled=true;
		document.entryform.schoolname.disabled=true;
		document.entryform.schoollevel.disabled=true;
		document.entryform.yclass.disabled=true;
		document.entryform.mixedgrades.disabled=true;
		document.entryform.numstudents.disabled=true;
		document.entryform.numteammember.disabled=true;
		document.entryform.member1.disabled=true;
		document.entryform.member2.disabled=true;
		document.entryform.member3.disabled=true;
		document.entryform.member4.disabled=true;
		document.entryform.member5.disabled=true;
	} 
}

function enableotherfield(ele,otherfld) {
	var x=document.getElementById(otherfld);
	
	if(ele.value=="other" || ele.value=="yes")
		x.disabled=false;
	else
		x.disabled=true;
}

function enablepermissionmusic(ele) {
	
	if(ele.value=="no")
		document.entryform.permissionmusic.disabled=false;
	else
		document.entryform.permissionmusic.disabled=true;
}

function enablefileupload(ele) {
	
	if(ele.value=="upload")
		document.entryform.upld.disabled=false;
	else
		document.entryform.upld.disabled=true;
}

function checkScore(fldname,fldvalue,maxscore) {

	var error = "";
	
	if (isNaN(parseInt(fldvalue))) {

	   error = "* The "+fldname+" score must be a number.\n\n";

	}

	else if (parseInt(fldvalue) > maxscore) {

		error = "* The "+fldname+" score cannot be more than "+maxscore+" \n\n";

	}

	return error;

}


