			
var account_code='THEFA11112';
var license_code='ZT78-WX41-KJ45-RX21';
var machine_id='';
				
function pcaByPostcodeBegin()
   {
	 
	 try
	 
	 {
	  var postcode = document.getElementById("Postcode").value;
      var scriptTag = document.getElementById("pcaScriptTag");
      var headTag = document.getElementsByTagName("head").item(0);
      var strUrl = "";
				      
      document.getElementById("divLoading").style.display = '';
	  setVisible('layer1');	      
      //Build the url
      strUrl = "https://services.postcodeanywhere.co.uk/inline.aspx?";
      strUrl += "&action=lookup";
      strUrl += "&type=by_postcode";
      strUrl += "&postcode=" + escape(postcode);
      strUrl += "&account_code=" + escape(account_code);
      strUrl += "&license_code=" + escape(license_code);
      strUrl += "&machine_id=" + escape(machine_id);
      strUrl += "&callback=pcaByPostcodeEnd";
			      
      //Make the request
      if (scriptTag)
         {
            //The following 2 lines perform the same function and should be interchangeable
            headTag.removeChild(scriptTag);
            //scriptTag.parentNode.removeChild(scriptTag);
         }
      scriptTag = document.createElement("script");
      scriptTag.src = strUrl
      scriptTag.type = "text/javascript";
      scriptTag.id = "pcaScriptTag";
      headTag.appendChild(scriptTag);		      
      }
      catch(ex)
      {
		alert(ex);
      }		      			      
   }

function pcaByPostcodeEnd()
   {
	  document.getElementById("divLoading").style.display = 'none';
					  
      //Test for an error
      if (pcaIsError)
         {
            //Show the error message
            document.getElementById("selectaddress").style.display = 'none';
            document.getElementById("btnFetch").style.display = 'none';
            document.getElementById("lblSelectAddress").style.display = 'none';
			setVisible('layer1');
            alert(pcaErrorMessage);
         }
      else
         {
            //Check if there were any items found
            if (pcaRecordCount==0)
               {
                  document.getElementById("selectaddress").style.display = 'none';
                  document.getElementById("lblSelectAddress").style.display = 'none';
				  document.getElementById("btnFetch").style.display = 'none';
                  alert("Sorry, no matching items found. Please try another postcode.");
                  setVisible('layer1');
                  
               }
            else
               {
				  document.getElementById("selectaddress").style.display = '';
				  document.getElementById("btnFetch") .style.display = '';
				  document.getElementById("lblSelectAddress").style.display = '';				  
				  for (i=document.getElementById("selectaddress").options.length-1; i>=0; i--){
					  document.getElementById("selectaddress").options[i] = null;
					}
				  for (i=0; i<pca_id.length; i++){
                    document.getElementById("selectaddress").options[document.getElementById("selectaddress").length] = new Option(pca_description[i], pca_id[i]);
                  }    
               }
         }
   }
				
function pcaFetchBegin()
   {
	  var address_id = document.getElementById("selectaddress").value;
      var scriptTag = document.getElementById("pcaScriptTag");
      var headTag = document.getElementsByTagName("head").item(0);
      var strUrl = "";
	
      //Build the url
      strUrl = "https://services.postcodeanywhere.co.uk/inline.aspx?";
      strUrl += "&action=fetch";
      strUrl += "&id=" + escape(address_id);
      strUrl += "&account_code=" + escape(account_code);
      strUrl += "&license_code=" + escape(license_code);
      strUrl += "&machine_id=" + escape(machine_id);
      strUrl += "&callback=pcaFetchEnd";

      //Make the request
      if (scriptTag)
         {
            //The following 2 lines perform the same function and should be interchangeable
            headTag.removeChild(scriptTag);
            //scriptTag.parentNode.removeChild(scriptTag);
         }
      scriptTag = document.createElement("script");
      scriptTag.src = strUrl
      scriptTag.type = "text/javascript";
      scriptTag.id = "pcaScriptTag";
      headTag.appendChild(scriptTag);
				      
      document.getElementById("selectaddress").style.display = 'none';
      document.getElementById("btnFetch") .style.display = 'none';
      document.getElementById("lblSelectAddress").style.display = 'none';
      setVisible('layer1');
   }

function pcaFetchEnd()
   {
      //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");                
               }
            else
               {
				  
				  document.getElementById("Address1").value = '' + pca_line1[0];
				  document.getElementById("Address2").value = '' + pca_line2[0];
				  document.getElementById("Address3").value = '' + pca_line3[0];
//				  document.getElementById("selectaddress").value = '' + pca_line4[0];
//				  document.getElementById("selectaddress").value = '' + pca_line5[0];
				  document.getElementById("Town").value = '' + pca_post_town[0];
				  document.getElementById("County").value = '' + pca_county[0];
				  document.getElementById("Postcode").value = '' + pca_postcode[0];			
               }
         }         
   }		
		 
		 
function pcaByPostcodeBeginEx()
   {
	 
	 try
	 
	 {
	  var postcode = document.getElementById("DelPostcode").value;
      var scriptTag = document.getElementById("pcaScriptTag");
      var headTag = document.getElementsByTagName("head").item(0);
      var strUrl = "";
				      
      document.getElementById("divLoadingEx").style.display = '';
	  setVisible('layer2');
	  		      
      //Build the url
      strUrl = "https://services.postcodeanywhere.co.uk/inline.aspx?";
      strUrl += "&action=lookup";
      strUrl += "&type=by_postcode";
      strUrl += "&postcode=" + escape(postcode);
      strUrl += "&account_code=" + escape(account_code);
      strUrl += "&license_code=" + escape(license_code);
      strUrl += "&machine_id=" + escape(machine_id);
      strUrl += "&callback=pcaByPostcodeEndEx";
			      
      //Make the request
      if (scriptTag)
         {
            //The following 2 lines perform the same function and should be interchangeable
            headTag.removeChild(scriptTag);
            //scriptTag.parentNode.removeChild(scriptTag);
         }
      scriptTag = document.createElement("script");
      scriptTag.src = strUrl
      scriptTag.type = "text/javascript";
      scriptTag.id = "pcaScriptTag";
      headTag.appendChild(scriptTag);		      
      }
      catch(ex)
      {
		alert(ex);
      }		      			      
   }
   
   function pcaByPostcodeEndEx()
   {
	  document.getElementById("divLoadingEx").style.display = 'none';
					  
      //Test for an error
      if (pcaIsError)
         {
            //Show the error message
            document.getElementById("selectaddressEx").style.display = 'none';
            document.getElementById("btnFetchEx").style.display = 'none';
            document.getElementById("lblSelectAddressEx").style.display = 'none';
			setVisible('layer2');
            alert(pcaErrorMessage);
         }
      else
         {
            //Check if there were any items found
            if (pcaRecordCount==0)
               {
                  document.getElementById("selectaddressEx").style.display = 'none';
                  document.getElementById("lblSelectAddressEx").style.display = 'none';
				  document.getElementById("btnFetchEx").style.display = 'none';
				  setVisible('layer2');
                  alert("Sorry, no matching items found. Please try another postcode.");
               }
            else
               {
				  document.getElementById("selectaddressEx").style.display = '';
				  document.getElementById("btnFetchEx") .style.display = '';
				  document.getElementById("lblSelectAddressEx").style.display = '';				  
				  for (i=document.getElementById("selectaddressEx").options.length-1; i>=0; i--){
					  document.getElementById("selectaddressEx").options[i] = null;
					}
				  for (i=0; i<pca_id.length; i++){
                    document.getElementById("selectaddressEx").options[document.getElementById("selectaddressEx").length] = new Option(pca_description[i], pca_id[i]);
                  }
               }
         }
   }
function pcaFetchBeginEx()
   {
	  var address_id = document.getElementById("selectaddressEx").value;
      var scriptTag = document.getElementById("pcaScriptTag");
      var headTag = document.getElementsByTagName("head").item(0);
      var strUrl = "";
	
      //Build the url
      strUrl = "https://services.postcodeanywhere.co.uk/inline.aspx?";
      strUrl += "&action=fetch";
      strUrl += "&id=" + escape(address_id);
      strUrl += "&account_code=" + escape(account_code);
      strUrl += "&license_code=" + escape(license_code);
      strUrl += "&machine_id=" + escape(machine_id);
      strUrl += "&callback=pcaFetchEndEx";

      //Make the request
      if (scriptTag)
         {
            //The following 2 lines perform the same function and should be interchangeable
            headTag.removeChild(scriptTag);
            //scriptTag.parentNode.removeChild(scriptTag);
         }
      scriptTag = document.createElement("script");
      scriptTag.src = strUrl
      scriptTag.type = "text/javascript";
      scriptTag.id = "pcaScriptTag";
      headTag.appendChild(scriptTag);
				      
      document.getElementById("selectaddressEx").style.display = 'none';
      document.getElementById("btnFetchEx") .style.display = 'none';
      document.getElementById("lblSelectAddressEx").style.display = 'none';
      setVisible('layer2');
   }

function pcaFetchEndEx()
   {
      //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");
               }
            else
               {
				  
				  document.getElementById("DelAddress1").value = '' + pca_line1[0];
				  document.getElementById("DelAddress2").value = '' + pca_line2[0];
				  document.getElementById("DelAddress3").value = '' + pca_line3[0];
				  document.getElementById("DelTown").value = '' + pca_post_town[0];
				  document.getElementById("DelCounty").value = '' + pca_county[0];
				  document.getElementById("DelPostcode").value = '' + pca_postcode[0];
               }
         }
   }		
   
   
/* -----------------------------------------------
   Floating layer - v.1
   (c) 2006 www.haan.net
   contact: jeroen@haan.net
   You may use this script but please leave the credits on top intact.
   Please inform us of any improvements made.
   When usefull we will add your credits.
  ------------------------------------------------ */

x = 70;
y = 40;
function setVisible(obj)
{	
	try
	{
		obj = document.getElementById(obj);
		obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
	}
	catch(ex)
	{
	}
}
function placeIt(obj)
{
	try
	{
		obj = document.getElementById(obj);
		if (document.documentElement)
		{
			theLeft = document.documentElement.scrollLeft;
			theTop = document.documentElement.scrollTop;
		}
		else if (document.body)
		{
			theLeft = document.body.scrollLeft;
			theTop = document.body.scrollTop;
		}
		theLeft += x;
		theTop += y;
		obj.style.left = theLeft + 'px' ;
		obj.style.top = theTop + 'px' ;
	
		setTimeout("placeIt('layer1')",500);
		setTimeout("placeIt('layer2')",500);
	}
	catch(ex)
	{
	}
}
function RefreshImage(valImageId) {	
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}
