if(!window.Modalbox){
var Modalbox=new Object();
}
Modalbox.Methods={overrideAlert:false,focusableElements:new Array,currFocused:0,initialized:false,active:true,options:{title:"ModalBox Window",overlayClose:true,width:500,height:90,overlayOpacity:0.65,overlayDuration:0.25,slideDownDuration:0.5,slideUpDuration:0.5,resizeDuration:0.25,inactiveFade:true,transitions:true,loadingString:"Please wait. Loading...",closeString:"Close window",closeValue:"&times;",params:{},method:"get",autoFocusing:true,aspnet:false},_options:new Object,setOptions:function(_1){
Object.extend(this.options,_1||{});
},_init:function(_2){
Object.extend(this._options,this.options);
this.setOptions(_2);
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});
var _3=this.options.aspnet?$(document.body).down("form"):$(document.body);
_3.insert({"top":this.MBwindow});
_3.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(_4,_5){
if(!this.initialized){
this._init(_5);
}
this.content=_4;
this.setOptions(_5);
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(_6){
if(this.initialized){
if(_6&&typeof _6.element!="function"){
Object.extend(this.options,_6);
}
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(_7){
_7.stop();
if(_7.element().id=="MB_overlay"&&!this.options.overlayClose){
return false;
}
this.hide();
},alert:function(_8){
var _9="<div class=\"MB_alert\"><p>"+_8+"</p><input type=\"button\" onclick=\"Modalbox.hide()\" value=\"OK\" /></div>";
Modalbox.show(_9,{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._fixAds("none");
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.MBoverlay).getWidth();
var _e=$(this.MBwindow).getHeight();
var _f=$(this.MBwindow).getWidth();
var _10=$(this.MBheader).getHeight();
var _11=$(this.MBcontent).getHeight();
var _12=((_e-_10+_b)<_11)?(_11+_10):(_e+_b);
var _13=_f+_a;
if(_c){
this.setOptions(_c);
}
if(this.options.transitions){
new Effect.Morph(this.MBwindow,{style:"width:"+_13+"px; height:"+_12+"px; left:"+((_d-_13)/2)+"px",duration:this.options.resizeDuration,beforeStart:function(fx){
fx.element.setStyle({overflow:"hidden"});
},afterFinish:function(fx){
fx.element.setStyle({overflow:"visible"});
this.event("_afterResize");
this.event("afterResize");
}.bind(this)});
}else{
this.MBwindow.setStyle({width:_13+"px",height:_12+"px"});
setTimeout(function(){
this.event("_afterResize");
this.event("afterResize");
}.bind(this),1);
}
},resizeToContent:function(_16){
var _17=this.options.height-this.MBwindow.offsetHeight;
if(_17!=0){
if(_16){
this.setOptions(_16);
}
Modalbox.resize(0,_17);
}
},resizeToInclude:function(_18,_19){
var el=$(_18);
var _1b=el.getHeight()+parseInt(el.getStyle("margin-top"))+parseInt(el.getStyle("margin-bottom"))+parseInt(el.getStyle("border-top-width"))+parseInt(el.getStyle("border-bottom-width"));
if(_1b>0){
if(_19){
this.setOptions(_19);
}
Modalbox.resize(0,_1b);
}
},_update:function(){
$(this.MBcontent).update($(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"){
var _1c=new RegExp(/<\/?[^>]+>/gi);
if(_1c.test(this.content)){
this._insertContent(this.content.stripScripts(),function(){
this.content.extractScripts().map(function(_1d){
return eval(_1d.replace("<!--","").replace("// -->",""));
}.bind(window));
}.bind(this));
}else{
new Ajax.Request(this.content,{method:this.options.method.toLowerCase(),parameters:this.options.params,onSuccess:function(_1e){
var _1f=new String(_1e.responseText);
this._insertContent(_1e.responseText.stripScripts(),function(){
_1f.extractScripts().map(function(_20){
return eval(_20.replace("<!--","").replace("// -->",""));
}.bind(window));
});
}.bind(this),onException:function(_21,_22){
Modalbox.hide();
throw ("Modalbox Loading Error: "+_22);
}});
}
}else{
if(typeof this.content=="object"){
this._insertContent(this.content);
}else{
Modalbox.hide();
throw ("Modalbox Parameters Error: Please specify correct URL or HTML element (plain HTML or object)");
}
}
}
},_insertContent:function(_23,_24){
$(this.MBcontent).hide().update("");
if(typeof _23=="string"){
this.MBcontent.update(new Element("div",{style:"display: none"}).update(_23)).down().show();
}else{
if(typeof _23=="object"){
var _25=_23.cloneNode(true);
if(_23.id){
_23.id="MB_"+_23.id;
}
$(_23).select("*[id]").each(function(el){
el.id="MB_"+el.id;
});
this.MBcontent.update(_25).down("div").show();
if(Prototype.Browser.IE){
$$("#MB_content select").invoke("setStyle",{"visibility":""});
}
}
}
if(this.options.height==this._options.height){
Modalbox.resize(0,$(this.MBcontent).getHeight()-$(this.MBwindow).getHeight()+$(this.MBheader).getHeight(),{afterResize:function(){
setTimeout(function(){
this._putContent(_24);
}.bind(this),1);
}.bind(this)});
}else{
this._setWidth();
this.MBcontent.setStyle({overflow:"auto",height:$(this.MBwindow).getHeight()-$(this.MBheader).getHeight()-13+"px"});
setTimeout(function(){
this._putContent(_24);
}.bind(this),1);
}
},_putContent:function(_27){
this.MBcontent.show();
this.focusableElements=this._findFocusableElements();
this._setFocus();
if(_27!=undefined){
_27();
}
this.event("afterLoad");
},activate:function(_28){
this.setOptions(_28);
this.active=true;
$(this.MBclose).observe("click",this.hideObserver);
if(this.options.overlayClose){
$(this.MBoverlay).observe("click",this.hideObserver);
}
$(this.MBclose).show();
if(this.options.transitions&&this.options.inactiveFade){
new Effect.Appear(this.MBwindow,{duration:this.options.slideUpDuration});
}
},deactivate:function(_29){
this.setOptions(_29);
this.active=false;
$(this.MBclose).stopObserving("click",this.hideObserver);
if(this.options.overlayClose){
$(this.MBoverlay).stopObserving("click",this.hideObserver);
}
$(this.MBclose).hide();
if(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);
if(this.options.overlayClose){
$(this.MBoverlay).observe("click",this.hideObserver);
}
if(Prototype.Browser.Gecko){
Event.observe(document,"keypress",this.kbdObserver);
}else{
Event.observe(document,"keydown",this.kbdObserver);
}
},_removeObservers:function(){
$(this.MBclose).stopObserving("click",this.hideObserver);
if(this.options.overlayClose){
$(this.MBoverlay).stopObserving("click",this.hideObserver);
}
if(Prototype.Browser.Gecko){
Event.stopObserving(document,"keypress",this.kbdObserver);
}else{
Event.stopObserving(document,"keydown",this.kbdObserver);
}
},_loadAfterResize:function(){
this._setWidth();
this._setPosition();
this.loadContent();
},_setFocus:function(){
if(this.focusableElements.length>0&&this.options.autoFocusing==true){
var _2a=this.focusableElements.find(function(el){
return el.tabIndex==1;
})||this.focusableElements.first();
this.currFocused=this.focusableElements.toArray().indexOf(_2a);
_2a.focus();
}else{
if($(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(_2c){
var _2d=_2c.element();
switch(_2c.keyCode){
case Event.KEY_TAB:
_2c.stop();
if(_2d!=this.focusableElements[this.currFocused]){
this.currFocused=this.focusableElements.toArray().indexOf(_2d);
}
if(!_2c.shiftKey){
if(this.currFocused==this.focusableElements.length-1){
this.focusableElements.first().focus();
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){
this._hide(_2c);
}
break;
case 32:
this._preventScroll(_2c);
break;
case 0:
if(_2c.which==32){
this._preventScroll(_2c);
}
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(_2d.tagName.toLowerCase())){
_2c.stop();
}else{
if((_2d.tagName.toLowerCase()=="input"&&["submit","button"].include(_2d.type))||(_2d.tagName.toLowerCase()=="a")){
_2c.stop();
}
}
break;
}
},_preventScroll:function(_2e){
if(!["input","textarea","select","button"].include(_2e.element().tagName.toLowerCase())){
_2e.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);
}
this._fixAds("");
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(el){
el.id=el.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 _30;
if(document.documentElement&&document.documentElement.scrollTop){
_30=document.documentElement.scrollTop;
}else{
if(document.body){
_30=document.body.scrollTop;
}
}
return _30;
},_prepareIE:function(_31,_32){
$$("html, body").invoke("setStyle",{width:_31,height:_31,overflow:_32});
$$("select").invoke("setStyle",{"visibility":_32});
},_fixAds:function(_33){
if(document.getElementById("AdControl1")!=null){
document.getElementById("AdControl1").style.display=_33;
}
if(document.getElementById("AdControl2")!=null){
document.getElementById("AdControl2").style.display=_33;
}
if(document.getElementById("AdControl3")!=null){
document.getElementById("AdControl3").style.display=_33;
}
if(document.getElementById("AdControl4")!=null){
document.getElementById("AdControl4").style.display=_33;
}
},event:function(_34){
if(this.options[_34]){
var _35=this.options[_34]();
this.options[_34]=null;
if(_35!=undefined){
return _35;
}else{
return true;
}
}
return true;
}};
Object.extend(Modalbox,Modalbox.Methods);
if(Modalbox.overrideAlert){
window.alert=Modalbox.alert;
}

