var Site=new Class({exf:null,old_size:null,cf_arr:null,snap_score:null,snap_votes:null,snap_id:null,score_tim:null,msg_box:null,initialize:function(){this.old_size=[];this.cf_arr=[];this.msg_box=new MessageBox()},send_feedback:function(){var B=$("user_feedback").value;if(B==""){site.msg_box.show("Please type your opinion.",false,null);return }site.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/send-feedback/",onSuccess:function(C,D){if(C.errno!=0){this.msg_box.show(C.error,false,null)}else{this.msg_box.show(C.out,false,null)}}.bind(this)}).send("msg="+B)},add_snap:function(){if(!confirm("Continue with the registration of this snap?")){return }var G=$("title").value;var A=$("cat").value;var F=$("desc").value;var E=$("usage").value;var B=$("tags").value;var D=code.getCode();if(G==""||A==0||F==""||E==""||B==""||code==""){site.msg_box.show("Please fill all fields",false,null);return }site.msg_box.show(null,true,null);var C=new Request.JSON({url:"/async/add-snap/",onSuccess:function(H,I){if(H.errno!=0){this.msg_box.show(H.error,false,null)}else{this.msg_box.show(H.out,false,null)}}.bind(this)}).send("title="+this.encode_post_string(G)+"&cat="+A+"&desc="+this.encode_post_string(F)+"&usage="+this.encode_post_string(E)+"&tags="+this.encode_post_string(B)+"&code="+this.encode_post_string(D))},update_snap:function(H){if(H==0){this.msg_box.show("Unknown snap, operation cancelled",false,null);return }var G=$("title").value;var A=$("cat").value;var F=$("desc").value;var E=$("usage").value;var B=$("tags").value;var D=code.getCode();if(G==""||A==0||F==""||E==""||B==""||code==""){site.msg_box.show("Please fill all fields",false,null);return }site.msg_box.show(null,true,null);var C=new Request.JSON({url:"/async/update-snap/",onSuccess:function(I,J){if(I.errno!=0){this.msg_box.show(I.error,false,null)}else{this.msg_box.show(I.out,false,null)}}.bind(this)}).send("id="+H+"&title="+this.encode_post_string(G)+"&cat="+A+"&desc="+this.encode_post_string(F)+"&usage="+this.encode_post_string(E)+"&tags="+this.encode_post_string(B)+"&code="+this.encode_post_string(D))},get_site_ip:function(){var C=$("domain").value;var A=$("hip");if(C==""){this.msg_box.show("Enter your site's domain name so we can retrieve server's IP!",false,null);return }site.msg_box.show(null,true,null);var B=new Request.JSON({url:"/async/get-site-ip/",onSuccess:function(D,E){if(D.errno!=0){this.msg_box.show(D.error,false,null)}else{this.msg_box.hide(true);$("ip").value=D.out}}.bind(this)}).send("domain="+this.encode_post_string(C))},uc_ap_disap_comment:function(D,B,C){this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/ap-disap-comment/",onSuccess:function(E,F){if(E.errno!=0){this.msg_box.show(E.error,false,null)}else{this.msg_box.show(E.out,false,'<a href="">Close and refresh this page</a>')}}.bind(this)}).send("id="+D+"&act="+B)},uc_remove_comment:function(B){if(!confirm("Deleting a comment will permanently delete it from the system.\nAre you sure you want to delete this comment?")){return }this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/delete-comment/",onSuccess:function(C,D){if(C.errno!=0){this.msg_box.show(C.error,false,null)}else{this.msg_box.hide();var E=new Fx.Tween($("uc_"+B),{property:"opacity",duration:1000});E.start(1,0).chain(function(){$("uc_"+B).destroy();E=null})}}.bind(this)}).send("id="+B)},uc_show_more:function(C,B){var A=$("ucsm_"+C);if(A.style.display=="none"){A.style.display="inline";B.innerHTML="Less";B.blur()}else{A.style.display="none";B.innerHTML="More";B.blur()}},go_fullscreen:function(){this.exf=$("exf");this.old_size=[code.style.width.toInt(),code.style.height.toInt()];var A=window.getSize();code.style.position="absolute";code.style.top="40px";code.style.left="0";code.style.width=(A.x-2)+"px";code.style.height=(A.y-40)+"px";window.scrollTo(0,0);this.exf.setStyle("display","block")},exit_fullscreen:function(){code.style.position="static";code.style.width=this.old_size[0]+"px";code.style.height=this.old_size[1]+"px";window.scrollTo(0,0);this.exf.setStyle("display","none")},get_class_file:function(){if(this.cf_arr.length!=0){window.location="/async/get-class-file/"}},add_to_class:function(C){var B=C+"|"+$("t_"+C).get("html");if(this.is_in_array(B,this.cf_arr)!=-1){this.msg_box.show("This snap is already included in your custom class file.",false,null);return }this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/add-to-class-list/",onSuccess:function(D,E){if(D.errno!=0){this.msg_box.show(D.error,false,null)}else{this.msg_box.show(D.out,false,null);this.cf_arr.push(B);this.rebuild_sscf_data()}}.bind(this)}).send("func="+this.encode_post_string(B))},clear_class_list:function(){this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/clear-class-list/",onSuccess:function(B,C){if(B.errno!=0){this.msg_box.show(B.error,false,null)}else{this.msg_box.show(B.out,false,null);this.cf_arr=[];$("ssfc").set("html","<i>None selected yet.</i>");$("ssfc_btns").setStyle("display","none")}}.bind(this)}).send(null)},rebuild_sscf_data:function(){if(this.cf_arr.length!=0){var C='<ul style="margin-top: 10px">';for(var B=0;B<this.cf_arr.length;B++){var A=this.cf_arr[B].split("|");C+="<li><b>"+A[1]+"</b></li>"}C+="</ul>";$("ssfc").set("html",C);$("ssfc_btns").setStyle("display","block")}},download_snap:function(A){window.location="/async/download-snap/"+A+"/"},set_rating_value:function(){var B=parseInt(this.snap_score);for(var A=0;A<B;A++){$("s"+(A+1)).setStyle("background","url(/images/rating-stars.gif) #fff 0 0  no-repeat")}$("sc").set("html",this.snap_score);$("sv").set("html",this.snap_votes)},rate_astar:function(A){for(var B=0;B<5;B++){$("s"+(B+1)).setStyle("background","url(/images/rating-stars.gif) #fff -31px 0  no-repeat")}for(var B=0;B<A;B++){$("s"+(B+1)).setStyle("background","url(/images/rating-stars.gif) #fff -62px 0  no-repeat")}if(this.score_tim!=null){clearTimeout(this.score_tim);this.score_tim=null}},rate_istar:function(A){for(var B=0;B<A;B++){$("s"+(B+1)).setStyle("background","url(/images/rating-stars.gif) #fff -31px 0  no-repeat")}this.score_tim=setTimeout(function(){this.set_rating_value()}.bind(this),500)},rate:function(B){if(this.snap_id<=0){return }this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/do-rating/",onSuccess:function(C,D){if(C.errno!=0){this.msg_box.show(C.error,false,null)}else{this.msg_box.show(C.out,false,null)}}.bind(this)}).send("id="+this.snap_id+"&val="+B)},add_comment:function(C){var B=$("comment");if(B.value==""){this.msg_box.show("Nothing to save...",false,null);return }this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/add-comment/",onSuccess:function(E,F){if(E.errno!=0){this.msg_box.show(E.error,false,null)}else{this.msg_box.hide(true);var D=$("currc");var G="<div><span>Posted 1 second by <b>me</b></span><p>"+B.value.replace(/\n/g,"<br />")+"</p></div>";if(E.out==0){D.set("html",G+'<p style="text-align: center;color: #ab0179;font-weight: bold;font-style: italic;">This comment has been queued for approval</p>')}else{D.set("html",G+D.get("html"))}B.value=""}}.bind(this)}).send("id="+C+"&comm="+this.encode_post_string(B.value))},show_pp_help:function(A){var B=$("pp_help");if(B.getStyle("display")=="none"){B.setStyle("display","block");A.innerHTML="Close help"}else{B.setStyle("display","none");A.innerHTML="Read help for the steps"}},start_add_paid_snap:function(){if(!confirm("Continue with the registration of this paid snap?")){return }var C=$("cat");var B=$("platform");var A=$("encoder");if($("title").value==""||C.options[C.selectedIndex].value==0||$("tags").value==""||$("desc").value==""||B.options[B.selectedIndex].value==0||A.options[A.selectedIndex].value==0||$("price").value==""){this.msg_box.show("All fields are mandatory",false,null);return }if($("file").value==""){this.msg_box.show("You cannot continue without adding a file",false,null);return }this.msg_box.show("Please wait, uploading file...",true,null);document.form1.submit();return false},upload_snap_file_ended:function(B,A){if(B!=""){this.msg_box.show(B,false,null);return }this.add_paid_snap(A)},add_paid_snap:function(F){if(F==""){return }var H=$("title");var G=$("cat");var J=$("tags");var C=$("desc");var A=$("platform");var E=$("encoder");var B=$("price");if(H.value==""||G.options[G.selectedIndex].value==0||J.value==""||C.value==""||A.options[A.selectedIndex].value==0||E.options[E.selectedIndex].value==0||B.value==""){this.msg_box.show("All fields are mandatory",false,null);return }var D="title="+this.encode_post_string(H.value)+"&cat="+parseInt(G.options[G.selectedIndex].value)+"&tags="+this.encode_post_string(J.value)+"&desc="+this.encode_post_string(C.value)+"&platform="+parseInt(A.options[A.selectedIndex].value)+"&encoder="+parseInt(E.options[E.selectedIndex].value)+"&price="+this.encode_post_string(B.value)+"&fn="+F;this.msg_box.show(null,true,null);var I=new Request.JSON({url:"/async/add-paid-snap/",onSuccess:function(K,L){if(K.errno!=0){this.msg_box.show(K.error,false,null)}else{this.msg_box.show(K.out,false,null)}}.bind(this)}).send(D)},start_update_paid_snap:function(){if($("file").value!=""){this.msg_box.show("Please wait, uploading file...",true,null);document.form1.submit();return false}else{this.update_paid_snap()}},upload_updated_snap_file_ended:function(A){if(A!=""){this.msg_box.show(A,false,null);return }this.update_paid_snap()},update_paid_snap:function(){var H=$("id");var B=$("cat");var G=$("desc");var A=$("platform");var D=$("encoder");var E=$("price");if(G.value==""||A.options[A.selectedIndex].value==0||D.options[D.selectedIndex].value==0){this.msg_box.show("All fields are mandatory",false,null);return }var F="id="+parseInt(H.value)+"&cat="+parseInt(B.options[B.selectedIndex].value)+"&desc="+this.encode_post_string(G.value)+"&platform="+parseInt(A.options[A.selectedIndex].value)+"&encoder="+parseInt(D.options[D.selectedIndex].value)+"&price="+this.encode_post_string(E.value);this.msg_box.show(null,true,null);var C=new Request.JSON({url:"/async/update-paid-snap/",onSuccess:function(I,J){if(I.errno!=0){this.msg_box.show(I.error,false,null)}else{this.msg_box.show(I.out,false,null)}}.bind(this)}).send(F)},set_paypal_vars:function(){var A=$("pp_email").value;var C=$("pp_cert_id").value;if(A==""||C==""){this.msg_box.show("Please fill both fields",false,null);return }this.msg_box.show(null,true,null);var B=new Request.JSON({url:"/async/set-paypal-vars/",onSuccess:function(D,E){if(D.errno!=0){this.msg_box.show(D.error,false,null)}else{this.msg_box.show(D.out,false,null)}}.bind(this)}).send("email="+A+"&certid="+C)},buy_snap:function(B){if(!confirm("Continue to the payment page for this snap?")){return }this.msg_box.show(null,true,null);var A=new Request.HTML({url:"/async/get-payment-data/",onSuccess:function(D,F,E,C){if(E.charAt(0)=="#"){this.msg_box.show(E.substr(1,E.length),false,null)}else{var G=new Element("div");G.set("html",E);$("content").grab(G);$("frm_pay").submit()}}.bind(this)}).send("id="+B)},add_words_snap:function(){var F=$("title");var A=$("cat");var B=$("tags");var D=tinyMCE.activeEditor.getContent();if(F.value==""||A.options[A.selectedIndex].value==0||B.value==""||D==""){this.msg_box.show("All fields are mandatory",false,null);return }var E="title="+this.encode_post_string(F.value)+"&cat="+parseInt(A.options[A.selectedIndex].value)+"&tags="+this.encode_post_string(B.value)+"&content="+this.encode_post_string(D);this.msg_box.show(null,true,null);var C=new Request.JSON({url:"/async/add-words-snap/",onSuccess:function(G,H){if(G.errno!=0){this.msg_box.show(G.error,false,null)}else{this.msg_box.show(G.out.msg,false,null)}}.bind(this)}).send(E)},update_words_snap:function(E){var A=$("cat");var C=tinyMCE.activeEditor.getContent();if(A.options[A.selectedIndex].value==0||C==""){this.msg_box.show("All fields are mandatory",false,null);return }var D="id="+E+"&cat="+parseInt(A.options[A.selectedIndex].value)+"&content="+this.encode_post_string(C);this.msg_box.show(null,true,null);var B=new Request.JSON({url:"/async/update-words-snap/",onSuccess:function(F,G){if(F.errno!=0){this.msg_box.show(F.error,false,null)}else{this.msg_box.show(F.out.msg,false,null)}}.bind(this)}).send(D)},is_in_array:function(D,B){var A=B.length;for(var C=0;C<B.length;C++){if(B[C]===D){return C}}return -1},encode_post_string:function(A){return(A=="")?"":encodeURIComponent(A)},html_entity_decode:function(B){var A=new Element("textarea",{html:B});B=A.value;A.dispose();return B}});var WindowBox=new Class({win:null,wrap:null,shd:null,fade:null,initialize:function(){this.create_window();this.fade=new Fx.Tween(this.win,{property:"opacity",duration:500})},create_window:function(){this.win=new Element("div",{"class":"window"});this.wrap=new Element("div",{"class":"wrap",html:""});this.shd=new Element("div",{"class":"shadow"});this.win.grab(this.wrap);this.win.grab(this.shd);$("content").grab(this.win)},show_win:function(A){this.win.setStyle("display","block");this.position(A)},hide_win:function(A){this.fade.start(1,0).chain(function(){this.win.setStyle("display","none");this.fade.set(1);if(A){this.wrap.set("html","")}}.bind(this))},position:function(A){var B=this.wrap.getComputedSize();this.win.setStyles({width:B.totalWidth,height:B.totalHeight});this.shd.setStyles({width:B.totalWidth+20,height:B.totalHeight+20,opacity:0.2});if(typeof (A)=="undefined"){this.win.position()}else{this.win.position(A)}},set_content:function(A){this.wrap.set("html",A)}});var MessageBox=new Class({Extends:WindowBox,initialize:function(){this.parent()},show:function(C,A,B){if(C==null){C="<p>Please wait, processing your request...</p>"}else{C="<p>"+C+"</p>"}if(A){C+='<img src="/images/loader_bar.gif" alt="" />'}else{if(B==null){C+='<span class="links"><a href="#mb-close" onclick="site.msg_box.hide();">Close</a></span>'}else{C+='<span class="links">'+B+"</span>"}}this.set_content(C);this.show_win()},hide:function(A){this.hide_win(A)}});var site=null;window.addEvent("domready",function(){site=new Site();_load()});
