/* results-filters
 
@author Jacob at Goby
 @version 03/08/10
@svn 109
*/

function OptionSet(params)
{this._construct(params);}
OptionSet.prototype={_construct:function(params)
{this.tagName="ul";this.values=new List();this.options=[];this.optionIndex={};this.optionIndex_2={};this._dom=null;this.limit=999;if(params)
for(var i in params)
this[i]=params[i];if(this._dom==null)
this._dom=document.createElement(this.tagName);},addOption:function(option)
{if(this.limit>this.options.length)
{option.optionSet=this;this.indexOption(option);this.options.push(option);this._dom.appendChild(option);}},getOptionByID:function(id)
{if(this.optionIndex[id]!=null)
return this.optionIndex[id];else
return false;},indexOption:function(option)
{this.optionIndex[option.getValue()]=option;},displayAll:function()
{return this.getElements({node:1,limit:999});},removeOption:function(option)
{if(option!=null)
{try
{if(option.getValue!=null)
{this.optionIndex[option.getValue()]=null;this.values.remove(option.getValue());option.close();return option;}}
catch(e)
{}}},getOptions:function()
{return this.options;},getValues:function()
{return this.values.toStack();},getElements:function(params)
{for(var i in this.options)
this._dom.appendChild(this.options[i]);return this._dom;},unselectOption:function(option)
{if(this.values.valid(option.getValue()))
{this._unselect(option);this.filter.setValues(this.getValues());this.filter.setParameters();this.filter.applyToResults();}},removeOptions:function()
{while(this.options.length>0)
{var option=this.options.pop();option.close();}
this.optionIndex={};this.options=[];},_select:function(option)
{if((option.getValue()!=OPTION_ALL)&&(this.getOptionByID(OPTION_ALL)))
{var o=this.getOptionByID(OPTION_ALL);o._unselect();}
this.values.add(option.getValue(),option.getValue());},_unselect:function(option)
{this.values.remove(option.getValue());},_destruct:function()
{this.removeOptions();for(var i in this)
this[i]=null;},selectOption:function(option)
{this.all_selected=(option.getValue()==OPTION_ALL?true:false);this.values.add(option.getValue(),option.getValue());if(option.getValue()==OPTION_ALL)
{for(var i in this.options)
if(this.options[i]!==option)
this.options[i]._unselect();this.values=new List();}
else if(this.getOptionByID(OPTION_ALL))
{this.getOptionByID(OPTION_ALL)._unselect();}
this.filter.setValues(this.getValues());this.filter.applyToResults();this.filter.setParameters();}}
function OptionMgr(params)
{if(params==null)
return false;for(var p in params)
this[p]=params[p];if(params.optionType)
this.optionType=params.optionType;else
this.optionType="FilterCheckbox";this.optionsets={'popup':new PopupOptionSet(),'main':new basicOptionSet()};for(var i in this.optionsets)
{this.optionsets[i].optionMgr=this;this.optionsets[i].filter=this.filter;}
this._construct();}
OptionMgr.prototype=new OptionSet();OptionMgr.prototype.count=0;OptionMgr.prototype.removeOptions=function()
{for(var node in this.optionsets)
this.optionsets[node].removeOptions();this.optionIndex=[];this.options=[];}
OptionMgr.prototype.getOptionSet=function(node)
{return this.optionsets[node];}
OptionMgr.prototype.addOption=function(option)
{this.optionsets.main.addOption(eval("new "+this.optionType+"(option)"));this.optionsets.popup.addOption(eval("new "+this.optionType+"(option)"));}
OptionMgr.prototype.setValues=function(values)
{var set=this.getOptionSet("popup");set.clearValues()
for(var i in values)
if(set.getOptionByID(values[i]))
{set.getOptionByID(values[i]).select();}
set.submit(1);}
OptionMgr.prototype.unselectOption=function(option)
{var popup=this.getOptionSet("popup");if(popup.getOptionByID(option.getValue()))
popup.getOptionByID(option.getValue()).unselect();if(this.values.valid(option.getValue()))
{this._unselect(option);this.filter.setValues(this.getValues());this.filter.applyToResults();this.filter.setParameters();}}
OptionMgr.prototype.selectOption=function(option)
{var popup=this.getOptionSet("popup");var main=this.getOptionSet("main");if(option.getValue()==OPTION_ALL)
{popup.clearValues();this._select(option);this.values.clear();this.filter.setValues(this.getValues());}
else
{popup.getOptionByID(option.getValue()).select();this._select(option);}
this.filter.applyToResults();this.filter.setParameters();}
OptionMgr.prototype.selectOptionSet=function(options,dontApply)
{this.values=new List();var mainSet=this.getOptionSet('main');this.all_selected=false;for(var o in mainSet.options)
mainSet.options[o]._unselect();for(var o in options)
{if(options[o]!=null)
{var option=options[o];mainSet.prependOption(option);this._select(option);}}
if(!dontApply)
{this.filter.setValues(this.getValues());this.filter.applyToResults();this.filter.setParameters();}
else
{this.filter.setValues(this.getValues());}}
OptionMgr.prototype.getElements=function(params)
{return this.getOptionSet("main").getElements();}
function PopupOptionSet(){this.title="more categories";this.parentList=null;this._construct();this.selectedOptions=[];}
PopupOptionSet.prototype=new OptionSet();PopupOptionSet.prototype.newoptions=[];PopupOptionSet.prototype.submitable=true;PopupOptionSet.prototype.submit=function(dont)
{this.optionMgr.selectOptionSet(this.selectedOptions,dont);if(this.popup!=null)
this.popup.close();};PopupOptionSet.prototype.clearValues=function()
{for(var i in this.selectedOptions)
{if(this.selectedOptions[i]!=null)
this.selectedOptions[i].unselect();}
this.selectedOptions=[];}
PopupOptionSet.prototype.organizeCategories=function()
{var list={};var optionScaffold=this.categoryScaffold;var j=0;if(this.parentList==null)
{for(var i in optionScaffold.parents)
{var data=optionScaffold.parents[i];list[data.node_id]=document.createElement("ul");if(this.getOptionByID(data.node_id))
{var parentNode=this.getOptionByID(data.node_id);}
else
{var parentNode=document.createElement("li");parentNode.innerHTML=data.node_value;$(parentNode).addClass("parentInert");}
$(parentNode).addClass("parentItem");list[data.node_id].appendChild(parentNode);var listContainer=document.createElement("li");listContainer.appendChild(list[data.node_id]);j++;list.count=j;this._dom.appendChild(listContainer);}}
else
list=this.parentList;for(var o in this.options)
{var option=this.options[o];if(optionScaffold.parents[option.getValue()]==null)
{if(optionScaffold.options[option.getValue()])
{var parentID=optionScaffold.options[option.getValue()];list[parentID].appendChild(option);}
else if(list[CAT_UNKNOWN]!=null)
{list[CAT_UNKNOWN].appendChild(option);}}}
if(list[CAT_UNKNOWN]!=null)
{if(list[CAT_UNKNOWN].childNodes.length<2)
{$(list[CAT_UNKNOWN]).hide();list.count=list.count-1;}
else
{$(list[CAT_UNKNOWN]).show();}}
return list;}
PopupOptionSet.prototype.display=function()
{var area=document.createElement("div");var title=document.createElement("h3");title.innerHTML=this.title;area.appendChild(title);area.id="categoryPopup";var button=document.createElement("input");button.value="search";button.type="button";button.className="button";$(button).css("float","right");button.optionset=this;button.onclick=function()
{this.optionset.submit();}
this.parentList=this.organizeCategories();area.appendChild(this._dom);var cols=this.parentList.count;var len=this.getOptions().length;if(len>9)
$(this._dom).css("height","220px");var width=270;$(this._dom).css("overflow","auto");$(this._dom).css("width",width);var cancel=document.createElement("a");cancel.innerHTML="cancel";cancel.className="cancelLink";cancel.optionset=this;cancel.onclick=function()
{var data=window.compileLink(null,this);this.href=data.href;this.hash=data.hash;this.optionset.popup.close();}
var clear=document.createElement("div");clear.className="clear";area.appendChild(clear);if(button)
area.appendChild(button);area.appendChild(cancel);this.popup=new Popup
({container:this.optionMgr.filter.fieldset,content:area,isMask:false,customClass:false,isShell:true,prepend:true,position:"right",fixed:false,automargin:false,ratio:0.5});this.popup.display();$(this.popup.getNode()).css("width",width);}
PopupOptionSet.prototype.unselectOption=function(option)
{this.selectedOptions[option.getValue()]=null;this._unselect(option);};PopupOptionSet.prototype.selectOption=function(option)
{this.selectedOptions[option.getValue()]=option;this._select(option);};function basicOptionSet(params){this._construct();this.limit=4;}
basicOptionSet.prototype=new OptionSet();basicOptionSet.prototype.unselectOption=function(option)
{this._unselect(option);this.optionMgr.unselectOption(option);},basicOptionSet.prototype.selectOption=function(option)
{if(option.getValue()==OPTION_ALL)
{this.values.clear();for(var i in this.options)
if(this.options[i].getValue()!=OPTION_ALL)
this.options[i]._unselect();}
this._select(option);this.optionMgr.selectOption(option);}
basicOptionSet.prototype.prependOption=function(option)
{if(option.getValue()==OPTION_ALL)
return false;if(this.getOptionByID(option.getValue()))
{var _option=this.getOptionByID(option.getValue());try
{_option._select();return _option;}
catch(e)
{}}
else
{if(this.options.length>=this.limit)
{var rmOpt=this.options.pop();var opt=this.removeOption(rmOpt);opt=null;}
var _option=new FilterCheckbox(option.settings);_option.optionSet=this;this.indexOption(_option);var all=this.options.shift();this.options.unshift(_option);$(_option).insertAfter(all);this.options.unshift(all);_option._select();return _option;}}
function KeywordFilter(module,resultSet)
{if(resultSet==null)
return false;if(!module)
{var module={method:"keyword",type:"keyword",label:"keywords",field:"keyword",queryFormat:queryFormat.EWIG}}
this.resultSet=resultSet;for(i in module)
this[i]=module[i];objects.push(this);this.init();}
KeywordFilter.prototype=new ResultFilter(null);KeywordFilter.prototype.display=function()
{return false;}
KeywordFilter.prototype.init=function()
{if(document.forms.keywordFilter==null)
return false;var f=ajaxForm(document.forms.keywordFilter);f.resultSet=this.resultSet;f.resultFilter=this;f.resultFilter.input=initKeywordField(f.elements.keyword,{callback_delete:{object:f.resultFilter,method:"clearFilter"}});f.resultFilter.f=f;f.select=function()
{if((!this.resultFilter.value)||(this.resultFilter.value==this.resultFilter.default_value))
{this.resultFilter.clearFilter();}
else if(this.elements.keyword.value)
{this.resultSet.getResults({filter:this.resultFilter,sort:{label:"relevance",dir:"ASC"}});}}
f.submit=function()
{this.resultFilter.setValues(this.elements.keyword.value);this.resultFilter.setParameters();trackEvent(["sort_box","keyword"]);this.select();}
f.init();return f;}
KeywordFilter.prototype.filterResult=function(result)
{var matchCnt=result.getKeywordRelevance(this.value);return(matchCnt>0?true:false);}
KeywordFilter.prototype.clearFilter=function(fromResult)
{this.setValues(false);this.resetInputs();if(!fromResult)
this.resultSet.clearFilters(this.getLabel());}
KeywordFilter.prototype.filterResults=function(results)
{var currentResults=[];for(var index in results)
{var result=results[index];if(this.filterResult(result))
currentResults.push(result);}
return currentResults;}
KeywordFilter.prototype.resetInputs=function(fromResult)
{this.input.setValue('');if(!fromResult)
this.setParameters();}
KeywordFilter.prototype.updateFilter=function(values)
{this.input.setValue(values);this.setValues(values);}
function AnchorFilter(module,resultSet)
{this._construct(module,resultSet);}
AnchorFilter.prototype=new ResultFilter;AnchorFilter.prototype.init=function(optionSet)
{for(var optionID in this.options)
{optionLabel=this.options[optionID].text;var name=optionLabel;var value=optionID;var option=document.createElement("span");option.className="optionbox";option.filter=this;urlParams={locationID:this.resultSet.locationID,locationName:this.resultSet.locationName,categoryID:this.resultSet.categoryID,categoryName:this.resultSet.categoryName,dateID:optionID,dateName:optionLabel,loader:5};var url=getFormattedUrl(urlParams,"search");option.node_id=optionID;option.node_value=optionLabel;var link=document.createElement("a");link.appendChild(document.createTextNode(name.toLowerCase()));link.href=url;link.option=option;option.select=function()
{this.filter.resultSet.dateID=this.node_id;this.filter.resultSet.setDateID(dateID);this.filter.resultSet.dateName=this.node_value;this.filter.resultSet.fetchNewResults({page:new Parameter("page",null,0),sort:new Parameter("sort",null,{label:"relevance",dir:"ASC"}),filters:new Parameter("filters",null,[])});}
option.appendChild(link);if(value==this.defaultValue)
{$(link).addClass("sel");}
var comma=document.createTextNode(",");option.appendChild(comma);optionSet.appendChild(option);}
option.removeChild(comma);return optionSet;}
function AnchorCatsFilter(module,resultSet)
{this._construct(module,resultSet);}
AnchorCatsFilter.prototype=new ResultFilter;AnchorCatsFilter.prototype.init=function(optionSet)
{var categories=[];for(var i in this.options)
{categories.push(this.options[i]);}
if(categories.length<=0)
{return false;}
var listSet=document.createElement("div");var catLen=categories.length;charLen=120;if(catLen>8)
catLen=8;totalLength=0;for(var j=0;j<catLen;j++)
{var item=categories.shift();if(!item.node_value)
continue;var itemDiv=document.createElement("span");var length=item.node_value.length;totalLength=totalLength+length;var urlparams={locationID:this.resultSet.locationID,locationName:this.resultSet.locationName,categoryID:item.node_id,categoryName:item.node_value};var url=getFormattedUrl(urlparams,"search");itemDiv.innerHTML="<a href=\""+url+"\">"+item.node_value.toString().toLowerCase()+"</a>"+(j<(catLen-1)?",&nbsp;&nbsp;&nbsp;":"&nbsp;");itemDiv.totalLength=totalLength;$(itemDiv).click(function()
{trackEvent(["filters","related_categories"]);});listSet.appendChild(itemDiv);}
var minChr=46;var maxChr=64;var minChr2=120;if((totalLength>=minChr)&&(totalLength<=maxChr))
{for(j=(listSet.childNodes.length-1);j>0;j--)
{var node=listSet.childNodes[j];if((node.totalLength>=minChr)&&(node.totalLength<=maxChr))
{listSet.removeChild(node);}
else if(node.totalLength<minChr)
{j=-1;}}}
else if((totalLength>=minChr2))
{for(j=(listSet.childNodes.length-1);j>0;j--)
{var node=listSet.childNodes[j];if((node.totalLength>=minChr2))
{listSet.removeChild(node);}
else if(node.totalLength<minChr2)
{j=-1;}}}
$(optionSet).append(listSet);var clear=document.createElement("div");$("clear").addClass("clear");$(optionSet).append(clear);var urlparams={locationID:this.resultSet.locationID,locationName:this.resultSet.locationName};var allLink=document.createElement("a");allLink.href=getFormattedUrl(urlparams,"location");;allLink.innerHTML="...view all categories";var arrow=document.createElement("span");arrow.innerHTML="&nbsp;&#187;"
var allCtr=document.createElement("span");allCtr.className="all";allCtr.appendChild(document.createTextNode(" "));allCtr.appendChild(allLink);allCtr.appendChild(arrow);listSet.appendChild(allCtr);$(optionSet).addClass("relatedCategories");return optionSet;}
function EnumFilter()
{}
EnumFilter.prototype=new ResultFilter;EnumFilter.prototype.indexResult=function(result)
{if(this.resultIndex[OPTION_ALL]==null)
this.resultIndex[OPTION_ALL]=[];for(var i in result.facets.categorySet)
{if(this.resultIndex[i]==null)
this.resultIndex[i]=[];this.resultIndex[i].push(result);}
this.resultIndex[OPTION_ALL].push(result);}
EnumFilter.prototype.deserialize=function()
{var value=null;var value=this.value.join(",");if(value!=null)
return this.field+":"+value;}
EnumFilter.prototype.filterResult=function(result)
{return false;}
EnumFilter.prototype.resetInputs=function(fromResult)
{this.values=[];var option=this.optionSet.getOptionByID(OPTION_ALL);this.optionSet.values.clear();option._select();if(option.getValue()==OPTION_ALL)
{var options=this.optionSet.options;for(var i in options)
if(options[i]!==option)
options[i]._unselect();}
if(!fromResult)
this.setParameters();}
EnumFilter.prototype.filterResults=function(results)
{var _results=[];var values=this.optionSet.values;for(var index in results)
{var result=results[index];if(values.valid([result.facets[this.field]]))
_results.push(result);}
return _results;return currentResults;}
EnumFilter.prototype.clearFilter=function(fromResult)
{this.optionSet.values.clear();this.setValues(this.optionSet.getValues());this.resultSet.clearFilter(this.getLabel());}
EnumFilter.prototype.applyToResults=function()
{this.setValues(this.optionSet.getValues());var hadData=false;var values=this.optionSet.values;if((values.length<1)||(values[OPTION_ALL]))
{this.clearFilter();}
else
{this.resultSet.getResults({filter:this});}}
EnumFilter.prototype.updateData=function()
{values=this.value;}
EnumFilter.prototype._destruct=function()
{for(var i in this)
this[i]=null;}
EnumFilter.prototype.updateFilter=function(values)
{if(values.replace!=null)
var values=[values];for(var i in values)
if(this.optionSet.options[values[i]]!=null)
{this.optionSet.getOptionByID(values[i])._select();this.optionSet.values.add(values[i],values[i]);}}
EnumFilter.prototype.display=function()
{fs=document.createElement("fieldset");this.fieldset=fs;var more=this.getMore();$(fs).addClass(this.type);label=document.createElement("label");label.appendChild(document.createTextNode(this.label));if(this.byline)
{var small=document.createElement("small");small.innerHTML="&nbsp;"+"("+this.byline+")";label.appendChild(small);}
var clear=document.createElement("div");clear.className="clear";fs.appendChild(label);fs.appendChild(this.optionSet.getElements());fs.appendChild(clear);while(more.length>0)
fs.appendChild(more.pop());this.fieldset=fs;$("#filterContent").append(fs);}
EnumFilter.prototype.getContainer=function()
{return this.fieldset;}
EnumFilter.prototype.getMore=function()
{return[];}
function CategoryFilter(module,resultSet)
{if(resultSet!=null)
{this.resultSet=resultSet;this.options=this.resultSet.categorySet;for(i in module)
this[i]=module[i];objects.push(this);this.optionSet=new OptionMgr({field:this.field,resultSet:this.resultSet,filter:this});this.resultIndex={};}}
CategoryFilter.prototype=new EnumFilter;CategoryFilter.prototype.setOptions=function(options)
{this.options=options;}
CategoryFilter.prototype.getMore=function()
{this.setOptions(this.resultSet.categorySet);this.init();var moreLink=document.createElement("a");moreLink.innerHTML="...more categories&nbsp;<span>&#187;</span>";moreLink.className="morelink";moreLink.filter=this;moreLink.onclick=function()
{var filter=this.filter;var optionset=filter.optionSet.getOptionSet("popup");optionset.display();}
this.moreLink=moreLink;return[moreLink];}
CategoryFilter.prototype.resetInputs=function(fromResult)
{if(fromResult)
{var main=this.optionSet.getOptionSet("main");var all=main.getOptionByID(OPTION_ALL);if(all!=null)
all.select();}
else
{}}
CategoryFilter.prototype.init=function()
{var count=0;var allOption=new FilterCheckbox({value:OPTION_ALL,text:"All",field:this.field,count:this.resultIndex[OPTION_ALL].length,checked:true});this.optionSet.getOptionSet("main").addOption(allOption);allOption._select();for(var optionValue in this.options)
{optionLabel=this.options[optionValue].name;if(optionLabel==null)
continue;var params={value:optionValue,type:"eq"};var len=(this.resultIndex[optionValue]!=null?this.resultIndex[optionValue].length:0);this.optionSet.addOption({value:optionValue,text:optionLabel,field:this.field,count:len});}
var count=this.optionSet.getOptionSet("popup").getOptions().length;if(count<4)
{this.hideMoreInfo=true;}
var data={action:"organizeCategories"};for(var i in this.options)
data[i]=i;var request=new AjaxRequest(AJAX_PATH+"result_requests.php",{object:this,method:"organizeOptions"},data,'GET');request.makeRequest();return this.optionSet;}
CategoryFilter.prototype.organizeOptions=function(data)
{this.optionSet.getOptionSet("popup").categoryScaffold=data;}
CategoryFilter.prototype.updateFilter=function(values)
{if(values.replace!=null)
var values=[values];this.optionSet.setValues(values);}
CategoryFilter.prototype.filterResults=function(results)
{var _results=new Array();var values=this.optionSet.getValues();if(values.length==0)
return results;for(var r in results)
{var result=results[r];for(var v in values)
{if(result.facets.categorySet[v]!=null)
{_results.push(results[r]);break;}}}
return _results;}
function SelectFilter()
{}
SelectFilter.prototype=new ResultFilter;SelectFilter.prototype.deserialize=function()
{var value=null;var value=this.value;if(value!=null)
return this.field+":"+value;}
SelectFilter.prototype.filterResult=function(result)
{var values=this.optionSet.getValues();if((result.facets.location!=null)&&(result.facets.location.state!=null))
if(values==result.facets.location.state)
return result;}
SelectFilter.prototype.filterResults=function(results)
{var finalResults=new Array();var values=this.optionSet.getValues();for(var r in results)
{var result=results[r];if((result.facets.location!=null)&&(result.facets.location.state!=null))
if(values==result.facets.location.state)
finalResults.push(result);}
return finalResults;}
SelectFilter.prototype.resetInputs=function(fromResult)
{this.optionSet.getOptionByID(OPTION_ALL).select();}
SelectFilter.prototype.clearFilter=function(fromResult)
{if(!fromResult)
{this.setValues([]);this.resultSet.clearFilter(this.getLabel());}}
SelectFilter.prototype.applyToResults=function()
{this.setValues(this.optionSet.getValues());var value=this.optionSet.getValues();if((value==OPTION_ALL)||(!value))
this.clearFilter();else
this.resultSet.getResults({filter:this});}
SelectFilter.prototype.updateData=function()
{values=this.value;}
SelectFilter.prototype.indexResult=function(result)
{if((result.facets.location==null)||(result.facets.location.state==null))
return false;var index=result.facets.location.state;if(this.resultIndex[index]==null)
this.resultIndex[index]=[];if(this.resultIndex[OPTION_ALL]==null)
this.resultIndex[OPTION_ALL]=[];this.resultIndex[index].push(result);this.resultIndex[OPTION_ALL].push(result);}
SelectFilter.prototype.updateFilter=function(value)
{if(this.value==value)
return false;if(value.push!=null)
var value=value.pop();if(this.optionSet.getOptionByID(value))
this.optionSet.getOptionByID(value).select();}
function RatingFilter(module,resultSet)
{if(resultSet==null)
return false;this.resultSet=resultSet;for(i in module)
this[i]=module[i];objects.push(this);this.optionSet=new OptionSet({field:this.field,resultSet:this.resultSet,filter:this,isNode:true,optionType:"ratingOption"});this.resultIndex=new BinaryTree(this.field);this.resultIndex.hldr=this;this.resultIndex.doIteration=function(node)
{this.result=this.result.concat(node.data);}
this.init(this.optionSet);}
RatingFilter.prototype=new EnumFilter;RatingFilter.prototype.init=function(optionSet)
{var count=0;optionSet.all_selected=true;for(var optionValue in this.options)
{if(count>4)
break;var option=new RatingOption({field:this.field,value:optionValue,text:this.options[optionValue]},optionSet);optionSet.addOption(option);}
return optionSet;}
RatingOption=function(params)
{if(params)
{this.settings=params;this.settings.field='rating';var node=document.createElement("li");node.className="optionbox";for(var i in this)
try{node[i]=this[i];}catch(e){}
node.init();return node;}}
RatingOption.prototype=new FilterCheckbox();RatingOption.prototype.getName=function()
{return this.settings.label;}
RatingOption.prototype.init=function()
{this.type=this.type;this.label=document.createElement("div");$(this).css("display","block");$(this).css("float","none");$(this).css("clear","both");if(this.getValue()!=OPTION_ALL)
{this.label.className="starContainer";for(var i=1;i<=5;i++)
{var star=document.createElement("div");$(star).addClass("star");$(star).css("float","left");if(this.getValue()>=i)
$(star).addClass("star_on");else
$(star).addClass("star_off");this.label.appendChild(star);}}
else
{$(this.label).css("float","left");this.label.appendChild(document.createTextNode(this.getText().toLowerCase()));}
var option=this.generateInput();this.appendChild(this.checkbox);this.appendChild(this.label);if(!navigator.isIE())
this.customizeInput(option);}
function StateFilter(module,resultSet)
{this.resultSet=resultSet;for(i in module)
this[i]=module[i];objects.push(this);this.optionSet=new SelectOptionSet({field:this.field,resultSet:this.resultSet,filter:this,tagName:"select",online:false});this.resultIndex={};this.init();}
StateFilter.prototype=new SelectFilter;StateFilter.prototype.init=function()
{this.optionSet.addOption(new FilterOption({field:this.field,label:"choose a state",value:OPTION_ALL}));for(var o in this.options)
{if((o.length>1)&&(this.options[o]))
{var cnt=(this.resultIndex[o]?this.resultIndex[o].length:0);this.optionSet.addOption(new FilterOption({field:this.field,label:this.options[o],value:o,count:cnt}));}}}
StateFilter.prototype.display=function()
{var fs=document.createElement("fieldset");$(fs).addClass(this.type);this.fieldset=fs;var moreLink=document.createElement("a");label=document.createElement("label");label.appendChild(document.createTextNode(this.label));fs.appendChild(label);fs.appendChild(this.optionSet.getElements());var mapicon=document.createElement("div");mapicon.className="map-icon";maptext=document.createElement('div');maptext.className="map-text";maptext.appendChild(document.createTextNode("...or expand search with map"));moreLink.appendChild(maptext);moreLink.appendChild(mapicon);moreLink.className="morelink";moreLink.filter=this;moreLink.id="stateFilterLink";moreLink.onmouseover=function()
{}
moreLink.onclick=function()
{if(Goby.exists('searchbox'))
Goby.get('searchbox').getField('where').openPanel();}
fs.appendChild(moreLink);$("#filterContent").append(fs);}
function SelectOptionSet(params)
{this._construct(params);this.values=null;this.value=OPTION_ALL;this.initD_OH_EM();}
SelectOptionSet.prototype=new OptionSet();SelectOptionSet.prototype.initD_OH_EM=function()
{this.container=document.createElement('div');$(this.container).addClass("selectWrapper");this.selector=new Selector({container:this.container,select:this.dom,className:"selectGhost",id:"stateGhost"},{callbackObject:this,callbackMethod:"selectGhostOption"});}
SelectOptionSet.prototype.getValues=function()
{return this.value;};SelectOptionSet.prototype.selectGhostOption=function(option)
{this.selectOption(option);}
SelectOptionSet.prototype.getElements=function(params)
{if(this.online==false)
{for(var i in this.options)
{var op=this.options[i];if((this.filter.resultIndex[op.getValue()]))
{op.setCount(this.filter.resultIndex[op.getValue()].length);op.updateGhost();}}
this.selector.display();}
return this.container;}
SelectOptionSet.prototype.selectOption=function(option)
{this.value=option.getValue();this.selectedOption=option;this.filter.applyToResults();this.filter.setParameters();}
SelectOptionSet.prototype.removeOptions=function()
{for(var i in this.options)
{this.options[i].ghost.remove();this.options[i].close();}
this.options=[];this.optionIndex=[];}
SelectOptionSet.prototype.addOption=function(option)
{option.optionSet=this;this.indexOption(option);this.options.push(option);option.setCount(option.settings.count);this.selector.addOption(option);}
function LocationFilter(module,resultSet)
{this.resultSet=resultSet;for(i in module)
this[i]=module[i];objects.push(this);this.coordinates=[];this.optionSet=new SelectOptionSet({field:this.field,resultSet:this.resultSet,filter:this,tagName:"select",online:true});this.resultIndex={};this.init();}
LocationFilter.prototype=new StateFilter;LocationFilter.prototype.queryFormat=queryFormat.PRE;LocationFilter.prototype.reloadOptions=function(data)
{for(var i in data.options)
{var item=data.options[i];if(this.optionSet.getOptionByID(item.id))
{var option=this.optionSet.getOptionByID(item.id);option.setCount(item.count);option.updateGhost();}
else
{this.optionSet.addOption(new FilterOption({field:this.field,label:item.name,value:item.id,count:item.count}));}}
this.optionSet.selector.updatePreamble();}
LocationFilter.prototype.preloadOptions=function(data)
{this.loadOptions(data);this.optionSet.selector.display();}
LocationFilter.prototype.loadOptions=function(data)
{if(data.options)
{var dft=data.defaultOption;this.optionSet.addOption(new FilterOption({field:this.field,label:dft.name,value:dft.value}));for(var o in data.options)
{var option=data.options[o];if(option!=null)
{this.optionSet.addOption(new FilterOption({field:this.field,label:option.name,value:option.id,count:option.count}));}}}}
LocationFilter.prototype.init=function(reinit)
{this.categoryID=this.resultSet.categoryID
var callback=(reinit?"reloadOptions":"preloadOptions");var request=new AjaxRequest(AJAX_PATH+"result_requests.php",{object:this,method:callback},{action:'getLocationsByCategory',categoryID:this.resultSet.categoryID,locationID:this.resultSet.locationID},'GET');request.makeRequest();}
LocationFilter.prototype._update=function()
{if(this.categoryID!=this.resultSet.categoryID)
this.init(true);}
LocationFilter.prototype.filterResults=function(results)
{return results;}
LocationFilter.prototype.serialize=function()
{return this.optionSet.getValues();}
LocationFilter.prototype.applyToResults=function()
{var option=this.optionSet.selector.getCurrent();if(option.getValue()==OPTION_ALL)
{var value=false;this.value=value;var optionData={label:"United States",id:LOC_US,parent:false,type:TYPE_LOCATION}
this.setValues(false);this.setParameters();this.resultSet.setLocationID(LOC_US);}
else
{var value=this.optionSet.getValues();this.value=value;var optionData={label:option.settings.label,id:option.getValue(),parent:LOC_US,type:TYPE_LOCATION}
this.resultSet.setLocationID(value);}
this.resultSet.loader=true;breadcrumbMgr.add(optionData);optionData.name=optionData.label;this.resultSet.updateTitle({location:optionData});if(Goby.has('searchbox'))
{var field=Goby.get("searchbox").getField('where');field.setValue(optionData.label);field.setID(optionData.id);}
this.resultSet.fetchNewResults({page:new Parameter("page",null,0),sort:new Parameter("sort",null,{label:"relevance",dir:"ASC"}),filters:new Parameter("filters",null,value)});}
function HeirarchyFilter(module,resultSet)
{this.resultSet=resultSet;this.options=[];for(i in module)
this[i]=module[i];objects.push(this);this.parentCrumb=null;this.optionSet=new HierarchyOptionMgr({field:this.field,resultSet:this.resultSet,filter:this,optionType:'FilterLink'});this.moreLink=null;this.resultIndex={};}
HeirarchyFilter.prototype=new CategoryFilter;HeirarchyFilter.prototype.queryFormat=queryFormat.PRE;HeirarchyFilter.prototype.indexResult=function(result)
{return false;}
HeirarchyFilter.prototype.updateFilter=function(values)
{}
HeirarchyFilter.prototype.setOptions=function(options)
{this.options=options;}
HeirarchyFilter.prototype.loadOptions=function(data)
{this.optionSet.removeOptions();if(data.options)
{this.updatable=data.children;var dft=data.defaultOption;option=data.options[this.categoryID];if(!data.options)
return false;var option=data.defaultOption;this.optionSet.addOption({value:option.node_id,text:option.node_value,field:this.field,count:option.child_count,all:true,active:option.active});if(data.options.self)
var option=data.options.self;this.parentCrumb=breadcrumbMgr.add({id:option.node_id,label:option.node_value,parent:option.parent,type:TYPE_CATEGORY});var primaryOption=new FilterLink({value:option.node_id,text:option.node_value,field:this.field,count:option.child_count,all:false,active:option.active});for(var o in data.options)
{var option=data.options[o];if(option!=null)
{this.optionSet.addOption({value:option.node_id,text:option.node_value,field:this.field,count:option.child_count,active:option.active});}}
this.optionSet.selectOption(primaryOption,this);this.optionSet.getOptionSet("main").getElements();}
if(data.count>4)
this.addMoreLink();else if(this.hasMoreLink())
this.removeMoreLink();}
HeirarchyFilter.prototype.getMore=function()
{this.setOptions(this.resultSet.categorySet);this.init();return[];}
HeirarchyFilter.prototype.hasMoreLink=function()
{return(this.moreLink!=null?true:false);}
HeirarchyFilter.prototype.addMoreLink=function()
{this.getContainer().appendChild(this.getMoreLink());}
HeirarchyFilter.prototype.removeMoreLink=function()
{this.getContainer().removeChild(this.moreLink);this.moreLink=null;}
HeirarchyFilter.prototype.getMoreLink=function()
{if(this.moreLink==null)
{var moreLink=document.createElement("a");moreLink.innerHTML="...more categories&nbsp;<span>&#187;</span>";moreLink.className="morelink";moreLink.filter=this;moreLink.onclick=function()
{var filter=this.filter;var optionset=filter.optionSet.getOptionSet("popup");optionset.display();}
this.moreLink=moreLink;}
return this.moreLink;}
HeirarchyFilter.prototype.init=function()
{this.categoryID=parseInt(resultSet.categoryID);this.optionSet.removeOptions();var request=new AjaxRequest(AJAX_PATH+"result_requests.php",{object:this,method:"loadOptions"},{action:'getRelatedCategories',categoryID:this.resultSet.categoryID,locationID:this.resultSet.locationID},'GET');var dom=this.optionSet.getOptionSet("main")._dom;request.makeRequest({useLoader:true,loaderParent:dom,loaderClass:"loader_filter"});}
HeirarchyFilter.prototype.filterResults=function(results)
{return results;}
HeirarchyFilter.prototype._update=function()
{if(this.categoryID!=this.resultSet.categoryID)
{return(this.updatable?this.init():false);}}
HeirarchyFilter.prototype.setValues=function(value)
{this.value=value;}
HeirarchyFilter.prototype.applyToResults=function()
{var value=this.value;this.resultSet.setCategoryID(value);this.resultSet.loader=true;this.resultSet.fetchNewResults({page:new Parameter("page",null,0),sort:new Parameter("sort",null,{label:"relevance",dir:"ASC"}),filters:new Parameter("filters",null,[])});}
function HierarchyOptionMgr(params)
{for(var p in params)
this[p]=params[p];this.optionType="FilterLink";this.optionsets={'popup':new PopupLinkSet(),'main':new basicLinkSet()};for(var i in this.optionsets)
{this.optionsets[i].optionMgr=this;this.optionsets[i].filter=this.filter;}
this._construct();}
HierarchyOptionMgr.prototype=new OptionMgr();HierarchyOptionMgr.prototype.unselectOption=function(option)
{var popup=this.getOptionSet("popup");if(popup.getOptionByID(option.getValue()))
popup.getOptionByID(option.getValue()).unselect();if(this.values.valid(option.getValue()))
{this._unselect(option);this.filter.setValues(this.getValues());this.filter.setParameters();}}
HierarchyOptionMgr.prototype.selectOption=function(option,set)
{var popup=this.getOptionSet("popup");var main=this.getOptionSet("main");this.selectedOption=option;if(set===popup)
{this.filter.resultSet.updateTitle({category:{id:option.getValue(),name:option.getText()}});Goby.get('searchbox').autoSelect('what',option.getValue(),option.getText());if(this.parentCrumb!=null)
breadcrumbMgr.add({id:option.getValue(),label:option.getText(),parent:this.parentCrumb.node_id,type:TYPE_CATEGORY});else
breadcrumbMgr.add({id:option.getValue(),label:option.getText(),type:TYPE_CATEGORY});this.value=option.getValue();this.filter.setValues(option.getValue());this.filter.applyToResults();this.filter.setParameters();main.updateOption(option);}
else if(set===main)
{this.filter.resultSet.updateTitle({category:{id:option.getValue(),name:option.getText()}});Goby.get('searchbox').autoSelect('what',option.getValue(),option.getText());var parentCrumb=this.filter.parentCrumb;breadcrumbMgr.add({id:option.getValue(),label:option.getText(),parent:parentCrumb.node_id,type:TYPE_CATEGORY});this.filter.setValues(option.getValue());this.filter.applyToResults();this.filter.setParameters();popup.updateOption(option);}
else
{main.updateOption(option);popup.updateOption(option);return false;}}
function PopupLinkSet(){this.title="more categories";this._construct();this.selectedOption;}
PopupLinkSet.prototype=new PopupOptionSet();PopupLinkSet.prototype.newoptions=[];PopupLinkSet.prototype.clearValues=function()
{if(this.selectedOption!=null)
this.selectedOption.unselect();this.selectedOption=null;}
PopupLinkSet.prototype.display=function()
{var area=document.createElement("div");var title=document.createElement("h3");title.innerHTML=this.title;area.appendChild(title);area.appendChild(this.getElements());area.id="categoryPopup";var len=this.getOptions().length;var cols=1;var width=cols*230;if(len>32)
$(this._dom).css("height","220px");$(this._dom).css("width",width);var cancel=document.createElement("a");cancel.innerHTML="cancel";cancel.className="cancelLink";cancel.optionset=this;cancel.onclick=function()
{var data=window.compileLink(null,this);this.href=data.href;this.hash=data.hash;this.optionset.popup.close();}
var clear=document.createElement("div");clear.className="clear";area.appendChild(clear);area.appendChild(cancel);this.popup=new Popup
({container:this.optionMgr.filter.fieldset,content:area,isMask:false,customClass:false,isShell:true,prepend:true,position:"right",fixed:false,automargin:false,ratio:0.5});this.popup.display();$(this.popup.getNode()).css("width",width);}
PopupLinkSet.prototype.unselectOption=function(option)
{if(option!=null)
this.selectedOption._unselect();};PopupLinkSet.prototype.updateOption=function(option)
{if(this.selectedOption!=null)
this.selectedOption._unselect();var option=this.getOptionByID(option.getValue());option._select();this.selectedOption=option;}
PopupLinkSet.prototype.submitable=false;PopupLinkSet.prototype.selectOption=function(option)
{if(this.selectedOption!=null)
this.selectedOption._unselect();this.selectedOption=option;this.optionMgr.selectOption(this.selectedOption,this);if(this.popup!=null)
this.popup.close();};function basicLinkSet(params){this._construct();this.limit=4;}
basicLinkSet.prototype=new OptionSet();basicLinkSet.prototype.unselectOption=function(option)
{if(this.selectedOption!=null)
this.selectedOption._unselect();},basicLinkSet.prototype.updateOption=function(option)
{if(this.selectedOption!=null)
this.selectedOption._unselect();this.selectedOption=this.prependOption(option);}
basicLinkSet.prototype.selectOption=function(option)
{this.values.clear();if(this.selectedOption===option)
return false;if(this.selectedOption!=null)
this.selectedOption._unselect();this.selectedOption=option;this._select(option);this.optionMgr.selectOption(option,this);}
basicLinkSet.prototype.prependOption=function(option)
{if(option.getValue()==OPTION_ALL)
return false;if(this.getOptionByID(option.getValue()))
{var _option=this.getOptionByID(option.getValue());try
{_option._select();return _option;}
catch(e)
{alert(e.message);}}
else
{if(this.options.length>=this.limit)
{var rmOpt=this.options.pop();var opt=this.removeOption(rmOpt);opt=null;}
var _option=new FilterLink(option.settings);_option.optionSet=this;this.indexOption(_option);var all=this.options.shift();this.options.unshift(_option);$(_option.getElement()).insertAfter(all.getElement());this.options.unshift(all);_option._select();return _option;}}
function PriceSlider(module,resultSet)
{if(resultSet==null)
return false;this.resultSet=resultSet;for(i in module)
this[i]=module[i];objects.push(this);var optionSet=document.createElement("div");optionSet.options=[];optionSet.values=[];optionSet.field=this.field;optionSet.type=this.type;optionSet.resultSet=this.resultSet;optionSet.hldr=this;optionSet._destruct=function()
{try
{this.hldr.$slideFilter.slider('destroy');}
catch(e)
{}}
objects.push(optionSet);this.resultIndex=null;this.optionSet=optionSet;this.optionSet=this.init(optionSet);}
PriceSlider.prototype=new ResultFilter;PriceSlider.prototype.queryFormat=queryFormat.PRE;PriceSlider.prototype.indexResult=function(result)
{return false;}
PriceSlider.prototype.deserialize=function()
{var value=this.value.join("-");}
PriceSlider.prototype.update=function(module)
{if(this.options.max<module.value.max)
this.options.max=module.value.max;if(this.options.min>module.value.min)
this.options.min=module.value.min;this.resetInputs();}
PriceSlider.prototype.filterResult=function(result)
{if(!result.facets[this.field])
return false;var max=this.value.max;var min=this.value.min;if((result.facets[this.field].lo<=max)&&(result.facets[this.field].lo>=min)||(result.facets[this.field].hi<=max)&&(result.facets[this.field].hi>=min)||(result.facets[this.field].hi>=min)&&(result.facets[this.field].lo<=max)||(result.facets[this.field].lo<=max)&&(result.facets[this.field].hi==-1))
{return true;}
else
return false;}
PriceSlider.prototype.filterResults=function(results)
{var currentResults=[];for(var index in results)
{var result=results[index];if(this.filterResult(result))
currentResults.push(result);}
return currentResults;}
PriceSlider.prototype.resetInputs=function(fromResult)
{this.setValues({min:this.options.min,max:this.options.max});this.displaySlider();this.updateData();if(!fromResult)
this.setParameters();}
PriceSlider.prototype.updateFilter=function(values)
{this.setValues({min:values[0],max:values[1]});this.displaySlider();this.updateData();}
PriceSlider.prototype.init=function()
{var optionSet=this.optionSet;link=document.createElement("a");if(this.options.max==this.options.min)
return false;this.options.max=(this.options.max?this.options.max:500);this.options.min=(this.options.min?this.options.min:50);this.setValues(this.options);$(this.optionSet).addClass("sliderContainer");var inputmax=document.createElement("div");var slideFilter=document.createElement("div");var slideWrap=document.createElement("div");var inputmin=document.createElement("div");var unitBtn=document.createElement("input");var clearBtn=document.createElement("input");this.inputs={max:document.createElement("div"),min:document.createElement("div"),top:document.createElement("div"),bot:document.createElement("div")}
inputmax.style.display="none";inputmin.style.display="none";inputmax.className="sliderMax";inputmin.className="sliderMin";inputmax.appendChild(document.createTextNode(formatFacet(this.options.max,this.format)+"+"));inputmin.appendChild(document.createTextNode(formatFacet(this.options.min,this.format)));inputmax.name=this.label+"[max]";inputmin.name=this.label+"[min]";this.inputs.top.appendChild(document.createTextNode(formatFacet(this.options.max,this.format)+"+"));this.inputs.bot.appendChild(document.createTextNode(formatFacet(this.options.min,this.format)));link.max=inputmax;link.min=inputmin;unitBtn.type="button";unitBtn.value="Test Tha Spanz";clearBtn.type="button";clearBtn.value="Clear";clearBtn.filterSet=this;clearBtn.onclick=function(e)
{this.filterSet.clearFilter();}
slideWrap.className="slideWrapWrap";slideFilter.className="slideWrapper";slideFilter.filterSet=this;h=95;switch(this.position)
{case"horizontal":var labelWrapper=document.createElement("div");labelWrapper.className="sliderPopup";$(this.inputs.top).css("position","relative");$(this.inputs.bot).css("position","relative");$(this.inputs.top).css("display","inline");$(this.inputs.bot).css("display","inline");labelWrapper.appendChild(this.inputs.bot);labelWrapper.appendChild(document.createTextNode(" to "));labelWrapper.appendChild(this.inputs.top);optionSet.appendChild(labelWrapper);optionSet.appendChild(inputmax);slideWrap.appendChild(slideFilter);optionSet.appendChild(slideWrap);optionSet.appendChild(inputmin);break;case"vertical":optionSet.appendChild(inputmax);slideWrap.appendChild(slideFilter);optionSet.appendChild(slideWrap);optionSet.appendChild(inputmin);optionSet.appendChild(this.inputs.bot);optionSet.appendChild(this.inputs.top);$(this.inputs.top).css("margin-top","-10px");$(this.inputs.bot).css("margin-top","85px");break;}
this.slideFilter=slideFilter;this.displaySlider();$(this.optionSet).addClass("wideFilter");return optionSet;}
PriceSlider.prototype.displaySlider=function()
{if(this.$slideFilter!=null)
{this.$slideFilter.slider('destroy');}
$(this.slideFilter).slider({orientation:(this.position?this.position:'vertical'),min:this.options.min,max:this.options.max,range:true,filterSet:this,values:[this.value.min,this.value.max],start:function(e,ui)
{var h=95;baseMax=parseInt(this.filterSet.options.max);baseMin=parseInt(this.filterSet.options.min);var diff=Math.abs(baseMax-baseMin);var maxPc=(Math.abs(ui.values[1]-baseMin)/diff);var minPc=(Math.abs(ui.values[0]-baseMin)/diff);},stop:function(event,ui)
{},change:function(event,ui)
{this.filterSet.setValues({min:ui.values[0],max:ui.values[1]});this.filterSet.updateData();this.filterSet.setParameters();if((ui.values[1]==this.filterSet.options.max)&&(ui.values[0]==this.filterSet.options.min))
{this.filterSet.clearFilter();}
else
{this.filterSet.applyToResults();}},slide:function(event,ui)
{var h=95;this.filterSet.setValues({min:ui.values[0],max:ui.values[1]});this.filterSet.updateData();baseMax=parseInt(this.filterSet.options.max);baseMin=parseInt(this.filterSet.options.min);var diff=Math.abs(baseMax-baseMin);var maxPc=(Math.abs(ui.values[1]-baseMin)/diff);var minPc=(Math.abs(ui.values[0]-baseMin)/diff);if(Math.abs(maxPc-minPc)<.10)
{$(this).stop();$(this).mouseup();try
{$(this).dragend();}
catch(e)
{displayException(e);}}
else
{}}});this.$slideFilter=$(this.slideFilter);}