if(!window.MModalbox){var MModalbox=new Object()}MModalbox.Methods={overrideAlert:false,focusableElements:new Array,currFocused:0,initialized:false,active:true,options:{title:"MModalbox Window",overlayClose:false,width:500,height:90,overlayOpacity:0.65,overlayDuration:0.15,slideDownDuration:0.1,slideUpDuration:0.1,resizeDuration:0.1,inactiveFade:true,transitions:true,loadingString:"Please wait. Loading...",closeString:"Close window",closeValue:"<img src='/image/close.png' alt='Close window'>",params:{},method:"post",autoFocusing:false,aspnet:false},_options:new Object,setOptions:function(a){Object.extend(this.options,a||{})},_init:function(b){Object.extend(this._options,this.options);this.setOptions(b);this.MMBoverlay=new Element("div",{id:"MMB_overlay",opacity:"0"});this.MMBwindow=new Element("div",{id:"MMB_window",style:"display: none"}).update(this.MMBframe=new Element("div",{id:"MMB_frame"}).update(this.MMBheader=new Element("div",{id:"MMB_header"}).update(this.MMBcaption=new Element("div",{id:"MMB_caption"}))));this.MMBclose=new Element("a",{id:"MMB_close",title:this.options.closeString,href:"#"}).update("<span>"+this.options.closeValue+"</span>");this.MMBheader.insert({bottom:this.MMBclose});this.MMBcontent=new Element("div",{id:"MMB_content"}).update(this.MMBloading=new Element("div",{id:"MMB_loading"}).update(this.options.loadingString));this.MMBframe.insert({bottom:this.MMBcontent});var a=this.options.aspnet?$(document.body).down("form"):$(document.body);a.insert({top:this.MMBwindow});a.insert({top:this.MMBoverlay});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(b,a){if(!this.initialized){this._init(a)}this.content=b;this.setOptions(a);if(this.options.title){$(this.MMBcaption).update(this.options.title)}else{$(this.MMBheader).hide();$(this.MMBcaption).hide()}if(this.MMBwindow.style.display=="none"){this._appear();this.event("onShow")}else{this._update();this.event("onUpdate")}},hide:function(a){if(this.initialized){if(a&&typeof a.element!="function"){Object.extend(this.options,a)}this.event("beforeHide");if(this.options.transitions){Effect.SlideUp(this.MMBwindow,{duration:this.options.slideUpDuration,transition:Effect.Transitions.sinoidal,afterFinish:this._deinit.bind(this)})}else{$(this.MMBwindow).hide();this._deinit()}}else{throw ("MModalbox is not initialized.")}},_hide:function(a){a.stop();if(a.element().id=="MMB_overlay"&&!this.options.overlayClose){return false}this.hide()},alert:function(b){var a='<div class="MMB_alert"><p>'+b+'</p><input type="button" onclick="MModalbox.hide()" value="OK" /></div>';MModalbox.show(a,{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.MMBoverlay).setStyle({opacity:0});new Effect.Fade(this.MMBoverlay,{from:0,to:this.options.overlayOpacity,duration:this.options.overlayDuration,afterFinish:function(){new Effect.SlideDown(this.MMBwindow,{duration:this.options.slideDownDuration,transition:Effect.Transitions.sinoidal,afterFinish:function(){this._setPosition();this.loadContent()}.bind(this)})}.bind(this)})}else{$(this.MMBoverlay).setStyle({opacity:this.options.overlayOpacity});$(this.MMBwindow).show();this._setPosition();this.loadContent()}this._setWidthAndPosition=this._setWidthAndPosition.bindAsEventListener(this);Event.observe(window,"resize",this._setWidthAndPosition)},resize:function(g,h,c){var f=$(this.MMBwindow).getHeight();var d=$(this.MMBwindow).getWidth();var e=$(this.MMBheader).getHeight();var b=$(this.MMBcontent).getHeight();var a=((f-e+h)<b)?(b+e-f):h;if(c){this.setOptions(c)}if(this.options.transitions){new Effect.ScaleBy(this.MMBwindow,g,a,{duration:this.options.resizeDuration,afterFinish:function(){this.event("_afterResize");this.event("afterResize")}.bind(this)})}else{this.MMBwindow.setStyle({width:d+g+"px",height:f+a+"px"});setTimeout(function(){this.event("_afterResize");this.event("afterResize")}.bind(this),1)}},resizeToContent:function(a){var b=this.options.height-this.MMBwindow.offsetHeight;if(b!=0){if(a){this.setOptions(a)}MModalbox.resize(0,b)}},resizeToInclude:function(c,b){var d=$(c);var a=d.getHeight()+parseInt(d.getStyle("margin-top"))+parseInt(d.getStyle("margin-bottom"))+parseInt(d.getStyle("border-top-width"))+parseInt(d.getStyle("border-bottom-width"));if(a>0){if(b){this.setOptions(b)}MModalbox.resize(0,a)}},_update:function(){$(this.MMBcontent).update("");this.MMBcontent.appendChild(this.MMBloading);$(this.MMBloading).update(this.options.loadingString);this.currentDims=[this.MMBwindow.offsetWidth,this.MMBwindow.offsetHeight];MModalbox.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"){var htmlRegExp=new RegExp(/<\/?[^>]+>/gi);if(htmlRegExp.test(this.content)){this._insertContent(this.content.stripScripts());this._putContent(function(){this.content.extractScripts().map(function(script){return eval(script.replace("<!--","").replace("// -->",""))}.bind(window))}.bind(this))}else{new Ajax.Request(this.content,{method:this.options.method.toLowerCase(),parameters:this.options.params,onSuccess:function(transport){var response=new String(transport.responseText);this._insertContent(transport.responseText.stripScripts());this._putContent(function(){response.extractScripts().map(function(script){return eval(script.replace("<!--","").replace("// -->",""))}.bind(window))})}.bind(this),onException:function(instance,exception){MModalbox.hide();throw ("MModalbox Loading Error: "+exception)}})}}else{if(typeof this.content=="object"){this._insertContent(this.content);this._putContent()}else{MModalbox.hide();throw ("MModalbox Parameters Error: Please specify correct URL or HTML element (plain HTML or object)")}}}},_insertContent:function(b){$(this.MMBcontent).hide().update("");if(typeof b=="string"){setTimeout(function(){this.MMBcontent.update(b)}.bind(this),1)}else{if(typeof b=="object"){var a=b.cloneNode(true);if(b.id){b.id="MMB_"+b.id}$(b).select("*[id]").each(function(c){c.id="MMB_"+c.id});this.MMBcontent.appendChild(a);this.MMBcontent.down().show();if(Prototype.Browser.IE){$$("#MMB_content select").invoke("setStyle",{visibility:""})}}}},_putContent:function(a){if(this.options.height==this._options.height){setTimeout(function(){MModalbox.resize(0,$(this.MMBcontent).getHeight()-$(this.MMBwindow).getHeight()+$(this.MMBheader).getHeight(),{afterResize:function(){this.MMBcontent.show().makePositioned();setTimeout(function(){if(a!=undefined){a()}this.event("afterLoad")}.bind(this),1)}.bind(this)})}.bind(this),1)}else{this._setWidth();this.MMBcontent.setStyle({overflow:"auto",height:$(this.MMBwindow).getHeight()-$(this.MMBheader).getHeight()-13+"px"});this.MMBcontent.show();setTimeout(function(){if(a!=undefined){a()}this.event("afterLoad")}.bind(this),1)}},activate:function(a){this.setOptions(a);this.active=true;$(this.MMBclose).observe("click",this.hideObserver);if(this.options.overlayClose){$(this.MMBoverlay).observe("click",this.hideObserver)}$(this.MMBclose).show();if(this.options.transitions&&this.options.inactiveFade){new Effect.Appear(this.MMBwindow,{duration:this.options.slideUpDuration})}},deactivate:function(a){this.setOptions(a);this.active=false;$(this.MMBclose).stopObserving("click",this.hideObserver);if(this.options.overlayClose){$(this.MMBoverlay).stopObserving("click",this.hideObserver)}$(this.MMBclose).hide();if(this.options.transitions&&this.options.inactiveFade){new Effect.Fade(this.MMBwindow,{duration:this.options.slideUpDuration,to:0.75})}},_initObservers:function(){$(this.MMBclose).observe("click",this.hideObserver);if(this.options.overlayClose){$(this.MMBoverlay).observe("click",this.hideObserver)}if(Prototype.Browser.IE){Event.observe(document,"keydown",this.kbdObserver)}else{Event.observe(document,"keypress",this.kbdObserver)}},_removeObservers:function(){$(this.MMBclose).stopObserving("click",this.hideObserver);if(this.options.overlayClose){$(this.MMBoverlay).stopObserving("click",this.hideObserver)}if(Prototype.Browser.IE){Event.stopObserving(document,"keydown",this.kbdObserver)}else{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{if($(this.MMBclose).visible()){$(this.MMBclose).focus()}}},_findFocusableElements:function(){this.MMBcontent.select("input:not([type~=hidden]), select, textarea, button, a[href]").invoke("addClassName","MMB_focusable");return this.MMBcontent.select(".MMB_focusable")},_kbdHandler:function(b){var a=b.element();switch(b.keyCode){case Event.KEY_TAB:if(a!=this.focusableElements[this.currFocused]){this.currFocused=this.focusableElements.toArray().indexOf(a)}if(!b.shiftKey){if(this.currFocused==this.focusableElements.length-1){this.currFocused=0}else{this.currFocused++;this.focusableElements[this.currFocused].focus()}}else{if(this.currFocused==0){this.focusableElements.last().focus();this.currFocused=this.focusableElements.length-1}else{this.currFocused--;this.focusableElements[this.currFocused].focus()}}break;case Event.KEY_ESC:if(this.active){MModalbox.hide()}break;case 32:this._preventScroll(b);break;case 0:if(b.which==32){this._preventScroll(b)}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(a.tagName.toLowerCase())){b.stop()}else{if((a.tagName.toLowerCase()=="input"&&["submit","button"].include(a.type))||(a.tagName.toLowerCase()=="a")){b.stop()}}break}},_preventScroll:function(a){if(!["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.MMBoverlay,"appear",{duration:this.options.overlayDuration,afterFinish:this._removeElements.bind(this)})}else{this.MMBoverlay.hide();this._removeElements()}$(this.MMBcontent).setStyle({overflow:"",height:""})},_removeElements:function(){$(this.MMBoverlay).remove();$(this.MMBwindow).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(/MMB_/)){this.content.id=this.content.id.replace(/MMB_/,"")}this.content.select("*[id]").each(function(a){a.id=a.id.replace(/MMB_/,"")})}this.initialized=false;this.event("afterHide");this.setOptions(this._options)},_setWidth:function(){$(this.MMBwindow).setStyle({width:this.options.width+"px",height:this.options.height+"px"})},_setPosition:function(){$(this.MMBwindow).setStyle({left:Math.round((Element.getWidth(document.body)-Element.getWidth(this.MMBwindow))/2)+"px"})},_setWidthAndPosition:function(){$(this.MMBwindow).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;if(b!=undefined){return b}else{return true}}return true}};Object.extend(MModalbox,MModalbox.Methods);if(MModalbox.overrideAlert){window.alert=MModalbox.alert}Effect.ScaleBy=Class.create();Object.extend(Object.extend(Effect.ScaleBy.prototype,Effect.Base.prototype),{initialize:function(b,c,d,a){this.element=$(b);var a=Object.extend({scaleFromTop:true,scaleMode:"box",scaleByWidth:c,scaleByHeight:d},arguments[3]||{});this.start(a)},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 c=this.dims[0]+(this.deltaY*a);var b=this.dims[1]+(this.deltaX*a);c=(c>0)?c:0;b=(b>0)?b:0;this.setDimensions(c,b)},setDimensions:function(a,e){var f={};f.width=e+"px";f.height=a+"px";var c=Math.round((a-this.dims[0])/2);var b=Math.round((e-this.dims[1])/2);if(this.elementPositioning=="absolute"||this.elementPositioning=="fixed"){if(!this.options.scaleFromTop){f.top=this.originalTop-c+"px"}f.left=this.originalLeft-b+"px"}else{if(!this.options.scaleFromTop){f.top=-c+"px"}f.left=-b+"px"}this.element.setStyle(f)}});
