/*
 * autosuggest(www.nonprints.com)
 */
function AutoSuggestControl(_,$){this.cur=-1;this.itemList=10;this.layer=null;this.provider=$;this.textbox=_;this.oTextboxVal=_.value;this.init()}AutoSuggestControl.prototype.autosuggest=function($,_){if($.length>0){if(_)this.typeAhead($[0]);this.createSuggestions($)}else{this.hideSuggestions();this.layer.innerHTML="";this.cur=-1}};AutoSuggestControl.prototype.createDropDown=function(){var $=this;this.layer=document.createElement("div");this.layer.className="suggestions";this.layer.style.visibility="hidden";this.layer.style.width=this.textbox.offsetWidth;this.layer.onmousedown=this.layer.onmouseup=this.layer.onmouseover=function(_){_=_||window.event;oTarget=_.target||_.srcElement;if(_.type=="mousedown"){$.textbox.value=oTarget.firstChild.nodeValue;$.hideSuggestions()}else if(_.type=="mouseover")$.highlightSuggestion(oTarget);else $.textbox.focus()};document.body.appendChild(this.layer)};AutoSuggestControl.prototype.getLeft=function(){var _=this.textbox,$=0;while(_.tagName!="BODY"){$+=_.offsetLeft;_=_.offsetParent}return $};AutoSuggestControl.prototype.getTop=function(){var _=this.textbox,$=0;while(_.tagName!="BODY"){$+=_.offsetTop;_=_.offsetParent}return $};AutoSuggestControl.prototype.handleKeyDown=function($){if(!this.layer||!this.layer.innerHTML)return false;switch($.keyCode){case 38:this.showSuggestions();this.previousSuggestion();break;case 40:this.showSuggestions();this.nextSuggestion();break;case 13:this.hideSuggestions();break}};AutoSuggestControl.prototype.handleKeyUp=function(_){var $=_.keyCode;if($==8||$==46){this.oTextboxVal=this.textbox.value;this.provider.requestSuggestions(this,false)}else if($<32||($>=33&&$<46)||($>=112&&$<=123));else{this.oTextboxVal=this.textbox.value;this.provider.requestSuggestions(this,false)}};AutoSuggestControl.prototype.hideSuggestions=function(){this.layer.style.visibility="hidden"};AutoSuggestControl.prototype.showSuggestions=function(){if(this.layer)if(this.layer.innerHTML)this.layer.style.visibility="visible"};AutoSuggestControl.prototype.highlightSuggestion=function($){for(var A=0;A<this.layer.childNodes.length;A++){var _=this.layer.childNodes[A];if(_==$){_.className="current";this.cur=A}else if(_.className=="current")_.className=""}};AutoSuggestControl.prototype.init=function(){var $=this;this.textbox.onkeyup=function(_){if(!_)_=window.event;$.handleKeyUp(_)};this.textbox.onkeydown=function(_){if(!_)_=window.event;$.handleKeyDown(_)};this.textbox.onblur=function(){$.hideSuggestions()};this.createDropDown()};AutoSuggestControl.prototype.nextSuggestion=function(){var _=this.layer.childNodes;if(this.cur==_.length-1){this.cur=-1;this.textbox.value=this.oTextboxVal;return this.highlightSuggestion(null)}else if(this.cur>_.length-1)this.cur=-1;if(_.length>0){var $=_[++this.cur];this.highlightSuggestion($);this.textbox.value=$.firstChild.nodeValue}};AutoSuggestControl.prototype.previousSuggestion=function(){var _=this.layer.childNodes;if(this.cur<0)this.cur=_.length;else if(this.cur==0){this.textbox.value=this.oTextboxVal;this.cur=-1;return this.highlightSuggestion(null)}if(_.length>0){var $=_[--this.cur];this.highlightSuggestion($);this.textbox.value=$.firstChild.nodeValue}};AutoSuggestControl.prototype.selectRange=function(A,_){if(this.textbox.createTextRange){var $=this.textbox.createTextRange();$.moveStart("character",A);$.moveEnd("character",_-this.textbox.value.length);$.select()}else if(this.textbox.setSelectionRange)this.textbox.setSelectionRange(A,_);this.textbox.focus()};AutoSuggestControl.prototype.createSuggestions=function(_){var $=null;this.layer.innerHTML="";this.cur=-1;for(var A=0;A<_.length&&A<this.itemList;A++){$=document.createElement("div");$.appendChild(document.createTextNode(_[A]));this.layer.appendChild($)}this.layer.style.left=this.getLeft()+"px";this.layer.style.top=(this.getTop()+this.textbox.offsetHeight)+"px";this.layer.style.visibility="visible"};AutoSuggestControl.prototype.typeAhead=function(_){if(this.textbox.createTextRange||this.textbox.setSelectionRange){var $=this.textbox.value.length;this.textbox.value=_;this.selectRange($,_.length)}};StateSuggestions.prototype.requestSuggestions=function(F,D){var C=[],A=F.textbox.value,E=this.states;if(F.textbox.name=="country")E=this.countrys;if(A.length>0){var B=A.toLowerCase();for(var G=0,_=0;G<E.length;G++){var $=E[G];if($.toLowerCase().indexOf(B)==0){C.push(E[G]);if(++_>=10)break}}}F.autosuggest(C,D)};function cpCty($){this.country=document.getElementById("country").value;if($&&"||USA|UK|Australia|United States|United Kingdom|England, UK|Scotland, UK|".indexOf("|"+this.country+"|")!=-1){this.obj=new StateSuggestions();this.states=this.obj.states;this.country="";for(var A=0,_=this.states.length;A<_;++A)if(this.states[A]==$){if(A<=53)this.country="USA";else if(A>60)this.country="UK";else this.country="Australia";break}if(this.country)document.getElementById("country").value=this.country}}

function StateSuggestions(){
  this.states=[
	  "AK","AL","AZ","AR","CA","CO","CT","DC","DE","FL","GA","HI","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VA","VT","WA","WI","WV","WY","PR","VI","GU",
	  "New South Wales","Western Australia","South Australia","Queensland","Victoria","Australian Capital Territory","Northern Territory",
	  "Berkshire","Cambridgeshire","Cheshire","Cleveland","Cornwall","Derbyshire","Devon","Durham","East Yorkshire","East Sussex","Essex","Gloucestershire","Greater Manchester","Hampshire","Hertfordshire","Kent","Lancashire","Lincolnshire","London","Merseyside","Norfolk","North Yorkshire","Northumberland","Nottinghamshire","Shropshire","Somerset","South Yorkshire","Suffolk","Suffolk","Tyne and Wear","West Midlands","West Sussex","West Yorkshire","Wiltshire","Worcestershire","Antrim","Argyll and Bute","East Lothian","Renfrewshire","Fife","North Lanarkshire","South Lanarkshire","Renfrewshire","West Lothian","Bridgend","Isle of Anglesey","The Vale of Glamorgan"
  ];
  this.countrys=["USA","UK","Australia","Argentina","Armenia","Albania","Algeria","Andorra","Angola","Anguilla","Antigua and Barbuda","Aruba","Austria","Azerbaijan Republic","Belgium","Brunei","Bolivia","Brazil","Bahamas","Bahrain","Barbados","Belize","Benin","Bermuda","Bhutan","Bosnia and Herzegovina","Botswana","British Virgin Islands","Bulgaria","Burkina Faso","Burundi","Canada","Cyprus","Czech Republic","Cambodia","Cape Verde","Cayman Islands","Chad","Chile","China","Colombia","Comoros","Cook Islands","Costa Rica","Croatia","Denmark","Democratic Republic of the Congo","Djibouti","Dominica","Dominican Republic","Ecuador","El Salvador","Eritrea","Estonia","Ethiopia","England, UK","France","Finland","Falkland Islands","Faroe Islands","Federated States of Micronesia","Fiji","French Guiana","French Polynesia","Greece","Germany","Guinea Bissau","Gabon Republic","Gambia","Gibraltar","Greenland","Grenada","Guadeloupe","Guatemala","Guinea","Guyana","Honduras","Hong Kong","Hungary","Italy","India","Ireland","Iceland","Indonesia","Israel","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Kuwait","Kyrgyzstan","Laos","Latvia","Lesotho","Liechtenstein","Lithuania","Luxembourg","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Martinique","Mauritania","Mauritius","Mayotte","Mexico","Mongolia","Montserrat","Morocco","Mozambique","Netherlands","New Zealand","Norway","Namibia","Nauru","Nepal","Netherlands Antilles","New Caledonia","Nicaragua","Niger","Niue","Norfolk Island","Oman","Palau","Panama","Papua New Guinea","Peru","Philippines","Pitcairn Islands","Poland","Portugal","Qatar","Republic of the Congo","Reunion","Romania","Russia","Rwanda","Spain","Singapore","Sweden","Switzerland","South Africa","Saint Vincent and the Grenadines","Samoa","San Marino","Saudi Arabia","Senegal","Seychelles","Sierra Leone","Slovakia","Slovenia","Solomon Islands","Somalia","South Korea","Sri Lanka","Suriname","Svalbard and Jan Mayen Islands","Swaziland","Scotland, UK","Taiwan","Tajikistan","Tanzania","Thailand","Togo","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Turks and Caicos Islands","Tuvalu","Uganda","Ukraine","United Arab Emirates","Uruguay","United States","United Kingdom","Vanuatu","Vatican City State","Venezuela","Vietnam","Wallis and Futuna Islands","Yemen","Zambia","St. Helena","St. Kitts and Nevis","St. Lucia","St. Pierre and Miquelon"];
}
