var addressInfo;var key="YH96-JN79-EX38-PB75";$(document).ready(function(){$("#postcodeAnywhere").click(function(){if($('#postcode').val()!=''){$('#postcodeWrapper').remove();PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10Begin($('#postcode').val());}else{alert("Please, Enter a Postcode");}});});function PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10Begin(Postcode)
{var scriptTag=document.getElementById("PCA38d38252878f434581f85b249661cd94");var headTag=document.getElementsByTagName("head").item(0);var strUrl="";strUrl="http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/RetrieveByPostcodeAndBuilding/v1.10/json.ws?";strUrl+="&Key="+escape(key);strUrl+="&Postcode="+escape(Postcode);strUrl+="&CallbackFunction=PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10End";if(scriptTag)
{try
{headTag.removeChild(scriptTag);}
catch(e)
{}}
scriptTag=document.createElement("script");scriptTag.src=strUrl
scriptTag.type="text/javascript";scriptTag.id="PCA38d38252878f434581f85b249661cd94";headTag.appendChild(scriptTag);}
function PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10End(response)
{if(response.length==1&&typeof(response[0].Error)!='undefined')
{alert(response[0].Description);}
else
{if(response.length==0)
{alert("Sorry, no matching items found");}
else
{addressInfo=response;var wrapper=$('<div/>');wrapper.attr('id','postcodeWrapper');var labelTag=$('<label/>');labelTag.html('Select an address');$(".App_WebForm_button").after(labelTag);var divTag=$('<div/>');divTag.addClass('App_ObjectAdmin_selector');var selectTag=$('<select/>');selectTag.attr('id','addressBox');selectTag.change(function(){useAddress($(this).val());$(this).html('');wrapper.remove();});optionTag=$('<option/>');optionTag.attr('value','');optionTag.html(' -- Select Address -- ');selectTag.append(optionTag);for(var i=0;i<response.length;i++){optionTag=$('<option/>');optionTag.attr('value',response[i].Udprn);optionTag.html(response[i].Line1);selectTag.append(optionTag);}
divTag.append(selectTag);wrapper.append(labelTag);labelTag.after(divTag);$('.App_WebForm_button').after(wrapper);}}}
function useAddress(Udprn){for(var i=0;i<addressInfo.length;i++){if(addressInfo[i].Udprn==Udprn){$("input[name$='[postcode]']").val(addressInfo[i].Postcode);$("input[name$='[company]']").val(addressInfo[i].Company);$("input[name$='[address1]']").val(addressInfo[i].Line1);$("input[name$='[address2]']").val(addressInfo[i].Line2);$("input[name$='[address3]']").val(addressInfo[i].Line3);$("input[name$='[address4]']").val(addressInfo[i].Line4);$("input[name$='[address5]']").val(addressInfo[i].Line5);$("input[name$='[town]']").val(addressInfo[i].PostTown);$("input[name$='[county]']").val(addressInfo[i].County);$("input[name$='[country]']").val(addressInfo[i].CountryName);}}}