function savedialog(b){var a=this;this.simple=typeof(b)!="undefined"?b:false;this.open=function(d,c){d.preventDefault();profiles.btnclicked=c;if(!profiles.checkUser()){profiles.logIn();return false}profiles.getDefault(function(f){if(f){profiles.loadProfiles(function(h){if(h){var i=$.cookie("simple_login");var g='<div id="profilelist">'+profiles.profileList+'<ul class="profiles new"><li id="profilenew" class="profile new">'+t("Create a new profile")+'</li></ul></div><div id="profileedit" style="display: none"><input id="profilename" size="30" type="text" /><div id="profilecontrols"><a id="profilesetdefault" class="btn" href="#">Set Default</a> <a id="profiledelete" class="btn" href="#">'+t("Delete")+'</a> <a id="profileedit" class="btn" href="#">'+t("Save")+'</a> <a id="profileeditcancel" class="btn" href="#">'+t("Cancel")+'</a></div><div id="profilenow" style="float: left; padding-left: 55px;"></div><div id="profilechange" style="float: right; padding-right: 55px;"></div></div>';profiles.createDialog(g,t("Edit Profiles"));if(i=="1"){profiles.dlg.dialog({close:function(j,k){$.cookie("simple_login",null);window.location.reload(true)}})}}})}})};this.profilenew=function(c){c.before('<div><input id="profilename" size="30" type="text" value="בחר שם לסינון"/> <a id="profilesave" href="#">'+t("Save")+'</a> <a id="profilecancel" href="#">'+t("Cancel")+"</a></br></div>");c.hide()};this.profilecancel=function(d,c){d.preventDefault();c.parent().remove();$("li#profilenew").show()};this.profilesave=function(g,c){g.preventDefault();var f=$("input#profilename").val();var d=c.parent();profiles.createProfile(f,function(j,h,i){if(j){log(h);profiles.getDefault(function(k){profiles.loadProfiles(function(l){if(l){profiles.dlg.find("ul.profiles:not(.new)").replaceWith(profiles.profileList);d.remove();$("li#profilenew").show();$("div.hand:last").after('<div class="right-bar-pref-name hand" id="pref_id_'+i+'">'+f+"</div>");profiles.savetoProfile(i,function(n,m){if(n){profiles.dlg.children("div#msg").html(m);log(m)}else{log(m)}})}})})}else{log(h)}})};this.profileeditmenu=function(c){var g=c.html();var d=c.data("id");profiles.dlg.children("div#msg").html("");profiles.dlg.find("input#profilename").val(g);profiles.dlg.find("input#profilename").data("profilename",g);profiles.dlg.find("input#profilename").data("profileid",d);profiles.filtersList(d,function(i,h){if(i){profiles.dlg.find("div#profilenow").html(h+"</ul>")}else{log(h)}});newarr=$("form#searchform").serializeArray();var f='<ul class="filters">';$.each(newarr,function(h,j){if(j.name!=="n"){$.get("/ajax/translate.php",{phrase_id:j.value.replace("#","")},function(i){f+="<li>"+i+"</li>";profiles.dlg.find("div#profilechange").html(f+"</ul>")})}});profiles.dlg.find("div#profilelist").slideToggle();profiles.dlg.find("div#profileedit").slideToggle()};this.profilesetdefault=function(){e.preventDefault();var c=profiles.dlg.find("input#profilename").data("profileid");profiles.setDefault(c,function(f,d){if(f){log(d);profiles.dlg.children("div#msg").html(d);profiles.getDefault(function(g){if(g){profiles.loadProfiles(function(h){if(h){profiles.dlg.find("ul.profiles:not(.new)").replaceWith(profiles.profileList)}})}})}else{log(d)}})};this.profileeditcancle=function(c){c.preventDefault();profiles.dlg.find("div#profilelist").slideToggle();profiles.dlg.find("div#profileedit").slideToggle();profiles.dlg.children("div#msg").html("")};this.profileedit=function(g){g.preventDefault();var f=profiles.dlg.find("input#profilename").data("profilename");var d=profiles.dlg.find("input#profilename").data("profileid");var c=profiles.dlg.find("input#profilename").val();if(c!==f){profiles.editProfilename(d,c,function(i,h){if(i){log(h);profiles.loadProfiles(function(k){if(k){profiles.dlg.find("ul.profiles:not(.new)").replaceWith(profiles.profileList);var j="div#pref_id_"+d+"";$(j).html(c)}})}else{log(h)}})}profiles.savetoProfile(d,function(i,h){if(i){log(h);profiles.dlg.children("div#msg").html(h)}else{log(h);profiles.dlg.children("div#msg").html(h)}})};this.profiledelete=function(d){d.preventDefault();var f=profiles.dlg.find("input#profilename").data("profileid");var c=t("You are about to delete a profile, are you sure")+"?";if(profiles.confirmDialog(c)){profiles.deleteProfile(f,function(g,h){if(g){profiles.loadProfiles(function(i){if(i){profiles.dlg.find("ul.profiles:not(.new)").replaceWith(profiles.profileList);profiles.dlg.children("div#msg").html(h);var j="div#pref_id_"+f+"";$(j).remove();log(h);profiles.dlg.find("div#profilelist").slideToggle();profiles.dlg.find("div#profileedit").slideToggle();profiles.dlg.children("div#msg").html("")}})}else{log(h)}})}};this.profilesimplesave=function(c){var d=c.data("id");profiles.savetoProfile(d,function(g,f){if(g){profiles.dlg.children("div#msg").html(f);log(f)}else{log(f)}})};this.complex=function(){$("a#save_search").click(function(c){a.open(c,$(this))});$("li#profilenew").live("click",function(){a.profilenew($(this))});$("a#profilecancel").live("click",function(c){a.profilecancel(c,$(this))});$("a#profilesave").live("click",function(c){a.profilesave(c,$(this))});$("li.profile:not(.new)").live("click",function(){a.profileeditmenu($(this))});$("a#profilesetdefault").live("click",function(c){a.profilesetdefault(c)});$("a#profileeditcancel").live("click",function(c){a.profileeditcancle(c)});$("a#profileedit").live("click",function(c){a.profileedit(c)});$("a#profiledelete").live("click",function(c){a.profiledelete(c)})};this.simple=function(){$("a#save_search").click(function(c){a.open(c,$(this))});$("li#profilenew").live("click",function(){a.profilenew($(this))});$("a#profilecancel").live("click",function(c){a.profilecancel(c,$(this))});$("li.profile:not(.new)").live("click",function(){a.profilesimplesave($(this))})};if(b){this.simple()}else{this.complex()}};
