var currentTrendsOffset=0;var engineDescriptions={web:"Get a listing of best-matching web pages according to the entered criteria",wpen:"Restrict your search to Wikipedia, a free online encyclopedia with millions of articles",img:"Search image content available in the web",video:"Locate relevant videos to your search, including YouTube",feed:"Search on RSS and ATOM feeds",blog:"Restrict your search to personal blogs",news:"Search your query among more than 25,000 news sources updated continuously",patent:"Extend your search to the United States patent database",local:"Find places near your that match your search query",book:"Locate books that are relevant to what you are looking for",flickr:"Search among Flickr's large image library",twitter:"Find the latest tweets that match your query",digg:"Search on digg user-submitted topics",facebook:"Search among Facebook users public information",rel:"Show recommended searches based on your input",amazon:"Search products from the internet's largest e-tailer",scribd:"Find online documents in the largest social publishing and reading site in the world",bing:"Search all the web on Bing, one of the most popular search engines",bnews:"Search results from the Bing news portal",bimg:"Find images from the Bing image database",shopzilla:"Search on Shopzilla.com's price comparison database",custom:"User-created engine targeted to a specific topic or theme"};function tabSelectorChanged(){var c=document.getElementById("tabSelector").selectedIndex+1;if(c!=currentTab){var b=$("#options-column-right").height();document.getElementById("options-column-left").innerHTML="";var a='<div class="settings-desc" style="height:';a+=b+'px;"><div style="padding-top:>'+Math.floor(b/3);a+='px;">Loading...</div></div>';document.getElementById("options-column-right").innerHTML=a;currentTab=c;$.getJSON("/getconf?tab="+currentTab,function(d){configurationString=d;parseConfiguration();createEntries()})}}function createEntries(){var a=document.getElementById("options-column-left");var g=(document.all&&(typeof(window.JSON)=="undefined"))?"className":"class";if(showTabBar){var h=document.createElement("label");h.setAttribute("for","tabSelector");h.innerText="Tab: ";h.textContent=h.innerText;var o=document.createElement("select");o.setAttribute("id","tabSelector");o.setAttribute("onchange","tabSelectorChanged();");var l=tabsString.split("|");for(var i=0;i<l.length;i++){var n=document.createElement("option");n.text=l[i];n.value=""+(i+1);o.appendChild(n)}o.selectedIndex=currentTab-1;var b=document.createElement("div");b.setAttribute("id","tabSelectorDiv");b.appendChild(h);b.appendChild(o);a.appendChild(b)}for(var i=0;i<configuration.length;i++){var k=document.createElement("div");if(i==0){k.setAttribute(g,"selected")}k.setAttribute("target",i);var j=document.createElement("span");j.setAttribute(g,"icon");var m=document.createElement("span");m.setAttribute(g,"label");if(configuration[i].args.n){m.innerText=configuration[i].args.n}else{if(engineParam[configuration[i].type]){m.innerText=engineParam[configuration[i].type][PARAM_NAME]}else{m.innerText=configuration[i].type.substr(0,1).toUpperCase()+configuration[i].type.substr(1)}}m.textContent=m.innerText;if(configuration[i].args.i){j.style.backgroundImage="url("+baseDomainCommon+configuration[i].args.i+".png)"}else{j.style.backgroundImage="url("+baseDomainCommon+configuration[i].type+".png)"}k.appendChild(j);k.appendChild(m);a.appendChild(k)}if(showOtherEngines==1){var e=document.createElement("div");e.setAttribute("target","-1");var d=document.createElement("span");d.setAttribute(g,"icon");var f=document.createElement("span");f.setAttribute(g,"label");f.innerText="Other";f.textContent=f.innerText;d.style.backgroundImage="url("+baseDomain+"search.png)";e.appendChild(d);e.appendChild(f);a.appendChild(e)}$("#options-column-left > div[target]").click(function(p){if(!$(this).hasClass("selected")){$("#options-column-left > div").removeClass("selected");$(this).addClass("selected");var c=parseInt($(this).attr("target"));fillConfigurationPanel(c);checkFooter()}});fillConfigurationPanel(0)}$(function(){document.getElementById("search-bar-text").focus();createEntries();$("#options-button").click(function(b){var a=$(this).find("#options-button-label");if(a.hasClass("opened")){a.removeClass("opened");a.text("Show Options");$("#options-table").slideUp("fast",function(){checkFooter()})}else{a.addClass("opened");a.text("Hide Options");removeFooterMargin();$("#options-table").slideDown("fast",function(){checkFooter()})}});if(loadTrends){refreshTrends()}if(loadTwitterTrends){refreshTwitterTrends()}});function fillConfigurationPanel(e){var a=document.getElementById("options-column-right");if(e>-1){var b=createSettings(configuration[e].type,configuration[e].args);var h=[];h.push('<div class="settings-desc">',engineDescriptions[configuration[e].type],'</div><div class="settings-separator"></div>');if(b.length>0){h.push('<form method="#" onsubmit="return searchSubmit();">');h=h.concat(b);h.push("</form>")}else{h.push('<div class="nosettings">There are no options for this search</div>')}a.innerHTML=h.join("");$('#options-column-right input[type="text"]').bind("focus",function(){var c=$(this).get(0);if(c.getAttribute("emptyString")){if(c.getAttribute("isEmpty")=="true"){c.removeAttribute("isEmpty");c.value=""}}});$('#options-column-right input[type="text"]').bind("blur",function(){var c=$(this).get(0);if(c.getAttribute("emptyString")){if(c.value==""){c.setAttribute("isEmpty","true");c.value=c.getAttribute("emptyString")}}})}else{var h="";h+='<form method="#" onsubmit="return searchSubmit();" id="engineSelectionForm">';var g=true;var i="";for(var k in engineParam){if((!engineParam[k][PARAM_TARGETED])&&(k!="custom")){var l=false;for(var j=0;(j<configuration.length)&&!l;j++){if(configuration[j].type==k){l=true}}if(!l){i+='<label for="'+k+'" style="background-image: url(';i+=baseDomain+k+".png";i+=');"><input type="radio" name="engine" value="'+k+'" id="'+k+'"';if(g){i+='checked="checked"';g=false}i+=" /><span>"+engineParam[k][PARAM_NAME]+"</span></label>"}}}if(i!=""){h+="<h3>Standard Engines</h3>"+i}var f="";for(var k in engineParam){if(engineParam[k][PARAM_TARGETED]){var l=false;for(var j=0;(j<configuration.length)&&!l;j++){if(configuration[j].type==k){l=true}}if(!l){f+='<label for="'+k+'" style="background-image: url(';f+=baseDomain+k+".png";f+=');"><input type="radio" name="engine" value="'+k+'" id="'+k+'"';if(g){f+='checked="checked"';g=false}f+=" /><span>"+engineParam[k][PARAM_NAME]+"</span></label>"}}}if(f!=""){h+='<h3 class="secondSection">Targeted Engines</h3>'+f}h+="<div></div></form>";a.innerHTML=h}}function searchSubmit(){var l=document.getElementById("search-bar-text");if(l.value==""){l.focus()}else{var g="/search?q=";g+=encodeURIComponent(document.getElementById("search-bar-text").value);var a=parseInt($("#options-column-left div.selected").attr("target"));if(a>-1){if(a>0){g+="&s="+configuration[a].id}var b=engineSettings[configuration[a].type];if(b){for(var k=0;k<b.length;k++){var d=b[k];var i=document.getElementById(d[SETTING_ID]);if(i){var e=null;if(d[SETTING_TYPE]=="text"){if(i.getAttribute("isEmpty")=="true"){e=""}else{e=i.value}}else{if(d[SETTING_TYPE]=="select"){e=i.options[i.selectedIndex].value}else{if(d[SETTING_TYPE]=="checkbox"){if(i.checked){e=findKey("true",d[SETTING_OPTIONS])}else{e=findKey("false",d[SETTING_OPTIONS])}}}}if(e!=null){var j=configuration[a].args[d[SETTING_ID]];if(typeof j!="string"){j=""}if(e!=j){g+="&"+d[SETTING_ID]+"="+encodeURIComponent(e)}}}}}}else{var h=null;var f=document.getElementById("engineSelectionForm");for(var k=0;(k<f.engine.length)&&(h==null);k++){if(f.engine[k].checked){h=f.engine[k].value}}g+="&s=_"+h}if(currentTab>1){g+="&tab="+currentTab}window.location=g}return false}function trendClick(a){var c=document.getElementById("search-bar-text");var b=a.target;if(!b){b=a.srcElement}if(b.textContent){c.value=b.textContent}else{c.value=b.innerText}searchSubmit();return false}function nextTrendsClick(a){if(currentTrendsOffset<10){currentTrendsOffset+=5}refreshTrends();$("#show-previous-trends").show();if(currentTrendsOffset>=10){$("#show-next-trends").hide();$("#show-trends-sep").hide()}else{$("#show-trends-sep").show()}return false}function prevTrendsClick(a){if(currentTrendsOffset>=5){currentTrendsOffset-=5}refreshTrends();$("#show-next-trends").show();if(currentTrendsOffset<5){$("#show-previous-trends").hide();$("#show-trends-sep").hide()}else{$("#show-trends-sep").show()}return false}function refreshTrends(){$("#hottrends-content").load("/trends/"+currentTrendsOffset,null,function(){$("#hottrends-content").attr("loading","false")})}function refreshTwitterTrends(){$("#twitter-trends-content").load("/twittertrends/",null,function(){$("#twitter-trends-content").attr("loading","false")})}function checkDefaultSettings(){var i=configuration[getConfigurationIndex(currentEngine)];var d=engineSettings[i.type];var b=false;var h=false;if(d==null){d=[]}for(var g=0;(g<d.length)&&(!b||!h);g++){var f=document.getElementById(d[g][SETTING_ID]);if(f){var e=null;if(d[g][SETTING_TYPE]=="text"){if(f.getAttribute("isEmpty")=="true"){e=""}else{e=f.value}}else{if(d[g][SETTING_TYPE]=="select"){e=f.options[f.selectedIndex].value}else{if(d[g][SETTING_TYPE]=="checkbox"){if(f.checked){e=findKey("true",d[g][SETTING_OPTIONS])}else{e=findKey("false",d[g][SETTING_OPTIONS])}}}}if(e!=null){if(!h){var a=mainSearchArguments[d[g][SETTING_ID]];if(typeof a!="string"){a=""}if(e!=a){h=true}}if(!b){var a=i.args[d[g][SETTING_ID]];if(typeof a!="string"){a=""}if(e!=a){b=true}}}}}if(i.id=="-"){document.getElementById("default-button").setAttribute("add","true");b=true}if(b){document.getElementById("default-button").style.display="block"}else{document.getElementById("default-button").style.display="none"}if(h){document.getElementById("apply-button").style.display="block"}else{document.getElementById("apply-button").style.display="none"}}function createSettings(k,i,e){var a=engineSettings[k];if(!a){return[]}var g="";if(typeof e!="undefined"){g=e+"-"}var d=[];for(var j=0;j<a.length;j++){var b=a[j];var f=i[b[SETTING_ID]];if(typeof f!="string"){f=""}if(b[SETTING_TYPE]=="separator"){d.push('<div class="separator"></div>')}else{if(b[SETTING_TYPE]=="title"){d.push('<div class="title">',b[SETTING_LABEL],"</div>")}else{if(b[SETTING_TYPE]=="text"){d.push('<div class="setting-label"><label for="',g,b[SETTING_ID],'">',b[SETTING_LABEL],':</label></div><div class="setting"><input type="text" id="',g,b[SETTING_ID],'" name="',g,b[SETTING_ID],'" ');if(b[SETTING_OPTIONS]){d.push('emptyString="',b[SETTING_OPTIONS][0],'" ');if((!i[b[SETTING_ID]])||(i[b[SETTING_ID]]=="")){d.push('isEmpty="true" value ="',b[SETTING_OPTIONS][0],'"')}else{d.push('value ="',i[b[SETTING_ID]],'"')}}else{d.push('value ="',((i[b[SETTING_ID]])?i[b[SETTING_ID]]:""),'"')}d.push("></div>")}else{if(b[SETTING_TYPE]=="select"){d.push('<div class="setting-label"><label for="',g,b[SETTING_ID],'">',b[SETTING_LABEL],':</label></div><div class="setting"><select id="',g,b[SETTING_ID],'" name="',g,b[SETTING_ID],'">');var h;if(!i[b[SETTING_ID]]){h=""}else{h=i[b[SETTING_ID]]}for(optionKey in b[SETTING_OPTIONS]){if(h==optionKey){d.push('<option value="',optionKey,'" selected="selected">',b[SETTING_OPTIONS][optionKey],"</option>")}else{d.push('<option value="',optionKey,'">',b[SETTING_OPTIONS][optionKey],"</option>")}}d.push("</select></div>")}else{if(b[SETTING_TYPE]=="checkbox"){if(b[SETTING_OPTIONS][f]=="true"){d.push('<div class="setting setting-checkbox"><label><input type="checkbox" id="',g,b[SETTING_ID],'" name="',g,b[SETTING_ID],'" value="',findKey("true",b[SETTING_OPTIONS]),'" checked="checked" /> ',b[SETTING_LABEL],"</label></div>")}else{d.push('<div class="setting setting-checkbox"><label><input type="checkbox" id="',g,b[SETTING_ID],'" name="',g,b[SETTING_ID],'" value="',findKey("true",b[SETTING_OPTIONS]),'" /> ',b[SETTING_LABEL],"</label></div>")}}}}}}}return d}function processEditEngineAttributes(f){var k=getConfigurationIndex(f);var l=configuration[k];var d=engineSettings[l.type];var h;if(f==currentEngine){h="side-"}else{h=f+"-"}var c=document.getElementById(h+"n").value;var j=document.getElementById(h+"i").getAttribute("data-value");var a=document.getElementById(h+"p");var i=parseInt(a.options[a.selectedIndex].value);var g=engineParam[configuration[k].type][PARAM_NUMPREVIEWS];if((c=="")||(c==engineParam[configuration[k].type][PARAM_NAME])){if(l.args.n){delete (l.args.n)}c=engineParam[configuration[k].type][PARAM_NAME]}else{l.args.n=c}if(j==configuration[k].type){if(l.args.i){delete (l.args.i)}}else{if(j){l.args.i=j}}if((i<g[2])||(i==g[0])){if(l.args.p){delete (l.args.p)}}else{l.args.p=""+i}var e;var b;if(f==currentEngine){e=document.getElementById("main-engine-label");b=document.getElementById("main-engine-icon")}else{b=$("#engine"+f+" .icon").get(0);e=$("#engine"+f+" .label").get(0)}e.textContent=c;e.innerText=c;b.style.backgroundImage="url("+baseDomainCommon+j+".png)"}function setDefaultSettings(f){var b;var g="";if(typeof f!="undefined"){b=f;g=f+"-"}else{b=currentEngine}var n=getConfigurationIndex(b);var o=configuration[n];var a=engineSettings[o.type];if(a==null){a=[]}if(o.id=="-"){var i=getHighestId();i++;o.id=i.toString(36);currentEngine=o.id;b=currentEngine;parsedUri.queryKey["s"]=currentEngine;document.getElementById("default-button").setAttribute("add","false")}for(var m=0;m<a.length;m++){var k=document.getElementById(g+a[m][SETTING_ID]);if(k){var d=null;if(a[m][SETTING_TYPE]=="text"){if(k.getAttribute("isEmpty")=="true"){d=""}else{d=k.value}}else{if(a[m][SETTING_TYPE]=="select"){d=k.options[k.selectedIndex].value}else{if(a[m][SETTING_TYPE]=="checkbox"){if(k.checked){d=findKey("true",a[m][SETTING_OPTIONS])}else{d=findKey("false",a[m][SETTING_OPTIONS])}}}}if(d!=null){var l=o.args[a[m][SETTING_ID]];if(typeof l!="string"){l=""}if(d!=l){if(d==""){delete (o.args[a[m][SETTING_ID]])}else{o.args[a[m][SETTING_ID]]=d}}}}}saveConfiguration();if(b==currentEngine){checkDefaultSettings()}else{try{engineInstances[n]=engineFactories[configuration[n].type].createInstance(false,"engine"+configuration[n].id,configuration[n],configuration[n].args);if(configuration[n].show){var h=document.getElementById("engine"+configuration[n].id);if(configuration[n].show){if(h.populated){h.wrapper.innerHTML=getPreviewContent(n)}}else{if(showingEngineTooltip&&(engineTooltipIndex==n)){document.getElementById("tooltip2").innerHTML=getPreviewContent(n)}}}engineInstances[n].execute(searchQuery)}catch(j){alert("Number: "+m+", Type: "+configuration[m].type+", Error: "+j)}}return false}function applySettings(){var g=configuration[getConfigurationIndex(currentEngine)];var b=engineSettings[g.type];if(b==null){b=[]}for(var f=0;f<b.length;f++){var e=document.getElementById(b[f][SETTING_ID]);if(e){var d=null;if(b[f][SETTING_TYPE]=="text"){if(e.getAttribute("isEmpty")=="true"){d=""}else{d=e.value}}else{if(b[f][SETTING_TYPE]=="select"){d=e.options[e.selectedIndex].value}else{if(b[f][SETTING_TYPE]=="checkbox"){if(e.checked){d=findKey("true",b[f][SETTING_OPTIONS])}else{d=findKey("false",b[f][SETTING_OPTIONS])}}}}if(d!=null){var a=g.args[b[f][SETTING_ID]];if(typeof a!="string"){a=""}if(d!=a){parsedUri.queryKey[b[f][SETTING_ID]]=encodeURIComponent(d)}else{if(parsedUri.queryKey[b[f][SETTING_ID]]!=undefined){delete (parsedUri.queryKey[b[f][SETTING_ID]])}}}}}doRedirect();return false}function findKey(a,c){for(var b in c){if(c[b]==a){return b}}return null};
