/** Neat Complete v1.4.0 (c) 2017 Abletech Ltd. https://github.com/AbleTech/neat-complete/blob/develop/LICENSE.md */ (function(){var t=[].slice,e=function(t,e){return function(){return t.apply(e,arguments)}},i=function(t,e){function i(){this.constructor=t}for(var n in e)s.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},s={}.hasOwnProperty;!function(t,e){"function"==typeof define&&define.amd?define(function(){return e(t)}):t.NeatComplete=e(t)}(this,function(s){var n;return n={},n.addDomEvent=function(t,e,i){var s;return t.addEventListener?t.addEventListener(e,i,!1):(s=function(){return i.apply(t,arguments)},t.attachEvent("on"+e,s))},n.removeDomEvent=function(t,e,i){t.removeEventListener?t.removeEventListener(e,i,!1):t.detachEvent&&t.detachEvent("on"+e,null)},Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e,i,s,n;if(null==this)throw new TypeError;if(n=Object(this),0===(i=n.length>>>0))return-1;if(s=0,arguments.length>0&&(s=Number(arguments[1]),s!==s?s=0:0!==s&&Infinity!==s&&-Infinity!==s&&(s=(s>0||-1)*Math.floor(Math.abs(s)))),s>=i)return-1;for(e=s>=0?s:Math.max(i-Math.abs(s),0);e=this.results.length&&(e=-1),null!=(s=this.results[e])&&s.highlight(),this.element.value=null!=this.highlighted?this.highlighted.value:this._val},s.prototype._getSuggestionsWithTimeout=function(){return null!=this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout(function(t){return function(){return t._getSuggestions()}}(this),this.options.timeout)},s.prototype._getSuggestions=function(){var t,e,i,s,n;if(this.enabled){if(!this._servicesReady())return void(this.searchQueued=!0);if(this._val=this.element.value,this.error_content=null,""!==this._val){for(i=this.services,s=[],t=0,e=i.length;t0)self._completeHandlers.shift()(e)}function success(resp){var type=o.type||resp&&setType(resp.getResponseHeader("Content-Type"));resp=type!=="jsonp"?self.request:resp;var filteredResponse=globalSetupOptions.dataFilter(resp.responseText,type),r=filteredResponse;try{resp.responseText=r}catch(e){}if(r)switch(type){case"json":try{resp=context.JSON?context.JSON.parse(r):eval("("+r+")")}catch(err){return error(resp,"Could not parse JSON in response",err)}break;case"js":resp=eval(r);break;case"html":resp=r;break;case"xml":resp=resp.responseXML&&resp.responseXML.parseError&&resp.responseXML.parseError.errorCode&&resp.responseXML.parseError.reason?null:resp.responseXML}self._responseArgs.resp=resp,self._fulfilled=!0,fn(resp),self._successHandler(resp);while(self._fulfillmentHandlers.length>0)resp=self._fulfillmentHandlers.shift()(resp);complete(resp)}function timedOut(){self._timedOut=!0,self.request.abort()}function error(e,t,n){e=self.request,self._responseArgs.resp=e,self._responseArgs.msg=t,self._responseArgs.t=n,self._erred=!0;while(self._errorHandlers.length>0)self._errorHandlers.shift()(e,t,n);complete(e)}this.url=typeof o=="string"?o:o.url,this.timeout=null,this._fulfilled=!1,this._successHandler=function(){},this._fulfillmentHandlers=[],this._errorHandlers=[],this._completeHandlers=[],this._erred=!1,this._responseArgs={};var self=this;fn=fn||function(){},o.timeout&&(this.timeout=setTimeout(function(){timedOut()},o.timeout)),o.success&&(this._successHandler=function(){o.success.apply(o,arguments)}),o.error&&this._errorHandlers.push(function(){o.error.apply(o,arguments)}),o.complete&&this._completeHandlers.push(function(){o.complete.apply(o,arguments)}),this.request=getRequest.call(this,success,error)}function reqwest(e,t){return new Reqwest(e,t)}function normalize(e){return e?e.replace(/\r?\n/g,"\r\n"):""}function serial(e,t){var n=e.name,r=e.tagName.toLowerCase(),i=function(e){e&&!e.disabled&&t(n,normalize(e.attributes.value&&e.attributes.value.specified?e.value:e.text))},s,o,u,a;if(e.disabled||!n)return;switch(r){case"input":/reset|button|image|file/i.test(e.type)||(s=/checkbox/i.test(e.type),o=/radio/i.test(e.type),u=e.value,(!s&&!o||e.checked)&&t(n,normalize(s&&u===""?"on":u)));break;case"textarea":t(n,normalize(e.value));break;case"select":if(e.type.toLowerCase()==="select-one")i(e.selectedIndex>=0?e.options[e.selectedIndex]:null);else for(a=0;e.length&&aAddress not found. Please verify the spelling.
For brand new addresses, please type it in manually.",location_content:"Addresses near me",location_unavailable:"Location information unavailable. Please type in your address.",location_not_found:"No nearby addresses found. Please type in your address.",location_loading:"Loading your location...",max_results:t.options.maxItems});var s=null,r=t.widget.addService("addy",function(e,o){if(e.length<3)return o(e,new Array),void t.widget._hideResults();s=new RegExp("("+e.split(" ").join("|")+")","gi"),"address"===t.mode?t.makeRequest("api/search",t.searchSuffix+"&s="+e,function(t){var i=new Array;if(t)for(var n=0;n$1')}});t.setOption=function(e,o){e&&"exclude_postbox"===e?t.options.excludePostBox=o:t.widget.setOption(e,o),d()},t.setExcludeRural=function(e){t.options.exRural=e,d()},t.setExcludePostbox=function(e){t.options.excludePostBox=e,d()},t.setExcludeUndeliverable=function(e){t.options.exUndeliver=e,d()},t.setExcludeSpelling=function(e){t.options.exSpelling=e,d()},t.setExcludeWordRemoval=function(e){t.options.exWord=e,d()},t.setExcludeIpOrder=function(e){t.options.exIp=e,d()},t.setExcludePostcodes=function(e){t.options.exPostcodes=Array.isArray(e)?e.join("-"):e,d()},t.setIncludePostcodes=function(e){t.options.inPostcode=Array.isArray(e)?e.join("-"):e,d()},t.setExcludeRegions=function(e){t.options.exRegion=Array.isArray(e)?e.join("-"):e,d()},t.setIncludeRegions=function(e){t.options.inRegion=Array.isArray(e)?e.join("-"):e,d()},t.setExcludeTerritories=function(e){t.options.exTerritory=Array.isArray(e)?e.join("-"):e,d()},t.setIncludeTerritories=function(e){t.options.inTerritory=Array.isArray(e)?e.join("-"):e,d()},t.setTag=function(e){t.options.tag=e,d()},t.setUniqueId=function(e){t.options.uniqueId=e,d()},t.getOption=function(e){return t.widget.getOption(e)},t.getMaxResults=function(){return t.widget.getOption("max_results")},t.enableLocation=function(){t.options.enableLocation=!0},t.disableLocation=function(){t.options.enableLocation=!1},t.enable=function(){t.widget.enable()},t.disable=function(){t.widget.disable()},t.setPostcodeMode=function(e){t.mode="postcode",t.setOption("empty_content","Postcode not found. Please verify the spelling.")};NeatComplete.addDomEvent(e,"focus",function(o){t.options.enableLocation&&""===e.value&&r._response(r.last_query,[{value:t.getOption("location_content"),data:{id:"location"}}])}),t._onLocationResultsEmpty=function(e){var o=t.widget.getOption("empty_content");t.options.enableLocation=!1,t.setOption("empty_content",e),setTimeout(function(){t.setOption("empty_content",o)},2e3)},t.handleLocationError=function(o){t.makeRequest("api/errorlog","&message=GeoFailCode:"+o.code+":"+o.message,function(e){}),t._onLocationResultsEmpty(t.getOption("location_unavailable")),r._response(r.last_query,[]),e.placeholder=n},t.reverseGeocode=function(o){t.makeRequest("api/geocode","&x="+o.coords.longitude+"&y="+o.coords.latitude+"&limit="+t.getMaxResults(),function(o){var i=new Array;if(o)for(var s=0;s-1||i.indexOf(o.options[n].value.toUpperCase())>-1){o.selectedIndex=n;break}}else o.value=e.region},t.loadAddress=function(e){t.makeRequest("api/address/"+e,"",function(e){e&&(t.assignAddressFields(e),t.assignRegion(e),t.addressSelected(e))}.bind(this))},t.loadLocation=function(){e.value="",e.placeholder=t.getOption("location_loading"),navigator.geolocation.getCurrentPosition(t.reverseGeocode,t.handleLocationError)},t.widget.on("result:select",function(e,o){"address"===t.mode?"location"===o.id?t.loadLocation():t.loadAddress(o.id):t.postcodeSelected(o)}),t.checkDemo=function(){return!(!t.key||"demo-api-key"!==t.key.toLowerCase())&&(t.setOption("footer_content",'Demo Mode: Create a free account at addy.co.nz'),!0)},t.checkDemo(),d()}else console.warn("Input field is missing");function d(){t.searchSuffix="&max="+t.getMaxResults(),t.options.excludePostBox&&(t.searchSuffix+="&expostbox=true"),t.options.exUndeliver&&(t.searchSuffix+="&exundeliver=true"),t.options.exRural&&(t.searchSuffix+="&exrural=true"),t.options.exSpelling&&(t.searchSuffix+="&exspelling=true"),t.options.exWord&&(t.searchSuffix+="&exword=true"),t.options.exIp&&(t.searchSuffix+="&exip=true"),t.options.exPostcodes&&""!==t.options.exPostcodes&&(t.searchSuffix+="&expostcode="+t.options.exPostcodes),t.options.inPostcode&&""!==t.options.inPostcode&&(t.searchSuffix+="&inpostcode="+t.options.inPostcode),t.options.exRegion&&""!==t.options.exRegion&&(t.searchSuffix+="&exregion="+t.options.exRegion),t.options.inRegion&&""!==t.options.inRegion&&(t.searchSuffix+="&inregion="+t.options.inRegion),t.options.exTerritory&&""!==t.options.exTerritory&&(t.searchSuffix+="&exterritory="+t.options.exTerritory),t.options.inTerritory&&""!==t.options.inTerritory&&(t.searchSuffix+="&interritory="+t.options.inTerritory),t.requestSuffix="",t.options.tag&&""!==t.options.tag&&(t.requestSuffix+="&tag="+t.options.tag),t.options.uniqueId&&""!==t.options.uniqueId&&(t.requestSuffix+="&uniqueid="+t.options.uniqueId)}}function initAddyByCss(){var e=["","2-","3-","4-"],o="addy-";function t(e){var t=document.getElementsByClassName(o+e);return 1===t.length?t[0]:null}for(var i=0;i