var isEditing=false;var editingIndex=-1;var isAdding=false;var helpHtml=null;var selectedIndex=-1;var className=(document.all&&(typeof(window.JSON)=="undefined"))?"className":"class";var operations=new Array();var operationIndex=0;var modifiedIcon=null;var calledMyEngines=false;var myEnginesHTML=null;operations[operationIndex]=configurationString;$(function(){$("#buttonsPanel > div").disableSelection();refreshEngineList()});function refreshEngineList(){var b=document.getElementById("engineList");var h=false;while(b.hasChildNodes()){b.removeChild(b.lastChild)}for(var g=0;g<configuration.length;g++){var f=document.createElement("div");if(g==selectedIndex){f.setAttribute(className,"selected");h=true}f.setAttribute("target",g);f.setAttribute("id","engine-"+g);var e=document.createElement("span");e.setAttribute(className,"icon");var a=document.createElement("span");a.setAttribute(className,"label");if(configuration[g].args.n){a.innerText=configuration[g].args.n}else{if(engineParam[configuration[g].type]){a.innerText=engineParam[configuration[g].type][PARAM_NAME]}else{a.innerText=configuration[g].type.substr(0,1).toUpperCase()+configuration[g].type.substr(1)}}a.textContent=a.innerText;if(configuration[g].args.i){e.style.backgroundImage="url("+baseDomain+configuration[g].args.i+".png)"}else{e.style.backgroundImage="url("+baseDomain+configuration[g].type+".png)"}var d=null;if(a.textContent!=engineParam[configuration[g].type][PARAM_NAME]){var d=document.createElement("span");d.setAttribute(className,"type");d.innerText=engineParam[configuration[g].type][PARAM_NAME];d.textContent=d.innerText}f.appendChild(e);f.appendChild(a);if(d!=null){f.appendChild(d)}b.appendChild(f)}$("#engineList > div").disableSelection();$("#engineList > div").click(function(i){var j=$(this).get(0);var c=parseInt(j.getAttribute("target"));if(selectedIndex==c){document.getElementById("engine-"+selectedIndex).setAttribute(className,"");selectedIndex=-1}else{if(selectedIndex>-1){document.getElementById("engine-"+selectedIndex).setAttribute(className,"")}j.setAttribute(className,"selected");selectedIndex=c}refreshButtons()});if(!h){selectedIndex=-1}refreshButtons()}function refreshButtons(){var a=document.getElementById("moveUpButton");var d=document.getElementById("moveDownButton");var f=document.getElementById("deleteButton");var b=document.getElementById("undoButton");var c=document.getElementById("redoButton");var e=document.getElementById("editButton");if(selectedIndex>0){a.setAttribute(className,"")}else{a.setAttribute(className,"disabled")}if((selectedIndex>-1)&&(selectedIndex<(configuration.length-1))){d.setAttribute(className,"")}else{d.setAttribute(className,"disabled")}if((selectedIndex>-1)&&(configuration.length>1)){f.setAttribute(className,"")}else{f.setAttribute(className,"disabled")}if(e.getAttribute(className)!="open"){if(selectedIndex>-1){e.setAttribute(className,"")}else{e.setAttribute(className,"disabled")}}if(operationIndex>0){b.setAttribute(className,"")}else{b.setAttribute(className,"disabled")}if(operationIndex<(operations.length-1)){c.setAttribute(className,"")}else{c.setAttribute(className,"disabled")}}function saveNewState(){saveConfiguration();operationIndex++;operations[operationIndex]=configurationString;operations.length=operationIndex+1}function moveUp(){if(selectedIndex>0){checkCancel();var a=configuration[selectedIndex-1];configuration[selectedIndex-1]=configuration[selectedIndex];configuration[selectedIndex]=a;selectedIndex--;saveNewState();refreshEngineList()}return false}function moveDown(){if((selectedIndex>-1)&&(selectedIndex<(configuration.length-1))){checkCancel();var a=configuration[selectedIndex+1];configuration[selectedIndex+1]=configuration[selectedIndex];configuration[selectedIndex]=a;selectedIndex++;saveNewState();refreshEngineList()}return false}function deleteEngine(){if((selectedIndex>-1)&&(configuration.length>1)){checkCancel();configuration.splice(selectedIndex,1);saveNewState();refreshEngineList()}return false}function undo(){if(operationIndex>0){checkCancel();operationIndex--;configurationString=operations[operationIndex];parseConfiguration();saveConfiguration();refreshEngineList()}return false}function redo(){if(operationIndex<(operations.length-1)){checkCancel();operationIndex++;configurationString=operations[operationIndex];parseConfiguration();saveConfiguration();refreshEngineList()}return false}function add(){checkCancel();var c=document.getElementById("addButton");var d=document.getElementById("rightPanel");if(helpHtml==null){helpHtml=d.innerHTML}c.setAttribute(className,"open");d.setAttribute(className,"open");var b='<div id="accordion">';b+='<h3><a href="#">Standard</a></h3>';b+="<div><ul>";for(var a in engineParam){if((a!="custom")&&!engineParam[a][PARAM_TARGETED]){b+='<li><img src="'+baseDomain+a+'.png" width="16" height="16"/><a href="#" onclick="addEngine(\''+a+"'); return false;\">"+engineParam[a][PARAM_NAME]+"</a></li>"}}b+="</ul></div>";b+='<h3><a href="#">Targeted</a></h3>';b+="<div><ul>";for(var a in engineParam){if((a!="custom")&&engineParam[a][PARAM_TARGETED]){b+='<li><img src="'+baseDomain+a+'.png" width="16" height="16"/><a href="#" onclick="addEngine(\''+a+"'); return false;\">"+engineParam[a][PARAM_NAME]+"</a></li>"}}b+="</ul></div>";b+='<h3><a href="#" onclick="loadMyEngines(); return false;">My custom engines</a></h3>';b+='<div id="myCustomEnginesList">';if(myEnginesHTML!=null){b+=myEnginesHTML}else{b+='<img src="'+baseDomain+'loading.gif" width="32" height="32" style="margin: auto;"/>'}b+="</div>";b+="</div>";d.innerHTML=b;$("#accordion").accordion({fillSpace:true});isAdding=true;return false}function addEngine(b){var c=getHighestId();c++;var a=new Object();a.id=c.toString(36);a.type=b;a.args=new Array();a.show=false;configuration.push(a);saveConfiguration();saveNewState();refreshEngineList();checkCancel()}function addCustomEngine(h,b,e){var f=-1;for(var g=0;g<configuration.length;g++){var a=parseInt(configuration[g].id,36);if(a>f){f=a}}f++;var d=new Object();d.id=f.toString(36);d.type="custom";d.args=new Array();d.args.n=b;d.args.i=e;d.args.ce=""+h;d.show=false;configuration.push(d);saveConfiguration();saveNewState();refreshEngineList();checkCancel()}function edit(){if(selectedIndex>-1){checkCancel();var b=document.getElementById("editButton");var a=document.getElementById("rightPanel");if(helpHtml==null){helpHtml=a.innerHTML}b.setAttribute(className,"open");a.setAttribute(className,"open");isEditing=true;editingIndex=selectedIndex;modifiedIcon=null;fillConfigurationPanel(editingIndex)}return false}function checkCancel(){if(isAdding){var a=document.getElementById("addButton");var b=document.getElementById("rightPanel");a.setAttribute(className,"");b.setAttribute(className,"");b.innerHTML=helpHtml;refreshButtons();isAdding=false}else{if(isEditing){var c=document.getElementById("editButton");var b=document.getElementById("rightPanel");document.getElementById("iconPalette").style.display="none";c.setAttribute(className,"");b.setAttribute(className,"");b.innerHTML=helpHtml;refreshButtons();isEditing=false}}}function fillConfigurationPanel(f){var e=document.getElementById("rightPanel");var d=createSettings(configuration[f].type,configuration[f].args);var h=[];h.push('<form method="#" onsubmit="return editFinished();"><div class="setting-label"><label for="n">Name:</label></div><div class="setting"><input type="text" id="n" name="n" value="');if(configuration[f].args.n){h.push(configuration[f].args.n)}else{h.push(engineParam[configuration[f].type][PARAM_NAME])}h.push('" /></div><div class="setting-label"><label for="i">Icon:</label></div><div class="setting"><img id="i" name="i" src="',baseDomain);if(configuration[f].args.i){h.push(configuration[f].args.i)}else{h.push(configuration[f].type)}h.push('.png" width="16" height="16"/><a href="#" onclick="return changeIcon();" />Change</a></div><div class="setting setting-checkbox"><label><input type="checkbox" id="show" name="show" value="1"');if(configuration[f].show){h.push(' checked="checked"')}h.push(' /> Expand preview</label></div><div class="setting-label"><label for="p">Show:</label></div><div class="setting"><select id="p" name="p">');var b=engineParam[configuration[f].type][PARAM_NUMPREVIEWS];var a=b[0];if(configuration[f].args.p){a=parseInt(configuration[f].args.p)}for(var i=b[2];i<=b[1];i+=b[2]){if(a==i){h.push('<option value="',i,'" selected="selected">',i,"</option>")}else{h.push('<option value="',i,'">',i,"</option>")}}h.push("</select> preview items</div>");if(configuration[f].type=="local"){var g=0;if(configuration[f].args.pm){g=parseInt(configuration[f].args.pm)}h.push('<div class="setting-label"><label for="pm">Preview type:</label></div><div class="setting"><select id="pm" name="pm">');for(var i=0;i<=1;i++){h.push('<option value="',i,'"');if(g==i){h.push(' selected="selected"')}h.push(">");if(i==0){h.push("Map view")}else{h.push("List view")}h.push("</option>")}h.push("</select></div>")}if(d.length>0){h=h.concat(d)}h.push('</form><div id="saveButtonContainer"><div id="saveButton" onclick="editFinished();">Save</div></div>');e.innerHTML=h.join("");$('#rightPanel 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=""}}});$('#rightPanel 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")}}})}function editFinished(){var m=configuration[editingIndex];var e=engineSettings[m.type];var d=document.getElementById("n").value;var l=document.getElementById("i").value;var a=document.getElementById("p");var k=parseInt(a.options[a.selectedIndex].value);var g=engineParam[configuration[editingIndex].type][PARAM_NUMPREVIEWS];if((d=="")||(d==engineParam[configuration[editingIndex].type][PARAM_NAME])){if(m.args.n){delete (m.args.n)}}else{m.args.n=d}if(modifiedIcon==configuration[editingIndex].type){if(m.args.i){delete (m.args.i)}}else{if(modifiedIcon){m.args.i=modifiedIcon}}if((k<g[2])||(k==g[0])){if(m.args.p){delete (m.args.p)}}else{m.args.p=""+k}if(m.type=="local"){var b=document.getElementById("pm");if(b.selectedIndex>0){m.args.pm="1"}else{if(m.args.pm){delete (m.args.pm)}}}m.show=document.getElementById("show").checked;if(e){for(var j=0;j<e.length;j++){var h=document.getElementById(e[j][SETTING_ID]);if(h){var f=null;if(e[j][SETTING_TYPE]=="text"){if(h.getAttribute("isEmpty")=="true"){f=""}else{f=h.value}}else{if(e[j][SETTING_TYPE]=="select"){f=h.options[h.selectedIndex].value}else{if(e[j][SETTING_TYPE]=="checkbox"){if(h.checked){f=findKey("true",e[j][SETTING_OPTIONS])}else{f=findKey("false",e[j][SETTING_OPTIONS])}}}}if(f!=null){var i=m.args[e[j][SETTING_ID]];if(typeof i!="string"){i=""}if(f!=i){if(f==""){delete (m.args[e[j][SETTING_ID]])}else{m.args[e[j][SETTING_ID]]=f}}}}}}saveConfiguration();checkCancel();refreshEngineList();return false}function changeIcon(){var b=findPos(document.getElementById("i"));var a=document.getElementById("iconPalette");a.style.top=""+b[1]+"px";a.style.left=""+(b[0]+16)+"px";a.style.display="block";return false}function iconClicked(a){modifiedIcon=a;document.getElementById("i").setAttribute("src",baseDomain+a+".png");document.getElementById("iconPalette").style.display="none"}function iconCancelClick(){document.getElementById("iconPalette").style.display="none";return false}function findPos(a){var b=curtop=0;if(a.offsetParent){do{b+=a.offsetLeft;curtop+=a.offsetTop}while(a=a.offsetParent)}return[b,curtop]}function loadMyEngines(){if(!calledMyEngines){calledMyEngines=true;$.get("/ajaxmyengines?r="+Math.floor(Math.random()*1000001),function(a){var b=document.getElementById("myCustomEnginesList");if(b){b.innerHTML=a}myEnginesHTML=a})}}var jaaulde=window.jaaulde||{};jaaulde.utils=jaaulde.utils||{};jaaulde.utils.cookies=(function(){var d=[];var b={hoursToLive:8760,path:"/",domain:window.location.hostname,secure:false};var g=function(h){var i;if(typeof h!=="object"||h===null){i=b}else{i={hoursToLive:(typeof h.hoursToLive==="number"?h.hoursToLive:b.hoursToLive),path:(typeof h.path==="string"&&h.path!=""?h.path:b.path),domain:(typeof h.domain==="string"&&h.domain!=""?h.domain:b.domain),secure:(typeof h.secure==="boolean"&&h.secure!=""?h.secure:b.secure)}}return i};var f=function(h){h=g(h);return((h.hoursToLive!==0?"; expires="+a(h.hoursToLive):"")+"; path="+h.path+"; domain="+h.domain+(h.secure?"; secure":""))};var a=function(h){var i=new Date();i.setTime(i.getTime()+(h*60*60*1000));return i.toGMTString()};var e=function(){d=[];var l,j,h=document.cookie.split(";");for(var k=0;k<h.length;k++){l=h[k].split("=");j=l[0].replace(/^\s*/,"").replace(/\s*$/,"");value=decodeURIComponent(l[1]);d[j]=decodeURIComponent(value)}return d};var c=function(){};c.prototype.get=function(j){var h;e();if(typeof j==="string"){h=(typeof d[j]!=="undefined")?d[j]:null}else{if(typeof j==="object"&&j!==null){h=[];for(var i in j){h[j[i]]=(typeof d[j[i]]!=="undefined")?d[j[i]]:null}}else{h=d}}return h};c.prototype.set=function(k,i,h){if(typeof i==="undefined"||i===null){if(typeof h!=="object"||h===null){h={}}i="";h.hoursToLive=-8760}var j=f(h);document.cookie=k+"="+escape(i)+j};c.prototype.del=function(i,h){if(typeof h!=="object"||h===null){h={}}this.set(i,null,h)};c.prototype.test=function(){var i=false,h="cT",j="data";this.set(h,j);if(this.get(h)==j){this.del(h);i=true}return i};c.prototype.setOptions=function(h){if(typeof h!=="object"){h=null}b=g(h)};return new c()})();(function(){if(typeof jQuery!=="undefined"){jQuery.cookies=jaaulde.utils.cookies;var a={cookify:function(b){return this.each(function(){var c="",g="",f=["name","id"],e=0,d;while(e<f.length&&(typeof c!=="string"||c==="")){c=jQuery(this).attr(f[e]);e++}if(typeof c==="string"||c!==""){d=jQuery(this).attr("type").toLowerCase();if(d!=="radio"&&d!=="checkbox"){g=jQuery(this).attr("value");if(typeof g!=="string"||g===""){g=null}jQuery.cookies.set(c,g,b)}}e=0})},cookieFill:function(){return this.each(function(){var c="",f,e=["name","id"],d=0,b;while(d<e.length&&(typeof c!=="string"||c==="")){c=jQuery(this).attr(e[d]);d++}if(typeof c==="string"&&c!==""){f=jQuery.cookies.get(c);if(f!==null){b=this.nodeName.toLowerCase();if(b==="input"||b==="textarea"){jQuery(this).attr("value",f)}else{jQuery(this).html(f)}}}d=0})},cookieBind:function(b){return this.each(function(){$(this).cookieFill().change(function(){$(this).cookify(b)})})}};jQuery.each(a,function(b){jQuery.fn[b]=this})}})();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(f,b){var a=engineSettings[f];if(!a){return[]}var e=[];for(var i=0;i<a.length;i++){var g=a[i];var h=b[g[SETTING_ID]];if(typeof h!="string"){h=""}if(g[SETTING_TYPE]=="separator"){e.push('<div class="separator"></div>')}else{if(g[SETTING_TYPE]=="title"){e.push('<div class="title">',g[SETTING_LABEL],"</div>")}else{if(g[SETTING_TYPE]=="text"){e.push('<div class="setting-label"><label for="',g[SETTING_ID],'">',g[SETTING_LABEL],':</label></div><div class="setting"><input type="text" id="',g[SETTING_ID],'" name="',g[SETTING_ID],'" ');if(g[SETTING_OPTIONS]){e.push('emptyString="',g[SETTING_OPTIONS][0],'" ');if((!b[g[SETTING_ID]])||(b[g[SETTING_ID]]=="")){e.push('isEmpty="true" value ="',g[SETTING_OPTIONS][0],'"')}else{e.push('value ="',b[g[SETTING_ID]],'"')}}else{e.push('value ="',((b[g[SETTING_ID]])?b[g[SETTING_ID]]:""),'"')}e.push("></div>")}else{if(g[SETTING_TYPE]=="select"){e.push('<div class="setting-label"><label for="',g[SETTING_ID],'">',g[SETTING_LABEL],':</label></div><div class="setting"><select id="',g[SETTING_ID],'" name="',g[SETTING_ID],'">');var d;if(!b[g[SETTING_ID]]){d=""}else{d=b[g[SETTING_ID]]}for(optionKey in g[SETTING_OPTIONS]){if(d==optionKey){e.push('<option value="',optionKey,'" selected="selected">',g[SETTING_OPTIONS][optionKey],"</option>")}else{e.push('<option value="',optionKey,'">',g[SETTING_OPTIONS][optionKey],"</option>")}}e.push("</select></div>")}else{if(g[SETTING_TYPE]=="checkbox"){if(g[SETTING_OPTIONS][h]=="true"){e.push('<div class="setting setting-checkbox"><label><input type="checkbox" id="',g[SETTING_ID],'" name="',g[SETTING_ID],'" value="',findKey("true",g[SETTING_OPTIONS]),'" checked="checked" /> ',g[SETTING_LABEL],"</label></div>")}else{e.push('<div class="setting setting-checkbox"><label><input type="checkbox" id="',g[SETTING_ID],'" name="',g[SETTING_ID],'" value="',findKey("true",g[SETTING_OPTIONS]),'" /> ',g[SETTING_LABEL],"</label></div>")}}}}}}}return e}function setDefaultSettings(){var h=configuration[getConfigurationIndex(currentEngine)];var b=engineSettings[h.type];if(b==null){b=[]}if(h.id=="-"){var f=getHighestId();f++;h.id=f.toString(36);currentEngine=h.id;parsedUri.queryKey["s"]=currentEngine;document.getElementById("default-button").setAttribute("add","false")}for(var g=0;g<b.length;g++){var e=document.getElementById(b[g][SETTING_ID]);if(e){var d=null;if(b[g][SETTING_TYPE]=="text"){if(e.getAttribute("isEmpty")=="true"){d=""}else{d=e.value}}else{if(b[g][SETTING_TYPE]=="select"){d=e.options[e.selectedIndex].value}else{if(b[g][SETTING_TYPE]=="checkbox"){if(e.checked){d=findKey("true",b[g][SETTING_OPTIONS])}else{d=findKey("false",b[g][SETTING_OPTIONS])}}}}if(d!=null){var a=h.args[b[g][SETTING_ID]];if(typeof a!="string"){a=""}if(d!=a){if(d==""){delete (h.args[b[g][SETTING_ID]])}else{h.args[b[g][SETTING_ID]]=d}}}}}saveConfiguration();checkDefaultSettings();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 getHighestId(){var b=-1;for(var d=0;d<configuration.length;d++){var a=parseInt(configuration[d].id,36);if(a>b){b=a}}return b}function findKey(a,c){for(var b in c){if(c[b]==a){return b}}return null};
