var Qas=Class.create();Qas.prototype={initialize:function(requestUrl,postCodeField,townField,streetAddressField){this.requestUrl=requestUrl;this.postCodeField=postCodeField;this.streetAddressField=streetAddressField;this.townField=townField;},setPostCode:function(postCode){this.postCode=postCode;},getPostCode:function(){return this.postCode;},getAddressList:function(){jQuery.ajax({type:"POST",url:this.requestUrl,data:{postCode:this.getPostCode()},dataType:"json",success:function(data){if(data.error==true){alert(data.message);}else{addressFinder.postCodeData=data.postCode;addressFinder.townData=data.town;addressFinder.drawAddressListArea(data.addressList);}}});},drawAddressListArea:function(addressList){var block='<div class="addressBox"><ul></ul></div>';jQuery(this.postCodeField+'-'+this.attr).before(block);jQuery.each(addressList,function(key,value){jQuery('.addressBox ul').append('<li><a href="#" class="selectAddress">'+value+'</a></li>');});this.initSelect();},initSelect:function(){jQuery('.selectAddress').click(function(){var addr=jQuery(this).html();addr=addr.replace(/&amp;/gi,'&');jQuery(addressFinder.postCodeField+'-'+addressFinder.attr).val(addressFinder.postCodeData);jQuery(addressFinder.streetAddressField+'-'+addressFinder.attr).val(addr);jQuery(addressFinder.townField+'-'+addressFinder.attr).val(addressFinder.townData);jQuery('.addressBox').remove();return false;});},initClick:function(attr){this.setAttr(attr);var postCode=jQuery(this.postCodeField+'-'+attr).val();if(postCode!=''&&jQuery('.country-qas-'+attr+' select').val()=='GB'){if(typeof(postCode)!="undefined"){this.setPostCode(postCode);this.getAddressList();}}
return false;},setAttr:function(attr){this.attr=attr;}}
