var GDACDelay=50;var GDACLocale="";function GDACFormatMatch(b){return b[0]}function GDACFormatItem(b){return(b[1]!=""?'<img src="http://www.tzoo-img.com/static/images/flagtiny/'+b[1]+".png?"+versionString+'" /> ':"")+b[5]}function GDACFormatResult(b){return b[0]}function parseStringToArray(j){var h=[];var i=j.split("\n");for(var g=0;g<i.length;g++){var f=$.trim(i[g]);if(f){f=f.split("|");h[h.length]=f}}return h}function lookupLocationCode(h,i,g){var j=$.ajax({type:"GET",url:"/GeoDataAutocompleteHandler.ashx",data:{type:i,q:h,ex_cc:g,l:GDACLocale},async:false}).responseText;var f=parseStringToArray(j);return f[0]}$().ready(function(){$(".gdac_enabled").autocomplete("/GeoDataAutocompleteHandler.ashx",{highlight:false,delay:GDACDelay,cacheLength:1,formatItem:GDACFormatItem,formatMatch:GDACFormatMatch,formatResult:GDACFormatResult,matchSubset:false,minChars:3,max:20}).result(function(e,g,h){var f="#"+($(this).attr("gdaccodefield")?$(this).attr("gdaccodefield"):$(this).attr("id")+"Code");if(g&&$(f).val()!=g[2]){$(f).val(g[2])}$(this).trigger("postresult",[g])}).bind("change",function(){var b="#"+($(this).attr("gdaccodefield")?$(this).attr("gdaccodefield"):$(this).attr("id")+"Code");if($(this).val()==""){$(b).val("")}}).bind("focus",function(){$(this).select();var c=$(this).attr("gdactype");var d=$(this).attr("gdacexcc");$(this).setOptions({extraParams:{type:c,ex_cc:d,l:GDACLocale}})}).blur(function(g){var d=$(this).val();var e=lookupLocationCode(d,$(this).attr("gdactype"),$(this).attr("gdacexcc"));var h="#"+($(this).attr("gdaccodefield")?$(this).attr("gdaccodefield"):$(this).attr("id")+"Code");if(e.length>0){if($(this).val()!=e[0]){$(this).val(e[0])}if($(h).val()!=e[2]){$(h).val(e[2])}$(this).trigger("postresult",[e])}else{$(this).val("");$(h).val("")}})});