function PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10Begin(Key, Postcode, Building, UserName, Target){

var callback = 'PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10End';

if(Target==2) callback = 'PostcodeAnywhere_Interactive_RetrieveByPostcode2';

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

      //Build the url
      strUrl = "https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/RetrieveByPostcodeAndBuilding/v1.10/json.ws?";
      strUrl += "&Key=" + escape(Key);
      strUrl += "&Postcode=" + escape(Postcode);
      strUrl += "&Building=" + escape(Building);
      strUrl += "&UserName=" + escape(UserName);
      strUrl += "&CallbackFunction="+callback;

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

function PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10End(response){
      //Test for an error
      if (response.length==1 && typeof(response[0].Error) != 'undefined'){
            //Show the error message
            alert(response[0].Description);
         } else{
            //Check if there were any items found
            if (response.length==0){
                  alert("Sorry, no matching items found");
               }else{
			   
			 
			   
                  //PUT YOUR CODE HERE
                  //FYI: The output is an array of key value pairs (e.g. response[0].Udprn), the keys being:
                  //Udprn
                  //Company
                  //Department
                  //Line1
                  //Line2
                  //Line3
                  //Line4
                  //Line5
                  //PostTown
                  //County
                  //Postcode
                  //Mailsort
                  //Barcode
                  //Type
                  //DeliveryPointSuffix
                  //SubBuilding
                  //BuildingName
                  //BuildingNumber
                  //PrimaryStreet
                  //SecondaryStreet
                  //DoubleDependentLocality
                  //DependentLocality
                  //PoBox
                  //CountryName
				  
			
				 document.getElementById('address_options').options[0] = new Option("Select your address",null);
				 for(i=0;i<response.length;i++){ 
				 
			  
				 var label="";
				 if(response[i].Company !="") label+= response[i].Company+", ";
				 if(response[i].Line1 !="") label+= response[i].Line1+", " ;
				 if(response[i].Line2 !="") label+= response[i].Line2+", " ;
				 if(response[i].Line3 !="") label+= response[i].Line3+", " ;
				 if(response[i].PostTown !="") label+= response[i].PostTown;
				 document.getElementById('address_options').options[i+1] = new Option(label,i);  
				 } 
				 
				 document.getElementById('address_options').onchange = function(){
				 
				 var index = document.getElementById('address_options').selectedIndex -1;
				 
				 document.getElementById("address_company").value= response[index].Company;
				document.getElementById("address_address1").value= response[index].Line1;
				document.getElementById("address_address2").value= response[index].Line2;
				document.getElementById("address_address3").value= response[index].Line3;
				document.getElementById("address_towncity").value= response[index].PostTown;
				document.getElementById("address_county").value= response[index].County;
				document.getElementById("address_postcode").value= response[index].Postcode;
				 }
				 
				



               }
       
   }
   }
   
   
   
   
   
   function PostcodeAnywhere_Interactive_RetrieveByPostcode2(response){
      //Test for an error
      if (response.length==1 && typeof(response[0].Error) != 'undefined'){
            //Show the error message
            alert(response[0].Description);
         } else{
            //Check if there were any items found
            if (response.length==0){
                  alert("Sorry, no matching items found");
               }else{
			   
			 
				  
			
				 document.getElementById('address_options_del').options[0] = new Option("Select your address",null);
				 for(i=0;i<response.length;i++){ 
				 
			  
				 var label="";
				 if(response[i].Company !="") label+= response[i].Company;
				 if(response[i].Line1 !="") label+= response[i].Line1+", " ;
				 if(response[i].Line2 !="") label+= response[i].Line2+", " ;
				 if(response[i].Line3 !="") label+= response[i].Line3+", " ;
				 if(response[i].PostTown !="") label+= response[i].PostTown;
				 document.getElementById('address_options_del').options[i+1] = new Option(label,i);  
				 } 
				 
				 document.getElementById('address_options_del').onchange = function(){
				 
				 var index = document.getElementById('address_options_del').selectedIndex -1;
				 
				 document.getElementById("address_company_del").value= response[index].Company;
				document.getElementById("address_address1_del").value= response[index].Line1;
				document.getElementById("address_address2_del").value= response[index].Line2;
				document.getElementById("address_address3_del").value= response[index].Line3;
				document.getElementById("address_towncity_del").value= response[index].PostTown;
				document.getElementById("address_county_del").value= response[index].County;
				document.getElementById("address_postcode_del").value= response[index].Postcode;
				 }
				}
       
   }
   }
