// JavaScript Document

function validate(frm) {
  var msg;
  var err = 0;
  msg = "The following errors occurred:\n";

// Required Fields

if (frm.name.value != "") {
		if (IsAlphaApprovedCharacters(frm.name.value)) {
		} else {
			msg += "\tName will only accept letters & selected characters.\n";
			err = 1;
		}
	} else {
		msg += "\tYou have not supplied your name.\n";
		err = 1;
	}
  
 
  if (frm.postal_address.value != "") {
		if (IsAlphaNumericApprovedCharacters(frm.postal_address.value)) {
		} else {
			msg += "\tPostal address will only accept letters & numbers.\n";
			err = 2;
		}
	} else {
		msg += "\tYou have not supplied your postal address\n";
		err = 2;
	}  
  

  if (frm.postcode.value != "") {
		if (IsAlphaNumericApprovedCharacters(frm.postcode.value)) {
		} else {
			msg += "\tPostcode will only accept letters & numbers.\n";
			err = 3;
		}
	} else {
		msg += "\tYou have not supplied your postcode\n";
		err = 3;
	}
    

  if (frm.email_address.value != "") {
		if (IsAlphaNumericApprovedCharacters(frm.email_address.value)) {
		} else {
			msg += "\tThis is not a valid email address.\n";
			err = 4;
		}
	} else {
		msg += "\tYou have not supplied your email address\n";
		err = 4;
	}


// Just Character Validation

  if (IsTelephoneNo(frm.home_phone.value)) {
		} else {
			msg += "\tHome telephone will only accept numbers.\n";
			err = 5;
		}

  if (IsTelephoneNo(frm.work_phone.value)) {
		} else {
			msg += "\tWork telephone will only accept numbers.\n";
			err = 6;
		}
		
  if (IsNumeric(frm.expirydateday.value)) {
		} else {
			msg += "\tExpiry day will only accept numbers.\n";
			err = 7;
		}
		
  if (IsNumeric(frm.expirydatemonth.value)) {
		} else {
			msg += "\tExpiry month will only accept numbers.\n";
			err = 8;
		}
		
  if (IsNumeric(frm.expirydateyear.value)) {
		} else {
			msg += "\tExpiry year will only accept numbers.\n";
			err = 9;
		}

// Email Contents



  if (err > 0) {
	alert(msg);
  } else {
	
	frm.submit();

  }   

}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

   }
   
function IsTelephoneNo(sText)
{
   var ValidChars = "0123456789.()+ ";
   var IsTelephoneNo=true;
   var Char;


   for (i = 0; i < sText.length && IsTelephoneNo == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsTelephoneNo = false;
         }
      }
   return IsTelephoneNo;

   }

function IsAlphaApprovedCharacters(sText)
{
   var ValidChars = "-—_., abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ /^[a-zA-Z\-\séåü]+$/. \s ";
   var IsAlphaApprovedCharacters=true;
   var Char;


   for (i = 0; i < sText.length && IsAlphaApprovedCharacters == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsAlphaApprovedCharacters = false;
         }
      }
   return IsAlphaApprovedCharacters;

   }


function IsAlphaNumericApprovedCharacters(sText)
{
   var ValidChars = "0123456789-—_. abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ /^[a-zA-Z\-\séåü]+$/. \s @ ";
   var IsAlphaNumericApprovedCharacters=true;
   var Char;


   for (i = 0; i < sText.length && IsAlphaNumericApprovedCharacters == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsAlphaNumericApprovedCharacters = false;
         }
      }
   return IsAlphaNumericApprovedCharacters;

   }
  

