function CheckNewsletterSignup(form) {

  if (form.firstname.value == "") {
    alert('Please provide your first name');
    form.firstname.focus();
    return false;
  }
  if (form.lastname.value == "") {
    alert('Please provide your last name');
    form.lastname.focus();
    return false;
  }
  if (form.email.value == "") {
    alert('Please provide your email address');
    form.email.focus();
    return false;
  }
  if(!checkEmail(form.email)) {
    form.email.focus();
    return false;
  }
  if (form.phone.value == "" || form.phone.value.length<8) {
    alert('Please provide a phone contact');
    form.phone.focus();
    return false;
  }
  if (form.math.value != 2) {
    alert('Please answer this simple maths question to continue');
    form.math.focus();
    return false;
  }
  return true;
}

function CheckInstantSignup(form) {

  if (form.firstname.value == "") {
    alert('Please provide your first name');
    form.firstname.focus();
    return false;
  }
  if (form.lastname.value == "") {
    alert('Please provide your last name');
    form.lastname.focus();
    return false;
  }
  if (form.email.value == "") {
    alert('Please provide your email address');
    form.email.focus();
    return false;
  }
  if(!checkEmail(form.email)) {
    form.email.focus();
    return false;
  }
  if (form.phone.value == "" || form.phone.value.length<8) {
    alert('Please provide a phone contact');
    form.phone.focus();
    return false;
  }
  if (form.math.value != 2) {
    alert('Please answer this simple maths question to continue');
    form.math.focus();
    return false;
  }
  return true;
}

function CheckNewsletterSignup_byid(firstname,lastname,email,phone,math) {

  if (document.getElementById(firstname).value == "") {
  	alert('Please provide your first name');
  	document.getElementById(firstname).focus();
  	return false;
  }
  if (document.getElementById(lastname).value == "") {
  	alert('Please provide your last name');
  	document.getElementById(lastname).focus();
  	return false;
  }
  if (document.getElementById(email).value == "") {
  	alert('Please provide your email address');
  	document.getElementById(email).focus();
  	return false;
  }
  if(!checkEmail(document.getElementById(email))) {
    document.getElementById(email).focus();
  	return false;
  }
  if (document.getElementById(phone).value == "" || document.getElementById(phone).value.length<8) {
  	alert('Please provide a phone contact');
  	document.getElementById(phone).focus();
  	return false;
  }
  if (document.getElementById(math).value != 2) {
    alert('Please answer this simple maths question to continue');
    document.getElementById(math).focus();
    return false;
  }
  return true;
}

function CheckWebContactSignup(form) {

// gonna check to make sure we have at least 1 kind of contact method present

  if (form.firstname.value == "") {
  	alert('Please provide your first name');
  	form.firstname.focus();
  	return false;
  }
  if (form.lastname.value == "") {
  	alert('Please provide your last name');
  	form.lastname.focus();
  	return false;
  }
  if (form.email.value == "" && form.phone.value == "") {
  	alert('Please provide either an email address or a contact phone number (or both?) so we can get in touch with you!');
  	form.email.focus();
  	return false;
  }
  if (form.math.value!="2") {
    alert('Please answer the simple maths question to continue');
    form.math.focus();
    return false;
  }
  return true;
}



function CheckRegForm(form) {

  if (form.firstname.value == "") {
  	alert('Please provide your first name');
  	form.firstname.focus();
  	return false;
  }
  if (form.lastname.value == "") {
  	alert('Please provide your last name');
  	form.lastname.focus();
  	return false;
  }
  if (form.email.value == "") {
  	alert('Please provide your email address');
  	form.email.focus();
  	return false;
  }
  if(!checkEmail(form.email)) {
    form.email.focus();
  	return false;
  }
  if (form.phone.value == "" || form.phone.value.length<8) {
  	alert('Please provide a contact number');
  	form.phone.focus();
  	return false;
  }

  if(form.password1.value.length==0) {
    alert('It\'s important that you provide a password for your account so that only you can access it');
  	form.password1.focus();
  	return false;
  }
  if(form.password1.value!=form.password2.value) {
    alert('Please check that your "double check" password matches your originally entered password.');
  	form.password1.focus();
  	return false;
  }
  if (form.math.value!="2") {
    alert('Please answer this simple maths question to continue');
    form.math.focus();
    return false;
  }


  return true;
}


	function verify_ccard(inNumber, type) {
		// returns 0 if valid, positive number if invalid.

		//alert(inNumber);
		//alert(type);

        total = 1*0;
        tmp = 1*0;

        number = "";

        // make sure there are only numbers in the string...
        for(i = 0; i < inNumber.length; i++)
        {
		    if(inNumber.charAt(i) >= "0" && inNumber.charAt(i) <= "9")
                {
                        number = number + inNumber.charAt(i);
                }
        }

        if(number.length < 13) return 10; // too short for anything

        first = "" + number.charAt(0);
        second = "" + number.charAt(1);
        third = "" + number.charAt(2);
        firstTwo = first + second;
        firstFour = firstTwo + third + number.charAt(3);

        if (type == "MC")
        {
                if(first != "5" || second < "1" || second > "5")
                        return 11;// invalid Mastercard prefix
                if(number.length != 16)
                        return 21;
        }
        else if(type == "VISA")
        {
                if(first != "4")
                        return 12;// invalid Visa prefix
                if(number.length != 13 && number.length != 16)
                        return 22;
        }
        else if(type == "AMEX")
        {
                if(first != "3" || (second != "4" && second != "7"))
                        return 13;// invalid American Express Prefix
                if(number.length != 15)
                        return 23;
        }
        else if(type == "DISC")
        {
                        if(firstFour != "6011")
                                return 14;// invalid prefix.
                        if(number.length != 16)
                                return 24;
        }
        else if(type == "DCCB")
        {
                if(firstTwo != "36"
                        && firstTwo != "38"
                        && (firstTwo != "30" ||
                                (third < "0" || third > "5")))
                {
                        return 15;
                }
                if(number.length != 14)
                        return 25;
        }
        else if(type == "enRoute")
        {
                if(firstFour != "2014"
                        && firstFour != "2149")
                        return 16;// invalid enRoute card
                if(number.length != 15)
                        return 26;
		return 0; // no check sum calculation needed
        }
        else if(type == "JCB")
        {
                if(firstFour != "2131"
                        && firstFour != "1800"
                        && (first != "3") )
                        return 17;
                if(number.length != 16 && first =="3")
                        return 27;
                if(number.length != 15 && first != "3")
                        return 28;
        }

        // now check the credit card suffix and length vs. the type


         // do the check sum
        for(loc = number.length - 2; loc >= 0; loc -= 2)
        {
                total += 1 * number.charAt(loc +1);
                tmp = number.charAt(loc) * 2;
		if(tmp > 9) total += 1;
		total += tmp%10;
        }

		if(number.length % 2 > 0)
		total += 1 * number.charAt(0);


        return (total % 10);
	}

	function confirmCard(CardNumber, CardType) {
		//alert(CardType);
        errorStrings = new Array(
                "Hee Hee.  No error here!", //0
                "Check sum failed", //1
                "Check sum failed", //2
                "Check sum failed", //3
                "Check sum failed", //4
                "Check sum failed", //5
                "Check sum failed", //6
                "Check sum failed", //7
                "Check sum failed", //8
                "Check sum failed", //9
                "Number of digits must be greater than 12", //10
                "Invalid Master Card Prefix", //11
                "Invalid Visa Prefix", //12
                "Invalid American Express Prefix", //13
                "Invalid Discover Prefix", //14
                "Invalid Diner's Club/Carte Blanche Prefix", //15
                "Invalid enRoute Prefix", //16
                "Invalid JCB Prefix", //17
                "Why are you reading my source?", //18
                "Are you just a glutton for punishment?", //19
                "Insert comment here.", //20
                "Number of digits must be 16 for Master Card", //21
                "Number of digits must be 13 or 16 for Visa", //22
                "Number of digits must be 15 for American Express", //23
                "Number of digits must be 16 for Discover ", //24
                "Number of digits must be 14 for Diner's Club/Carte Blanche", //25
                "Number of digits must be 15 for enRoute", //26
                "Number of digits must be 16 for JCB with this prefix", //27
                "Number of digits must be 15 for JCB with this prefix") //28

        if ((reason = verify_ccard(CardNumber, CardType)) == 0) {
			//alert('succeeded!');
			return 0;
			}
        else {
			//alert(reason);
            return 1;
			}
	}

  function checkEmail ( addressField ) {

      if ( noAtSign ( addressField.value ) )
          alert ( "Uh oh! Your email address needs to have a '@' character" );
      else if ( nothingBeforeAt ( addressField.value ) )
          alert ( "Uh oh! An email address must contain at least one character before the '@' character" );
      else if ( noLeftBracket ( addressField.value ) )
          alert ( "Uh oh! The email address contains a right square bracket ']',\nbut no corresponding left square bracket '['" );
      else if ( noRightBracket ( addressField.value ) )
          alert ( "Uh oh! The email address contains a left square bracket '[',\nbut no corresponding right square bracket ']'" );
      else if ( noValidPeriod ( addressField.value ) )
          alert ( "Uh oh! An email address must contain a period ('.') character" );
      else if ( noValidSuffix ( addressField.value ) )
          alert ( "Uh oh! An email address must contain a two or three character suffix" );
      else
          return true;

      return false;
  }

  function linkCheckValidation ( formField ) {
      if ( checkValidation ( formField ) == true ) {
          return true;
      }

      return ( false );
  }

  function stringEmpty ( address ) {
      // CHECK THAT THE STRING IS NOT EMPTY
      if ( address.length < 1 ) {
          return ( true );
      } else {
          return ( false );
      }
  }

  function noAtSign ( address ) {
      // CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING
      if ( address.indexOf ( '@', 0 ) == -1 ) {
          return ( true )
      } else {
          return ( false );
      }
  }

  function nothingBeforeAt ( address ) {
      // CHECK THERE IS AT LEAST ONE CHARACTER BEFORE THE '@' CHARACTER
      if ( address.indexOf ( '@', 0 ) < 1 ) {
          return ( true )
      } else {
          return ( false );
      }
  }

  function noLeftBracket ( address ) {
      // IF email ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR LEFT BRACKET
      if ( address.indexOf ( '[', 0 ) == -1 && address.charAt ( address.length - 1 ) == ']' ) {
          return ( true )
      } else {
          return ( false );
      }
  }

  function noRightBracket ( address ) {
      // IF email ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR RIGHT BRACKET
      if ( address.indexOf ( '[', 0 ) > -1 && address.charAt ( address.length - 1 ) != ']' ) {
          return ( true );
      } else {
          return ( false );
      }
  }

  function noValidPeriod ( address ) {
      // IF email ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
      if ( address.indexOf ( '@', 0 ) > 1 && address.charAt ( address.length - 1 ) == ']' )
          return ( false );

      // CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING
      if ( address.indexOf ( '.', 0 ) == -1 )
          return ( true );

      return ( false );
  }

  function noValidSuffix ( address ) {
      // IF email ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
      if ( address.indexOf ( '@', 0 ) > 1 && address.charAt ( address.length - 1 ) == ']' )
          return ( false );

      // CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD
      var len = address.length;
      var pos = address.lastIndexOf ( '.', len - 1 ) + 1;
      if ( ( len - pos ) < 2 || ( len - pos ) > 3 ) {
          return ( true );
      } else {
          return ( false );
      }
  }

  function nextPage(page) {
    document.location.href='index.php?page_id='+page;
  }






function CheckNewsletterSignup_byid_test(firstname,lastname,email,country,phone,math) {

  if (document.getElementById(firstname).value == "") {
    alert('Please provide your first name');
    document.getElementById(firstname).focus();
    return false;
  }
  if (document.getElementById(lastname).value == "") {
    alert('Please provide your last name');
    document.getElementById(lastname).focus();
    return false;
  }
  if (document.getElementById(email).value == "") {
    alert('Please provide your email address');
    document.getElementById(email).focus();
    return false;
  }
  if(!checkEmail(document.getElementById(email))) {
    document.getElementById(email).focus();
    return false;
  }
  if(document.getElementById(country).value=="UK") {
    if(!checkUKTelephone(document.getElementById(phone).value)) {
      alert('Please provide a valid UK phone number');
      document.getElementById(phone).focus();
      return false;
    }
  }
  if (document.getElementById(phone).value == "" || document.getElementById(phone).value.length<8) {
    alert('Please provide a phone contact');
    document.getElementById(phone).focus();
    return false;
  }
  if (document.getElementById(math).value != 2) {
    alert('Please answer this simple maths question to continue');
    document.getElementById(math).focus();
    return false;
  }
  return true;
}