// JavaScript Document

fncYearOptions = function (iYearStart, iYearEnd) {

	if (iYearStart < iYearEnd) {
	
		for (var i = iYearStart; i <= iYearEnd; i++) {
		
			document.write('<option value="' + i + '">' + i + '</option>');
		
		}
		
	} else {
	
		for (var i = iYearStart; i >= iYearEnd; i--) {
		
			document.write('<option value="' + i + '">' + i + '</option>');
		
		}
	
	}

}

function pcaFastAddressBegin(postcode, building, language, style, account_code, license_code, machine_id, options) {

	  var scriptTag = document.getElementById("pcaScriptTag");
	  var headTag = document.getElementsByTagName("head").item(0);
	  var strUrl = "";

	  //Build the url
	  strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
	  strUrl += "&action=fetch";
	  strUrl += "&postcode=" + escape(postcode);
	  strUrl += "&building=" + escape(building);
	  strUrl += "&language=" + escape(language);
	  strUrl += "&style=" + escape(style);
	  strUrl += "&account_code=" + escape(account_code);
	  strUrl += "&license_code=" + escape(license_code);
	  strUrl += "&machine_id=" + escape(machine_id);
	  strUrl += "&options=" + escape(options);
	  strUrl += "&callback=pcaFastAddressEnd";

	  //Make the request
	  if (scriptTag)
		 {
			headTag.removeChild(scriptTag);
		 }
	  scriptTag = document.createElement("script");
	  scriptTag.src = strUrl
	  scriptTag.type = "text/javascript";
	  scriptTag.id = "pcaScript";
	  headTag.appendChild(scriptTag);

}

function pcaFastAddressEnd() {

	  //Test for an error
	  if (pcaIsError)
		 {
			//Show the error message
			alert(pcaErrorMessage);
		 }
	  else
		 {
			//Check if there were any items found
			if (pcaRecordCount==0)
			   {
				  alert("Sorry, no matching items found.  Make sure you enter only the house number in the first address box and the full postcode.");
			   }
			else
			   {
				  document.getElementById("expanded_address").style.display	= 'block';
				  document.getElementById("strLeadAddress").value		= pca_line1[0];
				  document.getElementById("strLeadAddress2").value		= pca_line2[0];
				  document.getElementById("strLeadTownCity").value		= pca_post_town[0];
				  document.getElementById("strLeadPostcode").value		= pca_postcode[0];
			   }
		 }
		 document.getElementById("expanded_address").style.display	= 'block';

}

function ResetAddress() {

  document.getElementById("expanded_address").style.display	= 'none';
  document.getElementById("strLeadAddress").value		= '';
  document.getElementById("strLeadAddress2").value		= '';
  document.getElementById("strLeadTownCity").value		= '';
  document.getElementById("strLeadPostcode").value		= '';

}

function SetAddress() {

	if (document.getElementById("strLeadAddress").value != '' || document.getElementById("strLeadAddress2").value != '' || document.getElementById("strLeadTownCity").value != '') {

		document.getElementById("expanded_address").style.display = 'block';

	}

}
		
function fncValidateForm (f) {

	fncDisableSend();

	var i;

	var form_validation = new Array();

	form_validation['strLeadFirstName'] = new Array('First Name', 1);
	form_validation['strLeadLastName'] = new Array('Last Name', 1);
	form_validation['strLeadAddress'] = new Array('Address (Line 1)', 1);
	form_validation['strLeadTownCity'] = new Array('Address (Town/City)', 1);
	form_validation['strLeadPostcode'] = new Array('Postcode', 1, 'postcode');
	form_validation['strLeadPhone1'] = new Array('Telephone Number', 1, 'telephone');
	form_validation['strLeadData1'] = new Array('Preferred Contact Time', 1);
	form_validation['strLeadDOBDay'] = new Array('Birth Day', 1);
	form_validation['strLeadDOBMonth'] = new Array('Birth Month', 1);
	form_validation['strLeadDOBYear'] = new Array('Birth Year', 1);
	form_validation['strLeadData3'] = new Array('Amount of fund being used to provide annuity', 1, 'currency');
	form_validation['strLeadData23'] = new Array('Accept Terms & Conditions', 1);

	var form_valid = F.Validate(f, form_validation);

	if (!form_valid) {

		fncEnableSend();

		return false;

	} else {
	
		var i=0;
		do 
		{

		i=i+1;
		}
		while (i<100);
	
	}

}

function fncDisableSend() {

	document.getElementById('send').value 		= 'Please Wait..';

}

function fncEnableSend() {

	document.getElementById('send').value 		= 'Send Form >';

}

var min=9;
var max=16;

function increaseFontSize() {
   var p = document.getElementsByTagName('label');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}

function decreaseFontSize() {
   var p = document.getElementsByTagName('label');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}
