﻿        
        
        var account_code='NEVIS11112';
		var license_code='NH13-FM36-YB75-AA29';
		var machine_id='';

		
		
		function pcaByPostcodeBegin(postcode) {
		       var postcode = postcode; //$("#Postcode").val(); 
		       var scriptTag = $("#pcaScriptTag");
		       var headTag = $("#head"); 
		      var strUrl = "";
		      $("#divLoading").show();

		      //Build the url
		      var jsHost = (("https:" == document.location.protocol) ? "https://" : "http://");

		      strUrl = jsHost + "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
		             $("#scriptTag").remove(); 
		         }
		      scriptTag = document.createElement("script");
		      scriptTag.src = strUrl
		      scriptTag.type = "text/javascript";
		      scriptTag.id = "pcaScriptTag";
		      $('head', document).append(scriptTag);
		      
		   }

		function pcaByPostcodeEnd()
		   {
		       $("#divLoading").hide(); 

		      //Test for an error
		      if (pcaIsError)
		         {
		            //Show the error message
		             $("#selectaddress").hide();
		         }
		      else
		         {
		            //Check if there were any items found
		            if (pcaRecordCount==0)
		               {
		                   $("#selectaddress").hide();
		                  alert("Sorry, no matching items found. Please try another postcode.");
		               }
		            else
		               {
		                   $("#selectaddress").show();
		                   $('#selectaddress').empty()
		                   $('#selectaddress').append($('<option />').val('').text('Select Address'));
						  for (i=0; i<pca_id.length; i++){
						      $('#selectaddress').append($('<option />').val(pca_id[i]).text(pca_description[i]));
		                  }
		               }
		         }
		   }
		
		function pcaFetchBegin()
		   {
		       var address_id = $("#selectaddress").val();
		       var scriptTag = $("#pcaScriptTag"); 
		       var headTag = $("#head"); 
		      var strUrl = "";

		      //Build the url -1st one is secure
		      var jsHost = (("https:" == document.location.protocol) ? "https://" : "http://");
		      
		      strUrl = jsHost + "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
		             $("#scriptTag").remove();
		         }
		           
		      scriptTag = document.createElement("script");
		      scriptTag.src = strUrl
		      scriptTag.type = "text/javascript";
		      scriptTag.id = "pcaScriptTag";
		      $('head', document).append(scriptTag);
		      $("#selectaddress").hide();
		   }

		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
		               {
		                   $("#Company").val('' + pca_organisation_name[0]);
		                   $("#AddressLine1").val('' + pca_line1[0]);
		                   $("#AddressLine2").val('' + pca_line2[0]);
		                   $("#AddressLine3").val('' + pca_line3[0]);
//						  document.forms[0]["line4"].value = '' + pca_line4[0];
//						  document.forms[0]["line5"].value = '' + pca_line5[0];
		                   $("#TownCity").val('' + pca_post_town[0]);
		                   $("#County").val('' + pca_county[0]);
		                   $("#Postcode").val('' + pca_postcode[0]);

		                   $("#EngineersProfile_Company").val('' + pca_organisation_name[0]);
		                   $("#EngineersProfile_AddressLine1").val('' + pca_line1[0]);
		                   $("#EngineersProfile_AddressLine2").val('' + pca_line2[0]);
		                   $("#EngineersProfile_AddressLine3").val('' + pca_line3[0]);
//						  document.forms[0]["line4"].value = '' + pca_line4[0];
//						  document.forms[0]["line5"].value = '' + pca_line5[0];
		                   $("#EngineersProfile_TownCity").val('' + pca_post_town[0]);
		                   $("#EngineersProfile_County").val('' + pca_county[0]);
		                   $("#EngineersProfile_Postcode").val('' + pca_postcode[0]);
		               }
		         }
		   }
