
var pModal=function(file,config){this.uniqueid='PMODAL'+Math.random();if(!file)
file='';config=config||{}
if(typeof file=='object'){config=file;file='';}
this.body={};this.config={file:file,className:config.className||'',showOverlay:(config.showOverlay==undefined||config.showOverlay)?true:config.showOverlay,autoScroll:(config.autoScroll==undefined||config.autoScroll)?true:config.autoScroll,effects:null};pModal.createOverlay();this.create();};var pModalElements=[];var pModalEvent={};pModalEvent.ONCREATE='oncreate';pModalEvent.ONCOMPLETE='oncomplete';pModalEvent.ONERROR='onerror';pModalEvent.ONCLOSE='onclose';pModalEvent.ONSHOW='onshow';pModalEvent.ONHIDE='onhide';pModalEvent.ONCHANGE='onchange';pModal.prototype.EVENTS=new pEvent();pModal.prototype.addListener=function(event,action){this.EVENTS.addListener(this.uniqueid,event,action,this);}
pModal.prototype.create=function(){pModalElements.push(this);this.body.modal=new Element('div').addClassName('modal').hide();pModal.overlay.insert({after:this.body.modal});this.body.content=new Element('div').addClassName('modal-content');this.body.modal.insert({top:this.body.content});this.load();this.EVENTS.fireEvent(null,this.uniqueid,pModalEvent.ONCREATE);return this;};pModal.prototype.load=function(file,className){if(file)
this.config.file=file;if(className)
this.config.className=className;new Ajax.Request(this.config.file,{onComplete:function(transport){this.body.content.update(transport.responseText);this.body.content.addClassName(this.config.className);this.EVENTS.fireEvent(null,this.uniqueid,pModalEvent.ONCOMPLETE);}.bind(this),onError:function(){this.EVENTS.fireEvent(null,this.uniqueid,pModalEvent.ONERROR);this.close();}.bind(this)})
return this;}
pModal.prototype.close=function(){this.body.modal.remove();pModal.hideOverlay();this.EVENTS.fireEvent(null,this.uniqueid,pModalEvent.ONCLOSE);return this;};pModal.prototype.show=function(){this.body.modal.show();if(this.config.autoScroll)
this.body.content.scrollTo();this.params=$A(arguments);if(this.config.showOverlay)
pModal.showOverlay();this.EVENTS.fireEvent(null,this.uniqueid,pModalEvent.ONSHOW);return this;};pModal.prototype.hide=function(){this.body.modal.hide();pModal.hideOverlay();this.EVENTS.fireEvent(null,this.uniqueid,pModalEvent.ONHIDE);return this;};pModal.prototype.setStyle=function(iterator){this.body.content.setStyle(iterator||{});return this;};pModal.prototype.getStyle=function(style){return this.body.content.getStyle(style);};pModal.prototype.change=function(){this.EVENTS.fireEvent(null,this.uniqueid,pModalEvent.ONCHANGE);return this;};pModal.OVERLAY_CREATED=false;pModal.OVERLAY_DISPLAY=false;pModal.createOverlay=function(){if(pModal.OVERLAY_CREATED)
return;pModal.overlay=new Element('div').addClassName('overlay').setStyle({opacity:'0.5'}).update('<div class="under-overlay"><\/div>').hide();$$('.content').first().insert({after:pModal.overlay});pModal.OVERLAY_CREATED=true;return pModal;};pModal.dimensionOverlay=function(){var dimensions=window.getDimensions();pModal.overlay.setStyle({height:dimensions.pageHeight+'px'});return pModal;};pModal.showOverlay=function(){if(pModal.OVERLAY_DISPLAY)
return;if(!pModal.OVERLAY_CREATED)
pModal.createOverlay();pModal.dimensionOverlay();pModal.overlay.show();pModal.OVERLAY_DISPLAY=true;return pModal;};pModal.hideOverlay=function(){if(!pModal.OVERLAY_DISPLAY)
return;if(!pModal.OVERLAY_CREATED)
pModal.createOverlay();pModal.overlay.hide();pModal.OVERLAY_DISPLAY=false;return pModal;};