// *******************************************************************************
// **********  Call all Sponsor enquiry form checking functions ******************
// *******************************************************************************

function checkSponsorenq() {
	var myHowhear = document.getElementById('howhear').value;
	var myTitle = document.getElementById('title').value;
	var myFname = document.getElementById('firstname').value;
	var myLname = document.getElementById('lastname').value;
	var myAddress1 = document.getElementById('address1').value;
	var myPostcode = document.getElementById('postcode').value;
	var myCountry = document.getElementById('country').value;
	var myEmail = document.getElementById('email').value;

	if (checkEmpty(myHowhear))
	{
		alert ("Please tell us how you heard about the scheme");
		document.getElementById('howhear').focus();
		return false;
	}
		
	if (checkEmpty(myTitle))
	{
		alert ("You must enter a title");
		document.getElementById('title').focus();
		return false;
	}
		
	if (checkEmpty(myFname))
	{
		alert ("You must enter a first name");
		document.getElementById('firstname').focus();
		return false;
	}	
			
	if (checkEmpty(myLname))
	{
		alert ("You must enter a last name");
		document.getElementById('lastname').focus();
  	return false;
	}
	
	if (checkEmpty(myAddress1))
	{
		alert ("You must enter at least one line of address");
		document.getElementById('address1').focus();
  	return false;
	}
	
 	if (checkEmpty(myPostcode)) 
	{
		alert ("You must enter a postcode or zip code");
		document.getElementById('postcode').focus();
 		return false;
	} 
	
	if (checkEmpty(myCountry))
	{
		alert ("You must enter a country");
		document.getElementById('country').focus();
  	return false;
	}
	
	if (checkEmail(myEmail))
	{ 
		document.getElementById('email').focus();
		return false;			
	}
	
				
	return true;
}

// *******************************************************************************
// **********  Call all join mailing list form checking functions  ***************
// *******************************************************************************

function checkJoinmailing() {
	var myEmail = document.getElementById('email').value;
	var myFname = document.getElementById('firstname').value;
	var myLname = document.getElementById('lastname').value;
	var myCountry = document.getElementById('country').value;

	if (checkEmpty(myFname))
	{
		alert ("You must enter a first name");
		document.getElementById('firstname').focus();
		return false;
	}	
			
	if (checkEmpty(myLname))
	{
		alert ("You must enter a last name");
		document.getElementById('lastname').focus();
  	return false;
	}
	
	if (checkEmail(myEmail))
	{ 
		document.getElementById('email').focus();
		return false;			
	}
	
	if (checkEmpty(myCountry))
	{
		alert ("You must enter a country");
		document.getElementById('country').focus();
  	return false;
	}
			
	return true;
}

// *******************************************************************************
// ******************************  Check for empty fields ************************
// *******************************************************************************

function checkEmpty(fieldtotest) {
	 var formOK = false;
     if (fieldtotest == "") {
       formOK = true;
     }
     return formOK;
   }

// *******************************************************************************
// ************************************  Check Emails ****************************
// *******************************************************************************

function checkEmail(emailadd) {
  if (emailadd.length == 0) {
    window.alert("You must provide an e-mail address.");
    return true;
    }
  if (emailadd.indexOf("/") > -1) {
    window.alert("E-mail address has invalid character: /");
    return true;
    }
  if (emailadd.indexOf(":") > -1) {
    window.alert("E-mail address has invalid character: :");
    return true;
    }
  if (emailadd.indexOf(",") > -1) {
    window.alert("E-mail address has invalid character: ,");
    return true;
    }
  if (emailadd.indexOf(";") > -1) {
    window.alert("E-mail address has invalid character: ;");
    return true;
    }
  if (emailadd.indexOf("@") < 0) {
    window.alert("E-mail address is missing @");
    return true;
    }
  if (emailadd.indexOf("\.") < 0) {
    window.alert("E-mail address is missing .");
    return true;
    }

  return false;
  }


