if(typeof Protoplasm=="undefined"){throw ("protoplasm.js not loaded, could not intitialize dialog")}if(typeof Effect=="undefined"){Protoplasm.useScriptaculous("effects")}var Dialog={active:null,close:function(){if(Dialog.active){Dialog.active.close()}},success:function(){if(Dialog.active){Dialog.active.success()}},failure:function(){if(Dialog.active){Dialog.active.failure()}}};Dialog.Base=Class.create({initialize:function(b,a){b=$(b);this.options=Object.extend({},a||{});this.createComponents();this.contents=$(b);this.dialog.appendChild(this.contents);this.keyListener=null;Object.extend(b,{show:this.show.bind(this),hide:this.close.bind(this),success:this.success.bind(this),failure:this.failure.bind(this)})},createComponents:function(){if(!this.overlay){this.overlay=new Element("div");this.overlay.setStyle({position:"fixed",top:0,left:0,zIndex:90,width:"100%",height:"100%",backgroundColor:"#000",display:"none"});document.body.appendChild(this.overlay);if(!this.options.ignoreClicks){this.overlay.on("click",this.close.bindAsEventListener(this))}}if(!this.dialog){this.dialog=new Element("div");this.dialog.setStyle({position:"fixed",display:"none",zIndex:91});console.log(this.options.height);if(this.options.width||this.options.height){this.dialog.style.overflow="auto";if(this.options.width){this.dialog.style.width=this.options.width+"px"}if(this.options.height){this.dialog.style.height=this.options.height+"px"}}if(this.options.dialogClass){this.dialog.addClassName(this.options.dialogClass)}document.body.appendChild(this.dialog)}},baseShow:function(){if(this.shown&&Dialog.active==this){return}Dialog.close();Dialog.active=this;if(typeof Effect=="undefined"){this.overlay.show();this.dialog.show()}else{new Effect.Appear(this.overlay,{duration:0.1,from:0,to:0.3});new Effect.Appear(this.dialog,{duration:0.1})}this.resize();this.keyListener=document.on("keydown",function(a){if(a.keyCode==Event.KEY_ESC){if(!this.options.ignoreEsc){this.close()}Event.stop(a)}if(!(Event.findElement(a,"#dialog_box")||a.shiftKey||a.altKey||a.metaKey||a.ctrlKey)){Event.stop(a)}}.bindAsEventListener(this));if(this.options.onOpen){this.options.onOpen(this.contents)}this.shown=true},show:function(){this.baseShow()},resize:function(){var d=Element.getDimensions(this.dialog);var b=Element.getDimensions(this.contents);var c=document.viewport.getDimensions();this.dialog.style.left=((c.width-d.width)/2)+"px";if(d.height>(c.height-100)){var a=d.height-b.height;this.dialog.style.top="50px";this.dialog.style.height=(c.height-100)+"px";this.contents.style.height=(c.height-100-a)+"px";this.contents.style.overflow="auto"}else{this.dialog.style.top=((c.height-d.height)/2)*0.7+"px"}},close:function(a){if(!this.shown){return}if(this.keyListener){this.keyListener.stop();this.keyListener=null}if(Dialog.active==this){Dialog.active=null}if(typeof Effect=="undefined"){this.overlay.hide();this.dialog.hide();if(this.options.onClose){this.options.onClose()}}else{new Effect.Fade(this.overlay,{duration:0.1});new Effect.Fade(this.dialog,{duration:0.1,afterFinish:function(){if(this.options.onClose){this.options.onClose()}}.bind(this)})}if(this.options.onClose){this.options.onClose(this.contents)}if(a){Event.stop(a)}this.shown=false},success:function(a){this.close();if(this.options.onSuccess){this.options.onSuccess(a,this.contents)}},failure:function(a){this.close();if(this.options.onFailure){this.options.onFailure(a,this.contents)}}});Dialog.HTML=Class.create(Dialog.Base,{initialize:function($super,b,a){if(Object.isString(b)){$super(new Element("div").update(b),a)}else{$super(b,a)}}});Dialog.Frame=Class.create(Dialog.Base,{initialize:function($super,e,c,b){var a=Object.isString(c)?new Element("div").update(c):c;var d=new Element("div",{"class":"_pp_dialog _pp_panel"});if(b&&b.height){d.style.height=b.height+"px";delete b.height}d.appendChild(new Element("div",{"class":"_pp_title"}).update(e));d.appendChild(a);$super(d,b)}});Dialog.Ajax=Class.create(Dialog.Base,{initialize:function($super,b,a){$super(new Element("div"),a);this.url=b},show:function(){var a='<div style="text-align: center; color: #999;">Loading...</div>';if(this.options.loadingIcon){a='<div style="text-align: center;"><img src="'+this.options.loadingIcon+'" /></div><br />'+a}this.contents.update(a);new Ajax.Updater(this.contents,this.url,{method:"get",onComplete:function(b){}});this.baseShow()}});Protoplasm.register("dialog",Dialog.HTML);