function alltrim(s)
   {
   	  slen = s.length
   	  cnt = 0
      	  for(i=0;i<slen;i++)
   	  {
   	  	if(s.charAt(i) == " ")
   	  	    cnt++
   	  	else
   	  		break
   	  }

   	  if (cnt == slen)
   	  	return ""

   	  s = s.substring(cnt)

	  slen = s.length
   	  cnt = 0
   	  for(i=slen-1;i>=0;i--)
   	  {
   	  	if(s.charAt(i) == " ")
   	  		cnt++
   	  	else
   	  		break
   	  }
	  s = s.substring(0,slen-cnt)

     return s
}

//Function to check for valid email address.
function checkemail(email)
{
	var emailLength			= email.length
	var isATexistsFirst		= email.indexOf("@")
	var	isATexistsLast		= email.lastIndexOf("@")
	var isDOTexistsFirst	= email.indexOf(".",isATexistsFirst+1)
	var isDOTexistsNext1	= email.indexOf(".",isATexistsFirst+1)
	var isDOTexistsNext2 
	var isDOTexistsLast		= email.lastIndexOf(".")
	if ((isDOTexistsFirst < isATexistsFirst+3) || (isATexistsFirst < 2) ||
		(isDOTexistsLast == emailLength-1) || (isATexistsLast == emailLength-1) ||
		(isDOTexistsFirst == 0) || (isATexistsFirst == 0) || (isATexistsFirst == isDOTexistsFirst) ||
		(isATexistsFirst != isATexistsLast))
		{
			return false;
		}
		while (isDOTexistsNext1 < isDOTexistsLast)
		{	
			isDOTexistsNext2	= email.indexOf(".", isDOTexistsNext1+1)
			if (isDOTexistsNext1+1 == isDOTexistsNext2)
			{
				return false;
			}
			isDOTexistsNext1 = isDOTexistsNext2
		}

	isATexistsFirst    = email.indexOf(" ")
	if (isATexistsFirst != -1)
	{
		return false;
	}

	return true;
}
//Function to check for special characters.
function fnValidateSpecialCharacters(sFieldName)
{
	//Check for Special Characters.
	var arrAlpha = new Array("!", "$", "%", "^", "*", "=", "\\", "|", "~", "?");
	var iCodeLength = sFieldName.length;
	var iAlphaFound;
	for(j=0;j<iCodeLength;j++)
	{
		for(i=0;i<arrAlpha.length;i++)
		{
			iAlphaFound = sFieldName.indexOf(arrAlpha[i])
			if(iAlphaFound != -1)
			{
				return false;
			}
		}
	}
	return true;
}

function validate_NameSearch (strPayMethod,SearchType) 
  {


	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmNameSearch;
	var sName                = alltrim(oForm.name.value);
	var sTelephone           = alltrim(oForm.tel.value);
	var sEmail               = alltrim(oForm.email.value);	
	var sConfirmEmail        = alltrim(oForm.confirm_email.value);
	var sMCForName           = alltrim(oForm.MC_forname.value);
	var sMCMiddleName        = alltrim(oForm.MC_middle_name.value);	
	var sMCSurname           = alltrim(oForm.MC_surname.value);
	var sMCTown              = alltrim(oForm.MC_town.value);
	var sMCCounty            = alltrim(oForm.MC_county.value);
    var sMCAdditionalInfo    = alltrim(oForm.MC_additional_info.value);
	

	if (sName == "")
	{
		errorMsg += "\n\tName \t\t- Enter your Name";
	}
	
	   if(!fnValidateSpecialCharacters(sTelephone))
		{
			errorMsg += "\n\tTelephone \t\- Invalid Telephone Number";
		}
	//Check for Email Address
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}
	//Check for Confirm Email Address
	if (sConfirmEmail == "")
	{
		errorMsg += "\n\tConfirm Email \t\- Please enter a Confirm Email";
	}
    else
	 {
	   //Check for valid Confirm Email Address.
		if(!checkemail(sConfirmEmail))
		{
			errorMsg += "\n\tConfirm Email  \t\- Please enter a valid Confirm Email";
		}
	}
	//Check for similar Email and Confirm Email Address	
	if (sEmail != sConfirmEmail && (sEmail != "" )&& (sConfirmEmail != "" ))
	 {
	  errorMsg += "\n\tConfirm Email  \t\- Please enter a similar Email and confirm Email";
	 }

	//Check for Forname	
	if (sMCForName == "")
	{
		errorMsg += "\n\tForName \t\t- Please enter a Forname";
	}
   
   //Check for Middle Name	
	if (sMCSurname == "")
	{
		errorMsg += "\n\tSur Name \t\- Please enter a SurName";
	}
	
	//Check for Town	
	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
  if ((errorMsg == "") || (errorMsgLong == ""))
   { 	
         if(strPayMethod=="paypal")
         {
			oForm.payer_email.value	 = alltrim(sEmail);	
			oForm.first_name.value	 = alltrim(sName);
			oForm.last_name.value	 = alltrim(oForm.MC_surname.value);
			oForm.city.value         = alltrim(oForm.MC_town.value);    
            oForm.item_name.value    = SearchType + ' Details: -  Telephone :' + sTelephone + ' , Middlde Name :' + sMCMiddleName + ' , County :' + sMCCounty + ' ,Additional Info :' + sMCAdditionalInfo;	
 		    oForm.action='submit_paypal.php';
			oForm.method='post';
			oForm.submit();
		 }
         else
          {
		    return true;
		  }
   }
}

function validate_SurNameSearch (strPayMethod,SearchType) 
  {
	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmSurNameSearch;
	var sName                = alltrim(oForm.name.value);
	var sTelephone           = alltrim(oForm.tel.value);
	var sEmail               = alltrim(oForm.email.value);	
	var sConfirmEmail        = alltrim(oForm.confirm_email.value);	
	var sMCSurname           = alltrim(oForm.MC_surname.value);
	var sMCTown              = alltrim(oForm.MC_town.value);
	var sMCCounty            = alltrim(oForm.MC_county.value);
	var sMCAdditionalInfo    = alltrim(oForm.MC_additional_info.value);
    var sMCAdditionalInfo    = alltrim(oForm.MC_additional_info.value);

	//var sIAgree              = oForm.Iagree.checked;

	
	//Check for a name
	if (sName == "")
	{
		errorMsg += "\n\tName \t\t- Enter your Name";
	}
	
	   if(!fnValidateSpecialCharacters(sTelephone))
		{
			errorMsg += "\n\tTelephone \t\- Invalid Telephone Number";
		}
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}
	//Check for Confirm Email Address
	if (sConfirmEmail == "")
	{
		errorMsg += "\n\tConfirm Email \t\- Please enter a Confirm Email";
	}
    else
	 {
	   //Check for valid Confirm Email Address.
		if(!checkemail(sConfirmEmail))
		{
			errorMsg += "\n\tConfirm Email  \t\- Please enter a valid Confirm Email";
		}
	}
	//Check for similar Email and Confirm Email Address	
	if (sEmail != sConfirmEmail && (sEmail != "" )&& (sConfirmEmail != "" ))
	 {
	  errorMsg += "\n\tConfirm Email  \t\- Please enter a similar Email and confirm Email";
	 }	
  
	//Check for Sur Name	
	if (sMCSurname == "")
	{
		errorMsg += "\n\tSur Name \t\- Please enter a SurName";
	}
	
	 
	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
		if(strPayMethod=="paypal"){

			oForm.payer_email.value	 = alltrim(sEmail);	
			oForm.first_name.value	 = alltrim(sName);
			oForm.last_name.value	 = alltrim(oForm.MC_surname.value);
			oForm.city.value         = alltrim(oForm.MC_town.value);
            oForm.item_name.value    = SearchType + ' Details: -  Telephone :' + sTelephone + ' , County :' + sMCCounty + ',Additional Info :' + sMCAdditionalInfo;			
			oForm.action='submit_paypal.php';
			oForm.method='post';
			oForm.submit();
			}else{
				return true;
				}

}

function validate_FamilySearch (strPayMethod,SearchType) 
  {


	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmFamilySearch;
	var sName                = alltrim(oForm.name.value);
	var sTelephone           = alltrim(oForm.tel.value);
	var sEmail               = alltrim(oForm.email.value);	
	var sConfirmEmail        = alltrim(oForm.confirm_email.value);
	var sMCForName           = alltrim(oForm.MC_forname.value);
	var sMCMiddleName        = alltrim(oForm.MC_middle_name.value);
	var sMCSurname           = alltrim(oForm.MC_surname.value);

    var sFore_Name1          = alltrim(oForm.fore_name1.value);
	var sMiddle_Name1        = alltrim(oForm.middle_name1.value);	
	var sSurName1            = alltrim(oForm.surname1.value);
   
    var sFore_Name2          = alltrim(oForm.fore_name2.value);
	var sMiddle_Name2        = alltrim(oForm.middle_name2.value);	
	var sSurName2            = alltrim(oForm.surname2.value);

    var sFore_Name3          = alltrim(oForm.fore_name3.value);
	var sMiddle_Name3        = alltrim(oForm.middle_name3.value);	
	var sSurName3            = alltrim(oForm.surname3.value);

	var sMCTown              = alltrim(oForm.MC_town.value);
	var sMCCounty            = alltrim(oForm.MC_county.value);
    var sMCAdditionalInfo    = alltrim(oForm.MC_additional_info.value);
	
	//Check for a name
	if (sName == "")
	{
		errorMsg += "\n\tName \t\t- Enter your Name";
	}
	
	   if(!fnValidateSpecialCharacters(sTelephone))
		{
			errorMsg += "\n\tTelephone \t\- Invalid Telephone Number";
		}
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}
	//Check for Confirm Email Address
	if (sConfirmEmail == "")
	{
		errorMsg += "\n\tConfirm Email \t\- Please enter a Confirm Email";
	}
    else
	 {
	   //Check for valid Confirm Email Address.
		if(!checkemail(sConfirmEmail))
		{
			errorMsg += "\n\tConfirm Email  \t\- Please enter a valid Confirm Email";
		}
	}
	//Check for similar Email and Confirm Email Address	
	if (sEmail != sConfirmEmail && (sEmail != "" )&& (sConfirmEmail != "" ))
	 {
	  errorMsg += "\n\tConfirm Email  \t\- Please enter a similar Email and confirm Email";
	 }

	//Check for Forname	
	if (sMCForName == "")
	{
		errorMsg += "\n\tForName \t\t- Please enter a Forname";
	}
   
	if (sMCSurname == "")
	{
		errorMsg += "\n\tSurName \t\t- Please enter a SurName";
	}

	//Check for Sur Name1	
/*	if (sFore_Name1 == "")
	{
		errorMsg += "\n\tForName1 \t\- Please enter a Forname1";
	}


	//Check for Sur Name1	
	if (sSurName1 == "")
	{
		errorMsg += "\n\tSurName1 \t\- Please enter a SurName1";
	}

	//Check for Sur Name2	
	if (sFore_Name2 == "")
	{
		errorMsg += "\n\tForName2 \t\- Please enter a Forname2";
	}


	//Check for Sur Name2	
	if (sSurName2 == "")
	{
		errorMsg += "\n\tSurName2 \t\- Please enter a SurName2";
	}

//Check for Sur Name3	
	if (sFore_Name3 == "")
	{
		errorMsg += "\n\tForName3 \t\- Please enter a Forname3";
	}


	//Check for Sur Name3	
	if (sSurName3 == "")
	{
		errorMsg += "\n\tSurName3 \t\- Please enter a SurName3";
	}
*/
	
	 

	//Assign the additional values to the description field of the worldpay
      oForm.desc.value    = SearchType + ' Details: -  Telephone :' + sTelephone + ' , Middlde Name :' + sMCMiddleName;   
      oForm.desc.value   += ' , Fore Name1 :' + sFore_Name1 + ' , Middlde Name1 :' + sMiddle_Name1 + ' ,Sur Name1 :' + sSurName1;
      oForm.desc.value   += ' , Fore Name2 :' + sFore_Name2 + ' , Middlde Name2 :' + sMiddle_Name2 + ' ,Sur Name2 :' + sSurName2;
      oForm.desc.value   += ' , Fore Name3 :' + sFore_Name3 + ' , Middlde Name3 :' + sMiddle_Name3 + ' ,Sur Name3 :' + sSurName3;
      oForm.desc.value   += ' , County :' + sMCCounty + ' ,Additional Info :' + sMCAdditionalInfo;	

	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
  if ((errorMsg == "") || (errorMsgLong == ""))
   { 	
         if(strPayMethod=="paypal")
         {
			oForm.payer_email.value	 = alltrim(sEmail);	
			oForm.first_name.value	 = alltrim(sName);
			oForm.last_name.value	 = alltrim(oForm.MC_surname.value);
			oForm.city.value         = alltrim(oForm.MC_town.value);   

          oForm.item_name.value    = SearchType + ' Details: -  Telephone :' + sTelephone + ' , Middlde Name :' + sMCMiddleName;   
          oForm.item_name.value   += ' , Fore Name1 :' + sFore_Name1 + ' , Middlde Name1 :' + sMiddle_Name1 + ' ,Sur Name1 :' + sSurName1;
          oForm.item_name.value   += ' , Fore Name2 :' + sFore_Name2 + ' , Middlde Name2 :' + sMiddle_Name2 + ' ,Sur Name2 :' + sSurName2;
          oForm.item_name.value   += ' , Fore Name3 :' + sFore_Name3 + ' , Middlde Name3 :' + sMiddle_Name3 + ' ,Sur Name3 :' + sSurName3;
          oForm.item_name.value   += ' , County :' + sMCCounty + ' ,Additional Info :' + sMCAdditionalInfo;            
	      oForm.action='submit_paypal.php';
		  oForm.method='post';
		  oForm.submit();
		 }
         else
          {
		    return true;
		  }
   }
}






//Address Search Validation
function validate_AddressSearch(strPayMethod,SearchType) 
  {

	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmAddressSearch;
	var sName                = alltrim(oForm.name.value);
	var sTelephone           = alltrim(oForm.tel.value);
	var sEmail               = alltrim(oForm.email.value);	
	var sConfirmEmail        = alltrim(oForm.confirm_email.value);
	var sFlatNumber          = alltrim(oForm.flat_number.value);
	var sHouseNumber         = alltrim(oForm.house_number.value);	
	var sStreetName          = alltrim(oForm.street_name.value);
    var sMCTown              = alltrim(oForm.MC_town.value);
	var sPostCode            = alltrim(oForm.post_code.value);	
	var sMCAdditionalInfo    = alltrim(oForm.MC_additional_info.value);
	//var sIAgree              = oForm.Iagree.checked;
	
	//Check for a name
	if (sName == "")
	{
		errorMsg += "\n\tName \t\t- Enter your Name";
	}
	
	   if(!fnValidateSpecialCharacters(sTelephone))
		{
			errorMsg += "\n\tTelephone \t\- Invalid Telephone Number";
		}
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}
	//Check for Confirm Email Address
	if (sConfirmEmail == "")
	{
		errorMsg += "\n\tConfirm Email \t\- Please enter a Confirm Email";
	}
    else
	 {
	   //Check for valid Confirm Email Address.
		if(!checkemail(sConfirmEmail))
		{
			errorMsg += "\n\tConfirm Email  \t\- Please enter a valid Confirm Email";
		}
	}
	//Check for similar Email and Confirm Email Address	
	if (sEmail != sConfirmEmail && (sEmail != "" )&& (sConfirmEmail != "" ))
	 {
	  errorMsg += "\n\tConfirm Email  \t\- Please enter a similar Email and confirm Email";
	 }
	if (sStreetName == "")
	{
		errorMsg += "\n\tStreet Name \t\- Please enter a Street Name";
	}
	
	//Check for Post Code
	if (sPostCode == "")
	{
		errorMsg += "\n\tPost Code \t\- Please enter a Post Code";
	}
	 
	 
	//Check for I Agree Condition
	/*if (sIAgree != true )
	{
		errorMsg += "\n\tI Agree Condition \t\- Please check I agree to the terms and conditions";
	}*/

    //Assign the additional values to the description field of the worldpay
     oForm.desc.value    = SearchType + ' Details: -  Telephone :' + sTelephone + ', Flat Number : ' +   sFlatNumber +  ', House Number : ' + sHouseNumber +  ', Street Name : ' + sStreetName + ', Town: ' + sMCTown + ', Post Code : ' + sPostCode;	

	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	if(strPayMethod=="paypal"){
	
			oForm.payer_email.value	 = sEmail;	
			oForm.first_name.value	 = sName;
			oForm.address1.value     = sFlatNumber +sHouseNumber +sStreetName+sMCTown;
			oForm.zip.value          = sPostCode;
            oForm.item_name.value    = SearchType + ' Details: -  Telephone :' + sTelephone + 'Additional Info :' + sMCAdditionalInfo;	
			oForm.action='submit_paypal.php';
			oForm.method='post';
			oForm.submit();
			}else{
				return true;
				}
}

//Register Owner Search
function validate_RegOwnerSearch(strPayMethod,SearchType) 
  {

	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmRegOwnerSearch;
	var sName                = alltrim(oForm.name.value);
	var sTelephone           = alltrim(oForm.tel.value);
	var sEmail               = alltrim(oForm.email.value);	
	var sConfirmEmail        = alltrim(oForm.confirm_email.value);
	var sFlatNumber          = alltrim(oForm.flat_number.value);
	var sHouseNumber         = alltrim(oForm.house_number.value);	
	var sStreetName          = alltrim(oForm.street_name.value);
    var sMCTown              = alltrim(oForm.MC_town.value);	
	var sPostCode            = alltrim(oForm.post_code.value);	
	var sMCAdditionalInfo    = alltrim(oForm.MC_additional_info.value);
	//var sIAgree              = oForm.Iagree.checked;
	
	//Check for a name
	if (sName == "")
	{
		errorMsg += "\n\tName \t\t- Enter your Name";
	}
	
	   if(!fnValidateSpecialCharacters(sTelephone))
		{
			errorMsg += "\n\tTelephone \t\- Invalid Telephone Number";
		}
	
	//Check for Email Address
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}
	//Check for Confirm Email Address
	if (sConfirmEmail == "")
	{
		errorMsg += "\n\tConfirm Email \t\- Please enter a Confirm Email";
	}
    else
	 {
	   //Check for valid Confirm Email Address.
		if(!checkemail(sConfirmEmail))
		{
			errorMsg += "\n\tConfirm Email  \t\- Please enter a valid Confirm Email";
		}
	}
	//Check for similar Email and Confirm Email Address	
	if (sEmail != sConfirmEmail && (sEmail != "" )&& (sConfirmEmail != "" ))
	 {
	  errorMsg += "\n\tConfirm Email  \t\- Please enter a similar Email and confirm Email";
	 }

	
	//Check for Street Name	
	if (sStreetName == "")
	{
		errorMsg += "\n\tStreet Name \t\- Please enter a Street Name";
	}
	
	
	if (sPostCode == "")
	{
		errorMsg += "\n\tPost Code \t\- Please enter a Post Code";
	}
	 
	 
	 
     oForm.desc.value    = SearchType + ' Details : -  Telephone :' + sTelephone + ', Flat Number : ' +   sFlatNumber +  ', House Number : ' + sHouseNumber +  ', Street Name : ' + sStreetName + ', Town : ' + sMCTown+ ', Post Code : ' + sPostCode;	

	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
	if(strPayMethod=="paypal"){
			oForm.payer_email.value	 = sEmail;	
			oForm.first_name.value	 = sName;
			oForm.zip.value			 = sPostCode;
			oForm.city.value         = sTown;
			oForm.address1.value     = sFlatNumber + sHouseNumber + sStreetName ;
            oForm.item_name.value    =  SearchType + ' Details: -  Telephone :' + sTelephone + ',Additional Info :' + sMCAdditionalInfo;				
			oForm.action='submit_paypal.php';
			oForm.method='post';
			oForm.submit();
			}else{
				return true;
				}
}


function validate_BirthSearch(strPayMethod,SearchType) 
  {

	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmBirthSearch;
	var sName                = alltrim(oForm.name.value);
	var sTelephone           = alltrim(oForm.tel.value);
	var sEmail               = alltrim(oForm.email.value);	
	var sConfirmEmail        = alltrim(oForm.confirm_email.value);	
	var sEventType           = alltrim(oForm.event_type.value);
	var sMCSurname           = alltrim(oForm.MC_surname.value);
	var sMCForname           = alltrim(oForm.MC_forname.value);
    var sMonth               = alltrim(oForm.month.value);
	var sYear                = alltrim(oForm.year.value);
	var sMothersMaidenName   = alltrim(oForm.mothers_maiden_name.value);
	var sSpousesSurname      = alltrim(oForm.spouses_surname.value);
	var sBirthDate           = alltrim(oForm.birth_date.value);
	
	//var sIAgree              = oForm.Iagree.checked;
	
	if (sName == "")
	{
		errorMsg += "\n\tName \t\t- Enter your Name";
	}
	
	   if(!fnValidateSpecialCharacters(sTelephone))
		{
			errorMsg += "\n\tTelephone \t\- Invalid Telephone Number";
		}
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}
	if (sConfirmEmail == "")
	{
		errorMsg += "\n\tConfirm Email \t\- Please enter a Confirm Email";
	}
    else
	 {
	   //Check for valid Confirm Email Address.
		if(!checkemail(sConfirmEmail))
		{
			errorMsg += "\n\tConfirm Email  \t\- Please enter a valid Confirm Email";
		}
	}
	//Check for similar Email and Confirm Email Address	
	if (sEmail != sConfirmEmail && (sEmail != "" )&& (sConfirmEmail != "" ))
	 {
	  errorMsg += "\n\tConfirm Email  \t\- Please enter a similar Email and confirm Email";
	 }
	 
	 //Check for a SurName
	if (sMCSurname == "")
	{
		errorMsg += "\n\tSurName \t\t- Enter a SurName";
	}
	
	 //Check for a ForName
	if (sMCForname == "")
	{
		errorMsg += "\n\tForName \t\t- Enter a ForName";
	}
	
 /*Check for a Month
	if (sMonth == "")
	{
		errorMsg += "\n\tsMonth \t\t- Enter a Month";
}
	 //Check for a Year
	if (sYear == "")
	{
		errorMsg += "\n\tYear \t\t- Enter a Year";
	}
	
	 //Check for a Mothers Maiden Name
	if (sMothersMaidenName == "")
	{
		errorMsg += "\n\tMothers Name \t\- Enter a Mothers Maiden Name";
	}
	
	 //Check for a Spouses Surname
	if (sSpousesSurname == "")
	{
		errorMsg += "\n\tSpouses Surname \t\- Enter a Spouses Surname";
	}
	 //Check for a Birth Date
	if (sBirthDate == "")
	{
		errorMsg += "\n\tBirth Date \t\- Enter a Birth Date";
	}
	 //Check for I Agree Condition
     oForm.desc.value    = SearchType + ' Details : -  Telephone :' + sTelephone + ', Event Type :' + sEventType + ', Year:' + sYear + ', Month:' + sMonth + ' , Mothers Mainden Name:' + sMothersMaidenName + ' , Spouses SurName:' + sSpousesSurname + ', Birth Date:' + sBirthDate;	
	 
	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
	if(strPayMethod=="paypal"){
			oForm.payer_email.value	 = sEmail;	
			oForm.first_name.value	 = sName;
			oForm.last_name.value	 = sMCSurname + sMCForname;
			oForm.address1.value     = SearchType + " Deatails : - Event type : "+ sEventType + " , Year : " + sYear + ",  Mothers Maiden Name :" + sMothersMaidenName + ", Spouses Surname : " + sSpousesSurname + " , Birth Date : " + sBirthDate ;			
			oForm.action='submit_paypal.php';
			oForm.method='post';
			oForm.submit();
			}else{
				return true;
				}
				
}

///Birth Certificate
function validate_BirthCertificate(strPayMethod) 
  {

	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmBirthCertificate;
    var sSpeed               = alltrim(oForm.speed.value);    
    var sMCForname           = alltrim(oForm.MC_forname.value);
    var sMCSurname           = alltrim(oForm.MC_surname.value);
	var sAddress             = alltrim(oForm.address2.value);
	var sTelephone           = alltrim(oForm.tel.value);
    var sPostCode            = alltrim(oForm.post_code.value);
    var sCountry             = alltrim(oForm.country1.value);
    var sEmail               = alltrim(oForm.email.value);
    var sReasonForCertificate = alltrim(oForm.reason_for_certificate.value);
    var sSurNameATBirth      = alltrim(oForm.surname_at_birth.value);
    var sForenameAtBirth    = alltrim(oForm.Forename_at_birth.value);
    var sDateofBirth         = alltrim(oForm.dateofbirth.value);
    var sFathersSurname      = alltrim(oForm.fathers_surname.value);
    var sFathersForename      = alltrim(oForm.fathers_forename.value);
    var sMothersSurname      = alltrim(oForm.mothers_surname.value);
    var sMothersForename      = alltrim(oForm.mothers_forename.value);
    var sMothersMaidenName   = alltrim(oForm.mothers_maiden_name.value);
    var sPlaceOfBirth        = alltrim(oForm.place_of_birth.value);
  
   if (sSpeed == 7)
    {
      oForm.amount.value = 24.95;
      //alert(oForm.amount.value);
    }
   else if (sSpeed == 21)
	{
     oForm.amount.value = 14.95;
     //alert(oForm.amount.value);
    } 
   //Check for a ForName
	if (sMCForname == "")
	{
		errorMsg += "\n\tForName \t\t- Enter a ForName";
	}

   //Check for a SurName
	if (sMCSurname == "")
	{
		errorMsg += "\n\tSurName \t\t- Enter a SurName";
	}

  //Check for a Address
	if (sAddress == "")
	{
		errorMsg += "\n\tAddress \t\t- Enter a Address";
	}	

	   if(!fnValidateSpecialCharacters(sTelephone))
		{
			errorMsg += "\n\tTelephone \t\- Invalid Telephone Number";
		}
	if (sPostCode == "")
	{
		errorMsg += "\n\tPost Code \t\- Please enter a Post Code";
	}

	if (sCountry == "")
	{
		errorMsg += "\n\tCountry \t\t- Please select  a Country";
	}

	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}


     oForm.desc.value  =  ' Birth Certificate - England and Wales Details : -  Telephone :' + sTelephone + ', Speed :' +  sSpeed;	
     oForm.desc.value  += ', Address 2 :' +  sAddress + ', Post Code :' + sPostCode + ', Country :' + sCountry  + ', ReasonForCertificate :' + sReasonForCertificate;
     oForm.desc.value  += ', SurName AT Birth:' +  sSurNameATBirth + ', Fore Name At Birth :' + sForenameAtBirth + ', Date of Birth :' + sDateofBirth  + ', Fathers Surname :' + sFathersSurname;
     oForm.desc.value  += ', Fathers Fore name:' +  sFathersForename + ', Mothers Sur name :' + sMothersSurname + ', Mothers Forename:' + sMothersForename  + ', Place Of Birth :' + sPlaceOfBirth;
    
	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	if(strPayMethod=="paypal"){
			oForm.payer_email.value= sEmail;
            oForm.address1.value   = sAddress  
            oForm.first_name.value = sForenameAtDeath;
            oForm.last_name.value  = sSurNameATDeath;   

            oForm.item_name.value  =  'Birth Certificate - England and Wales Details : -  Telephone :' + sTelephone + ', Speed :' +  sSpeed;	
            oForm.item_name.value  += ', Post Code :' + sPostCode + ', Country :' + sCountry  + ', ReasonForCertificate :' + sReasonForCertificate;
            oForm.item_name.value  += ', SurName AT Birth:' +  sSurNameATBirth + ', Fore Name At Birth :' + sForenameAtBirth + ', Date of Birth :' + sDateofBirth  + ', Fathers Surname :' + sFathersSurname;
            oForm.item_name.value  += ', Fathers Fore name:' +  sFathersForename + ', Mothers Sur name :' + sMothersSurname + ', Mothers Forename:' + sMothersForename  + ', Place Of Birth :' + sPlaceOfBirth;	
			oForm.action='submit_paypal.php';
			oForm.method='post';
			oForm.submit();
			}else{
				return true;
				}
}

//Birth Search
function validate_EWBirthCertificate(strPayMethod) 
  {

	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmEWBirthCertificate;
	var sMCForname           = alltrim(oForm.MC_forname.value);
	var sMCSurname           = alltrim(oForm.MC_surname.value);	
	var sAddress             = alltrim(oForm.address.value);
	var sEmail               = alltrim(oForm.email.value);		

		 //Check for a ForName
	if (sMCForname == "")
	{
		errorMsg += "\n\tForName \t\t- Enter a ForName";
	}
	 
	 //Check for a SurName
	if (sMCSurname == "")
	{
		errorMsg += "\n\tSurName \t\t- Enter a SurName";
	}	
	
	 //Check for a Address
	if (sAddress == "")
	{
		errorMsg += "\n\tAddress \t\t- Enter a Address";
	}	
	
	//Check for Email Address
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}
	
	 
	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	if(strPayMethod=="paypal"){
	
		oForm.payer_email.value	 = sEmail;	
			oForm.first_name.value	 = sMCForname;
			oForm.last_name.value	 = sMCSurname;
			oForm.address1.value      = sAddress;			
			oForm.action='submit_paypal.php';
			oForm.method='post';
			oForm.submit();
			}else{
				return true;
				}
}



//Ancestory Search
function validate_ancestrysearch(strPayMethod) 
  {
	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.AncestrySearch;
	var sFirstName           = alltrim(oForm.name.value);
	var sMCSurname           = alltrim(oForm.MC_surname.value);
	var sEmail               = alltrim(oForm.email.value);
    var sSpelling            = alltrim(oForm.spelling.value);
    var sOption              = alltrim(oForm.option.value);
    var sFromYear            = alltrim(oForm.fromyear.value);
    var sToYear              = alltrim(oForm.toyear.value);
    var sCountryKeyword      = alltrim(oForm.country_keyword.value);
    var sCountryRecordType   = alltrim(oForm.country_record_type.value);
	
	//Check for First Name
	if (sFirstName == "")
	{
		errorMsg += "\n\tFirst Name \t\- Enter your First Name";
	}
	
	//Check for First Name
	if (sMCSurname == "")
	{
		errorMsg += "\n\tSurName \t\t- Enter your SurName";
	}
	
		//Check for Email Address
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}
		 
     //Assign the additional values to the description field of the worldpay
      oForm.desc.value    = "Ancestry Search" + ' Details : -  Spelling :' + sSpelling + ', Option :' + sOption + ', From Year:' + sFromYear + ', To Year :' + sToYear + ' , Country Keyword :' + sCountryKeyword + ' , Country Record Type :' + sCountryRecordType;	

	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	

	if(strPayMethod=="paypal"){
			oForm.payer_email.value	 = sEmail;	
			oForm.first_name.value	 = sFirstName;
			oForm.last_name.value	 = sMCSurname;
          //Assign the additional values to the description field of the worldpay
            oForm.item_name.value    = "Ancestry Search" + ' Details : -  Spelling :' + sSpelling + ', Option :' + sOption + ', From Year:' + sFromYear + ', To Year :' + sToYear + ' , Country Keyword :' + sCountryKeyword + ' , Country Record Type :' + sCountryRecordType;	
			oForm.action='submit_paypal.php';
			oForm.method='post';
			oForm.submit();
			}else{
				return true;
				}
}

//Ancestory Search
function validate_EnglishCensusSearch(strPayMethod) 
  {

	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmEnglishCensusSearch;
	var sFirstName           = alltrim(oForm.first_name.value);
	var sMCSurname           = alltrim(oForm.MC_surname.value);
	var sEmail               = alltrim(oForm.email.value);
	var sSpelling            = alltrim(oForm.spelling.value);
	var sCountry1            = alltrim(oForm.country1.value);
	var sCensus_year         = alltrim(oForm.census_year.value);
	var sCounty              = alltrim(oForm.county.value);
	var sDistrict            = alltrim(oForm.district.value);
	var sGender              = alltrim(oForm.gender.value);
	var sAge                 = alltrim(oForm.age.value);
    var sBitrhplaceCountyIsland  = alltrim(oForm.bitrhplace_county_island.value);
    var sBitrhplaceParishPlace  = alltrim(oForm.bitrhplace_parish_place.value);
	
	//Check for First Name
	if (sFirstName == "")
	{
		errorMsg += "\n\tFirst Name \t\- Enter your First Name";
	}
	
	//Check for First Name
	if (sMCSurname == "")
	{
		errorMsg += "\n\tSurName \t\t- Enter your SurName";
	}
	
	//Check for Email Address
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}

	//Check for Country
	if (sCountry1 == "")
	{
		errorMsg += "\n\tCountry\t\t- Select a Country";
	}
 
 //Check for Census year
	if (sCensus_year == "")
	{
		errorMsg += "\n\tCensus year \t\- Enter a Census year";
	}

//Check for Age
	if (sAge == "")
	{
		errorMsg += "\n\tAge\t\t- Enter your age";
	}
		 
   //Assign the additional values to the description field of the worldpay
    oForm.desc.value = "English Census Records Search" + ' Details : -  Spelling :' + sSpelling + ', Country :' + sCountry1 + ', Census year:' + sCensus_year ;	
    oForm.desc.value += ', County :' + sCounty + ' , District :' + sDistrict + ' , Gender :' + sGender + ' , Age :' + sAge + ' , Bitrh place County Island :' + sBitrhplaceCountyIsland + ' , Bitrh place Parish Place :' + sBitrhplaceParishPlace;    
	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
	if(strPayMethod=="paypal"){
	
			oForm.payer_email.value	 = sEmail;	
			oForm.first_name.value	 = sFirstName;
			oForm.last_name.value	 = sMCSurname;
            oForm.address1.value	 = sDistrict + sCounty + sCountry1;
           //Assign the additional values to the description field of the worldpay
            oForm.item_name.value = "English Census Records Search" + ' Details : -  Spelling :' + sSpelling + ', Census year:' + sCensus_year ;	
            oForm.item_name.value +=' , Gender :' + sGender + ' , Age :' + sAge + ' , Bitrh place County Island :' + sBitrhplaceCountyIsland + ' , Bitrh place Parish Place :' + sBitrhplaceParishPlace;    
			oForm.action='submit_paypal.php';
			oForm.method='post';
			oForm.submit();
			}else{
				return true;
				}
}


//Ancestory Search
function validate_CensusSearch(strPayMethod) 
  {

	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmCensusSearch;
	var sFirstName           = alltrim(oForm.first_name.value);
	var sMCSurname           = alltrim(oForm.MC_surname.value);
	var sEmail               = alltrim(oForm.email.value);
	var sType                = alltrim(oForm.type.value);
    var sVolume              = alltrim(oForm.volume.value);
    var sDistricts           = alltrim(oForm.districts.value);
    var sQuarter             = alltrim(oForm.quarter.value);
    var sYear                = alltrim(oForm.year.value);
	//Check for First Name
	if (sFirstName == "")
	{
		errorMsg += "\n\tFirst Name \t\- Enter your First Name";
	}
	
	//Check for First Name
	if (sMCSurname == "")
	{
		errorMsg += "\n\tSurName \t\t- Enter your SurName";
	}
	
	//Check for Email Address
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}
		 
   //Assign the additional values to the description field of the worldpay
    oForm.desc.value = "England and Wales, Civil Registration Index: 1837-1900";
    oForm.desc.value +=' Details : -  Type :' + sType + ', Volume :' + sVolume + ', Districts:' + sDistricts ;	
    oForm.desc.value += ', Quarter :' + sQuarter + ' , Year :' + sYear;    

	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
	if(strPayMethod=="paypal"){
	
			oForm.payer_email.value	 = sEmail;	
			oForm.first_name.value	 = sFirstName;
			oForm.last_name.value	 = sMCSurname;
			oForm.address1.value	 = sDistricts;

            //Assign the additional values to the description field of the worldpay
            oForm.item_name.value = "England and Wales, Civil Registration Index: 1837-1900";
            oForm.item_name.value +=' Details : -  Type :' + sType + ', Volume :' + sVolume;	
            oForm.item_name.value += ', Quarter :' + sQuarter + ' , Year :' + sYear;    

			oForm.action='submit_paypal.php';
			oForm.method='post';
			oForm.submit();
			}else{
				return true;
				}
}

//People Tracer Search
function validate_PeopleTracer(strPayMethod) 
  {

	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmPeopleTracer;
	var sName                = alltrim(oForm.MC_surname.value);
	var sAddress             = alltrim(oForm.address2.value);    
    var sTelephone           = alltrim(oForm.Telephone.value);
	var sEmail               = alltrim(oForm.email.value);	
	var sReasonForTrace      = alltrim(oForm.reason_for_trace.value);	
    var sNameToTrace         = alltrim(oForm.nametotrace.value);
    var sDateOfBirth         = alltrim(oForm.dateofbirth.value);	
    var sKnownAddress        = alltrim(oForm.known_address.value);
    var sOtherInfo           = alltrim(oForm.otherinfo.value);
    var sContactMe           = alltrim(oForm.contact_me.value);	
	
	 //Check for Name
	if (sName == "")
	{
		errorMsg += "\n\tName \t\t- Enter your Name";
	}

   //Check for Address
	if (sAddress == "")
	{
		errorMsg += "\n\tAddress \t\t- Enter your Address";
	}

  //Check for Telephone
	if (sTelephone == "")
	{
		errorMsg += "\n\tTelephone \t\- Enter your Telephone";
	}
	
	//Check for Email Address
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}	
    
   //Check for Reason For Trace
	if (sReasonForTrace == "")
	{
		errorMsg += "\n\tReason For Trace \t\- Enter your Reason For Trace";
	}

   //Check for Name To Trace
	if (sNameToTrace == "")
	{
		errorMsg += "\n\tName To Trace \t\- Enter a Name To Trace";
	}
 
	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	
	if(strPayMethod=="Send"){
	
		   //Assign the additional values to the description field of the worldpay
            oForm.payer_email.value = sEmail;
            oForm.first_name.value = sName;
			oForm.desc.value = "People Tracer";
			oForm.desc.value +=' Details : - <br> Name :' + sName + '<br> Email :' + sEmail + '<br> Address :' + sAddress + '<br> Known Address :' + sKnownAddress + '<br> Telephone :' + sTelephone + '<br> Reason For Trace:' + sReasonForTrace ;	
			oForm.desc.value += '<br> Name To Trace :' + sNameToTrace + '<br> Date Of Birth :' + sDateOfBirth + '<br> Known Address :' + sKnownAddress +'<br> Other Info :'  + sOtherInfo + '<br> Contact Me:' + sContactMe;    			           
			oForm.action='thanks.php?id=2';
			oForm.method='post';
			oForm.submit();
			}else{
				return true;
				}
}

///Birth Certificate
function validate_DeathCertificate(strPayMethod) 
  {

	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmDeathCertificate;
    var sSpeed               = alltrim(oForm.speed.value);    
    var sMCForname           = alltrim(oForm.MC_forname.value);
    var sMCSurname           = alltrim(oForm.MC_surname.value);
	var sAddress             = alltrim(oForm.address2.value);
	var sTelephone           = alltrim(oForm.tel.value);
    var sPostCode            = alltrim(oForm.post_code.value);
    var sCountry             = alltrim(oForm.country1.value);
    var sEmail               = alltrim(oForm.email.value);
    var sReasonForCertificate  = alltrim(oForm.reason_for_certificate.value);
    var sSurNameATDeath      = alltrim(oForm.surname_at_death.value);
    var sForenameAtDeath    = alltrim(oForm.forename_at_death.value);
    var sDateofBirth         = alltrim(oForm.dateofbirth.value);    
    var sDateOfDeath         = alltrim(oForm.dateofdeath.value);
    var sGroreference        = alltrim(oForm.groreference.value);
	
  //Check the speed of the service and assign the price according to that
   if (sSpeed == 7)
    {
      oForm.amount.value = 24.95;
      //alert(oForm.amount.value);
    }
   else if (sSpeed == 21)
	{
     oForm.amount.value = 14.95;
     //alert(oForm.amount.value);
    } 
 
   //Check for a ForName
	if (sMCForname == "")
	{
		errorMsg += "\n\tForName \t\t- Enter a ForName";
	}

   //Check for a SurName
	if (sMCSurname == "")
	{
		errorMsg += "\n\tSurName \t\t- Enter a SurName";
	}

  //Check for a Address
	if (sAddress == "")
	{
		errorMsg += "\n\tAddress \t\t- Enter a Address";
	}	

	   if(!fnValidateSpecialCharacters(sTelephone))
		{
			errorMsg += "\n\tTelephone \t\- Invalid Telephone Number";
		}
	if (sPostCode == "")
	{
		errorMsg += "\n\tPost Code \t\- Please enter a Post Code";
	}

	if (sCountry == "")
	{
		errorMsg += "\n\tCountry \t\t- Please select  a Country";
	}

	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}


     oForm.desc.value  =  ' Death Certificate - England and Wales Details : -  Telephone :' + sTelephone + ', Speed :' +  sSpeed;	
     oForm.desc.value  += ', Address 2 :' +  sAddress + ', Post Code :' + sPostCode + ', Country :' + sCountry  + ', ReasonForCertificate :' + sReasonForCertificate;
     oForm.desc.value  += ', SurName AT Death:' +  sSurNameATDeath + ', Fore Name At Death :' + sForenameAtDeath + ', Date of Birth :' + sDateofBirth;
     oForm.desc.value  += ', Date Of Death :' + sDateOfDeath + ', GRO Reference :' + sGroreference;


	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	if(strPayMethod=="paypal"){
	  oForm.payer_email.value	 = sEmail;
      oForm.address1.value	     = sAddress;
      oForm.first_name.value	 = sForenameAtDeath;
      oForm.last_name.value	     = sSurNameATDeath;  

//Assign the additional values to the description field of the worldpay         
     oForm.item_name.value  =  ' Death Certificate - England and Wales Details : -  Telephone :' + sTelephone + ', Speed :' +  sSpeed;	
     oForm.item_name.value  += ', Post Code :' + sPostCode + ', Country :' + sCountry  + ', ReasonForCertificate :' + sReasonForCertificate;
     oForm.item_name.value  += ', SurName AT Death:' +  sSurNameATDeath + ', Fore Name At Death :' + sForenameAtDeath + ', Date of Birth :' + sDateofBirth ;
     oForm.item_name.value  += ', Date Of Death :' + sDateOfDeath + ', GRO Reference :' + sGroreference;	
			oForm.action='submit_paypal.php';
			oForm.method='post';
			oForm.submit();
			}else{
				return true;
				}
}

///Marriage Certificate
function validate_MarriageCertificate(strPayMethod) 
  {

	//Intialise variables
	var errorMsg             = "";
	var errorMsgLong         = "";
    var oForm                = document.frmMarriageCertificate;
    var sSpeed               = alltrim(oForm.speed.value);    
    var sMCForname           = alltrim(oForm.MC_forname.value);
    var sMCSurname           = alltrim(oForm.MC_surname.value);
	var sAddress             = alltrim(oForm.address2.value);
	var sTelephone           = alltrim(oForm.tel.value);
    var sPostCode            = alltrim(oForm.post_code.value);
    var sCountry             = alltrim(oForm.country1.value);
    var sEmail               = alltrim(oForm.email.value);
    var sReasonForCertificate  = alltrim(oForm.reason_for_certificate.value);
    var sMalesSurname      = alltrim(oForm.males_surname.value);
    var sMalesForname    = alltrim(oForm.males_forname.value);
    var sFemalesSurname      = alltrim(oForm.females_surname.value);
    var sFemalesForname    = alltrim(oForm.females_forname.value);
    var sDateOfMarriage         = alltrim(oForm.dateofmarriage.value);   
    var sGroreference      = alltrim(oForm.groreference.value);


	if (sSpeed == 7)
    {
      oForm.amount.value = 24.95;
     // alert(oForm.amount.value);
    }
   else if (sSpeed == 21)
	{
     oForm.amount.value = 14.95;
     //alert(oForm.amount.value);
    } 
		 
   //Check for a ForName
	if (sMCForname == "")
	{
		errorMsg += "\n\tForName \t\t- Enter a ForName";
	}

   //Check for a SurName
	if (sMCSurname == "")
	{
		errorMsg += "\n\tSurName \t\t- Enter a SurName";
	}

  //Check for a Address
	if (sAddress == "")
	{
		errorMsg += "\n\tAddress \t\t- Enter a Address";
	}	

	   if(!fnValidateSpecialCharacters(sTelephone))
		{
			errorMsg += "\n\tTelephone \t\- Invalid Telephone Number";
		}
	if (sPostCode == "")
	{
		errorMsg += "\n\tPost Code \t\- Please enter a Post Code";
	}

 //Check for Country
	if (sCountry == "")
	{
		errorMsg += "\n\tCountry \t\t- Please select  a Country";
	}

   //Check for Email Address
	if (sEmail == "")
	{
		errorMsg += "\n\tEmail \t\t- Enter your Email";
	}
    else
	 {
	  //Check for valid email address.
		if(!checkemail(sEmail))
		{
			errorMsg += "\n\tEmail \t\t- Please enter a valid Email";
		}
	}

     oForm.desc.value  =  ' Marriage Certificate - England and Wales : -  Telephone :' + sTelephone + ', Speed :' +  sSpeed;	
     oForm.desc.value  += ', Address 2 :' +  sAddress + ', Post Code :' + sPostCode + ', Country :' + sCountry  + ', ReasonForCertificate :' + sReasonForCertificate;
     oForm.desc.value  += ', Males Surname:' +  sMalesSurname + ', Males Forname:' + sMalesForname + ', Females Forname Surname:' +  sFemalesSurname + ', Females Forname:' + sFemalesForname + ', Date Of Marriage :' + sDateOfMarriage;
     oForm.desc.value  += ', GRO Reference :' + sGroreference;


	if ((errorMsg != "") || (errorMsgLong != ""))
	{
		msg = "___________________________________________________________________\n\n";
		msg += "Your Comments have not been added because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "___________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return false;
	}
	if(strPayMethod=="paypal"){
			oForm.payer_email.value	 = sEmail;
            oForm.address1.value	 = sAddress;
            oForm.first_name.value	 = sMalesSurname;
            oForm.last_name.value	 = sMalesForname;

           //Assign the additional values to the description field of the worldpay         
			 oForm.item_name.value  =  ' Marriage Certificate - England and Wales : -  Telephone :' + sTelephone + ', Speed :' +  sSpeed;	
			 oForm.item_name.value  += ', Post Code :' + sPostCode + ', Country :' + sCountry  + ', ReasonForCertificate :' + sReasonForCertificate;
			 oForm.item_name.value  += ', Males Surname:' +  sMalesSurname + ', Males Forname:' + sMalesForname + ', Females Forname Surname:' +  sFemalesSurname + ', Females Forname:' + sFemalesForname + ', Date Of Marriage :' + sDateOfMarriage;
			 oForm.item_name.value  += ', GRO Reference :' + sGroreference;	
			 oForm.action='submit_paypal.php';
			 oForm.method='post';
			 oForm.submit();
			}else{
				return true;
				}
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
