if(!window.Modalbox)var Modalbox={};
Modalbox.Methods={overrideAlert:false,focusableElements:[],currFocused:0,initialized:false,active:true,options:{title:"ModalBox Window",overlayClose:false,width:400,height:90,overlayOpacity:0.65,overlayDuration:0.15,slideDownDuration:0.25,slideUpDuration:0.15,resizeDuration:0.15,inactiveFade:true,transitions:true,loadingString:"Please wait. Loading...",closeString:"Close window",closeValue:"&times;",params:{},method:"get",autoFocusing:true,aspnet:false},_options:{},setOptions:function(a){Object.extend(this.options,
a||{})},_init:function(a){Object.extend(this._options,this.options);this.setOptions(a);this.MBoverlay=new Element("div",{id:"MB_overlay",opacity:"0"});this.MBwindow=(new Element("div",{id:"MB_window",style:"display: none"})).update(this.MBframe=(new Element("div",{id:"MB_frame"})).update(this.MBheader=(new Element("div",{id:"MB_header"})).update(this.MBcaption=new Element("div",{id:"MB_caption"}))));this.MBclose=(new Element("a",{id:"MB_close",title:this.options.closeString,href:"#"})).update("<span>"+
this.options.closeValue+"</span>");this.MBheader.insert({bottom:this.MBclose});this.MBcontent=(new Element("div",{id:"MB_content"})).update(this.MBloading=(new Element("div",{id:"MB_loading"})).update(this.options.loadingString));this.MBframe.insert({bottom:this.MBcontent});a=this.options.aspnet?$(document.body).down("form"):$(document.body);a.insert({top:this.MBwindow});a.insert({top:this.MBoverlay});this.initScrollX=window.pageXOffset||document.body.scrollLeft||document.documentElement.scrollLeft;
this.initScrollY=window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop;this.hideObserver=this._hide.bindAsEventListener(this);this.kbdObserver=this._kbdHandler.bindAsEventListener(this);this._initObservers();this.initialized=true},show:function(a,b){this.initialized||this._init(b);this.content=a;this.setOptions(b);if(this.options.title)$(this.MBcaption).update(this.options.title);else{$(this.MBheader).hide();$(this.MBcaption).hide()}if(this.MBwindow.style.display=="none"){this._appear();
this.event("onShow")}else{this._update();this.event("onUpdate")}},hide:function(a){if(this.initialized){a&&typeof a.element!="function"&&Object.extend(this.options,a);this.event("beforeHide");if(this.options.transitions)Effect.SlideUp(this.MBwindow,{duration:this.options.slideUpDuration,transition:Effect.Transitions.sinoidal,afterFinish:this._deinit.bind(this)});else{$(this.MBwindow).hide();this._deinit()}}else throw"Modalbox is not initialized.";},_hide:function(a){a.stop();if(a.element().id=="MB_overlay"&&
!this.options.overlayClose)return false;this.hide()},alert:function(a){Modalbox.show('<div class="MB_alert"><p>'+a+'</p><input type="button" onclick="Modalbox.hide()" value="OK" /></div>',{title:"Alert: "+document.title,width:300})},_appear:function(){if(Prototype.Browser.IE&&!navigator.appVersion.match(/\b7.0\b/)){window.scrollTo(0,0);this._prepareIE("100%","hidden")}this._setWidth();this._setPosition();if(this.options.transitions){$(this.MBoverlay).setStyle({opacity:0});new Effect.Fade(this.MBoverlay,
{from:0,to:this.options.overlayOpacity,duration:this.options.overlayDuration,afterFinish:function(){new Effect.SlideDown(this.MBwindow,{duration:this.options.slideDownDuration,transition:Effect.Transitions.sinoidal,afterFinish:function(){this._setPosition();this.loadContent()}.bind(this)})}.bind(this)})}else{$(this.MBoverlay).setStyle({opacity:this.options.overlayOpacity});$(this.MBwindow).show();this._setPosition();this.loadContent()}this._setWidthAndPosition=this._setWidthAndPosition.bindAsEventListener(this);
Event.observe(window,"resize",this._setWidthAndPosition)},resize:function(a,b,c){var d=$(this.MBwindow).getHeight(),e=$(this.MBwindow).getWidth(),f=$(this.MBheader).getHeight(),g=$(this.MBcontent).getHeight();b=d-f+b<g?g+f-d:b;c&&this.setOptions(c);if(this.options.transitions)new Effect.ScaleBy(this.MBwindow,a,b,{duration:this.options.resizeDuration,afterFinish:function(){this.event("_afterResize");this.event("afterResize")}.bind(this)});else{this.MBwindow.setStyle({width:e+a+"px",height:d+b+"px"});
setTimeout(function(){this.event("_afterResize");this.event("afterResize")}.bind(this),1)}},resizeToContent:function(a){var b=this.options.height-this.MBwindow.offsetHeight;if(b!=0){a&&this.setOptions(a);Modalbox.resize(0,b)}},resizeToInclude:function(a,b){var c=$(a);c=c.getHeight()+parseInt(c.getStyle("margin-top"))+parseInt(c.getStyle("margin-bottom"))+parseInt(c.getStyle("border-top-width"))+parseInt(c.getStyle("border-bottom-width"));if(c>0){b&&this.setOptions(b);Modalbox.resize(0,c)}},_update:function(){$(this.MBcontent).update("");
this.MBcontent.appendChild(this.MBloading);$(this.MBloading).update(this.options.loadingString);this.currentDims=[this.MBwindow.offsetWidth,this.MBwindow.offsetHeight];Modalbox.resize(this.options.width-this.currentDims[0],this.options.height-this.currentDims[1],{_afterResize:this._loadAfterResize.bind(this)})},loadContent:function(){if(this.event("beforeLoad")!=false)if(typeof this.content=="string")if(RegExp(/<\/?[^>]+>/gi).test(this.content)){this._insertContent(this.content.stripScripts());this._putContent(function(){this.content.extractScripts().map(function(a){return eval(a.replace("<!--",
"").replace("// --\>",""))}.bind(window))}.bind(this))}else new Ajax.Request(this.content,{method:this.options.method.toLowerCase(),parameters:this.options.params,onSuccess:function(a){var b=new String(a.responseText);this._insertContent(a.responseText.stripScripts());this._putContent(function(){b.extractScripts().map(function(c){return eval(c.replace("<!--","").replace("// --\>",""))}.bind(window))})}.bind(this),onException:function(a,b){Modalbox.hide();throw"Modalbox Loading Error: "+b;}});else if(typeof this.content==
"object"){this._insertContent(this.content);this._putContent()}else{Modalbox.hide();throw"Modalbox Parameters Error: Please specify correct URL or HTML element (plain HTML or object)";}},_insertContent:function(a){$(this.MBcontent).hide().update("");if(typeof a=="string")setTimeout(function(){this.MBcontent.update(a)}.bind(this),1);else if(typeof a=="object"){var b=a.cloneNode(true);if(a.id)a.id="MB_"+a.id;$(a).select("*[id]").each(function(c){c.id="MB_"+c.id});this.MBcontent.appendChild(b);this.MBcontent.down().show();
Prototype.Browser.IE&&$$("#MB_content select").invoke("setStyle",{visibility:""})}},_putContent:function(a){if(this.options.height==this._options.height)setTimeout(function(){Modalbox.resize(0,$(this.MBcontent).getHeight()-$(this.MBwindow).getHeight()+$(this.MBheader).getHeight(),{afterResize:function(){this.MBcontent.show().makePositioned();this.focusableElements=this._findFocusableElements();this._setFocus();setTimeout(function(){a!=undefined&&a();this.event("afterLoad")}.bind(this),1)}.bind(this)})}.bind(this),
1);else{this._setWidth();this.MBcontent.setStyle({overflow:"auto",height:$(this.MBwindow).getHeight()-$(this.MBheader).getHeight()-13+"px"});this.MBcontent.show();this.focusableElements=this._findFocusableElements();this._setFocus();setTimeout(function(){a!=undefined&&a();this.event("afterLoad")}.bind(this),1)}},activate:function(a){this.setOptions(a);this.active=true;$(this.MBclose).observe("click",this.hideObserver);this.options.overlayClose&&$(this.MBoverlay).observe("click",this.hideObserver);
$(this.MBclose).show();this.options.transitions&&this.options.inactiveFade&&new Effect.Appear(this.MBwindow,{duration:this.options.slideUpDuration})},deactivate:function(a){this.setOptions(a);this.active=false;$(this.MBclose).stopObserving("click",this.hideObserver);this.options.overlayClose&&$(this.MBoverlay).stopObserving("click",this.hideObserver);$(this.MBclose).hide();this.options.transitions&&this.options.inactiveFade&&new Effect.Fade(this.MBwindow,{duration:this.options.slideUpDuration,to:0.75})},
_initObservers:function(){$(this.MBclose).observe("click",this.hideObserver);this.options.overlayClose&&$(this.MBoverlay).observe("click",this.hideObserver);Prototype.Browser.IE?Event.observe(document,"keydown",this.kbdObserver):Event.observe(document,"keypress",this.kbdObserver)},_removeObservers:function(){$(this.MBclose).stopObserving("click",this.hideObserver);this.options.overlayClose&&$(this.MBoverlay).stopObserving("click",this.hideObserver);Prototype.Browser.IE?Event.stopObserving(document,
"keydown",this.kbdObserver):Event.stopObserving(document,"keypress",this.kbdObserver)},_loadAfterResize:function(){this._setWidth();this._setPosition();this.loadContent()},_setFocus:function(){if(this.focusableElements.length>0&&this.options.autoFocusing==true){var a=this.focusableElements.find(function(b){return b.tabIndex==1})||this.focusableElements.first();this.currFocused=this.focusableElements.toArray().indexOf(a);a.focus()}else $(this.MBclose).visible()&&$(this.MBclose).focus()},_findFocusableElements:function(){this.MBcontent.select("input:not([type~=hidden]), select, textarea, button, a[href]").invoke("addClassName",
"MB_focusable");return this.MBcontent.select(".MB_focusable")},_kbdHandler:function(a){var b=a.element();switch(a.keyCode){case Event.KEY_TAB:a.stop();if(b!=this.focusableElements[this.currFocused])this.currFocused=this.focusableElements.toArray().indexOf(b);if(a.shiftKey)if(this.currFocused==0){this.focusableElements.last().focus();this.currFocused=this.focusableElements.length-1}else{this.currFocused--;this.focusableElements[this.currFocused].focus()}else if(this.currFocused==this.focusableElements.length-
1){this.focusableElements.first().focus();this.currFocused=0}else{this.currFocused++;this.focusableElements[this.currFocused].focus()}break;case Event.KEY_ESC:this.active&&this._hide(a);break;case 32:this._preventScroll(a);break;case 0:a.which==32&&this._preventScroll(a);break;case Event.KEY_UP:case Event.KEY_DOWN:case Event.KEY_PAGEDOWN:case Event.KEY_PAGEUP:case Event.KEY_HOME:case Event.KEY_END:if(Prototype.Browser.WebKit&&!["textarea","select"].include(b.tagName.toLowerCase()))a.stop();else if(b.tagName.toLowerCase()==
"input"&&["submit","button"].include(b.type)||b.tagName.toLowerCase()=="a")a.stop()}},_preventScroll:function(a){["input","textarea","select","button"].include(a.element().tagName.toLowerCase())||a.stop()},_deinit:function(){this._removeObservers();Event.stopObserving(window,"resize",this._setWidthAndPosition);if(this.options.transitions)Effect.toggle(this.MBoverlay,"appear",{duration:this.options.overlayDuration,afterFinish:this._removeElements.bind(this)});else{this.MBoverlay.hide();this._removeElements()}$(this.MBcontent).setStyle({overflow:"",
height:""})},_removeElements:function(){$(this.MBoverlay).remove();$(this.MBwindow).remove();if(Prototype.Browser.IE&&!navigator.appVersion.match(/\b7.0\b/)){this._prepareIE("","");window.scrollTo(this.initScrollX,this.initScrollY)}if(typeof this.content=="object"){if(this.content.id&&this.content.id.match(/MB_/))this.content.id=this.content.id.replace(/MB_/,"");this.content.select("*[id]").each(function(a){a.id=a.id.replace(/MB_/,"")})}this.initialized=false;this.event("afterHide");this.setOptions(this._options)},
_setWidth:function(){$(this.MBwindow).setStyle({width:this.options.width+"px",height:this.options.height+"px"})},_setPosition:function(){$(this.MBwindow).setStyle({left:Math.round((Element.getWidth(document.body)-Element.getWidth(this.MBwindow))/2)+"px"})},_setWidthAndPosition:function(){$(this.MBwindow).setStyle({width:this.options.width+"px"});this._setPosition()},_getScrollTop:function(){var a;if(document.documentElement&&document.documentElement.scrollTop)a=document.documentElement.scrollTop;
else if(document.body)a=document.body.scrollTop;return a},_prepareIE:function(a,b){$$("html, body").invoke("setStyle",{width:a,height:a,overflow:b});$$("select").invoke("setStyle",{visibility:b})},event:function(a){if(this.options[a]){var b=this.options[a]();this.options[a]=null;return b!=undefined?b:true}return true}};Object.extend(Modalbox,Modalbox.Methods);if(Modalbox.overrideAlert)window.alert=Modalbox.alert;Effect.ScaleBy=Class.create();
Object.extend(Object.extend(Effect.ScaleBy.prototype,Effect.Base.prototype),{initialize:function(a,b,c,d){this.element=$(a);d=Object.extend({scaleFromTop:true,scaleMode:"box",scaleByWidth:b,scaleByHeight:c},d||{});this.start(d)},setup:function(){this.elementPositioning=this.element.getStyle("position");this.originalTop=this.element.offsetTop;this.originalLeft=this.element.offsetLeft;this.dims=null;if(this.options.scaleMode=="box")this.dims=[this.element.offsetHeight,this.element.offsetWidth];if(/^content/.test(this.options.scaleMode))this.dims=
[this.element.scrollHeight,this.element.scrollWidth];if(!this.dims)this.dims=[this.options.scaleMode.originalHeight,this.options.scaleMode.originalWidth];this.deltaY=this.options.scaleByHeight;this.deltaX=this.options.scaleByWidth},update:function(a){var b=this.dims[0]+this.deltaY*a;a=this.dims[1]+this.deltaX*a;b=b>0?b:0;a=a>0?a:0;this.setDimensions(b,a)},setDimensions:function(a,b){var c={};c.width=b+"px";c.height=a+"px";var d=Math.round((a-this.dims[0])/2),e=Math.round((b-this.dims[1])/2);if(this.elementPositioning==
"absolute"||this.elementPositioning=="fixed"){if(!this.options.scaleFromTop)c.top=this.originalTop-d+"px";c.left=this.originalLeft-e+"px"}else{if(!this.options.scaleFromTop)c.top=-d+"px";c.left=-e+"px"}this.element.setStyle(c)}});
