﻿
/*========================== 文档版本说明 ======================================================================*/
/*
文件名：MessageBox.js
功能描述：主要实现了各种消息框和公共通用方法。
创建人：赵志良
创建日期：2007年11月
最终修改人：赵志良
最终修改日期：2007-12-18
备注：允许通过设置预定义消息框图片文件所在路径变量“MessageBoxImages”的值使用自定义目录。
*/


/*========================== 此文件包含的方法集合 ==============================================================*/
/*
方法：MessageBoxImages
功能：预定义消息框图片文件所在路径。允许通过设置此变量的值使用自定义目录。
备注：允许为此变量赋值为空字符串或一个有效的路径字符串，对于这两种赋值情况，前者表示各个方法所需的外部资源均在此文件所在目录，后者需要以路径分隔符做为后缀结束。
调用示例：
    第一种情况：MessageBoxImages = "";
    第二种情况：MessageBoxImages = "/MessageBox/";
*/
/*
方法：$(cId)
功能：检索指定ID所对应的 HTML 控件。
参数说明：
    cId：需要检索的控件 ID。
*/
/*
方法：HtmlEncode(s)
功能：将字符串转换为 HTML 编码的字符串。
参数说明：
    s：要编码的字符串。
*/
/*
方法：HtmlDecode(s)
功能：将已经进行过 HTML 编码的字符串转换为已解码的字符串。
参数说明：
    s：要解码的字符串。
*/
/*
方法：TextToHtml(Text)
功能：将纯文本转换成具有相似格式编排的 HTML 代码文本。
参数说明：
    Text：一个 string 对象。可能具有格式编排的文本。
*/
/*
方法：GetUriParameter(uri, Name)
功能：从指定的 URI 中获取指定的参数的值。
参数说明：
    uri：一个可能包含参数的 uri 字符串。
    Name：参数名。
*/
/*
方法：SetUriParameter(uri, Name, Value)
功能：为指定的 URI 设置参数。
参数：
    uri：一个可能包含参数的 uri 字符串。
    Name：参数名。
    Value：新的参数值。
*/
/*
方法：RemoveUriParameter(uri, Name)
功能：从指定的 URI 删除参数。
参数：
    uri：一个可能包含参数的 uri 字符串。
    Name：参数名。
*/
/*
方法：ClearUriParameter(uri)
功能：从指定的 URI 删除所有参数（从问号“?”开始到字符串结束的子串），只保留问号“?”之前的部分。
参数：
    uri：一个可能包含参数的 uri 字符串。
*/
/*
方法：GetUriPath(uri)
功能：获取指定的 URI 的路径（不包含文件名和参数部分）。
参数：
    uri：一个 uri 字符串。
返回值：找不到返回 null，否则返回找到的值。
备注：下列情况中(*.*)视为文件名
    1、xxxx://domain/(*.*)
    2、xxxx://domain/(*.*)?parameters
    注意：由于 URL 存在的允许特殊使用原因，下列特殊情况不包含在内，即以路径分隔符结束的情况：
    1、xxxx://domain/(*.*)/
    2、xxxx://domain/(*.*)/?parameters
调用示例：
    alert(GetUriPath("http://www.163.com/a.aspx?id=1&name=2"));//输出 http://www.163.com
    alert(GetUriPath("http://www.163.com/?id=1&name=2"));//输出 http://www.163.com/
    alert(GetUriPath("http://www.163.com?id=1&name=2"));//输出 http://www.163.com
    alert(GetUriPath("http://www.163.com/"));//输出 http://www.163.com/
    alert(GetUriPath("http://www.163.com"));//输出 http://www.163.com
    alert(GetUriPath("http://www.163.com/a.aspx/?id=1&name=2"));//输出 http://www.163.com/a.aspx/
*/
/*
方法：offsetWidth()
功能：获取浏览器工作区宽度（包含滚动条）
*/
/*
方法：clientWidth()
功能：获取浏览器工作区宽度（无滚动条）
*/
/*
方法：clientHeight()
功能：获取浏览器工作区高度（无滚动条）
*/
/*
方法：NewGUID()
功能：产生一个 GUID。
*/
/*
方法：GetBrowser()
功能：获取浏览器类型。
*/
/*
方法：MousePosition={"x", "y"}
功能：定义通用获取鼠标位置的方法。
调用示例：
    获取鼠标水平坐标：MousePosition.x
    获取鼠标垂直坐标：MousePosition.y
*/
/*
方法：MoveForm(id)
功能：开始鼠标拖动控件。
参数说明：
    id：需要拖动的控件 ID。
*/
/*
方法：StopMoveForm()
功能：停止鼠标拖动控件。
*/
/*
方法：MessageBoxBase(message, title, okButton, cancelButton, icon, closingCallbak, closedCallbak, defaultButton, autoClickTime)
功能：显示一个对话框的基方法，允许开发人员使用更多的自定义效果。
参数：
    message：消息正文（HTML 格式）
    title：对话框标题（HTML 格式，取值为 null 时显示文本“系统提示”）
    okButton：设置确定按钮显示的文本。（取值为 null 时显示“确 定”）
    cancelButton：设置取消按钮显示的文本。（取值为 null 时显示“取 消”）
    icon：显示在消息正文左侧的图标的 URL。（取值为 null 或空字符串时不显示）
    closingCallbak：对话框准备关闭回调此事件。此事件调用的函数有一个参数用来指示用户点击了哪个按钮（OK 表示点击了示意为确定的按钮，Cancel 表示点击了示意为取消的按钮），并且允许返回一个布尔值用来指示是否取消关闭对话框的事件。
    closedCallbak：对话框关闭后回调此事件
    defaultButton：默认按钮。（1表示第一个按钮；2表示第二个按钮。）
    autoClickTime：默认按钮自动点击倒计时时间。（单位：秒）取值为-1或 null 时表示禁用倒计时。

调用示例：下面的示例显示的对话框有（是、否）两个按钮，第二个按钮（否）设置为默认按钮并且具有焦点，5秒后自动引发默认按钮的单击事件。
    var pb = MessageBoxBase('消息正文'
     , '错误信息'
     , '是'
     , '否'
     , 'Error'
     , function(arg){alert("准备关闭，引发此事件的按钮类型是："+arg);return false;}
     , function(){alert('对话框已经关闭');}
     , 2, 5
     );
*/
/*
方法：MessageBox(message, title, buttons, icon, closingCallbak, closedCallbak, defaultButton, autoClickTime)
功能：显示一个对话框。
参数：
    message：消息正文
    title：对话框标题
    buttons：指示显示哪些按钮。
    icon：要在对话框上显示的图标
    closingCallbak：对话框准备关闭回调此事件。此事件调用的函数有一个参数用来指示用户点击了哪个按钮（OK 表示点击了示意为确定的按钮，Cancel 表示点击了示意为取消的按钮），并且允许返回一个布尔值用来指示是否取消关闭对话框的事件。
    closedCallbak：对话框关闭后回调此事件
    defaultButton：默认按钮。（1表示第一个按钮；2表示第二个按钮。）
    autoClickTime：默认按钮自动点击倒计时时间。（单位：秒）取值为-1时表示禁用倒计时。

参数 buttons 取值范围：
    None：不显示按钮
    OK：确定
    OKCancel：确定/取消
    YesNo：是/否。
    Close：关闭。

参数 icon 取值范围：
	Asterisk：该消息框包含一个符号，该符号是由一个圆圈及其中的小写字母 i 组成的。
	Error：该消息框包含一个符号，该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
	Exclamation：该消息框包含一个符号，该符号是由一个黄色背景的三角形及其中的一个感叹号组成的。
	Hand：该消息框包含一个符号，该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
	Information：该消息框包含一个符号，该符号是由一个圆圈及其中的小写字母 i 组成的。
	None,消息框未包含符号。
	Question：该消息框包含一个符号，该符号是由一个圆圈和其中的一个问号组成的。
	Stop：该消息框包含一个符号，该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
	Warning：该消息框包含一个符号，该符号是由一个黄色背景的三角形及其中的一个感叹号组成的。

调用示例：下面的示例显示的对话框有（是、否）两个按钮，第二个按钮（否）设置为默认按钮并且具有焦点，5秒后自动引发默认按钮的单击事件。
    var pb = MessageBox('消息正文'
     , '错误信息'
     , 'YesNo'
     , 'Error'
     , function(arg){alert("准备关闭，引发此事件的按钮类型是："+arg);return false;}
     , function(){alert('对话框已经关闭');}
     , 2, 5
     );
*/
/*
方法：
功能：关闭一个正在显示的对话框。
参数：
    mb：对话框。

调用示例：CloseMessageBox(mb)
    var mb = MessageBox('消息正文'
     , '错误信息'
     , 'YesNo'
     , 'Error'
     , function(arg){alert("准备关闭，引发此事件的按钮类型是："+arg);return false;}
     , function(){alert('对话框已经关闭');}
     , 2, 5
     );
    CloseProgressBar(mb);
*/
/*
方法：ProgressBar(message, title)
功能：显示一个进度条。
参数：
    message：消息正文
    title：对话框标题

调用示例：
    var pb = ProgressBar("正在提交数据", "");
*/
/*
方法：CloseProgressBar(br)
功能：隐藏一个正在显示的进度条。
参数：
    br：进度条对话框。

调用示例：
    var pb = ProgressBar("正在提交数据", "");
    CloseProgressBar(pb);
*/
/*
方法：PageBox(url, title, width, height, closingCallbak, closedCallbak, autoCloseTime, hasScroll, showShade)
功能：显示一个页面对话框。
参数：
    url：要显示的页面 URL。
    title：页面对话框标题
    width：网页宽度
    height：网页高度
    closingCallbak：对话框准备关闭回调此事件。此事件调用的函数有一个参数用来指示对话框的返回值，并且允许返回一个布尔值用来指示是否取消关闭对话框的事件。
    closedCallbak：对话框关闭后回调此事件。此事件调用的函数有一个参数用来指示对话框的返回值。
    autoCloseTime：自动关闭倒计时时间。（单位：秒）取值为-1时表示禁用倒计时。
    hasScroll：指示是否显示滚动条。
    showShade：指示是否显示阴影遮蔽。

调用示例：下面的示例显示的对话框5秒后自动关闭。
    var pb = PageBox('http://www.163.com/'
     , '新页面窗口'
     , function(returnValue){alert('准备关闭对话框，返回值是：'+returnValue);return false;}
     , function(returnValue){alert('对话框已经关闭，返回值是：'+returnValue);}
     , 5
     , true
     );
*/
/*
方法：ClosePageBox(pb, returnValue)
功能：关闭一个正在显示的页面对话框，返回一个值如果有。
参数：
    pb：页面对话框句柄或被调用页面的 URL。如果是后者，一般设置为 window.location.href。
    returnValue：页面对话框关闭后的返回值。

调用示例：
    var pb = PageBox('http://www.163.com/'
     , '新页面窗口'
     , function(returnValue){alert('准备关闭对话框，返回值是：'+returnValue);return false;}
     , function(returnValue){alert('对话框已经关闭，返回值是：'+returnValue);}
     , 5
     );
    ClosePageBox(pb, "一个自定义返回值");
*/
/*
方法：SetPageBoxSize(pb, width, height)
功能：用于在被调用页获取页面对话框。
参数：
    pb：页面对话框句柄或被调用页面的 URL。如果是后者，一般设置为 window.location.href。
    width：宽度。
    height：高度。

调用示例：
    window.parent.SetPageBoxSize(window.location.href, 500, 500);
*/
/*
方法：SetPageBoxCenter(pb)
功能：用于在被调用页设置页面对话框居中显示。
参数：
    pb：页面对话框句柄或被调用页面的 URL。如果是后者，一般设置为 window.location.href。

调用示例：
    window.parent.SetPageBoxCenter(window.location.href);
*/
/*
方法：SetPageBoxScroll(pb, hasScroll)
功能：用于在被调用页设置页面对话框是否显示滚动条。（此方法目前只支持火狐浏览器）
参数：
    pb：页面对话框句柄或被调用页面的 URL。如果是后者，一般设置为 window.location.href。
    hasScroll：一个布尔值。true表示自动根据需要显示滚动条；false表示隐藏滚动条。

调用示例：
    window.parent.SetPageBoxScroll(window.location.href, true);
*/
/*
方法：PreviewMessageBoxImages()
功能：预先加载图片。一个辅助方法，在显示对话框之前调用此方法，用来保证对话框图片能够正确及时显示。
备注：一般情况我们建议开发人员在文档加载完毕之后的空闲时段调用此方法。例如，在 HTML 页面的 <body> 元素的 onload 事件结束之前。
*/
/*
方法：Array.prototype.indexOf = function(p_var) 
功能：获取一个元素在 Array 中的索引值。（为 JavaScript Array 对象添加的扩展方法。）
参数列表：
    p_var：要检索的元素。
返回值：元素的索引值。找不到返回 -1。
调用示例：
    var a = new Array();
    a.push("abc");
    a.push("def");
    alert(a.indexOf("abc"));
    alert(a.indexOf("def"));
*/
/*
方法：Array.prototype.remove = function(o) 
功能：从 Array 中删除一个元素。（为 JavaScript Array 对象添加的扩展方法。）
参数列表：
    o：要删除的元素。
返回值：找到并且成功删除返回 true。否则返回 false。
调用示例：
    var a = new Array();
    a.push("abc");
    a.push("def");
    alert(a[0]);
    a.remove("abc");
    alert(a[0]);
*/
/*
方法：CloseBox( hand )
功能：统一的关闭窗口对话框。
参数列表：
    hand：窗体句柄，不指定此参数则关闭最后一个窗口。
调用示例：
    CloseBox();
*/
/*
方法：GetPageBoxIframe(pb)
功能：获取 Iframe 标签的 ID，此标签是 PageBox 对象的用于显示子页面的载体。
参数：
    pb：页面对话框句柄。

调用示例：
    var pb = PageBox('http://www.163.com/'
     , '新页面窗口'
     , null
     , null
     , 5
     );
    var iframeId = GetPageBoxIframe(pb);
*/
/*======================== 程序源代码开始 ======================================================================*/


/*
功能：预定义消息框图片文件所在路径。允许通过设置此变量的值使用自定义目录。
备注：允许为此变量赋值为空字符串或一个有效的路径字符串，对于这两种赋值情况，前者表示各个方法所需的外部资源均在此文件所在目录，后者需要以路径分隔符做为后缀结束。
调用示例：
    第一种情况：MessageBoxImages = "";
    第二种情况：MessageBoxImages = "/MessageBox/";
*/
var MessageBoxImages = "/util/MessageBox/";

var FormHandleColl = new Array();//窗体集合。窗体类型取值{1=MessageBox；2=ProgressBar；3=PageBox}


/*
功能：检索指定ID所对应的 HTML 控件。
参数说明：
    cId：需要检索的控件 ID。
*/
function $(cId)
{
    return document.getElementById(cId);
	
}


/*
功能：将字符串转换为 HTML 编码的字符串。
参数说明：
    s：要编码的字符串。
*/
function HtmlEncode(s)
{
    if(s==null) return null;
    return s.replace(/&/gi, "&amp;").replace(/\"/gi, "&quot;").replace(/</gi, "&lt;").replace(/>/gi, "&gt;").replace(/ /gi, "&nbsp;");
}


/*
功能：将已经进行过 HTML 编码的字符串转换为已解码的字符串。
参数说明：
    s：要解码的字符串。
*/
function HtmlDecode(s)
{
    if(s==null) return null;
    return s.replace(/&quot;/gi, "\"").replace(/&lt;/gi, "<").replace(/&gt;/gi, ">").replace(/&nbsp;/gi, " ").replace(/&amp;/gi, "&");
}


/*
功能：将纯文本转换成具有相似格式编排的 HTML 代码文本。
参数说明：
    Text：一个 string 对象。可能具有格式编排的文本。
*/
function TextToHtml(Text)
{
    if(Text==null) return null;
    return Text.replace(/&/gi, "&amp;").replace(/\"/gi, "&quot;").replace(/</gi, "&lt;").replace(/>/gi, "&gt;").replace(/ /gi, "&nbsp;").replace(/\t/gi, "&nbsp;&nbsp;&nbsp;&nbsp;").replace(/\n\r/gi, "<br />").replace(/\r\n/gi, "<br />").replace(/\r/gi, "<br />").replace(/\n/gi, "<br />");
}


/*
功能：从指定的 URI 中获取指定的参数的值。
参数说明：
    uri：一个可能包含参数的 uri 字符串。
    Name：参数名。
*/
function GetUriParameter(uri, Name)
{
    var uri = unescape(uri);
    var reg = new RegExp("(\\?|&)" + Name.replace(/\$/gi, "\\$") + "=([^&]*)", "gi");
    uri = uri.match(reg);
    if(uri)
    {
        return (uri + "").replace(reg, "$2");
    }
    return null;
}


/*
功能：为指定的 URI 设置参数。
参数：
    uri：一个可能包含参数的 uri 字符串。
    Name：参数名。
    Value：新的参数值。
*/
function SetUriParameter(uri, Name, Value)
{
    uri=uri.replace(/(\s|\?)*$/g, "");//消除 URI 中无参数但存在问号“...?”这种 URI 中的问号。
    if(uri.indexOf("?")==-1)
    {//如果无参数。
        return uri + "?" + Name + "=" + encodeURIComponent( Value );
    }
	else
	{//如果有参数。
	    var reg=new RegExp("(\\?|&)" + Name.replace(/\$/gi, "\\$") + "=([^&]*)","gi");//测试可能被替换的参数的正则表达式。
		if( reg.test(uri) )
		{//如果存在同名参数。
		    return uri.replace(reg, "$1" + Name.replace(/\$/gi, "$$$$") + "=" + encodeURIComponent( Value ));
		}
		else
		{//如果无同名参数。
			return uri + "&" + Name + "=" + encodeURIComponent( Value );
		}
	}
}


/*
功能：从指定的 URI 删除参数。
参数：
    uri：一个可能包含参数的 uri 字符串。
    Name：参数名。
*/
function RemoveUriParameter(uri, Name)
{
    Name=Name.replace(/\$/gi, "\\$");
    var reg=new RegExp("(\\?|&)" + Name + "=([^&]*)","gi");//测试可能被替换的参数的正则表达式。
	if( reg.test(uri) )
	{
        var reg1=new RegExp("\\?" + Name + "=([^&]*)&","gi");
        uri=uri.replace(reg1, "?");
        var reg2=new RegExp("\\?" + Name + "=([^&]*)","gi");
        uri=uri.replace(reg2, "");
        var reg3=new RegExp("&" + Name + "=([^&]*)","gi");
        uri=uri.replace(reg3, "");
	}
	return uri;
}


/*
功能：从指定的 URI 删除所有参数（从问号“?”开始到字符串结束的子串），只保留问号“?”之前的部分。
参数：
    uri：一个可能包含参数的 uri 字符串。
*/
function ClearUriParameter(uri)
{
    var reg=/\?(.*)/gi
    if( reg.test(uri) )
    {
        return uri.replace(reg, "")
    }
	return uri;
}


/*
功能：获取指定的 URI 的路径（不包含文件名和参数部分）。
参数：
    uri：一个 uri 字符串。
返回值：找不到返回 null，否则返回找到的值。
备注：下列情况中(*.*)视为文件名
    1、xxxx://domain/(*.*)
    2、xxxx://domain/(*.*)?parameters
    注意：由于 URL 存在的允许特殊使用原因，下列特殊情况不包含在内，即以路径分隔符结束的情况：
    1、xxxx://domain/(*.*)/
    2、xxxx://domain/(*.*)/?parameters
调用示例：
    alert(GetUriPath("http://www.163.com/a.aspx?id=1&name=2"));//输出 http://www.163.com
    alert(GetUriPath("http://www.163.com/?id=1&name=2"));//输出 http://www.163.com/
    alert(GetUriPath("http://www.163.com?id=1&name=2"));//输出 http://www.163.com
    alert(GetUriPath("http://www.163.com/"));//输出 http://www.163.com/
    alert(GetUriPath("http://www.163.com"));//输出 http://www.163.com
    alert(GetUriPath("http://www.163.com/a.aspx/?id=1&name=2"));//输出 http://www.163.com/a.aspx/
*/
function GetUriPath(uri)
{
    var path=ClearUriParameter(uri);
    var filename = path.replace(/^[^\/\\]+:\/\/(([^\/]+$)|([^\/]+\/+)*)/gi, "");
    if(filename!="" && /\./gi.test(filename))
    {
        path = path.substring(0, path.length - filename.length);
    }
    return path;
}


/*
功能：获取浏览器工作区宽度（包含滚动条）
*/
function offsetWidth()
{
	return (document.documentElement.offsetWidth||document.body.offsetWidth);
}

/*
功能：获取浏览器工作区宽度（无滚动条）
*/
function clientWidth()
{
	return (document.documentElement.clientWidth||document.body.clientWidth);
}

/*
功能：获取浏览器工作区高度（无滚动条）
*/
function clientHeight()
{
	return (self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight);
}

/*
功能：产生一个 GUID。
*/
function NewGUID()
{
    var guid = "{";
    for (var i = 1; i <= 32; i++)
    {
        var n = Math.floor(Math.random() * 16.0).toString(16);
        guid += n;
        if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) guid += "-";
    }
    guid += "}";
    return guid;
}

/*
功能：产生一个用作控件 ID 的 GUID。
*/
function NewControlGUID()
{
    var guid = "";
    for (var i = 1; i <= 32; i++)
    {
        var n = Math.floor(Math.random() * 16.0).toString(16);
        guid += n;
    }
    return guid;
}

/*
功能：获取浏览器类型。
*/
function GetBrowser()
{
   if(navigator.userAgent.indexOf("MSIE")>0) return "MSIE";
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0) return "Firefox";
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) return "Safari";
   if(isCamino=navigator.userAgent.indexOf("Camino")>0) return "Camino";
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0) return "Gecko";
}


//需要移动的控件。
var MoveFormsHandle=null;
/*
功能：定义通用获取鼠标位置的方法。
调用示例：
    获取鼠标水平坐标：MousePosition.x
    获取鼠标垂直坐标：MousePosition.y
*/
var MousePosition={"x":0, "y":0}
window.document.onmousemove=function(evt)
{
    evt=(evt || window.event);
    MousePosition.x=evt.clientX;
    MousePosition.y=evt.clientY;

    if(MoveFormsHandle!=null)
    {
        var tmp=MoveFormsHandle;
        var control=$(tmp.id);
        if(control==null || (control!=null && GetBrowser()=="MSIE" && event.button!=1))
        {//清除不可移动的控件。关闭处于移动状态的控件时会引发此控件不存在的错误，此处代码用于解决这个问题。
            StopMoveForm();
            return;
        }
        try
        {
            var sLeft = document.body.scrollLeft;
            var sTop = document.body.scrollTop;
            var sRight = document.body.scrollLeft + clientWidth();
            var sBottom = document.body.scrollTop + clientHeight();

            var left=evt.clientX - tmp.cx;
            if( left < sLeft ) left = sLeft;
            var top=evt.clientY - tmp.cy;
            if( top < sTop ) top = sTop;
            var right=left+control.offsetWidth;
            if( right > sRight ) left = sRight-control.offsetWidth;
            var bottom=top+control.offsetHeight;
            if( bottom > sBottom ) top = sBottom-control.offsetHeight;
            if( left < sLeft ) left = sLeft;//修正控件位置，避免拖拽区域不可控
            if( top < sTop ) top = sTop;//修正控件位置，避免拖拽区域不可控

            control.style.left = left + "px";
            control.style.top = top + "px";
        }
        catch(err){}
    }

}


/*
功能：开始鼠标拖动控件。
参数说明：
    id：需要拖动的控件 ID。
*/
function MoveForm(id)
{
    var c=$(id);
    if(c!=null)
    {
        if(MoveFormsHandle!=null)
        {
            if(MoveFormsHandle.id==id)
            {
                return;
            }
            StopMoveForm();
        }
        if(MoveFormsHandle==null)
        {
            if(GetBrowser()=="MSIE") c.setCapture();//对当前文档的某个对象设置鼠标捕获. 
            MoveFormsHandle = {"id":id, "cx":MousePosition.x-parseInt(c.style.left), "cy":MousePosition.y-parseInt(c.style.top)};
        }
    }

}


/*
功能：停止鼠标拖动控件。
*/
function StopMoveForm()
{
    if(MoveFormsHandle!=null)
    {
		var c=$(MoveFormsHandle.id);
		if(c!=null && GetBrowser()=="MSIE") c.releaseCapture();//为当前的应用程序释放鼠标捕获
        MoveFormsHandle=null;
    }

}


/*
功能：显示一个对话框的基方法，允许开发人员使用更多的自定义效果。
参数：
    message：消息正文（HTML 格式）
    title：对话框标题（HTML 格式，取值为 null 时显示文本“系统提示”）
    okButton：设置确定按钮显示的文本。（取值为 null 时显示“确 定”）
    cancelButton：设置取消按钮显示的文本。（取值为 null 时显示“取 消”）
    icon：显示在消息正文左侧的图标的 URL。（取值为 null 或空字符串时不显示）
    closingCallbak：对话框准备关闭回调此事件。此事件调用的函数有一个参数用来指示用户点击了哪个按钮（OK 表示点击了示意为确定的按钮，Cancel 表示点击了示意为取消的按钮），并且允许返回一个布尔值用来指示是否取消关闭对话框的事件。
    closedCallbak：对话框关闭后回调此事件
    defaultButton：默认按钮。（1表示第一个按钮；2表示第二个按钮。）
    autoClickTime：默认按钮自动点击倒计时时间。（单位：秒）取值为-1或 null 时表示禁用倒计时。

调用示例：下面的示例显示的对话框有（是、否）两个按钮，第二个按钮（否）设置为默认按钮并且具有焦点，5秒后自动引发默认按钮的单击事件。
    var pb = MessageBoxBase('消息正文'
     , '错误信息'
     , '是'
     , '否'
     , 'Error'
     , function(arg){alert("准备关闭，引发此事件的按钮类型是："+arg);return false;}
     , function(){alert('对话框已经关闭');}
     , 2, 5
     );
*/
function MessageBoxBase(message, title, okButton, cancelButton, icon, closingCallbak, closedCallbak, defaultButton, autoClickTime)
{
    var MSGID = "MessageBox" + NewControlGUID();
    var box = MSGID + "box";
    var btnOK = MSGID + "OK";
    var btnCancel = MSGID + "Cancel";
    var btnClose = MSGID + "Close";
    var ButtonClicked = "Cancel";//用户点击的按钮。
    var vDefaultButton = btnOK;

	var br=document.createElement("DIV");
	br.id=MSGID;
	br.style.zIndex=999;
	document.body.appendChild(br);
	if(message==null || message=="")
	{
	    message="&nbsp;";
	}
	if(title==null)
	{
	    title="系统提示";
	}
	else
	{
	    if(title=="")
	    {
	        title="&nbsp;";
        }
    }
	if(defaultButton==null)
	{
	    defaultButton=1;
	}
	if(autoClickTime==null)
	{
	    autoClickTime=-1;
    }
	var okHtml="";
	var cancelHtml="";
	var icoHtml="";
	if( okButton == null && cancelButton == null )
	{
        vDefaultButton = "";
    }
    else
    {
	    if(okButton != null)
	    {
            okHtml='<span style="padding-left: 20px;" ><input type="button" value="' + TextToHtml(okButton) + '" id="' + btnOK + '" style="border:none; background-image: url('+MessageBoxImages+'box.gif); background-position: -80px 0px; width: 69px; height: 24px; background-repeat:no-repeat; font-size:12px;" /></span>';
            vDefaultButton = btnOK;
	    }
	    if(cancelButton != null)
	    {
	        cancelHtml='<span style="padding-left: 20px;" ><input type="button" value="' + TextToHtml(cancelButton) + '" id="' + btnCancel + '" style="border:none; background-image: url('+MessageBoxImages+'box.gif); background-position: -80px 0px; width: 69px; height: 24px; background-repeat:no-repeat; font-size:12px;"/></span>';
	        vDefaultButton = btnCancel;
	    }
	    if( okButton != null && cancelButton != null )
	    {
            switch(defaultButton)
            {
                case 1:
                    vDefaultButton = btnOK;
                    break;
                case 2:
                    vDefaultButton = btnCancel;
                    break;
            }
        }
    }
    if( icon!=null && icon!="" )
    {
        icoHtml="<IMG alt=\"\" src=\"" + icon + "\" />"
        message = '<table cellpadding="0" cellspacing="0" border="0" style="width: 100%; color:#06559b; font-size:14px;"><tr><td style="width: 1px;">'+icoHtml+'</td><td style="padding-left: 10px; color:#06559b; font-size:14px;">'+message+'</td></tr></table>';
    }

	var Aok="100%";
	var Anc="100%";
	if(document.body.scrollWidth > clientWidth())
	{
		Aok=document.body.scrollWidth + "px";
	}
	if(document.body.scrollHeight > clientHeight())
	{
		Anc=document.body.scrollHeight + "px";
	}
	var u='<iframe style="position:absolute;top:0;left:0;width:'+Aok+';height:'+Anc+';opacity:0.00;-moz-opacity:0.00;filter:alpha(opacity=0);background-color:#000000;DISPLAY:block" frameBorder="0" scrolling="no" src="about:blank"></iframe><div style="position:absolute;top:0;left:0;width:'+Aok+';height:'+Anc+';opacity:0.07;-moz-opacity:0.07;filter:alpha(opacity=7);background-color:#000000;DISPLAY:block;"></div>'
	+'<div id="' + box + '" style="position:absolute;" onselectstart="return false;" ondrag="return false;">'
	+'<table cellpadding="0" cellspacing="0" border="0" style="width:300px;">'
	+'<tr><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: 0px 0px; width:3px; height:27px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="27"></td><td style="background-image: url('+MessageBoxImages+'tb.gif); background-position: 0px 0px; height:27px; background-repeat:repeat-x;">'
	+'<table style="width: 100%"><tr><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: -160px 0px; width:14px; height:14px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="14" height="14"></td><td style="color:#06559b; font-size:12px; cursor:default;" onmousedown="MoveForm(\''+box+'\');" onmouseup="StopMoveForm();">'+title+'</td><td style="width:8px;"><a href="javascript:;" title="关闭" id="' + btnClose + '"><img style="background-image: url('+MessageBoxImages+'box.gif); background-position: -56px -16px; width:16px; height:16px; background-repeat:no-repeat;" onmouseover="this.style.backgroundPosition=\'-56px -31px\';" onmouseout="this.style.backgroundPosition=\'-56px -16px\';" src="'+MessageBoxImages+'place.gif" width="16" height="16" border="0" /></a></td></tr></table>'
	+'</td><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: -10px 0px; width:3px; height:27px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="27"></td></tr>'
	+'<tr><td style="background-image: url('+MessageBoxImages+'lr.gif); background-position: 0px 0px; width:3px; background-repeat:repeat-y;"><img src="'+MessageBoxImages+'place.gif" width="3" height="1"></td>'
    +'<td style="background-image: url('+MessageBoxImages+'bg.gif); padding: 20px; color:#06559b; font-size:14px;">'+message+'</td>'
    +'<td style="background-image: url('+MessageBoxImages+'lr.gif); background-position: -10px 0px; width:3px; background-repeat:repeat-y;"><img src="'+MessageBoxImages+'place.gif" width="3" height="1"></td></tr>'
	+'<tr><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: -20px 0px; width:3px; height:44px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="44"></td><td style="background-image: url('+MessageBoxImages+'tb.gif); background-position: 0px -50px; height:44px; background-repeat:repeat-x; text-align: right; padding-right: 20px;">'
	+okHtml+cancelHtml
	+'</td><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: -30px 0px; width:3px; height:44px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="44"></td></tr>'
    +'</table>'
	+'</div>';

	br.innerHTML=u;
	var ag=br.lastChild;
	var h=ag.offsetHeight;
	var w=ag.offsetWidth;
	var x=(clientWidth()-w)/2+document.body.scrollLeft;
	var y=(clientHeight()-h)/2+document.body.scrollTop;
	ag.style.left=x+"px";
	ag.style.top=y+"px";
	$(btnClose).onclick=function ()//点击关闭对话框事件
	{
	    var cancelClose = false;//指示是否取消关闭对话框事件。
		if(closingCallbak != null && closingCallbak)
		{//对话框准备关闭回调此事件
			cancelClose = closingCallbak(ButtonClicked);
		}
		if( !cancelClose )
		{
            u=null;
            br.innerHTML="";
		    document.body.removeChild(br);
		    DeleteForm(br);
		    if(closedCallbak!=null && closedCallbak)
		    {//对话框关闭后回调此事件
			    closedCallbak();
		    }
		}
		return false;
		
	};
	if($(btnCancel))
	{
		$(btnCancel).onclick=function ()
		{
		    ButtonClicked="Cancel";
			$(btnClose).onclick();
		}
	};
	if($(btnOK))
	{
	    $(btnOK).onclick=function ()
	    {
		    ButtonClicked="OK";
		    $(btnClose).onclick();
	    }
	};
	if($(vDefaultButton))
	{
        $(vDefaultButton).focus();
        if( autoClickTime >= 0 )
        {
            var defaultButtonTime=autoClickTime;
            var defaultButtonText=$(vDefaultButton).value;
            var AutoClick=function()
            {
                var vdb = $(vDefaultButton);
                if(vdb)
                {
	                vdb.value=defaultButtonText + ' ['+defaultButtonTime+']';
	                if(defaultButtonTime<=0)
	                {
		                vdb.onclick();
	                }
	                else
	                {
		                defaultButtonTime--;
		                window.setTimeout(AutoClick, 1000);
	                }
                }

            }
            AutoClick();
        }
    }
    FormHandleColl.push({"hand": br, "type": 1});
	return br;

}


/*
功能：显示一个对话框。
参数：
    message：消息正文
    title：对话框标题
    buttons：指示显示哪些按钮。
    icon：要在对话框上显示的图标
    closingCallbak：对话框准备关闭回调此事件。此事件调用的函数有一个参数用来指示用户点击了哪个按钮（OK 表示点击了示意为确定的按钮，Cancel 表示点击了示意为取消的按钮），并且允许返回一个布尔值用来指示是否取消关闭对话框的事件。
    closedCallbak：对话框关闭后回调此事件
    defaultButton：默认按钮。（1表示第一个按钮；2表示第二个按钮。）
    autoClickTime：默认按钮自动点击倒计时时间。（单位：秒）取值为-1时表示禁用倒计时。

参数 buttons 取值范围：
    None：不显示按钮
    OK：确定
    OKCancel：确定/取消
    YesNo：是/否。
    Close：关闭。

参数 icon 取值范围：
	Asterisk：该消息框包含一个符号，该符号是由一个圆圈及其中的小写字母 i 组成的。
	Error：该消息框包含一个符号，该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
	Exclamation：该消息框包含一个符号，该符号是由一个黄色背景的三角形及其中的一个感叹号组成的。
	Hand：该消息框包含一个符号，该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
	Information：该消息框包含一个符号，该符号是由一个圆圈及其中的小写字母 i 组成的。
	None,消息框未包含符号。
	Question：该消息框包含一个符号，该符号是由一个圆圈和其中的一个问号组成的。
	Stop：该消息框包含一个符号，该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
	Warning：该消息框包含一个符号，该符号是由一个黄色背景的三角形及其中的一个感叹号组成的。

调用示例：下面的示例显示的对话框有（是、否）两个按钮，第二个按钮（否）设置为默认按钮并且具有焦点，5秒后自动引发默认按钮的单击事件。
    var pb = MessageBox('消息正文'
     , '错误信息'
     , 'YesNo'
     , 'Error'
     , function(arg){alert("准备关闭，引发此事件的按钮类型是："+arg);return false;}
     , function(){alert('对话框已经关闭');}
     , 2, 5
     );
*/
function MessageBox(message, title, buttons, icon, closingCallbak, closedCallbak, defaultButton, autoClickTime)
{
	if(message!=null && message!="")
	{
        message=TextToHtml(message);
    }
	if(title!=null && title!="")
	{
        title=TextToHtml(title);
    }
    if(buttons==null)
    {
	    buttons="OK";
	}
	if( icon==null )
	{
	    icon="None";
	}
	var okHtml=null;
	var cancelHtml=null;
	var icoHtml=null;
	switch(buttons.toLowerCase())
	{
	    case "none":
	        break;
	    case "ok":
	        okHtml='确 定';
	        break;
	    case "okcancel":
	        okHtml='确 定';
		    cancelHtml='取 消';
	        break;
	    case "yesno":
	        okHtml='是';
		    cancelHtml='否';
	        break;
	    case "close":
		    cancelHtml='关闭';
	        break;
	}
	switch(icon.toLowerCase())
	{
	    case "asterisk":
			icoHtml = "04";
	        break;
	    case "error":
			icoHtml = "01";
	        break;
	    case "exclamation":
			icoHtml = "03";
	        break;
	    case "hand":
			icoHtml = "01";
	        break;
	    case "information":
			icoHtml = "04";
	        break;
	    case "none":
	        break;
	    case "question":
			icoHtml = "02";
	        break;
	    case "stop":
			icoHtml = "01";
	        break;
	    case "warning":
			icoHtml = "03";
	        break;
    }
    if( icoHtml!=null )
    {
        icoHtml=MessageBoxImages+"messagebox" + icoHtml + ".gif";
    }

	return MessageBoxBase(message, title, okHtml, cancelHtml, icoHtml, closingCallbak, closedCallbak, defaultButton, autoClickTime);

}


/*
功能：关闭一个正在显示的对话框。
参数：
    mb：对话框。

调用示例：
    var mb = MessageBox('消息正文'
     , '错误信息'
     , 'YesNo'
     , 'Error'
     , function(arg){alert("准备关闭，引发此事件的按钮类型是："+arg);return false;}
     , function(){alert('对话框已经关闭');}
     , 2, 5
     );
    CloseProgressBar(mb);
*/
function CloseMessageBox(mb)
{
    mb.innerHTML="";
    document.body.removeChild(mb);
    DeleteForm(mb);
}



/*
功能：显示一个进度条。
参数：
    message：消息正文
    title：对话框标题

调用示例：
    var pb = ProgressBar("正在提交数据", "");
*/

var oldloadingBr;
function ProgressBar(message, title)
{
    var MSGID = "ProgressBar" + NewControlGUID();
    var box = MSGID + "box";

	var br=document.createElement("DIV");
	br.id=MSGID;
	br.style.zIndex=999;
	document.body.appendChild(br);
	if(message=="")
	{
	    message="&nbsp;";
	}
    else
    {
        message=TextToHtml(message);
    }
	if(title==null)
	{
	    title="正在执行操作，请稍等……";
	}
	else
	{
	    if(title=="")
	    {
	        title="&nbsp;";
        }
        else
        {
            title=TextToHtml(title);
        }
    }

	var Aok="100%";
	var Anc="100%";
	if(document.body.scrollWidth > clientWidth())
	{
		Aok=document.body.scrollWidth + "px";
	}
	if(document.body.scrollHeight > clientHeight())
	{
		Anc=document.body.scrollHeight + "px";
	}
	var u='<iframe style="position:absolute;top:0;left:0;width:'+Aok+';height:'+Anc+';opacity:0.00;-moz-opacity:0.00;filter:alpha(opacity=0);background-color:#000000;DISPLAY:block" frameBorder="0" scrolling="no" src="about:blank"></iframe><div style="position:absolute;top:0;left:0;width:'+Aok+';height:'+Anc+';opacity:0.07;-moz-opacity:0.07;filter:alpha(opacity=7);background-color:#000000;DISPLAY:block;"></div>'
	+'<div id="' + box + '" style="position:absolute;" onselectstart="return false;" ondrag="return false;">'
	+'<table cellpadding="0" cellspacing="0" border="0" style="width:300px;">'
	+'<tr><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: 0px 0px; width:3px; height:27px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="27"></td><td style="background-image: url('+MessageBoxImages+'tb.gif); background-position: 0px 0px; height:27px; background-repeat:repeat-x;">'
	+'<table style="width: 100%"><tr><td style="color:#06559b; font-size:12px; cursor:default;" onmousedown="MoveForm(\''+box+'\');" onmouseup="StopMoveForm();">'+title+'</td></tr></table>'
	+'</td><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: -10px 0px; width:3px; height:27px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="27"></td></tr>';
	if(message!=null&&message!="")
	{
	    u+='<tr><td style="background-image: url('+MessageBoxImages+'lr.gif); background-position: 0px 0px; width:3px; background-repeat:repeat-y;"><img src="'+MessageBoxImages+'place.gif" width="3" height="1"></td>'
        +'<td style="background-image: url('+MessageBoxImages+'bg.gif); padding: 20px; color:#06559b; font-size:14px;">'+message+'</td>'
        +'<td style="background-image: url('+MessageBoxImages+'lr.gif); background-position: -10px 0px; width:3px; background-repeat:repeat-y;"><img src="'+MessageBoxImages+'place.gif" width="3" height="1"></td></tr>';
    }
	u+='<tr><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: -20px 0px; width:3px; height:44px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="44"></td><td style="background-image: url('+MessageBoxImages+'tb.gif); background-position: 0px -50px; height:44px; background-repeat:repeat-x; text-align: center;">'
	+'<img src="'+MessageBoxImages+'progbar.gif" />'
	+'</td><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: -30px 0px; width:3px; height:44px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="44"></td></tr>'
    +'</table>'
	+'</div>';

	br.innerHTML=u;
	var ag=br.lastChild;
	var h=ag.offsetHeight;
	var w=ag.offsetWidth;
	var x=(clientWidth()-w)/2+document.body.scrollLeft;
	var y=(clientHeight()-h)/2+document.body.scrollTop;
	ag.style.left=x+"px";
	ag.style.top=y+"px";
    u=null;

    FormHandleColl.push({"hand": br, "type": 2});
	oldloadingBr=br;
	return br;

}


/*
功能：隐藏一个正在显示的进度条。
参数：
    br：进度条对话框。

调用示例：
    var pb = ProgressBar("正在提交数据", "");
    CloseProgressBar(pb);
*/

function CloseProgressBar(br)
{
	
	if(br){
		br.innerHTML="";
		document.body.removeChild(br);
		DeleteForm(br);
	}else{
		oldloadingBr.innerHTML="";
		document.body.removeChild(oldloadingBr);
		DeleteForm(oldloadingBr);
	}
}



/*
功能：显示一个页面对话框。
参数：
    url：要显示的页面 URL。
    title：页面对话框标题
    width：网页宽度
    height：网页高度
    closingCallbak：对话框准备关闭回调此事件。此事件调用的函数有一个参数用来指示对话框的返回值，并且允许返回一个布尔值用来指示是否取消关闭对话框的事件。
    closedCallbak：对话框关闭后回调此事件。此事件调用的函数有一个参数用来指示对话框的返回值。
    autoCloseTime：自动关闭倒计时时间。（单位：秒）取值为-1时表示禁用倒计时。
    hasScroll：指示是否显示滚动条。
    showShade：指示是否显示阴影遮蔽。

调用示例：下面的示例显示的对话框5秒后自动关闭。
    var pb = PageBox('http://www.163.com/'
     , '新页面窗口'
     , function(returnValue){alert('准备关闭对话框，返回值是：'+returnValue);return false;}
     , function(returnValue){alert('对话框已经关闭，返回值是：'+returnValue);}
     , 5
     , true
     );
*/
function PageBox(url, title, width, height, closingCallbak, closedCallbak, autoCloseTime, hasScroll, showShade)
{
    var MSGID = "PageBox" + NewControlGUID();
    var box = MSGID + "box";
    var btnClose = MSGID + "Close";
    var iframe = MSGID + "Iframe";

	var br=document.createElement("DIV");
	br.id=MSGID;
	br.style.zIndex=999;
	br.returnValue=null;
	document.body.appendChild(br);
	if(title==null)
	{
	    title="新窗口";
	}
	else
	{
	    if(title=="")
	    {
	        title="&nbsp;";
        }
        else
        {
            title=TextToHtml(title);
        }
    }
	if(width==null)
	{
	    width=300;
    }
	if(height==null)
	{
	    height=100;
    }
	if(autoCloseTime==null)
	{
	    autoCloseTime=-1;
    }
	if(hasScroll==null)
	{
	    hasScroll=true;
    }
	if(showShade==null)
	{
	    showShade=true;
    }

	var Aok="100%";
	var Anc="100%";
	if(document.body.scrollWidth > clientWidth())
	{
		Aok=document.body.scrollWidth + "px";
	}
	if(document.body.scrollHeight > clientHeight())
	{
		Anc=document.body.scrollHeight + "px";
	}
	var u='';
	if(showShade)
	{
        u+='<iframe style="position:absolute;top:0;left:0;width:'+Aok+';height:'+Anc+';opacity:0.00;-moz-opacity:0.00;filter:alpha(opacity=0);background-color:#000000;DISPLAY:block" frameBorder="0" scrolling="no" src="about:blank"></iframe><div style="position:absolute;top:0;left:0;width:'+Aok+';height:'+Anc+';opacity:0.07;-moz-opacity:0.07;filter:alpha(opacity=7);background-color:#000000;DISPLAY:block;"></div>';
	}
	u+='<div id="' + box + '" style="position:absolute;" onselectstart="return false;" ondrag="return false;">';
	if(!showShade)
	{
	    u+='<iframe style="position:absolute; z-index:-1; DISPLAY: block; width:100%; height:100%; left:0px; top: 0px; opacity:0.00;-moz-opacity:0.00;filter:alpha(opacity=0);background-color:#000000" frameBorder="0" scrolling="no" src="about:blank"></iframe>';
	}
	u+='<table cellpadding="0" cellspacing="0" border="0">'
	+'<tr><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: 0px 0px; width:3px; height:27px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="27"></td><td style="background-image: url('+MessageBoxImages+'tb.gif); background-position: 0px 0px; height:27px; background-repeat:repeat-x;">'
	+'<table style="width: 100%"><tr><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: -180px 0px; width:14px; height:14px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="14" height="14"></td><td style="color:#06559b; font-size:12px; cursor:default;" onmousedown="MoveForm(\''+box+'\');" onmouseup="StopMoveForm();">'+title+'</td><td style="width:8px;"><a href="javascript:;" title="关闭" id="' + btnClose + '"><img style="background-image: url('+MessageBoxImages+'box.gif); background-position: -56px -16px; width:16px; height:16px; background-repeat:no-repeat;" onmouseover="this.style.backgroundPosition=\'-56px -31px\';" onmouseout="this.style.backgroundPosition=\'-56px -16px\';" src="'+MessageBoxImages+'place.gif" width="16" height="16" border="0" /></a></td></tr></table>'
	+'</td><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: -10px 0px; width:3px; height:27px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="27"></td></tr>'
	+'<tr><td style="background-image: url('+MessageBoxImages+'lr.gif); background-position: 0px 0px; width:3px; background-repeat:repeat-y;"><img src="'+MessageBoxImages+'place.gif" width="3" height="1"></td>'
    +'<td style="background-image: url('+MessageBoxImages+'bg.gif); padding: 0px; color:#06559b; font-size:14px;"><iframe id="'+iframe+'" src="'+(url=='about:blank'? url: SetUriParameter(url, "PageBoxID", MSGID))+'" marginheight="0" marginwidth="0" frameborder="0" width="'+width+'" height="'+height+'" scrolling="'+(hasScroll?'auto': 'no')+'"></iframe></td>'
    +'<td style="background-image: url('+MessageBoxImages+'lr.gif); background-position: -10px 0px; width:3px; background-repeat:repeat-y;"><img src="'+MessageBoxImages+'place.gif" width="3" height="1"></td></tr>'
	+'<tr><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: -40px 0px; width:3px; height:3px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="3"></td><td style="background-image: url('+MessageBoxImages+'tb.gif); background-position: 0px -100px; height:3px; background-repeat:repeat-x;"></td><td style="background-image: url('+MessageBoxImages+'box.gif); background-position: -50px 0px; width:3px; height:3px; background-repeat:no-repeat;"><img src="'+MessageBoxImages+'place.gif" width="3" height="3"></td></tr>'
    +'</table>'
	+'</div>';

	br.innerHTML=u;
	var ag=br.lastChild;
    var h=ag.offsetHeight;
    var w=ag.offsetWidth;
    var x=(clientWidth()-w)/2+document.body.scrollLeft;
    var y=(clientHeight()-h)/2+document.body.scrollTop;
    ag.style.left=x+"px";
    ag.style.top=y+"px";

	var lastForm = null;
    for( var i = FormHandleColl.length - 1; i >= 0; i-- )
    {
        if( FormHandleColl[i].type==3 )
        {
            lastForm = FormHandleColl[i].hand;
            break;
        }
    }
    if(lastForm != null)
    {
        ag.style.left=parseInt(lastForm.lastChild.style.left)+10+"px";
        ag.style.top=parseInt(lastForm.lastChild.style.top)+10+"px";
	}
	$(btnClose).onclick=function ()//点击关闭对话框事件
	{
	    var cancelClose = false;//指示是否取消关闭对话框事件。
		if(closingCallbak != null && closingCallbak)
		{//对话框准备关闭回调此事件
			cancelClose = closingCallbak(br.returnValue);
		}
		if( !cancelClose )
		{
		    var rv=br.returnValue;
            u=null;
            br.innerHTML="";
		    document.body.removeChild(br);
		    DeleteForm(br);
		    if(closedCallbak!=null && closedCallbak)
		    {//对话框关闭后回调此事件
			    closedCallbak(rv);
			    return false;
		    }
		}
		br.returnValue=null;
		return false;
		
	};
    if( autoCloseTime >= 0 )
    {
        var defaultButtonTime=autoCloseTime;
        var AutoClick=function()
        {
            if($(btnClose))
            {
                if(defaultButtonTime<=0)
                {
	                $(btnClose).onclick();
                }
                else
                {
	                defaultButtonTime--;
	                window.setTimeout(AutoClick, 1000);
                }
            }

        }
        AutoClick();
    }

    FormHandleColl.push({"hand": br, "type": 3});
	return br;

}


/*
功能：关闭一个正在显示的页面对话框，返回一个值如果有。
参数：
    pb：页面对话框句柄或被调用页面的 URL。如果是后者，一般设置为 window.location.href。
    returnValue：页面对话框关闭后的返回值。

调用示例：
    var pb = PageBox('http://www.163.com/'
     , '新页面窗口'
     , function(returnValue){alert('准备关闭对话框，返回值是：'+returnValue);return false;}
     , function(returnValue){alert('对话框已经关闭，返回值是：'+returnValue);}
     , 5
     );
    ClosePageBox(pb, "一个自定义返回值");
*/
function ClosePageBox(pb, returnValue)
{
    if(typeof(pb) == "string")
    {
        var id = GetUriParameter(pb, "PageBoxID");
        if(id)
        {
            pb = $(id);
        }
    }
    if(pb)
    {
        if(returnValue!=null)
        {
            pb.returnValue=returnValue;
        }
        var btnClose = $(pb.id + "Close");
        if(btnClose)
        {
            btnClose.onclick();
        }
        else
        {//如果无法通过关闭按钮事件关闭对话框则强行执行代码关闭。
            pb.innerHTML="";
            document.body.removeChild(pb);
        }
    }
    DeleteForm(pb);

}


/*
功能：用于在被调用页获取页面对话框。
参数：
    pb：页面对话框句柄或被调用页面的 URL。如果是后者，一般设置为 window.location.href。
    width：宽度。
    height：高度。

调用示例：
    window.parent.SetPageBoxSize(window.location.href, 500, 500);
*/
function SetPageBoxSize(pb, width, height)
{
    if(typeof(pb) == "string")
    {
        var id = GetUriParameter(pb, "PageBoxID");
        if(id)
        {
            pb = $(id + "Iframe");
        }
    }
    else
    {
        if(pb)
        {
            pb = $(pb.id + "Iframe");
        }
    }
    if(pb)
    {
        pb.width=width;
        pb.height=height;
    }

}


/*
功能：用于在被调用页设置页面对话框居中显示。
参数：
    pb：页面对话框句柄或被调用页面的 URL。如果是后者，一般设置为 window.location.href。

调用示例：
    window.parent.SetPageBoxCenter(window.location.href);
*/
function SetPageBoxCenter(pb)
{
    if(typeof(pb) == "string")
    {
        var id = GetUriParameter(pb, "PageBoxID");
        if(id)
        {
            pb = $(id + "box");
        }
    }
    else
    {
        if(pb)
        {
            pb = $(pb.id + "box");
        }
    }
    if(pb)
    {
        var ag=pb;
        var h=ag.offsetHeight;
        var w=ag.offsetWidth;
        var x=(clientWidth()-w)/2+document.body.scrollLeft;
        var y=(clientHeight()-h)/2+document.body.scrollTop;
        ag.style.left=x+"px";
        ag.style.top=y+"px";
    }

}


/*
功能：用于在被调用页设置页面对话框是否显示滚动条。（此方法目前只支持火狐浏览器）
参数：
    pb：页面对话框句柄或被调用页面的 URL。如果是后者，一般设置为 window.location.href。
    hasScroll：一个布尔值。true表示自动根据需要显示滚动条；false表示隐藏滚动条。

调用示例：
    window.parent.SetPageBoxScroll(window.location.href, true);
*/
function SetPageBoxScroll(pb, hasScroll)
{
    if(typeof(pb) == "string")
    {
        var id = GetUriParameter(pb, "PageBoxID");
        if(id)
        {
            pb = $(id + "Iframe");
        }
    }
    else
    {
        if(pb)
        {
            pb = $(pb.id + "Iframe");
        }
    }
    if(pb)
    {
        pb.scrolling=hasScroll? "auto": "no";
    }

}

/*
功能：预先加载图片。一个辅助方法，在显示对话框之前调用此方法，用来保证对话框图片能够正确及时显示。
备注：一般情况我们建议开发人员在文档加载完毕之后的空闲时段调用此方法。例如，在 HTML 页面的 <body> 元素的 onload 事件结束之前。
*/
function PreviewMessageBoxImages()
{
    var imgs = new Array();
    imgs[0]="bg.gif";
    imgs[1]="box.gif";
    imgs[2]="lr.gif";
    imgs[3]="tb.gif";
    imgs[4]="place.gif";
    imgs[5]="progbar.gif";
    imgs[6]="messagebox01.gif";
    imgs[7]="messagebox02.gif";
    imgs[8]="messagebox03.gif";
    imgs[9]="messagebox04.gif";
    for(var i=0;i<imgs.length;i++)
    {
	    var t=document.createElement("IMG");
	    t.style.position="absolute";
	    t.style.left="0px";
	    t.style.top="0px";
	    t.style.width="0px";
	    t.style.height="0px";
	    t.src= MessageBoxImages+imgs[i];
	    document.body.appendChild(t);
    }
}

/*
功能：获取一个元素在 Array 中的索引值。（为 JavaScript Array 对象添加的扩展方法。）
参数列表：
    p_var：要检索的元素。
返回值：元素的索引值。找不到返回 -1。
调用示例：
    var a = new Array();
    a.push("abc");
    a.push("def");
    alert(a.indexOf("abc"));
    alert(a.indexOf("def"));
*/
if(!Array.prototype.indexOf)
{
    Array.prototype.indexOf = function(p_var) 
    {
        for (var i=0; i<this.length; i++) 
        {
            if (this[i] == p_var) 
            {
                return(i);
            } 
        } 
        return(-1);
    }
}

/*
功能：从 Array 中删除一个元素。（为 JavaScript Array 对象添加的扩展方法。）
参数列表：
    o：要删除的元素。
返回值：找到并且成功删除返回 true。否则返回 false。
调用示例：
    var a = new Array();
    a.push("abc");
    a.push("def");
    alert(a[0]);
    a.remove("abc");
    alert(a[0]);
*/
if(!Array.prototype.remove)
{
    Array.prototype.remove = function(o) 
    {
        var i = this.indexOf(o);
        if (i>-1) this.splice(i,1);
        return (i>-1);
    }
}

/*
功能：从窗体管理器中移除指定的窗体。此方法仅供文件内部使用，禁止外部调用。
*/
function DeleteForm(hand)
{
    if( hand )
    {
        for( var i = 0; i < FormHandleColl.length; i++ )
        {
            if( FormHandleColl[i].hand == hand )
            {
                FormHandleColl.remove(FormHandleColl[i]);
                return;
            }
        }
    }
}

/*
功能：统一的关闭窗口对话框。
参数列表：
    hand：窗体句柄，不指定此参数则关闭最后一个窗口。
调用示例：
    CloseBox();
*/
function CloseBox( hand )
{
    if( hand == null )
    {
        if( FormHandleColl.length > 0 )
        {
            hand = FormHandleColl.pop();
        }
    }
    else
    {
        for( var i = 0; i < FormHandleColl.length; i++ )
        {
            if( FormHandleColl[i].hand == hand )
            {
                hand=FormHandleColl[i];
                FormHandleColl.remove(hand);
                break;
            }
        }
    }
    if( hand != null )
    {
        switch(hand.type)
        {
            case 1:
                CloseMessageBox(hand.hand);
                break;
            case 2:
                CloseProgressBar(hand.hand);
                break;
            case 3:
                ClosePageBox(hand.hand);
                break;
        }
    }

}


/*
功能：获取 Iframe 标签的 ID，此标签是 PageBox 对象的用于显示子页面的载体。
参数：
    pb：页面对话框句柄。

调用示例：
    var pb = PageBox('http://www.163.com/'
     , '新页面窗口'
     , null
     , null
     , 5
     );
    var iframeId = GetPageBoxIframe(pb);
*/
function GetPageBoxIframe(pb)
{
    if(pb)
    {
        return pb.id + "Iframe";
    }
    return null;
}


