var CategorySearch=new Class({mDejax:null,mAjaxMode:"free",mFormName:"categorysearchboxform",initialize:function(){this.mDejax=new Dejax();this.attachEvents()},attachEvents:function(){this.getFormElement("problems").getDomElement().addEvent("change",this.eChangeProblems.bind(this));this.getFormElement("products").getDomElement().addEvent("change",this.eChangeProducts.bind(this));this.getFormElement("growings").getDomElement().addEvent("change",this.eChangeGrowings.bind(this));document.getElement("#categorysearchboxform_send").addEvent("click",this.eSendForm.bind(this));document.getElement("#categorysearchboxform_reset").addEvent("click",this.eResetForm.bind(this))},detachEvents:function(){this.getFormElement("problems").getDomElement().removeEvents("change");this.getFormElement("products").getDomElement().removeEvents("change");this.getFormElement("growings").getDomElement().removeEvents("change")},eResetForm:function(a){a.stop();this.getData(null,null,"/ajax/Search/GetProductsCategories/","products");this.getData(null,null,"/ajax/Search/GetGrowingsCategories/","growings");this.getData(null,null,"/ajax/Search/GetProblemsCategories/","problems")},eSendForm:function(a){a.stop();window.location="/wyszukaj-wg-kategorii/produkty,"+$("categorysearchboxform_products").value+"/problemy,"+$("categorysearchboxform_problems").value+"/uprawy,"+$("categorysearchboxform_growings").value+".html"},eChangeProblems:function(a){var b=this.getFormElement("problems").getValue();this.disposeSelectOptions("problems",b);this.getData(b,"problem","/ajax/Search/GetProducts/","products");this.getData(b,"problem","/ajax/Search/GetGrowings/","growings");this.detachEvents()},eChangeProducts:function(a){var b=this.getFormElement("products").getValue();this.disposeSelectOptions("products",b);this.getData(b,"product","/ajax/Search/GetProblems/","problems");this.getData(b,"product","/ajax/Search/GetGrowings/","growings");this.detachEvents()},eChangeGrowings:function(a){var b=this.getFormElement("growings").getValue();this.disposeSelectOptions("growings",b);this.getData(b,"growing","/ajax/Search/GetProblems/","problems");this.getData(b,"growing","/ajax/Search/GetProducts/","products");this.detachEvents()},getFormElement:function(a){return window[this.mFormName+"_"+a]},showSpinner:function(){document.getElement("#categorysearchboxform_send").removeEvents("click");document.getElement("#categorysearchboxform_send img").setAttribute("src","/p/ajax-loader-small.gif")},hideSpinner:function(){document.getElement("#categorysearchboxform_send img").setAttribute("src","/p/amall_arrow.png");document.getElement("#categorysearchboxform_send").addEvent("click",this.eSendForm.bind(this))},putInToSelect:function(b,a){if(!b){return false}this.getFormElement(a).getDomElement().getElements("option").dispose();new Hash(b).each(function(c,d){new Element("option",{value:d}).set("html",c).injectInside(this.getFormElement(a).getDomElement())},this)},disposeSelectOptions:function(a,d){var b=this.getFormElement(a).getDomElement().getElements("option");for(var c=0;c<b.length;c++){if(d!=b[c].value){b[c].dispose()}}},getData:function(c,a,b,d){this.showSpinner();this.mDejax.newRequest({url:b,"eval":false,mode:this.mAjaxMode,data:{id:c,type:a},onComplete:function(e){this.putInToSelect(e,d);this.hideSpinner()}.bind(this)})}});window.addEvent("domready",function(){new CategorySearch()});
