
CMS.define('FL_SearchForm',{initialize:function(config)
{this.config=config;this.countryfield=$(config.nodename+'_country');this.vendorfield=$(config.nodename+'_vendor');this.categoryfield=$(config.nodename+'_category');this.techfield=$(config.nodename+'_technology');this.locationfield=$(config.nodename+'_town');this.keywordfield=$(config.nodename+'_keyword');this.fromyearfield=$(config.nodename+'_fromyear');this.frommonthfield=$(config.nodename+'_frommonth');this.toyearfield=$(config.nodename+'_toyear');this.tomonthfield=$(config.nodename+'_tomonth');
this.updatebutton=$(config.nodename+'_updatebutton');
this.resetbutton=$(config.nodename+'_resetbutton');this.eventlanguage=$(config.nodename+'_eventlanguage');this.guaranteedfield=$(config.nodename+'_guaranteed');this.searchpanel=$(config.nodename+'_searchpanel');this.modeswitch=$(config.nodename+'_modeswitch');if(this.modeswitch)
{Event.observe(this.modeswitch,'click',this.switchPanel.bind(this));}
tmp=$$('div.searchresultpreview');if(tmp.length)
{this.resultpreviewpanel=tmp[0];this.resultpreview=$(this.resultpreviewpanel.id+'_content');var loadingindicator=document.createElement('div');this.loadingindicator=$(loadingindicator);this.loadingindicator.innerHTML=this.config.loadingindicator;}
tmp=$$('div.searchresult');if(tmp.length)
{this.resultview=tmp[0];if(config.initialhighlight)
{this.highlightResult(config.initialhighlight);}}
Event.observe(this.countryfield,'change',this.countryChanged.bind(this));if(this.resultpreview)
{Event.observe(this.tomonthfield,'change',this.toMonthChanged.bind(this));Event.observe(this.vendorfield,'change',this.vendorChanged.bind(this));Event.observe(this.locationfield,'change',this.updateResultPreviewDelayed.bind(this));Event.observe(this.techfield,'change',this.updateResultPreviewDelayed.bind(this));Event.observe(this.keywordfield,'change',this.updateResultPreviewDelayed.bind(this));
Event.observe(this.keywordfield,'keypress',this.onEnter.bind(this));
//Event.observe(this.updatebutton,'click',this.updateResultPreviewDelayed.bind(this));
Event.observe(this.updatebutton,'click',this.showResults.bind(this));
Event.observe(this.fromyearfield,'change',this.updateResultPreviewDelayed.bind(this));Event.observe(this.frommonthfield,'change',this.updateResultPreviewDelayed.bind(this));Event.observe(this.toyearfield,'change',this.updateResultPreviewDelayed.bind(this));Event.observe(this.guaranteedfield,'change',this.updateResultPreviewDelayed.bind(this));if(this.eventlanguage)
{Event.observe(this.eventlanguage,'change',this.updateResultPreview.bind(this));}
Event.observe(this.resetbutton,'click',this.resetSearch.bind(this));}
this.updateLocationList();},switchPanel:function(evt)
{this.modeswitch.hide();this.searchpanel.show();},collectSearchCriteria:function()
{data={country:$F(this.countryfield),tech:$F(this.techfield).join(','),keywords:$F(this.keywordfield),fromdate:$F(this.fromyearfield)+$F(this.frommonthfield),todate:$F(this.toyearfield)+$F(this.tomonthfield),guaranteed:$F(this.guaranteedfield)?'1':'0'}
if(this.locationfield.selectedIndex)
{data.town=$F(this.locationfield);}
if($F(this.vendorfield))
{data.vendors=$F(this.vendorfield).join(',');}
if(this.categoryfield&&$F(this.categoryfield))
{data.cats=$F(this.categoryfield).join(',');}
if(this.eventlanguage)
{data.eventlanguage=$F(this.eventlanguage);}
return data;},toMonthChanged:function(evt)
{if(!$F(this.toyearfield))
{this.toyearfield.selectedIndex=this.fromyearfield.selectedIndex;}
this.updateResultPreview(evt);},vendorChanged:function(evt)
{this.updateTechnologyList();this.updateResultPreviewDelayed();},
onEnter: function(evt)
{
	if (evt.keyCode == Event.KEY_RETURN)
	{
		this.showResults();
	}
},
updateResultPreview:function(evt)
{data=this.collectSearchCriteria();data.preview='1';this.resultpreviewpanel.show();new Ajax.Updater({success:this.resultpreview},this.config.execute,{parameters:data,onLoading:this.resultPreviewIndicateLoading.bind(this)});},updateResultPreviewDelayed:function()
{window.clearTimeout(this.timeoutactive);this.timeoutactive=window.setTimeout('CMS.FL_SearchForm.updateResultPreview()',1000);},resultIndicateLoading:function()
{Element.update(this.resultview,this.loadingindicator.innerHTML);},resultPreviewIndicateLoading:function()
{Element.update(this.resultpreview,this.loadingindicator.innerHTML);},countryChanged:function()
{this.updateVendorList();this.updateLocationList();},updateLocationList:function()
{data={country:$F(this.countryfield)};new Ajax.Request(this.config.getlocationlist,{parameters:data,onSuccess:this.updateLocationListHandler.bind(this)});},updateLocationListHandler:function(t,json)
{if(json)
{this.locationList=json;}
else if(t.responseJSON)
{this.locationList=t.responseJSON;}
else
{CMS.raiseError(4500);return;}
clearSelectBox(this.locationfield);option=new Option(this.config.alllocationsitem,'0',false,true);$(option).addClassName('defaultoption');try{this.locationfield.add(option,null);}catch(e){this.locationfield.add(option);}
option=new Option(this.config.vlearninglocation,'-1',false);try{this.locationfield.add(option,null);}catch(e){this.locationfield.add(option);}
for(var i=0,len=this.locationList.length;i<len;i++)
{option=new Option(this.locationList[i]['translatedname'],this.locationList[i]['town'],false);try{this.locationfield.add(option,null);}catch(e){this.locationfield.add(option);}}},updateTechnologyList:function()
{this.techfield_previous=$F(this.techfield);this.techfield.selectedIndex=-1;data={vendors:$F(this.vendorfield).join(',')};new Ajax.Request(this.config.gettechnologylist,{parameters:data,onSuccess:this.updateTechnologyListHandler.bind(this)});},updateTechnologyListHandler:function(t,json)
{if(json)
{this.technologyList=json;}
else if(t.responseJSON)
{this.technologyList=t.responseJSON;}
else
{CMS.raiseError(4500);return;}
clearSelectBox(this.techfield);var option=new Option(this.config.alltechnologiesitem,'0',false);$(option).addClassName('defaultoption');try
{this.techfield.add(option,null);}
catch(e)
{this.techfield.add(option);}
for(var i=0,len=this.technologyList.length;i<len;i++)
{option=new Option(this.technologyList[i]['name'],this.technologyList[i]['id'],false,(this.techfield_previous&&this.techfield_previous.indexOf(this.technologyList[i]['id'].toString())>=0));try
{this.techfield.add(option,null);}
catch(e)
{this.techfield.add(option);}}},updateVendorList:function()
{this.vendorfield_previous=$F(this.vendorfield);this.vendorfield.selectedIndex=-1;data={country:$F(this.countryfield)};new Ajax.Request(this.config.getvendorlist,{parameters:data,onSuccess:this.updateVendorListHandler.bind(this)});this.updateTechnologyList();},updateVendorListHandler:function(t,json)
{if(json)
{this.vendorList=json;}
else if(t.responseJSON)
{this.vendorList=t.responseJSON;}
else
{CMS.raiseError(4501);return;}
clearSelectBox(this.vendorfield);var option=new Option(this.config.allvendorsitem,'0',false);option.setAttribute('class','defaultoption');try
{this.vendorfield.add(option,null);}
catch(e)
{this.vendorfield.add(option);}
for(var i=0,len=this.vendorList.length;i<len;i++)
{option=new Option(this.vendorList[i]['name'],this.vendorList[i]['id'],false,(this.vendorfield_previous&&this.vendorfield_previous.indexOf(this.vendorList[i]['id'].toString())>=0));try
{this.vendorfield.add(option,null);}
catch(e)
{this.vendorfield.add(option);}}
if(this.categoryfield)
{clearSelectBox(this.categoryfield);}},showResults:function()
{if(!this.resultview)
{CMS.raiseError(4503);return;}
data=this.collectSearchCriteria();new Ajax.Updater({success:this.resultview},this.config.execute,{parameters:data,evalScripts:true,onLoading:this.resultIndicateLoading.bind(this)});},highlightResult:function(terms)
{if(!CMS.CMS_Highlighter)
{return;}
CMS.CMS_Highlighter.highlight(this.resultview,terms);},resetSearch:function()
{this.keywordfield.value='';this.techfield.selectedIndex=-1;this.countryfield.selectedIndex=0;this.fromyearfield.selectedIndex=0;this.frommonthfield.selectedIndex=0;this.toyearfield.selectedIndex=0;this.tomonthfield.selectedIndex=0;this.updateVendorList();this.updateLocationList();this.resultpreviewpanel.hide();}});
