		//!!!Change these 2 values 
		var account_code='INDIV55378';
		var license_code='CE99-XH65-YF78-BC16';
		var machine_id='';
		
		function pcaByPostcodeBegin()
		   {
			  var postcode = document.getElementById("postcode").value;
		      var scriptTag = document.getElementById("pcaScriptTag");
		      var headTag = document.getElementsByTagName("head").item(0);
		      var strUrl = "";
		      document.getElementById('fo_addressAlert').style.display="none";
		      //document.getElementById("divLoading").style.display = '';
		      
		      //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 += "&style=raw";
		      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);
		      
		      
		      
		   }

		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('addressSelect').style.display="none";
		            document.getElementById('fo_addressAlert').style.display="";
		            document.getElementById('fo_addressAlert').innerHTML =pcaErrorMessage; 
		            //alert(pcaErrorMessage);
		         }
		      else
		         {
		            //Check if there were any items found
		            if (pcaRecordCount==0)
		               {
		                  document.getElementById("selectaddress").style.display = 'none';
		                 
						  //document.getElementById("btnFetch").style.display = 'none';
						// document.getElementById('addressSelect').style.display="none";
		                  document.getElementById('fo_addressAlert').style.display="";
		                  document.getElementById('addressBlock').style.display='';
		                  document.getElementById('fo_addressAlert').innerHTML ="Sorry, no matching items found. Please try another postcode.<br/> Or fill in the boxes below"; 
		                  //alert("Sorry, no matching items found. Please try another postcode.");
		               }
		            else
		               {
		            	document.getElementById("addressSelect").style.display = '';
		            	document.getElementById("selectAddressBox").style.display = ''; 
		            	document.getElementById("selectaddress").style.display = '';
		            	
		            	
		            	document.getElementById('fo_addressAlert').style.display="none";
						 // document.getElementById('addressSelect').style.display="";
						  //document.forms[0]["btnFetch"].style.display = '';
						  
						  for (i=document.getElementById("selectaddress").options.length-1; i>=0; i--){
							  document.getElementById("selectaddress").options[i] = null;
							}
						  document.getElementById("selectaddress").options[document.getElementById("selectaddress").length] = new Option("Select Address");
						  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 += "&style=raw";
		      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('addressSelect').style.display="none";
		      document.getElementById('addressDiv').style.display='';
		    
		     
		   }

		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
		               {

		            	firstLine=pca_line1[0];
		            	firstLineSplit=firstLine.split(' ');
		            	number=firstLineSplit[0];
		            	address=firstLine.substring(number.length+1);
		            	if (pca_line2[0]!=''){
		            		document.getElementById('house_name').value= '' + pca_building_name_or_number[0];
		            		document.getElementById('address').value=''+pca_thoroughfare_name[0]+' '+pca_thoroughfare_descriptor[0]+', '+pca_line2[0];
							}
						  else{
							  document.getElementById('house_name').value='' + pca_building_name_or_number[0];
				            	document.getElementById('address').value='' +pca_thoroughfare_name[0]+' '+pca_thoroughfare_descriptor[0] ;
							}
		            	
		            	
		            	document.getElementById('town').value='' + pca_post_town[0];
		            	document.getElementById('county').value='' + pca_county[0];

		            	document.getElementById('addressDiv').style.display='block';
		            	document.getElementById("addressSelect").style.display = 'none';
		            	/*
						  document.forms[0]["company"].value = '' + pca_organisation_name[0];
						  document.forms[0]["line1"].value = '' + pca_line1[0];
						  document.forms[0]["line2"].value = '' + pca_line2[0];
						  document.forms[0]["line3"].value = '' + pca_line3[0];
						  document.forms[0]["line4"].value = '' + pca_line4[0];
						  document.forms[0]["line5"].value = '' + pca_line5[0];
						  document.forms[0]["town"].value = '' + pca_post_town[0];
						  document.forms[0]["county"].value = '' + pca_county[0];
						  document.forms[0]["postcode"].value = '' + pca_postcode[0];
						  */
		               }
		         }
		   }