!function($,e,o,t){"use strict";$(e),$(o),$(o.body);var r={};$.llpgLookup=function(){return this},$.llpgLookup.prototype.name="llpgLookup",$.llpgLookup={init:function(e){r=$.extend({},$.llpgLookup.defaultOptions,e),$("#"+r.rowId).hide(),$("#"+r.errorMessageContainerId).hide(),$(o).on("keypress","#"+r.postcodeId,(function(e){if(13===e.keyCode)return $("#"+r.buttonId).click(),!1})),$("#"+r.selectAddressButtonId).on("click",(function(e){e.preventDefault(),$("#"+r.fieldIdentifier).val().length>0&&$("#"+r.formId).submit()})),$("#"+r.changeAddressButtonId).on("click",(function(e){e.preventDefault();var t=r.resetLocationUrl;if(!1!=!(void 0!==(n=t)&&n&&0!==n.length&&/[^\s]/.test(n)&&!/^\s*$/.test(n)&&""!==n.replace(/\s/g,""))){var n,s=$("#"+r.rowId),a=$("#"+r.errorMessageContainerId),d=$("#"+r.addressContainerId);$("#"+r.postcodeId).val(""),s.hide(),a.hide(),d.show()}else o.location.href=t})),$("#"+r.buttonId).click((function(e){e.preventDefault();var o=$("#"+r.rowId),t=$("#"+r.buttonId),n=$("#"+r.postcodeId),s=$("#"+r.errorMessageContainerId),a=$("#"+r.errorMessageId);$(o).hide(),$(t).prop("disabled",!0),$(n).removeClass("ErrorFormField"),$(s).hide(),$(n).val($.llpgLookup.reformatPostcode($(n).val())),$.ajax({contentType:"application/json; charset=utf-8",url:"/llpg/lookup",data:{postcode:$(n).val(),classification:r.classification},dataType:"jsonp"}).done((function(e){if(null==e||0===e.length)return $(n).addClass("ErrorFormField"),$(a).text(r.noResultsMessage),void $(s).show();var t=$("#"+r.fieldIdentifier).find("option").remove().end().append('<option value=""> - SELECT YOUR ADDRESS - </option>');$.each(e,(function(e,o){t.append('<option value="'+o.Uprn+'">'+o.AddressLine1+"</option>")})),$(o).show()})).fail((function(e,o,t){$(n).addClass("ErrorFormField");var d=null==t||0===t.length?r.defaultErrorMessage:t;$(a).text(d),$(s).show()})).always((function(){$(t).prop("disabled",!1)}))}))}},$.llpgLookup.reformatPostcode=function(e){var o=e.toUpperCase(),t=o;return(o=o.replace(/\s/g,"")).length>=5&&o.length<=7&&(t=o.substring(0,o.length-3)+" "+o.substring(o.length-3)),t},$.llpgLookup.defaultOptions={formId:"",fieldIdentifier:"",rowId:"",buttonId:"",selectAddressButtonId:"",changeAddressButtonId:"",resetLocationUrl:"",addressContainerId:"",postcodeId:"",errorMessageContainerId:"",errorMessageId:"",classification:"",callbackUrl:"/llpg/lookup",noResultsMessage:"Sorry, that does not appear to be a Southwark postcode",defaultErrorMessage:"There was a problem looking up this postcode, please try again later"}}(jQuery,window,document);