function URLDecode(B){var A=/\+/g;return unescape(String(B).replace(A," "));}function qstringvars(A){querystring=location.search.substring(1);startsearch=querystring.indexOf(A+"=");if(startsearch!=-1){startpos=querystring.indexOf("=",startsearch)+1;endpos=querystring.indexOf("&",startpos);if(endpos!=-1){ret_value=querystring.substring(startpos,endpos);}else{ret_value=querystring.substring(startpos);}return(URLDecode(ret_value));}else{return("");}}function multipleqstringvars(A){querystring=location.search.substring(1);var B="";pos=querystring.indexOf(A+"=");while(pos!=-1){startpos=querystring.indexOf("=",pos)+1;endpos=querystring.indexOf("&",startpos);if(endpos==-1){endpos=querystring.length;}if(endpos!=-1){B=querystring.substring(startpos,endpos)+"_"+B;}pos=querystring.indexOf(A,pos+1);}return B;}function convertParam(B,C){var A=C;if(C!=""){switch(B){case"min_year":A=C+"00";break;case"max_year":A=C+"12";break;case"source":switch(C){case"1":A="p";break;case"2":A="t";break;default:A="0";break;}break;case"sort":switch(C){case"0":A="specified_price";break;case"1":A="make";break;case"12":A="model";break;case"4":A="distance";break;case"5":A="neg_price";break;case"9":A="mileage";break;case"10":A="neg_year";break;case"14":A="neg_mileage";break;default:A="neg_price";break;}}}return A;}function broadcast(G,H,B){if(!G.disabled){if(H=="did_multiple"){var F=didqstring();}else{var F=qstringvars(H);}if(F==""&&B!=""){var E="";if(B=="county"){E=qstringvars(B);}else{E=qstringvars(B);}if(G.name==H){F=convertParam(B,E);}else{F=E;}}if(!(G.type)==true){var C="radio";}else{var C=G.type;}if(C=="select-one"){if(!(G.options)==false){var D=G.options.length;for(z=0;z<D;z++){if(G.options[z].value==F){G.selectedIndex=z;if(H=="make_id_EQI"){if(document.mainform.model_EQS!=null||document.mainform.model!=null){if(typeof UpdateDropDown=="function"){UpdateDropDown(G.selectedIndex);}else{if(typeof get_range=="function"){get_range(_model[G.selectedIndex]);}}}}}}}else{prefill_a_textbox(G,H);}}else{if(C=="select-multiple"){if(!(G.options)==false){var D=G.options.length;var A=F.split("_");for(f=0;f<A.length;f++){for(z=0;z<D;z++){if(G.options[z].value==A[f]){G.options[z].selected="checked";}}}}else{prefill_a_textbox(G,H);}}else{if(C=="text"){if(F!=""){G.value=F;}}else{if(C=="radio"||C=="checkbox"){if(F!=""){if(F==G.value){G.checked=1;}}}}}}}}function start_prefill(){handleCounties();var D=document.forms["mainform"].elements;var B=new Array("make_id_EQI","model_EQS","specified_price_GT","specified_price_LT","source_EQS","mileage_RANGE","keywords_LKSPLIT","photo","geolocate","postcode","orderby","year_CONV","currency","engine_cc","country","county_id_IN","county_sel","year_GT","year_LT","subcat_EQS","county","did_multiple","counties");var A=new Array("make","model","min_pr","max_pr","source","","keywords","","miles","postcode","sort","","currency","","country","county","","min_year","max_year","subcat","county","","counties");for(i=0;i<D.length;i++){var C=D[i];if(!(C)==false){for(j=0;j<B.length;j++){if(C.name==B[j]||C.name==A[j]){broadcast(C,B[j],A[j]);break;}}}}}function didqstring(){querystring=location.search.substring(1);var A="";pos=querystring.indexOf("did_multiple");while(pos!=-1){startpos=querystring.indexOf("=",pos)+1;endpos=querystring.indexOf("&",startpos);if(endpos!=-1){A=querystring.substring(startpos,endpos)+"_"+A;}pos=querystring.indexOf("did_multiple",pos+1);}return A;}function setKeyword(){if(document.mainform.keywords.value.indexOf("eg.")!=-1){document.mainform.keywords.value="";}}function getListOfParamValues(C){var A=location.search.substring(1);var F=new Array();var B=0;var G=A.indexOf(C+"=");while(G!=-1){var E=A.indexOf("=",G)+1;var D=A.indexOf("&",E);if(D==-1){D=A.length;}if(D!=-1){F[B]=A.substring(E,D);B++;}G=A.indexOf(C,G+1);}return F;}function handleCounties(){var C=getListOfParamValues("county");var B=document.forms["mainform"].county;for(var A=0;A<C.length;A++){$("input[value="+C[A]+"]").attr("checked","checked");}$("#national").click(function(){var D=$(this).attr("checked");if($(this).attr("checked")){$("input[name=county]").attr("checked","checked");}else{$("input[name=county]").removeAttr("checked");}});$("input[name=county]").click(function(){if($("input[name=counties]").attr("checked")&&!$(this).attr("checked")){$("#national").removeAttr("checked");}});}