var gActivityScreen=null;function PhotoUploader(e){var c=$(e.gallery);var f=$(e.btnUpload);var k=$(e.btnAdd);var d=$(e.forms);var l=$(e.frame);var g=0;var a={};var h={};var j=null;var i=null;var b=null;this.classForm="wClosable";this.classFormHeader="bar";this.classFormTitle="header";this.classAO="aoControl";this.classErrors="errors";this.idSuffix="suffix";this.idLoadType="image_load_type";this.idLoadLocal="load_from_disk";this.idLoadInet="load_from_url";this.idFileLocal="image_file";this.idFileInet="image_file_inet";this.idTitle="image_title";this.idTags="image_tags";this.idPutOnMain="image_put_on_main";this.idGallery="image_gallery";this.imgClose="/res/close.gif";this.imgActivity="/res/activity.gif";this.urlUpload="/image.php?action=add&IsCallback";this.urlAjax="/specs/gallery.php";this.getGalleryId=function(){return $F(c)};this.getFrameName=function(){return l.name};this.disableButton=function(){f.disable()};this.enableButton=function(){f.enable()};this.fileNotFoundMsg=e.fileNotFoundMsg;this.uploadProcessMsg=e.uploadProcessMsg;this.switchFormMode=function(q,p){var o=new Array(this.idFileLocal,this.idFileInet);for(var n=0,m=o.length;n<m;n++){$(o[n]+p)[o[n]==q?"removeAttribute":"setAttribute"]("disabled","disabled")}};this.createForm=function(){g++;try{var o=$(document.createElement("<form action='"+this.urlUpload+"' method='post' target='"+this.getFrameName()+"' enctype='multipart/form-data' />"))}catch(p){var o=$(document.createElement("form"));o.setAttribute("action",this.urlUpload);o.setAttribute("method","post");o.setAttribute("target",this.getFrameName());o.setAttribute("enctype","multipart/form-data")}o.addClassName(this.classForm).hide();o.id=this.classForm+g;a[o.id]={active:false};var n=$(document.createElement("div")).addClassName(this.classFormHeader);var m=$(document.createElement("img")).setStyle({"float":"right",cursor:"pointer"});m.setAttribute("src",this.imgClose);Event.observe(m,"click",(function(s,t){this.cancelForm(t)}).bindAsEventListener(this,o.id));Element.insert(n,{top:m});var r=$(document.createElement("h2")).addClassName(this.classFormTitle);Element.insert(r,{bottom:g});Element.insert(n,{bottom:r});Element.insert(o,{top:n});var q={suffixId:this.idSuffix,suffix:"_"+g,type:this.idLoadType,typeLocal:this.idLoadLocal,typeInet:this.idLoadInet,fileLocal:this.idFileLocal,fileInet:this.idFileInet,title:this.idTitle,tags:this.idTags,put_on_main:this.idPutOnMain,classAO:this.classAO};new Ajax.Request(this.urlAjax,{method:"get",parameters:{action:"getUploadForm",suffix:q.suffix,gallery:c.value},onSuccess:(function(w,v){try{Prototype.LoadScripts(w.responseText.extractSrcScripts());var s=$(document.createElement("div")).setStyle({margin:"10px"});Element.insert(o,{bottom:s});var t=$(document.createElement("div")).addClassName(this.classErrors);Element.insert(o,{bottom:t});Element.insert(d,{top:o});s.update(w.responseText);Event.observe($(q.typeLocal+q.suffix),"click",(function(x,z,y){this.switchFormMode(z,y)}).bindAsEventListener(this,q.fileLocal,q.suffix));Event.observe($(q.typeInet+q.suffix),"click",(function(x,z,y){this.switchFormMode(z,y)}).bindAsEventListener(this,q.fileInet,q.suffix));$(v).show();a[v].active=true;this.enableButton()}catch(u){alert(u.description!=null?u.description:u)}}).bindAsEventListener(this,o.id)})};this.cancelForm=function(m){delete a[m];$(m).remove();if($H(a).values().length<1){this.disableButton();g=0}};this.upload=function(n,s,o){if(!s){h=$H(a);h.each((function(u){if(!u.value.active){this.unset(u.key)}}).bind(h));this.disableButton();i.show()}else{h.unset(s);Event.stopObserving(l,"load",j);if(!o){if(l.contentDocument){var o=l.contentDocument}else{if(l.contentWindow){var o=l.contentWindow.document}else{var o=window.frames[l.id].document}}o=o.body.innerHTML}if(o==""){this.cancelForm(s)}else{var t=Element.select(s," ."+this.classErrors)[0].innerHTML=o}}if(h.keys().length>0){var p=h.keys()[0];j=this.upload.bindAsEventListener(this,p);Event.observe(l,"load",j);var q=$(p);if(q){var m=$(this.idGallery+"_"+p);if(!m){m=$(document.createElement("input"));m.setAttribute("type","hidden");m.setAttribute("name",this.idGallery);Element.insert(q,{bottom:m})}m.value=this.getGalleryId();try{if(typeof q.onsubmit=="function"){q.onsubmit()}q.fire("dom:submit");q.submit()}catch(r){this.upload(null,p,"<p>"+this.fileNotFoundMsg+"</p>")}}}else{this.enableButton();i.hide()}};this.init=function(){if(c&&f&&k&&d&&l){this.disableButton();b="<div style='padding: 10px; background-color: #FFFFFF; width: 300px; text-align: center'><h2 class='header' style='margin-bottom: 5px;'>"+this.uploadProcessMsg+"</h2><img src='"+this.imgActivity+"'></div>";gActivityScreen=i=WindowManager.BaseWindow({modal:true,center:true,elSrc:b});Event.observe(f,"click",this.upload.bindAsEventListener(this));Event.observe(k,"click",(function(m){Event.element(m).blur();this.createForm()}).bindAsEventListener(this))}};this.init()}var PhotoManager={editWindows:{},setGalleryIcon:function(c,b,a){c=parseInt(c);b=parseInt(b);if(c>0&&b>0){new Ajax.Request(a.urlGallery,{method:"post",parameters:{action:a.actionSetIcon,image:c,gallery:b},onSuccess:function(e){var d=Try.these(function(){return e.responseText.evalJSON()})||{};if(d.message){alert(d.message)}}})}},editPhoto:function(c,b){c=parseInt(c);if(c>0){var a="#{url}?image=#{id}&action=#{action}".interpolate({url:b.urlImage,action:b.actionEdit,id:c});new Ajax.Request(a,{method:"get",onSuccess:(function(e){Prototype.LoadScripts(e.responseText.extractSrcScripts());var d=e.responseText;if(d!=""){if(!this.editWindows[c]){this.editWindows[c]=WindowManager.BaseWindow({modal:true,center:true,elSrc:d,handlerSubmit:function(){Element.select(this.el,"form").each((function(f){f.request({onComplete:(function(h){this.hide();var g=Try.these(function(){return h.responseText.evalJSON()})||{};if(b.entities){if(b.entities.title&&typeof(g.title)!="undefined"){b.entities.title.innerHTML=g.title}if(b.entities.tags&&typeof(g.tags)!="undefined"){b.entities.tags.innerHTML=g.tags}}}).bind(this)})}).bind(this))}}).show()}else{this.editWindows[c].updateElement(d).setListeners().show()}}else{alert(b.mesCannotEdit)}}).bind(this)})}},favSwitchPhoto:function(d,a,b){d=parseInt(d);if(d>0){var c=!a;new Ajax.Request(b.urlImage,{method:"post",parameters:{action:(c?b.actionFavSet:b.actionFavUnset),image:d},onSuccess:(function(g,f){var e=Try.these(function(){return g.responseText.evalJSON()})||{};if(e.result&&typeof(f)=="function"){f()}}).bindAsEventListener(this,b.onSuccess)})}},dropPhoto:function(b,a){b=parseInt(b);if(b>0){if(confirm(a.confirmDrop)){new Ajax.Request(a.urlImage,{method:"post",parameters:{action:a.actionDrop,image:b},onSuccess:(function(e,d){var c=Try.these(function(){return e.responseText.evalJSON()})||{};if(c.result&&typeof(d)=="function"){d()}else{if(!c.result&&!c.message){c.message=a.mesCannotDrop}}if(c.message){alert(c.message)}}).bindAsEventListener(this,a.onSuccess)})}}}};var locationMapWindow=null;function ShowGalleryMap(b,c){if(locationMapWindow){locationMapWindow.show();return}var a=new CreateService();var d=new Array({Name:"GamePlaceId",Value:c});a.OnComplete=function(e){locationMapWindow=WindowManager.BaseWindow({modal:true,center:true,elSrc:e.Text}).show()};a.CallSimpleMethod("LocationDialog",d)}function SwitchLoadMode(a){if(a=="simple"){$("upload_simple_tab").className="active";$("upload_multi_tab").className="unactive";$("upload_multi_content").style.display="none";$("upload_simple_content").style.display=""}else{$("upload_simple_tab").className="unactive";$("upload_multi_tab").className="active";$("upload_multi_content").style.display="";$("upload_simple_content").style.display="none"}}var XmlHttpCommunicatorImage=new CreateService();function RotateImage(a,d,b){var c=new Array({Name:"ImageId",Value:d},{Name:"Clockwise",Value:a});XmlHttpCommunicatorImage.OnComplete=function(e){var f=$(b).src;if((ind=f.indexOf("?"))!=-1){f=f.substring(0,ind)}$(b).src=f+"?"+(new Date()).getTime()};XmlHttpCommunicatorImage.CallSimpleMethod("ImageRotate",c)};