﻿
eProject.Provide("eProject.Widgets.ModalMessageBox");eProject.Require("Libraries.jQuery.ui.interaction");eProject.Require("Libraries.jQuery.ui.effects");eProject.Require("Libraries.jQuery.ui.effectsSlide");(function()
{var TYPE={"NEUTRAL":0,"ERROR":1,"INFO":2,"WARNING":3,"VALIDATION":4,"PROMPT":5};var TEMPLATE_OVERLAY=$("<div class='messagebox-overlay' style='display:none;position:absolute;top:0px;left:0px;width:100%;height:100%;' />");var BASE_TEMPLATE=$("<div class='messagebox-container' style='visibility:hidden;outline:0;' hidefocus tabindex=0><div class='title'><span class='icon' /><span data='title' /></div><div class='message' data='msg' /><div class='buttons' data='buttons' /></div>");var TEMPLATE_NEUTRAL=BASE_TEMPLATE.clone().wrapInner("<div class='neutral'></div>");var TEMPLATE_ERROR=BASE_TEMPLATE.clone().wrapInner("<div class='error'></div>");var TEMPLATE_INFO=BASE_TEMPLATE.clone().wrapInner("<div class='info'></div>");var TEMPLATE_WARNING=BASE_TEMPLATE.clone().wrapInner("<div class='warning'></div>");var TEMPLATE_VALIDATION=BASE_TEMPLATE.clone().wrapInner("<div class='validation'></div>");var TEMPLATE_PROMPT=BASE_TEMPLATE.clone().wrapInner("<div class='neutral'></div>");var IE6_MESSABE_OVERLAY=null;if(jQuery.browser.msie&&parseInt(jQuery.browser.version,10)<7){IE6_MESSABE_OVERLAY=$("<iframe class='ie6-messagebox-container-overlay' src='javascript:\"<html></html>\";' frameborder='0' scrolling='no'/>");}
var overlay=null;var div=null;var hHide=null;var defaultOptions={"type":TYPE.NEUTRAL,"top":150,"min-width":300,"max-width":600,"overlay":true,"overlay-z-index":1004,"overlay-opacity":0.5,"z-index":1005,"close-on-esc":false,"onclose":null,"hide-delay":2500,"draggable":true,"fx":"slide","fx-speed":"fast"};var fnHeight=function(){if($.browser.msie&&$.browser.version<7){var scrollHeight=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);var offsetHeight=Math.max(document.documentElement.offsetHeight,document.body.offsetHeight);if(scrollHeight<offsetHeight){return $(window).height()+'px';}else{return scrollHeight+'px';}}else{return $(document).height()+'px';}};var fnWidth=function(){if($.browser.msie&&$.browser.version<7){var scrollWidth=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth);var offsetWidth=Math.max(document.documentElement.offsetWidth,document.body.offsetWidth);if(scrollWidth<offsetWidth){return $(window).width()+'px';}else{return scrollWidth+'px';}}else{return $(document).width()+'px';}};var ModalMessageBox=eProject.Widgets.ModalMessageBox={"TYPE":TYPE,"Info":function(msg){ModalMessageBox.Show("",msg,{"type":TYPE.INFO,"close-on-esc":true,"overlay":false,"top":-4,"min-width":150,"fx":"drop","fx-speed":"fast"});},"ValError":function(msg){ModalMessageBox.Show("",msg,{"type":TYPE.VALIDATION,"close-on-esc":true,"overlay":false,"top":-4,"min-width":150,"fx":"drop","fx-speed":100,"hide-delay":4000});},"Warn":function(title,msg,onclose){ModalMessageBox.Show(title,msg,{"type":TYPE.WARNING,"close-on-esc":true,"buttons":{"res:Button_Ok":null},"onclose":onclose});},"Error":function(title,msg,onclose){ModalMessageBox.Show(title,msg,{"type":TYPE.ERROR,"close-on-esc":true,"buttons":{"res:Button_Ok":null},"onclose":onclose});},"Confirm":function(title,msg,onconfirm,onclose){ModalMessageBox.Show(title,msg,{"type":TYPE.NEUTRAL,"close-on-esc":true,"buttons":{"res:Button_Yes":onconfirm,"res:Button_No":null},"onclose":onclose});},"Prompt":function(msg,callback){ModalMessageBox.Show(msg,"",{"type":TYPE.PROMPT,"close-on-esc":true,"overlay":true,"buttons":{"res:Button_Ok":callback},"fx":"drop","fx-speed":"fast"});},"Show":function(title,msg,options)
{var opts=$.extend({},defaultOptions,options);var onKeyDown=function(e){if(e.which==$.ui.keyCode.ESCAPE&&opts["close-on-esc"]){e.preventDefault();e.stopPropagation();ModalMessageBox.Close();return false;}
if(e.keyCode!==$.ui.keyCode.TAB)
return;var tabbables=div.find(':tabbable'),first=tabbables.filter(':first'),last=tabbables.filter(':last'),tabbedOut=!$(e.target).closest(".messagebox-container").length;if((tabbedOut||e.target===last[0])&&!e.shiftKey){first.focus();return false;}else if((tabbedOut||e.target===first[0])&&e.shiftKey){last.focus();return false;}};window.clearTimeout(hHide);if(overlay)
{overlay.stop(true,true);overlay.hide();}
if(div)div.stop(true,true);if(!overlay)
overlay=TEMPLATE_OVERLAY.clone().css("z-index",opts["overlay-z-index"]).css("opacity",opts["overlay-opacity"]).width(fnWidth()).height(fnHeight()).appendTo(document.body);if(div)div.remove();switch(opts.type)
{case TYPE.NEUTRAL:div=TEMPLATE_NEUTRAL.clone();break;case TYPE.ERROR:div=TEMPLATE_ERROR.clone();break;case TYPE.INFO:div=TEMPLATE_INFO.clone();break;case TYPE.WARNING:div=TEMPLATE_WARNING.clone();break;case TYPE.VALIDATION:div=TEMPLATE_VALIDATION.clone();break;case TYPE.PROMPT:div=TEMPLATE_PROMPT.clone();$("div.message",div).after("<input type='text' id='promptTextBox'/>");break;}
var dataObj={"title":title,"msg":msg&&msg.replace(/\n/gi,"<br/>")};$("[data]",div).each(function()
{$(this).html(dataObj[$(this).attr("data")])});div._opts=opts;for(var b in opts.buttons)
{$("<button/>").attr("data",b).addClass('secondarybigbutton').text(((b.indexOf("res:")!=-1)?PageCultureInfo.GetLocalizedResource(b.replace("res:","")):b)||"").appendTo(div.find("[data=buttons]")).one('click',function(){ModalMessageBox.Close();if(opts.buttons[$(this).attr("data")])
opts.buttons[$(this).attr("data")](this,$("#promptTextBox").val());});}
div.add(IE6_MESSABE_OVERLAY).appendTo(document.body);var divWidth=div.width();if(divWidth<opts["min-width"])
divWidth=opts["min-width"];else if(divWidth>opts["max-width"])
divWidth=opts["max-width"];div.add(IE6_MESSABE_OVERLAY).css({"visibility":"visible","position":($.browser.msie&&$.browser.version<7)?"absolute":"fixed","top":opts["top"],"left":$(document.body).width()/2-divWidth/2,"z-index":opts["z-index"],"width":divWidth});if(opts["overlay"])
overlay.fadeIn("normal");if(div.find("[data=buttons]").children().length==0)
{hHide=window.setTimeout(ModalMessageBox.Close,opts["hide-delay"]);div.click(ModalMessageBox.Close);div.mouseover(function(){window.clearTimeout(hHide)});div.mouseout(function(){hHide=window.setTimeout(ModalMessageBox.Close,opts["hide-delay"])});}
else
{if(opts["draggable"])div.draggable({"handle":".title","drag":function(e,ui){if(!IE6_MESSABE_OVERLAY){return;}
var div_position=div.position();IE6_MESSABE_OVERLAY.css({"top":div_position.top,"left":div_position.left});}});}
$(div).add(document).bind("keydown.modal-messagebox",onKeyDown);div.show(opts["fx"],{direction:"up"},opts["fx-speed"],function(){div.find("button:first").focus();});if(IE6_MESSABE_OVERLAY){IE6_MESSABE_OVERLAY.show().height(div.height());}},"Close":function()
{if(div)
{var opts=div._opts;$(document).unbind(".modal-messagebox");if(IE6_MESSABE_OVERLAY){IE6_MESSABE_OVERLAY.hide();}
if(opts["fx"]==="drop")
{opts["fx"]="slide";}
div.hide(opts["fx"],{direction:"up"},opts["fx-speed"],function(){if(opts["onclose"])opts["onclose"]();div.remove();div=null;});}
if(overlay&&overlay.is(":visible"))overlay.fadeOut();}}})();