if("undefined"===typeof(console)){console={log:function(){$.each(arguments,function(b,a){alert("argument "+b+": "+a)})}}}(function(c){var a={UP:38,DOWN:40,DEL:46,TAB:9,RETURN:13,ESC:27,COMMA:188,PAGEUP:33,PAGEDOWN:34,BACKSPACE:8};var b=function(){};var d=function(e,n){var m={scroll:true,scrollHeight:220,width:254,resultsClass:"ac_results",autoFill:false,highlight:function(x){return x},formatItem:function(A,y,z,x){return A[0]},addressesUrl:"",addressUrl:"",errornode:false,submitnode:false,fieldMap:false,errors:{noneFound:"No addresses found.",empty:"Please enter a postcode",invalid:"Please enter a valid postcode",ajax:"There was an error contacting the postcode lookup software"},postcodeFormat:/[A-Z]{1,2}[0-9]{1,2}[A-Z]?\s*[0-9][ABDEFGHJLNPQRSTUWXYZ]{1,2}/i,addressKey:"address",addressesKey:"addresses",idKey:"id",descriptionKey:"description",onAddresses:b,onAddress:b,onSearch:b,onAddressFail:b,onAddressesFail:b,onLoading:b,onLoaded:b,onPopulate:b,afterPopulate:b,error:b,errorFadeTime:2000};var h={},w="",o=false,g={},f={},i=false,v={mouseDownOnSelect:false};var k,l,q,u,p,r,t,j,s;s=function(y,x){h=c.extend({},m,x);e=c(e).attr("autocomplete","off").bind((c.browser.opera?"keypress":"keydown")+".autocomplete",function(z){switch(z.keyCode){case a.UP:if(o.visible()){o.prev();z.preventDefault()}break;case a.DOWN:if(o.visible()){o.next();z.preventDefault()}else{if(g[c(e).val().toLowerCase().replace(/\s/g,"")]){k()}}break;case a.PAGEUP:if(o.visible()){o.pageUp();z.preventDefault()}break;case a.PAGEDOWN:if(o.visible()){o.pageDown();z.preventDefault()}break;case a.RETURN:if(o.visible()){q()}else{k()}z.preventDefault();break;case a.TAB:if(o.visible()){q();z.preventDefault()}break;case a.ESC:o.hide();break;default:u();break}}).blur(function(){clearTimeout(i);if(!v.mouseDownOnSelect){i=setTimeout(o.hide,100)}else{var z=this;i=setTimeout(function(){z.focus()},25)}}).focus(function(){clearTimeout(i)});if(b!==h.error){r=h.error}if(!h.errornode){h.errornode=c("<label class='error' for='"+e.attr("id")+"'></label>");c(h.errornode).insertAfter(e)}if(!h.submitnode){h.submitnode=c("<div id='find_address'><input type='button' value='Find Address' /></div>");c(h.submitnode).insertAfter(e).css("margin-left","5px")}h.submitnode.bind("click",function(){e.focus();k()});o=c.Autocompleter.Select(h,e[0],q,v)};k=function(){u();var x=e.val().toLowerCase().replace(/\s/g,"");if(x&&x!==""){if(typeof(h.postcodeFormat.test)!="function"||h.postcodeFormat.test(x)){w=x;if(g[w]){p(g[w])}else{h.onSearch();h.onLoading();c.ajax({url:h.addressesUrl+w,dataType:"json",success:p,error:function(){h.onAddressesFail(arguments);h.onLoaded();r(h.errors.ajax,e,h.errornode)}})}}else{r(h.errors.invalid,e,h.errornode)}}else{r(h.errors.empty,e,h.errornode)}};l=function(x){if(f[x]){t(f[x])}else{h.onLoading();c.ajax({url:h.addressUrl+x,dataType:"json",success:t,error:function(){h.onAddressFail(arguments);h.onLoaded();r(h.errors.ajax,e,h.errornode)}})}};p=function(x){h.onLoaded();h.onAddresses();if(x.error_number){r(x.message,e,h.errornode)}else{if(!x||!x[h.addressesKey].length){r(h.errors.noneFound,e,h.errornode)}else{var y=[];var z=x[h.addressesKey];c.each(z,function(B,A){y.push({data:[A[h.descriptionKey],A[h.idKey]]})});o.display(y,w);o.show();g[w]=x}}};t=function(x){h.onAddress();h.onLoaded();j(x[h.addressKey][0]);if(x[h.addressKey][0][h.idKey]){f[x[h.addressKey][0][h.idKey]]=x}};q=function(){var x=o.selected();if(x&&x.data){l(x.data[1]);o.hide()}};j=function(x){h.onPopulate(x);if(typeof(h.fieldMap)=="function"){h.fieldMap(x)}else{jQuery.each(x,function(y,A){if(h.fieldMap){if(typeof(h.fieldMap)=="object"&&typeof(h.fieldMap[y])!==undefined){if(typeof(h.fieldMap[y])=="function"){y=h.fieldMap[y](y,A,x)}else{y=h.fieldMap[y]||y}}}var z=c("[name="+y+"]");if(z.length&&(z.attr("tagName")=="INPUT"||z.attr("tagName")=="SELECT"||z.attr("tagName")=="TEXTAREA")){z.val(A)}})}h.afterPopulate()};u=function(){o.hide();o.emptyList()};r=function(y,z,x){h.errornode.stop(true).text(y).show().fadeTo(50,1,function(){h.errornode.fadeOut(h.errorFadeTime)})};c(document).ready(function(){s(e,n)});return{hide:o.hide,clear:u,error:r}};c.fn.extend({jPostcode:function(e){d(this,e);return this}});if(typeof(c.Autocompleter)==="undefined"){c.Autocompleter={}}c.Autocompleter.Select=function(h,m,o,s){var l={ACTIVE:"ac_over"};var n,i=-1,u,p="",v=true,f,r;function q(){if(!v){return}f=c("<div/>").hide().addClass(h.resultsClass).css("position","absolute").appendTo(document.body);r=c("<ul/>").appendTo(f).mouseover(function(w){if(t(w).nodeName&&t(w).nodeName.toUpperCase()=="LI"){i=c("li",r).removeClass(l.ACTIVE).index(t(w));c(t(w)).addClass(l.ACTIVE)}}).click(function(w){w.preventDefault();c(t(w)).addClass(l.ACTIVE);o();m.focus();return false}).mousedown(function(){s.mouseDownOnSelect=true}).mouseup(function(){s.mouseDownOnSelect=false});if(h.width>0){f.css("width",h.width)}v=false}function t(x){var w=x.target;while(w&&w.tagName!="LI"){w=w.parentNode}if(!w){return[]}return w}function k(w){n.slice(i,i+1).removeClass(l.ACTIVE);j(w);var y=n.slice(i,i+1).addClass(l.ACTIVE);if(h.scroll){var x=0;n.slice(0,i).each(function(){x+=this.offsetHeight});if((x+y[0].offsetHeight-r.scrollTop())>r[0].clientHeight){r.scrollTop(x+y[0].offsetHeight-r.innerHeight())}else{if(x<r.scrollTop()){r.scrollTop(x)}}}}function j(w){i+=w;if(i<0){i=n.size()-1}else{if(i>=n.size()){i=0}}}function e(w){return h.max&&h.max<w?h.max:w}function g(){r.empty();var x=e(u.length);for(var y=0;y<x;y++){if(!u[y]){continue}var z=h.formatItem(u[y].data,y+1,x,u[y].value,p);if(z===false){continue}var w=c("<li/>").html(h.highlight(z,p)).addClass(y%2==0?"ac_even":"ac_odd").appendTo(r)[0];c.data(w,"ac_data",u[y])}n=r.find("li");if(h.selectFirst){n.slice(0,1).addClass(l.ACTIVE);i=0}if(c.fn.bgiframe){r.bgiframe()}}return{display:function(x,w){q();u=x;p=w;g()},next:function(){k(1)},prev:function(){k(-1)},pageUp:function(){if(i!=0&&i-8<0){k(-i)}else{k(-8)}},pageDown:function(){if(i!=n.size()-1&&i+8>n.size()){k(n.size()-1-i)}else{k(8)}},hide:function(){f&&f.hide();n&&n.removeClass(l.ACTIVE);i=-1},visible:function(){return f&&f.is(":visible")},current:function(){return this.visible()&&(n.filter("."+l.ACTIVE)[0]||h.selectFirst&&n[0])},show:function(){var y=c(m).offset();f.css({width:typeof h.width=="string"||h.width>0?h.width:c(m).width(),top:y.top+m.offsetHeight,left:y.left}).show();if(h.scroll){r.scrollTop(0);r.css({maxHeight:h.scrollHeight,overflow:"auto"});if(c.browser.msie&&typeof document.body.style.maxHeight==="undefined"){var w=0;n.each(function(){w+=this.offsetHeight});var x=w>h.scrollHeight;r.css("height",x?h.scrollHeight:w);if(!x){n.width(r.width()-parseInt(n.css("padding-left"))-parseInt(n.css("padding-right")))}}}},selected:function(){var w=n&&n.filter("."+l.ACTIVE).removeClass(l.ACTIVE);return w&&w.length&&c.data(w[0],"ac_data")},emptyList:function(){r&&r.empty()},unbind:function(){f&&f.remove()}}}})(jQuery);