//
// functions called on submit to validate
//
function validatefields(){

 // just going to do normal js validation on submit
 // need to grab lang and use field labels
// alert(document.forms['ectForm'].subject.value);

var  valid=1;
var feedbackSr="Please complete the following fields: ";

 if (document.forms['wbaClubsForm'].wbaClubsForm_name.value=="")
	 {
		document.getElementById('reqName').style.color = '#ffffff' ;
	 	valid=0;
	}else{
		document.getElementById('reqName').style.color = '#6A238B' ;
	}

 if (document.forms['wbaClubsForm'].wbaClubsForm_school.value=="")
	 {
		document.getElementById('reqSchool').style.color = '#ffffff' ;
	 	valid=0;
	}else{
		document.getElementById('reqSchool').style.color = '#6A238B' ;
	}

 if (document.forms['wbaClubsForm'].wbaClubsForm_address.value=="")
	 {
		document.getElementById('reqAddress').style.color = '#ffffff' ;
	 	valid=0;
	}else{
		document.getElementById('reqAddress').style.color = '#6A238B' ;
	}
	
 if (document.forms['wbaClubsForm'].wbaClubsForm_townCity.value=="")
	 {
		document.getElementById('reqTown').style.color = '#ffffff' ;
	 	valid=0;
	}else{
		document.getElementById('reqTown').style.color = '#6A238B' ;
	}

 if (document.forms['wbaClubsForm'].wbaClubsForm_country.value=="")
	 {
		document.getElementById('reqCountry').style.color = '#ffffff' ;
	 	valid=0;
	}else{
		document.getElementById('reqCountry').style.color = '#6A238B' ;
	}

 if (document.forms['wbaClubsForm'].wbaClubsForm_postCode.value=="")
	 {
		document.getElementById('reqPostCode').style.color = '#ffffff' ;
	 	valid=0;
	}else{
		document.getElementById('reqPostCode').style.color = '#6A238B' ;
	}
	
  if (document.forms['wbaClubsForm'].wbaClubsForm_emailAddress.value=="")
	 {
		document.getElementById('reqEmail').style.color = '#ffffff' ;
	 	valid=0;
	}else{
		document.getElementById('reqEmail').style.color = '#6A238B' ;
	}


		
	
if(valid==0){
	alert ("Please complete all required fields.");
	return false;
}else{

	 if (!validateEmail(document.forms['wbaClubsForm'].wbaClubsForm_emailAddress.value))
	 {
	 		alert ("Please enter a valid email address.");
			return false;
	}else{
		// alert ("this would have sent if I'd enabled the script....");
		//return true;

		// need to check they've selected at least one.
		var currentChecks=0;
		
		for(i=0; i<document.forms['wbaClubsForm'].length; i++)
			{
			if(document.forms['wbaClubsForm'].elements[i].type=="checkbox")
				{
										currentChecks=currentChecks + (document.forms['wbaClubsForm'].elements[i].checked ? 1 : 0)
				}
			}


		if (currentChecks==0){
				alert("Please select at least one club.");
				return false;
			}else{ // hooray we made it.
				return true;
			
			}
		
	}
}

}

function validateEmail(str) {
		
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		     return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		  
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		  
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		  
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		  
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		  
		    return false
		 }
		 if (str.indexOf(" ")!=-1){
		  
		    return false
		 }

 		 return true					
}
// -->