var profiles={url:"/admin/user_functions.php",defaultProfile:"",profileList:"",dlg:"",btnclicked:"",filtersarray:"",getDefault:function(a){$.post(this.url,{GetDefaultProfile:"1"},function(b){if(b!==""){profiles.defaultProfile=b;if(a!==undefined){a(true)}}else{if(b==""){profiles.defaultProfile="";log("No default profile");if(a!==undefined){a(true)}}else{log(b);if(a!==undefined){a(false)}}}})},setDefault:function(a,b){$.post(this.url,{SetDefaultProfile:a},function(c){if(c=="1"){b(true,"The profile was set as default")}else{b(false,"Error "+c.number+": "+c.message)}},"json")},filtersList:function(a,b){$.post(this.url,{GetPrefs:"1",Master:a},function(c){if(c.length>-1){var d='<ul class="filters">';$.each(c,function(e,f){$.get("/ajax/translate.php",{phrase_id:f.PrefValue},function(g){d+="<li>"+g+"</li>";b(true,d)})})}else{b(false,"There are no filters for this profile")}},"json")},loadFilters:function(b,c){b=typeof(b)!="undefined"?b:this.defaultProfile;var a=$("input#filtertrigger");$.post(this.url,{GetPrefs:"1",Master:b},function(d){if(d==""){$("input:checkbox").removeAttr("checked").parent().removeClass("marked");if(c===undefined){log("The profile is empty")}else{c.html(t("The profile is empty"))}}else{$("input:checkbox,input:radio").removeAttr("checked").parent().removeClass("marked");profiles.filtersarray="[";$.each(d,function(e,f){if(e+1<d.length){profiles.filtersarray+='{"name": "'+f.PrefID+'", "value": "'+f.PrefValue+'"}, '}else{profiles.filtersarray+='{"name": "'+f.PrefID+'", "value": "'+f.PrefValue+'"}'}if(f.PrefID==="cat_phrase[]"|f.PrefID==="brd_phrase[]"){prefvalue="#"+f.PrefValue}else{prefvalue=f.PrefValue}$('input[value="'+prefvalue+'"]').attr("checked","checked").parent().addClass("marked")});profiles.filtersarray+="]";profiles.filtersarray=$.parseJSON(profiles.filtersarray);if(a.length==1){a.trigger("click")}if(c===undefined){log("The filters ware loaded successfuly")}else{c.html(t("The filters ware loaded successfuly"))}}},"json")},createProfile:function(b,c){if(b!==""){var a='[{"PrefID":"Profile[]","PrefValue":"'+b+'"}]';$.post(this.url,{AddProfile:a},function(d){if(d.message=="insert_successful"){c(true,"You just created a profile",d.number)}else{c(false,"Error "+d.number+": "+d.message)}},"json")}else{c(false,t("Please insert a profile name"))}},deleteProfile:function(a,b){$.post(this.url,{DeleteProfile:a},function(c){if(c=="1"){b(true,"You just deleted a profile")}else{if(c=="0"){b(false,"Profile was not deleted")}else{b(false,c)}}})},loadProfiles:function(a){$.post(this.url,{GetPrefs:"1"},function(b){profiles.profileList='<ul class="profiles">';$.each(b,function(c,d){if(d.ID==profiles.defaultProfile){profiles.profileList+='<li class="profile defaultProfile" data-id="'+d.ID+'">'+d.PrefValue+"</li>"}else{profiles.profileList+='<li class="profile" data-id="'+d.ID+'">'+d.PrefValue+"</li>"}});profiles.profileList+="</ul>";if(a!==undefined){a(true)}},"json")},savetoProfile:function(b,c){var a=$("input:checkbox,input:radio").serializeArray();a=JSON.stringify(a);while(a.search("#")>-1){a=a.replace("#","")}$.post(this.url,{SetPrefs:a,Master:b},function(d){if(d=="1"){c(true,t("You saved the filters successfuly"))}else{if(d=="0"){c(false,"The filters ware not saved")}else{c(false,"The filters ware not saved")}}})},editProfilename:function(c,b,d){var a='[{"ID":"'+c+'","PrefValue":"'+b+'"}]';$.post(this.url,{EditProfile:a},function(e){if(e.message=="insert_successful"){d(true,"Profile name was updated")}else{d(false,"Error "+e.number+": "+e.message)}},"json")},createDialog:function(b,a){this.dlg=$('<div id="dlg"><div id="dlgmain" style="direction: rtl">'+b+'</div><div id="msg" style="float: right;padding-right: 60px;"></div></div>').dialog({modal:true,width:"30%",position:["center","center"],title:a,resizable:false,close:function(c,d){$("div#dlg").remove();$(this).dialog("destroy")}})},confirmDialog:function(a){var b=confirm(a);return b},saveCoupon:function(a,b){$.post(this.url,{SaveCoupon:a},function(c){if(c=="1"){b(true,"The coupon was saved successfully")}else{if(c=="2"){b(false,"The coupon is already saved")}else{b(false,"Error "+c.number+": "+c.message)}}},"json")},getCoupons:function(b,a){$.post(this.url,{GetCoupons:"yes"},function(c){if(c!==null){$.each(c,function(g,m){var f,k,l,j,e,h,d;j="../pub/coupons/entries/"+m.CouponID+".html";l="N/A";h="N/A";f="N/A";d="N/A";b.html("");$.get(j,function(i){b.append(i);a.hide();b.fadeIn()});k=g+1;$(".hello-note-box").html('<h3 style="color: white; padding-top: 10px; direction: rtl;">מציג קופונים של קטגוריות '+l+", באיזורים "+h+", ממותגים "+f+", מחנויות "+d+". נמצאו "+k+" תוצאות.</h3>")})}else{b.html('<a style="direction: rtl">לא נמצאו קופונים</a>');a.hide();b.fadeIn();$(".hello-note-box").html('<h2 style="color: white; padding-top: 5px; direction: rtl;">לא נמצאו קופונים</h2>')}},"json")},deleteCoupon:function(b,a){$.post(this.url,{DeleteCoupon:b},function(c){if(c=="1"){a(true,"The coupon was deleted successfully")}else{if(c=="0"){a(false,"Coupon was not deleted or there is no such coupon")}else{a(false,"Unknown error")}}})},checkUser:function(){var a=$.cookie("neto_coupons_auth_user");if(a==null){return false}else{return true}},logIn:function(){var a="<label>"+t("Email")+':</label><input type="text" size="30" id="email" style="margin-bottom: 5px" /><br><label>'+t("Password")+':</label><input type="password" size="26" id="password" />';profiles.createDialog(a,t("Log in"));profiles.dlg.children("div#msg").ajaxStart(function(){$(this).text(t("Loading")+"...")});$("input#password").live("keypress",function(f){if(f.keyCode==13){var d=profiles.dlg.children("div#dlgmain").children("input#email").val();var c=profiles.dlg.children("div#dlgmain").children("input#password").val();$.ajax({type:"POST",url:"/login_simple.php",data:{submitBtn:"Login",email:d,password:c},success:function(b){if(b=="1"){profiles.dlg.dialog("destroy");profiles.btnclicked.trigger("click");$.cookie("simple_login","1");$("input#password").die("keypress")}else{profiles.dlg.children("div#msg").text(t("Wrong username/password"))}}})}});profiles.dlg.dialog({buttons:{"כניסה":function(){var d=profiles.dlg.children("div#dlgmain").children("input#email").val();var c=profiles.dlg.children("div#dlgmain").children("input#password").val();$.ajax({type:"POST",url:"/login_simple.php",data:{submitBtn:"Login",email:d,password:c},success:function(b){if(b=="1"){profiles.dlg.dialog("destroy");profiles.btnclicked.trigger("click");$("input#password").die("keypress")}else{profiles.dlg.children("div#msg").text(t("Wrong username/password"))}}})},"הרשמה ללקוח חדש":function(){window.location.href="http://deals.neto.co.il/signup.php"}}})}};
