<!-- Hide from older browsers

   function activate09() {
      document.images["nine"].src = "http://www.financefinderus.com/images/index_09_.gif";
   }

   function deactivate09() {
      document.images["nine"].src = "http://www.financefinderus.com/images/index_09.gif";
   }

function activate10() {
      document.images["ten"].src = "http://www.financefinderus.com/images/index_10_.gif";
   }

   function deactivate10() {
      document.images["ten"].src = "http://www.financefinderus.com/images/index_10.gif";
   }
   
function activate11() {
      document.images["eleven"].src = "http://www.financefinderus.com/images/index_11_.gif";
   }

   function deactivate11() {
      document.images["eleven"].src = "http://www.financefinderus.com/images/index_11.gif";
   }
   
function activate12() {
      document.images["twelve"].src = "http://www.financefinderus.com/images/refinance_.gif";
   }

   function deactivate12() {
      document.images["twelve"].src = "http://www.financefinderus.com/images/refinance.gif";
   }

function activate13() {
      document.images["thirteen"].src = "http://www.financefinderus.com/images/index_13_.gif";
   }

   function deactivate13() {
      document.images["thirteen"].src = "http://www.financefinderus.com/images/index_13.gif";
   }
   
function activate14() {
      document.images["fourteen"].src = "http://www.financefinderus.com/images/index_14_.gif";
   }

   function deactivate14() {
      document.images["fourteen"].src = "http://www.financefinderus.com/images/index_14.gif";
   }
// End script hiding -->


// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

/*function ValidateForm(){
	var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }*/

function Check_State(){


if(document.clientdetails.businessage.value=="New Business")
	{
	Hide_MQ("ExistingBusiness");
	}
else
	{
	Show_MQ("ExistingBusiness");
	
	}
																								  
} //End Function


function Check_Employment_State(){

if(document.clientdetails.application[0].checked==true)
{
	Hide_MQ("ApplicantTwo");
}

else if(document.clientdetails.application[1].checked==true)
{
	Show_MQ("ApplicantTwo");
}

if(document.clientdetails.applicantoneemployed[0].checked==true)
{
	Show_MQ("IncomeOne");
	Hide_MQ("NetProfitsOne");
}
else if(document.clientdetails.applicantoneemployed[1].checked==true)
{
	Hide_MQ("IncomeOne");
	Show_MQ("NetProfitsOne");
}

if(document.clientdetails.applicanttwoemployed[0].checked==true)
{
	Show_MQ("IncomeTwo");
	Hide_MQ("NetProfitsTwo");
}
else if(document.clientdetails.applicanttwoemployed[1].checked==true)
{
	Hide_MQ("IncomeTwo");
	Show_MQ("NetProfitsTwo");
}



}

function Check_Mortgage_State(){
	var oOption = document.forms["clientdetails"].elements["type"];
	
	switch(oOption.value) {
		case "Remortgage":
			Hide_MQ("FoundProperty");
			Hide_MQ("FirstTimeBuyer");
			Hide_MQ("RentalIncome");
			Show_MQ("CCJ");
			Hide_MQ("Country");
			break;
		case "Purchase":
			Show_MQ("FoundProperty");
			Show_MQ("FirstTimeBuyer");
			Show_MQ("CCJ");
			Hide_MQ("RentalIncome");
			Hide_MQ("Country");
			break;
		case "Buy to let":
			Show_MQ("CCJ");
			Show_MQ("RentalIncome");
			Show_MQ("FoundProperty");
			Show_MQ("FirstTimeBuyer");
			Hide_MQ("Country");
			break;
		case "Overseas":
			Hide_MQ("RentalIncome");
			Show_MQ("CCJ");
			Show_MQ("Country");
			Show_MQ("FoundProperty");
			Show_MQ("FirstTimeBuyer");
			break;
		case "Second Home":
			Hide_MQ("RentalIncome");
			Hide_MQ("Country");
			Show_MQ("FoundProperty");
			Show_MQ("CCJ");
			Hide_MQ("FirstTimeBuyer");
			break;
		case "Right to Buy":
			Hide_MQ("RentalIncome");
			Hide_MQ("Country");
			Hide_MQ("FoundProperty");
			Show_MQ("FirstTimeBuyer");
			Show_MQ("CCJ");		
			break;
		case "Other":
			Hide_MQ("RentalIncome");
			Hide_MQ("Country");
			Show_MQ("FoundProperty");
			Show_MQ("FirstTimeBuyer");
			Show_MQ("CCJ");
			break;
	}
																								  
} //End Function



function Show_MQ(Element){
	var oId=document.getElementById(Element)
	if(null != oId) {
		oId.style.visibility = "visible";
		oId.style.display = "";
	}
}
function Hide_MQ(Element){
	var oId=document.getElementById(Element)
	if(null != oId) {
		oId.style.visibility = "hidden";
		oId.style.display = "none";
	}
}


function commercialMortgage(){
	var oFormElements = document.forms["clientdetails"].elements;
	//var oOption = document.forms["clientdetails"].elements["type"];
	var itemsMissing;
     itemsMissing = "";

	if(oFormElements["businessname"].value =="") {
        itemsMissing += "Business Name\n";
     }

    if(oFormElements["purchaseprice"].value =="") {
        itemsMissing += "Value of property\n";
     }

  	if(oFormElements["mortgage"].value =="") {
         itemsMissing += "Mortgage amount required\n";
     }

		 if(itemsMissing != "" ) {
          alert("The following information is required:\n\n" + itemsMissing);
      return false;
     }
     return true;

}

function residentialMortgage() {
	var oForm = document.forms["clientdetails"];
	
	var itemsMissing;
     itemsMissing = "";
	
    if(oForm.elements["purchaseprice"].value =="") {
        itemsMissing += "Value of property\n";
     }

  	if(oForm.elements["mortgage"].value =="") {
         itemsMissing += "Mortgage amount required\n";
     }

		 if(itemsMissing != "" ) {
          alert("The following information is required:\n\n" + itemsMissing);
      return false;
     }
     return true;
}





function contactDetails() {

     var itemsMissing;
     itemsMissing = "";

	 if(clientdetails.name.value =="") {
         itemsMissing += "Your full name\n";
     }

	 if(!ValidatePhoneNumber(clientdetails.telephone.value) && !ValidatePhoneNumber(clientdetails.mobile.value)) {
         itemsMissing += "A valid landline OR mobile number\n";
     }

	 if(!ValidateEmail(clientdetails.email.value)) {
         itemsMissing += "A valid email address\n";
    }

	if(clientdetails.street.value =="") {
         itemsMissing += "Your street address\n";
    }
	 
	if(!checkPostCode(clientdetails.postcode.value)) {
         itemsMissing += "A valid UK Postcode\n";
    }
	 	 	 
	if(clientdetails.dob.value =="") {
         itemsMissing += "Your date of birth\n";
    }

		 if(itemsMissing != "" ) {
          alert("The following information is required:\n\n" + itemsMissing);
      return false;
     }
     return true;
	
}
function ValidatePhoneNumber(phone){
	if ((phone==null)||(phone=="")){
		return false;
	}
	if (checkInternationalPhone(phone)==false){
		return false;
	}
	return true;
}


function checkIFADetails() {

     var itemsMissing;
     itemsMissing = "";


	 if(ifadetails.companyname.value =="") {
         itemsMissing += "Company Name\n";
     }

	 if(ifadetails.fsareg.value =="") {
         itemsMissing += "FSA Registration Number\n";
     }
	 
	 if(ifadetails.contactname.value =="") {
         itemsMissing += "Contact Name\n";
     }

	if(ifadetails.address1.value =="" && ifadetails.address2.value =="") {
         itemsMissing += "Address \n";
     	}

	if(ifadetails.town.value =="") {
         itemsMissing += "Town\n";
     	}

	if(ifadetails.county.value =="") {
         itemsMissing += "County\n";
     	}

	 if(!checkPostCode(ifadetails.postcode.value)) {
         itemsMissing += "A valid UK Postcode\n";
     }

	if(ifadetails.phone.value =="") {
         itemsMissing += "Telephone Number\n";
     	}

	
	 if(!ValidateEmail(ifadetails.email.value)) {
         itemsMissing += "A valid email address\n";
    	}


	 if(itemsMissing != "" ) {
          alert("The following information is required:\n\n" + itemsMissing);
      return false;
     }
     return true;
	
}




function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateEmail(emailID){
	if ((emailID ==null)||(emailID =="")){		
		return false
	}
	if (echeck(emailID)==false){
		return false
	}
	return true
 }


function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  

  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}



