// 浏览器常量
var gsAgent = navigator.userAgent;
var gfAppVer = parseFloat(navigator.appVersion);
var gIsOpera = gsAgent.indexOf("Opera") > -1;
var gIsKHTML = gsAgent.indexOf("KHTML") > -1 || gsAgent.indexOf("Konqueror") > -1 || gsAgent.indexOf("AppleWebKit") > -1;
var gIsSafari = gsAgent.indexOf("AppleWebKit") > -1;
var gIsIE = gsAgent.indexOf("compatible") > -1 && !gIsOpera;
var gIsTT = gIsIE ? (navigator.appVersion.indexOf("TencentTraveler") != -1 ? 1 : 0) : 0;
var gIsFF = gsAgent.indexOf("Gecko") > -1 && !gIsKHTML;
var gIsNS = !gIsIE && !gIsOpera && !gIsKHTML && (gsAgent.indexOf("Mozilla") == 0) && (navigator.appName == "Netscape");
if (gIsIE)
{
    var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
    reIE.test(navigator.userAgent);
    var gIEVer = parseFloat(RegExp["$1"]);
}

//----------------------------------------------------------------------//
//                                                                      //
//                          徐德飞  2007-05-16                          //
//                                                                      //
//              对 JavaScript 中 String 原型加上自定义方法              //
//                                                                      //
//----------------------------------------------------------------------//

/// <summary>
/// 对JavaScript的String加上trim()方法
/// </summary>
/// <returns>去除空格后的字符串</returns>
String.prototype.trim = function()
{
    return this.replace(/(^\s+)|\s+$/g, "");
}

/// <summary>
/// 计算字符串长度, 汉字算两个字符
/// </summary>
/// <returns>字符串所用字节数</returns>
String.prototype.dataLength = function()
{
    return this.replace(/[^\x00-\xff]/g, "**").length;
}

/// <summary>
/// 把字符串转换成JS变量的格式( 反斜杠, 单引号, 双引号, 回车, 换行, 制表符 ) 转换成对应的16进制值
/// </summary>
/// <returns>替换后的JS格式的字符串</returns>
String.prototype.toJSString = function()
{
    return this.replace(/\x5C/g, "\\x5C").replace(/\x27/g, "\\x27").replace(/\x22/g, "\\x22").replace(/\x0D/g, "\\x0D").replace(/\x0A/g, "\\x0A").replace(/\x09/g, "\\x09")
}

/// <summary>
/// 把字符串转换成XML格式( 并号, 左括号, 右括号 )
/// </summary>
/// <returns>替换后的XML格式的字符串</returns>
String.prototype.toXMLString = function()
{
    return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

/// <summary>
/// 验证字符串是不是有效整数, 不带小数点的长度在10位
/// </summary>
/// <returns>是否有效</returns>
String.prototype.isInt = function()
{
    if (this == "")
        return true;

    var rPattern = /^[-,+]?(0|([1-9]\d{0,10}))$/;

    if (rPattern.test(this))
        return true;

    return false;
}

/// <summary>
/// 验证字符串是不是有效整数, 不带小数点的长度在16位
/// </summary>
/// <returns>是否有效</returns>
String.prototype.isNum = function()
{
    if (this == "")
        return true;

    var rPattern = /^[-,+]?(0|([1-9]\d{0,15}))$/;
    
    if (rPattern.test(this))
        return true;

    return false;
}

/// <summary>
/// 验证字符串是不是有效整数, 带两位小数点的长度在16位
/// </summary>
/// <returns>是否有效</returns>
String.prototype.isNum2 = function()
{
    if (this == "")
        return true;

    var rPattern = /^[-,+]?(0|([1-9]\d{0,14}))((\.)\d{0,2})?$/;

    if (rPattern.test(this))
        return true;

    return false;
}

/// <summary>
/// 验证字符串是不是有效整数, 带四位小数点的长度在16位
/// </summary>
/// <returns>是否有效</returns>
String.prototype.isNum4 = function()
{
    if (this == "")
        return true;

    var rPattern =  /^[-,+]?(0|([1-9]\d{0,14}))((\.)\d{0,4})?$/;
    
    if(rPattern.test(this))
        return true;

    return false;
}

/// <summary>
/// 验证字符串是不是有效的日期格式
/// </summary>
/// <returns>是否有效</returns>
String.prototype.isDate = function()
{
    if (this == "") 
        return true;

    var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-/.])(\\d{1,2})\\4(\\d{1,2})\\s*$");

    result = this.match(yearFirstExp);

    if (result == null)
        return false;

    var year = (result[2].length == 4) ? result[2] : "20" + result[3];
    var month = result[5] - 1;
    var day = result[6];
    var d = new Date(year, month, day);

    return (typeof(d) == "object" && d.getFullYear() == year && d.getMonth() == month && d.getDate() == day);
}

/// <summary>
/// 验证字符串是不是email
/// </summary>
/// <returns>是否有效</returns>
String.prototype.isEmail = function()
{
    if (this == "")
        return true;

    var exp = new RegExp("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\.\\w+([-.]\\w+)*$");
    
    return (this.match(exp) != null);
}

/// <summary>
/// 验证字符串是不是有效密码
/// </summary>
/// <returns>是否有效</returns>
String.prototype.isPassword = function()
{
    if (this.length < 6 || this.length > 25)
        return false;

    return true;
}

/// <summary>
/// 验证字符串是不是有效的企业代码
/// </summary>
/// <returns>是否有效</returns>
String.prototype.isCompcode = function()
{
    var exp = new RegExp("^(\\d{4})?[0-9XxLlGg]\\d{7}[0-9Xx]$");
    return (this.match(exp) != null);
}

/// <summary>
/// 字符串是否前端一致
/// </summary>
/// <param name="value">子项字符串</param>
/// <returns>是否有效</returns>
String.prototype.startsWith = function(value)
{
    value = typeof(value) != "string" ? "" + value : value;
    return this.indexOf(value) == 0;
}

//----------------------------------------------------------------------//
//                                                                      //
//                          徐德飞  2007-08-29                          //
//                                                                      //
//                             常用方法简写                             //
//                                                                      //
//----------------------------------------------------------------------//

/// <summary>
/// 对 JavaScript 错误, 用弹出框显示出来
/// </summary>
/// <param name="msg">错误内容</param>
/// <returns>错误状态</returns>
window.onerror = function (msg, url, line) 
{
    if (top.__debug)
    {
       alert("JavaScript Error:\n" + "msg: " + msg + "\nline: " + line + "\nurl: " + url);
    }
    return true;
}

/// <summary>
/// 根据id查找对象
/// </summary>
/// <param name="id">id名称</param>
/// <param name="parent">容器对象</param>
/// <returns>页面元素对象</returns>
function $(id, parent)
{
    parent = (parent ? (parent.document ? parent.document : parent) : document);
    return parent.getElementById(id);
}

/// <summary>
/// 根据name查找对象
/// </summary>
/// <param name="name">name名称</param>
/// <param name="parent">容器对象</param>
/// <returns>名称对象集合</returns>
function $N(name, parent)
{
    parent = (parent ? (parent.document ? parent.document : parent) : document);
    return parent.getElementsByName(name);
}

/// <summary>
/// 根据id查找框架window对象
/// </summary>
/// <param name="id">id名称</param>
/// <param name="win">window对象</param>
/// <returns>框架window对象</returns>
function $F(id, win)
{
    var frame = $(id, win);
    if(!frame) return null;
    // firefox: frame.contentWindow; ie: window.frames[id]
    return frame.contentWindow ? frame.contentWindow : (win ? win : window).frames[id];
}

/// <summary>
/// 隐藏或显示对象
/// </summary>
/// <param name="obj">对象或者ID</param>
/// <param name="show">是否显示</param>
function $S(obj, show)
{
    obj = (typeof(obj) == "string" ? $(obj) : obj);
    if (obj) obj.style.display = (show ? "" : "none");
}

/// <summary>
/// 隐藏或显示对象列表
/// </summary>
/// <param name="name">对象NAME</param>
/// <param name="show">是否显示</param>
function $SN(name, show)
{
    var o = $N(name);
    for (var i = o.length - 1; i >= 0; i--) 
    {
        $S(o[i], show);
    }
}

/// <summary>
/// 判断对象是否有效
/// </summary>
/// <param name="value">判断的对象</param>
/// <returns>是否有效</returns>
function isNull(value)
{
    return (value == null || typeof(value) == "undefined");
}

/// <summary>
/// 判断对象是否可见
/// </summary>
/// <param name="obj">对象或者对象id</param>
/// <returns>是否可见</returns>
function isShow(obj)
{
    obj = (typeof(obj) == "string" ? $(obj) : obj);
    return obj ? (obj.style.display == "none" ? false : true) : false;
}

/// <summary>
/// 计算对象所在页面的绝对位置(左上角)
/// </summary>
/// <param name="obj">对象</param>
/// <returns>绝对位置(左上角)</returns>
function getPosition(obj)
{
    var pt = { top:obj.offsetTop, left:obj.offsetLeft };
    while (obj = obj.offsetParent)
    {
        //top.window.status += "." + obj.tagName;
        if (obj.scrollTop || obj.scrollTop == 0)
        {
            pt.top -= obj.scrollTop;
        }
        if (obj.scrollLeft || obj.scrollLeft == 0)
        {
            pt.left -= obj.scrollLeft;
        }
        pt.top += obj.offsetTop;
        pt.left += obj.offsetLeft;
    }
    return pt;
}

/// <summary>
/// 对数字型的串加上逗号
/// </summary>
/// <param name="value">数字</param>
/// <returns>加上逗号后数字</returns>
function addCommas(value)
{
    var objRegExp = new RegExp("([-,+]?[0-9]+)([0-9]{3})");
    while(objRegExp.test(value)) 
    {
        value = value.replace(objRegExp, "$1,$2");
    }
    return value;
}

/// <summary>
/// 移除数字中的逗号
/// </summary>
/// <param name="value">数字</param>
/// <returns>移除逗号后数字</returns>
function removeCommas(value)
{
    return value.replace(/,/g, "");
}

/// <summary>
/// 获取属性小写
/// </summary>
/// <param name="control">HTML对象</param>
/// <param name="name">属性名</param>
/// <return>属性值(小写)</return>
function getAttribute(control, name)
{
    if (!control) return null;
    var result = control.getAttribute(name);
    if (!isNull(result)) result = result.toLowerCase();
    return result;
}

/// <summary>
/// 控件类型是否货币类型
/// </summary>
/// <param name="datatype">控件类型</param>
/// <returns>是否货币类型</returns>
function isNumType(datatype)
{
    return (datatype == "int" || datatype == "num0" || datatype == "num2" || datatype == "num4");
}

/// <summary>
/// 控件类型错误消息
/// </summary>
/// <param name="obj">控件对象</param>
/// <returns>错误消息</returns>
function getErrorMsg(obj)
{
    var msg = "";
    switch(getAttribute(obj, "DataType"))
    {
        case "int":
            if(!(obj.value.trim().isInt()))
                msg = "您只能输入整数, 且长度不超过10位!";
            break;
        case "num0":
            if(!(obj.value.trim().isNum0()))
                msg = "您不能输入带有小数点的数, 且长度不超过16位!";
            break;
        case "num2":
            if(!(obj.value.trim().isNum2()))
                msg = "您只能输入带两位小数点的小数, 且长度不超过16位!";
            break;
        case "num4":
            if(!(obj.value.trim().isNum4()))
                msg = "您只能输入带四位小数点的小数, 且长度不超过16位!";
            break;
        case "date":
            if(!(obj.value.trim().isDate()))
                msg = "您只能输入有效的日期格式!";
            break;
        case "email":
            if(!(obj.value.trim().isEmail()))
                msg = "您只能输入有效的EMAIL格式!";
            break;
    }
    return msg;
}

/// <summary>
/// 日期1是否大于2
/// </summary>
/// <param name="str1">日期字符串1</param>
/// <param name="str2">日期字符串2</param>
/// <returns>1:大于 0:等于 -1:小于</returns>
function compareDate(str1, str2)
{
    str1 = str1.replace(/-/g, "/").replace(/\x2E/g, "/");
    str2 = str2.replace(/-/g, "/").replace(/\x2E/g, "/");

    var date1 = new Date(str1);
    var date2 = new Date(str2);

    if (date1 > date2)
        return 1

    if (date1 < date2)
        return -1

    return 0;
}

/// <summary>
/// 附加事件(跨浏览器通用)
/// </summary>
/// <param name="target">来源对象</param>
/// <param name="type">事件类型</param>
/// <param name="handler">处理方法</param>
/// <param name="remove">是否移除</param>
function addEvent(target, type, handler, remove)
{
    if (!target) return;

    if (target.attachEvent) 
    {
        // ie
        remove ? target.detachEvent("on" + type, handler) : target.attachEvent("on" + type, handler);
    }
    else if (target.addEventListener) 
    {
        // firefox
        remove ? target.removeEventListener(type, handler, false) : target.addEventListener(type, handler, false);
    }
    else 
    {
        // other
        target["on" +type] = remove ? null : handler;
    }
}


//----------------------------------------------------------------------//
//                                                                      //
//                          徐德飞  2007-05-16                          //
//                                                                      //
//                            DOM、XML 操作                             //
//                                                                      //
//----------------------------------------------------------------------//

/// <summary>
/// 创建 DOM 对象
/// </summary>
/// <param name="xml">XML字符串</param>
/// <returns>返回DOM对象</returns>
function createXmlDom(xml) 
{
    var oXmlDom = null;
    try
    {
        oXmlDom = new ActiveXObject("MSXML2.DOMDocument.4.0");
    }
    catch(ex1)
    {
        try
        {
            oXmlDom = new ActiveXObject("MSXML2.DOMDocument.3.0");
        }
        catch(ex2)
        {
            oXmlDom = new ActiveXObject("Microsoft.XMLDOM");
        }
    }

    if (xml != null)
    {
        oXmlDom.loadXML(xml);
    }

    if (oXmlDom == null)
        throw new Error("DOM对象创建失败, 请与软件提供商联系!");

    return oXmlDom;
}

/// <summary>
/// 给指定DOM创建一个字节点
/// </summary>
/// <param name="xmlDom">DOM对象</param>
/// <param name="parentNode">父节点</param>
/// <param name="childNodeName">节点名称</param>
/// <param name="childValue">节点值</param>
/// <returns>子节点对象</returns>
function addChildNode(xmlDom, parentNode, childNodeName, childValue)
{
    var newNode;
    newNode = xmlDom.createNode(1, childNodeName, "");
    newNode.text = childValue;
    if (parentNode == null)
        xmlDom.documentElement.appendChild(newNode)
    else
        parentNode.appendChild(newNode);
    return newNode;
}

/// <summary>
/// 对节点设置属性
/// </summary>
/// <param name="xmlDom">DOM对象</param>
/// <param name="node">节点对象</param>
/// <param name="attributeName">属性名称</param>
/// <param name="attributeValue">属性值</param>
function setNodeAttribute(xmlDom, node, attributeName, attributeValue)
{
    var attr = xmlDom.createAttribute(attributeName);
    attr.value = attributeValue;
    if (node == null)
        xmlDom.documentElement.setAttributeNode(attr)
    else
        node.setAttributeNode(attr);
}

//----------------------------------------------------------------------//
//                                                                      //
//                          徐德飞  2007-06-22                          //
//                                                                      //
//                  用 JavaScript 实现 C,Java 中堆栈类                  //
//                                                                      //
//                    暂时没有对堆栈的最大长度做限制                    //
//                                                                      //
//----------------------------------------------------------------------//

/// <summary>
/// 堆栈类定义
/// </summary>
function Stack()
{
    /// <summary>
    /// 栈的层数
    /// </summary>
    var Top = -1;

    /// <summary>
    /// 栈数据数组
    /// </summary>
    var List = new Array();

    /// <summary>
    /// 入栈操作
    /// </summary>
    /// <param name="value">数据</param>
    this.push = function(value)
    {
        List[++Top] = value;
    }

    /// <summary>
    /// 出栈操作
    /// </summary>
    /// <returns>出栈数据</returns>
    this.pop = function()
    {
        if (Top == -1)
        {
            throw new Error("栈已经为空, 不能进行出栈操作!");
        }
        return List[Top--];
    }

    /// <summary>
    /// 只取栈顶数据, 不进行出栈操作
    /// </summary>
    /// <returns>出栈数据</returns>
    this.getTop = function()
    {
        if (Top == -1)
        {
            throw new Error("栈已经为空, 不能取的栈顶数据!");
        }
        return List[Top];
    }

    /// <summary>
    /// 栈是否为空
    /// </summary>
    /// <returns>是否为空</returns>
    this.isEmpty = function()
    {
        return Top == -1;
    }

    /// <summary>
    /// 栈中数据数目
    /// </summary>
    /// <returns>数据数目</returns>
    this.length = function()
    {
        return Top + 1;
    }
}

//----------------------------------------------------------------------//
//                                                                      //
//                          徐德飞  2007-12-21                          //
//                                                                      //
//                      自定义对话框公用方法的实现                      //
//                                                                      //
//----------------------------------------------------------------------//

var dialog = 
{
    maskObj : null,                         // 遮盖div对象
    maskObjStack : new Stack(),

    moveObj : null,                         // 跟随鼠标移动的iframe对象
    moveObjStack : new Stack(),

    currentWindow : null,                   // 当前对话框调用页面的window对象
    currentWindowStack : new Stack(),

    currentDialogObj : null,                // 当前对话框iframe对象
    currentDialogObjStack : new Stack(),

    currentDialogWin : null,                // 当前对话框页面的window对象
    currentDialogWinStack : new Stack(),

    callback : null,                        // 页面关闭后需要执行的回调函数
    callbackStack : new Stack(),

    mainMouseDown : false,                  // 对话框页面移动部分鼠标是否按下
    cursorOldX : null,                      // 鼠标移动的上次X坐标
    cursorOldY : null,                      // 鼠标移动的上次Y坐标
    oldSrcollTop : null,                    // 垂直滚动条顶端值
    oldSrcollLeft : null,                   // 水平滚动条左端值
    currentDialogInterval : null            // 对话框标题闪烁效果的计时器
};

dialog.maskObjStack.push(null);
dialog.moveObjStack.push(null);
dialog.currentWindowStack.push(null);
dialog.currentDialogObjStack.push(null);
dialog.currentDialogWinStack.push(null);
dialog.callbackStack.push(null);

function createDialog(id, url, width, height, css, onloadEvent)
{
    // maskObj, moveObj 对象必须要在 baseObj 之前创建, 因为外围调用可能需要附加事件在这两个对象上面
    //if (!top.dialog.maskObj) 
    top.dialog.maskObj = $("dialog_mask_" + id, top);
    //if (!top.dialog.maskObj) 
    top.dialog.maskObj = createMask(top, id);
    top.dialog.maskObjStack.push(top.dialog.maskObj);

    //if (!top.dialog.moveObj) 
    top.dialog.moveObj = $("dialog_move_" + id, top);
    //if (!top.dialog.moveObj) 
    top.dialog.moveObj = createMove(top, id);
    top.dialog.moveObjStack.push(top.dialog.moveObj);

    // 默认对话框不用创建
    var result = false;
    var baseObj = $(id, top);
    if (!baseObj)
    {
        // 对话框还没有创建, 创建框架, 返回true表示创建
        baseObj = createPanel(top, id, url, css, onloadEvent);
        result = true;
    }

    baseObj.style.width = width;
    baseObj.style.height = height;
    
    top.dialog.currentWindow = window;
    top.dialog.currentWindowStack.push(top.dialog.currentWindow);
    
    top.dialog.currentDialogObj = baseObj;
    top.dialog.currentDialogObjStack.push(top.dialog.currentDialogObj);

    top.dialog.currentDialogWin = $F(id, top);
    top.dialog.currentDialogWinStack.push(top.dialog.currentDialogWin);

    // 返回是否是新创建
    return result;
}

function showDialog()
{
    // 如果当前对话框没有创建, 返回
    if (!top.dialog.currentDialogObj) return;


    // 如果当前对话框已经显示, 返回
    if (isShow(top.dialog.currentDialogObj)) return;

    // 设置遮盖框架的左上角位置
    fDialogTopWindowResize();

    // 计算对话框位置到屏幕中心
    var tb = top.document.body;
    top.dialog.currentDialogObj.style.left = (tb.clientWidth - parseInt(top.dialog.currentDialogObj.style.width)) / 2 + tb.scrollLeft;
    top.dialog.currentDialogObj.style.top = (tb.clientHeight - parseInt(top.dialog.currentDialogObj.style.height)) / 2 + tb.scrollTop - 30;

    top.dialog.oldSrcollTop = tb.scrollTop;
    top.dialog.oldSrcollLeft = tb.scrollLeft;

    addEvent(top.dialog.maskObj, "mousemove", fDialogMaskMouseMove);
    addEvent(top.dialog.maskObj, "mousedown", fDialogMaskMouseDown);
    addEvent(top, "scroll", fDialogTopWindowScroll);
    addEvent(top, "resize", fDialogTopWindowResize);

    $S(top.dialog.maskObj, true);
    $S(top.dialog.moveObj, true);
    $S(top.dialog.currentDialogObj, true);
}

function closeDialog()
{
    if (!top.dialog.currentDialogObj)
        return;

    // 如果对话框正在移动, 自动停止
    if (top.dialog.mainMouseDown) fDialogMainMouseUp();
    $S(top.dialog.maskObj, false);
    $S(top.dialog.moveObj, false);
    $S(top.dialog.currentDialogObj, false);

    addEvent(top.dialog.maskObj, "mousemove", fDialogMaskMouseMove, true);
    addEvent(top.dialog.maskObj, "mousedown", fDialogMaskMouseDown, true);
    addEvent(top, "scroll", fDialogTopWindowScroll, true);
    addEvent(top, "resize", fDialogTopWindowResize, true);

    top.dialog.maskObjStack.pop();
    top.dialog.maskObj = top.dialog.maskObjStack.getTop();
    
    top.dialog.moveObjStack.pop();
    top.dialog.moveObj = top.dialog.moveObjStack.getTop();

    top.dialog.currentWindowStack.pop();
    top.dialog.currentWindow = top.dialog.currentWindowStack.getTop();

    top.dialog.currentDialogObjStack.pop();
    top.dialog.currentDialogObj = top.dialog.currentDialogObjStack.getTop();

    top.dialog.currentDialogWinStack.pop();
    top.dialog.currentDialogWin = top.dialog.currentDialogWinStack.getTop();

}

/// <summary>
/// 创建满屏遮盖对象
/// </summary>
/// <param name="win">window对象</param>
/// <returns>满屏遮盖对象</returns>
function createMask(win, id)
{
    win = win ? win : window;
    var mask = win.document.createElement("div");
    mask.id = "dialog_mask_" + id;
    mask.className = "DialogMask" + id;
    mask.style.display = "none";
    // 由于如果把 div, iframe 动态加在 body 最后, ie 中会导致底部回出现一个占位, 所以插入 body 最前
    //win.document.body.appendChild(mask);
    win.document.body.insertBefore(mask, win.document.body.firstChild);
    return mask;
}

/// <summary>
/// 创建鼠标移动跟随对象
/// </summary>
/// <param name="win">window对象</param>
/// <returns>跟随对象</returns>
function createMove(win, id)
{
    win = win ? win : window;
    // ie5动态创建iframe后不能访问内部, 但是在innerHTML下的动态创建可以绕过该问题
    var span = win.document.createElement("span");
    span.innerHTML = '<iframe id="dialog_move_' + id + '" name="dialog_move_' + id + '" class="DialogMove' + id + '" frameborder="0" scrolling="no" style="display:none;" src="about:blank"></iframe>';
    // 由于如果把 div, iframe 动态加在 body 最后, ie 中会导致底部回出现一个占位, 所以插入 body 最前
    //win.document.body.appendChild(span.childNodes[0]);
    win.document.body.insertBefore(span.childNodes[0], win.document.body.firstChild);
    return $("dialog_move_" + id, win);
}

/// <summary>
/// 创建对话框显示区域
/// </summary>
/// <param name="win">window对象</param>
/// <param name="id">ID</param>
/// <param name="url">URL</param>
/// <param name="onloadEvent">onload事件</param>
/// <returns>区域对象</returns>
function createPanel(win, id, url, css, onloadEvent)
{
    win = win ? win : window;

    // ie5动态创建iframe后不能访问内部, 但是在innerHTML下的动态创建可以绕过该问题
    var span = win.document.createElement("span");
    span.innerHTML = '<iframe id="' + id + '" name="' + id + '" frameborder="0" scrolling="no" style="display:none;" class="' + (css ? css : 'DialogMain') + '"' + (url ? ' src="' + url + '"' : '') + '></iframe>';
    var panel = span.childNodes[0];

    // 对于页面动态创建 iframe 指定 src 后, ie进度条不能完成, 在框架页面加载完成后, 在框架页面中添加一个空 iframe 可以解决此问题
    if (gIsIE && url) addEvent(panel, "load",
        function()
        {
            var contentWindow = $F(id, win);
            span = contentWindow.document.createElement("span");
            span.innerHTML = '<iframe style="top:0px;left:0px;width:0px;height:0px;display:none;"></iframe>';
            contentWindow.document.body.appendChild(span.childNodes[0]);
        });
    if (onloadEvent) addEvent(panel, "load", onloadEvent);
    // 由于如果把 div, iframe 动态加在 body 最后, ie 中会导致底部回出现一个占位, 所以插入 body 最前
    //win.document.body.appendChild(panel);
    win.document.body.insertBefore(panel, win.document.body.firstChild);

    return panel;
}

function fDialogMaskMouseMove(e)
{
    if (!top.dialog.moveObj) return;

    top.dialog.moveObj.style.top = e.clientY - 2;    // IE: 鼠标位置往上移两个象素
    top.dialog.moveObj.style.left = e.clientX - 2;   // IE: 鼠标位置往左移两个象素
    // 在 ie 中 可能会出现越界问题
    if (top.dialog.moveObj.offsetTop > top.dialog.maskObj.offsetTop + top.dialog.maskObj.offsetHeight - top.dialog.moveObj.offsetHeight)
    {
        top.dialog.moveObj.style.top = top.dialog.maskObj.offsetTop + top.dialog.maskObj.offsetHeight - top.dialog.moveObj.offsetHeight;
    }
    // 在 ie 中 可能会出现越界问题
    if (top.dialog.moveObj.offsetLeft > top.dialog.maskObj.offsetLeft + top.dialog.maskObj.offsetWidth - top.dialog.moveObj.offsetWidth)
    {
        top.dialog.moveObj.style.left = top.dialog.maskObj.offsetLeft + top.dialog.maskObj.offsetWidth - top.dialog.moveObj.offsetWidth;
    }
//    if (top.__debug)
//    {
//        top.window.status = "function fDialogMaskMouseMove top = " + top.dialog.moveObj.style.top + ", left = " + top.dialog.moveObj.style.left;
//    }
}

function fDialogMaskMouseDown(e)
{
    // 无论左右中键按下, 都设置焦点
    // 暂时点击外框不设置焦点, 由框架页面设置焦点按钮
    // setTimeout(function(){top.dialog.currentDialogWin.focus()}, 0);
    // ie鼠标左键为1, firefox鼠标左键为0
    if((gIsIE && e.button == 1) || gIsNS && e.button == 0)
    {
        if (top.dialog.currentDialogInterval) clearInterval(top.dialog.currentDialogInterval);
        var times = 1;
        var titlebar = $("DialogTitleBar", top.dialog.currentDialogWin);
        top.dialog.currentDialogInterval = setInterval(
            function()
            {
                if (titlebar) titlebar.className = times % 2 ? "DialogMainTitleBarFlash" : "DialogMainTitleBar";
                if (times == 4) return clearInterval(top.dialog.currentDialogInterval);
                times ++;
            }, 50);
    }
}

function fDialogMainMouseDown(e)
{
    // 若点击的是不用移动的, 不用执行
    if ((e.target ? e.target : e.srcElement).id == "no_move") return;
    top.dialog.cursorOldX = e.screenX;
    top.dialog.cursorOldY = e.screenY;
    top.dialog.mainMouseDown = true;
    // 鼠标快速移动的时候, 当前鼠标位置可能移区域, 所以也捕获遮盖对象的鼠标移动事件
    addEvent(top.dialog.maskObj, "mousemove", fDialogMainMouseMove);
    addEvent(top.dialog.maskObj, "mouseup", fDialogMainMouseUp);
//    if (top.__debug)
//    {
//        top.window.status = "function fDialogMainMouseDown e.screenX = " + e.screenX + ", e.screenY = " + e.screenY;
//    }
}

function fDialogMainMouseMove(e)
{
    if(top.dialog.mainMouseDown) 
    {
        // 需要保证对话框在遮盖的范围之内
        var posleft = parseInt(top.dialog.currentDialogObj.style.left) + e.screenX - top.dialog.cursorOldX;
        if (posleft < top.document.body.scrollLeft)
        {
            posleft = top.document.body.scrollLeft;
        }
        else if (posleft > top.dialog.maskObj.offsetWidth + top.document.body.scrollLeft - parseInt(top.dialog.currentDialogObj.style.width))
        {
            posleft = top.dialog.maskObj.offsetWidth + top.document.body.scrollLeft - parseInt(top.dialog.currentDialogObj.style.width);
        }
        var posTop = parseInt(top.dialog.currentDialogObj.style.top) + e.screenY - top.dialog.cursorOldY;
        if (posTop < top.document.body.scrollTop)
        {
            posTop = top.document.body.scrollTop;
        }
        else if (posTop > top.dialog.maskObj.offsetHeight + top.document.body.scrollTop - parseInt(top.dialog.currentDialogObj.style.height))
        {
            posTop = top.dialog.maskObj.offsetHeight + top.document.body.scrollTop - parseInt(top.dialog.currentDialogObj.style.height);
        }
        top.dialog.currentDialogObj.style.left = posleft;
        top.dialog.currentDialogObj.style.top = posTop;
        top.dialog.cursorOldX = e.screenX;
        top.dialog.cursorOldY = e.screenY;
//        if (top.__debug)
//        {
//            top.window.status = "function fDialogMainMouseMove e.screenX = " + e.screenX + ", e.screenY = " + e.screenY;
//            top.window.status += "top.dialog.maskObj.offsetWidth = " + top.dialog.maskObj.offsetWidth + " top.dialog.maskObj.offsetHeight = " + top.dialog.maskObj.offsetHeight;
//        }
    }
}

function fDialogMainMouseUp(e) 
{
    if (top.dialog.mainMouseDown)
    {
        top.dialog.mainMouseDown = false;
        addEvent(top.dialog.maskObj, "mousemove", fDialogMainMouseMove, true);
        addEvent(top.dialog.maskObj, "mouseup", fDialogMainMouseUp, true);
//        if (top.__debug)
//        {
//            top.window.status = "function fDialogMainMouseUp e.screenX = " + e.screenX + ", e.screenY = " + e.screenY;
//        }
    }
}

function fDialogTopWindowResize(e) 
{
    // 当窗口尺寸变小的时候, 把移动框架位置设置左上角, 否则回出现滚动条
    top.dialog.moveObj.style.top = top.document.body.scrollTop;
    top.dialog.moveObj.style.left = top.document.body.scrollLeft;
    // 当窗口尺寸变小的时候, 移动遮盖框架左上角到滚动条位置
    top.dialog.maskObj.style.top = top.document.body.scrollTop;
    top.dialog.maskObj.style.left = top.document.body.scrollLeft;
//    if (top.__debug)
//    {
//        top.window.status = "function fDialogTopWindowResize scrollTop = " + top.document.body.scrollTop + ", scrollLeft = " + top.document.body.scrollLeft;
//    }
}

function fDialogTopWindowScroll(e) 
{
    // 把遮盖的左上角移动到滚动条位置
    top.dialog.maskObj.style.top = top.document.body.scrollTop;
    top.dialog.maskObj.style.left = top.document.body.scrollLeft;
    // 根据当前滚动条位置、滚动条上次位置, 来计算当前位置
    top.dialog.currentDialogObj.style.top = top.dialog.currentDialogObj.offsetTop + top.document.body.scrollTop - top.dialog.oldSrcollTop;
    top.dialog.currentDialogObj.style.left = top.dialog.currentDialogObj.offsetLeft + top.document.body.scrollLeft - top.dialog.oldSrcollLeft;
    // 保存滚动条当前位置
    top.dialog.oldSrcollTop = top.document.body.scrollTop;
    top.dialog.oldSrcollLeft = top.document.body.scrollLeft;
//    if (top.__debug)
//    {
//        top.window.status = "Scroll scrollTop = " + top.document.body.scrollTop + ", scrollLeft = " + top.document.body.scrollLeft;
//    }
}

//----------------------------------------------------------------------//
//                                                                      //
//                          徐德飞  2007-12-25                          //
//                                                                      //
//                             跨浏览器方法                             //
//                                                                      //
//----------------------------------------------------------------------//


/// <summary>
/// 把小写字母变成大写, [2008-06-02 沈剑峰修改：增加必须为字母，其他字符过滤]
/// </summary>
/// <param name="e">消息对象</param>
function keypressToUpper(e)
{
    e = e ? e : event;
    if (gIsIE && e.keyCode >= 97 && e.keyCode <= 122)
    {
        // ie 小写变大写
        e.keyCode = e.keyCode - 32;
    }
    else if (gIsIE && e.keyCode >= 65 && e.keyCode <= 90)
    {
        // ie 大写
    }
    else if (gIsIE)
    {
        if (e.keyCode != 13) {e.keyCode = null;}
    }
    else if (gIsNS && e.charCode >= 97 && e.charCode <= 122)
    {
        // firefox 小写变大写
        var evt = document.createEvent("KeyEvents"); 
        evt.initKeyEvent( "keypress", true, true, document.defaultView, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, 0, e.charCode - 32);
        e.target.dispatchEvent(evt);
        e.preventDefault(); 
    }
    else if (gIsNS && e.charCode >= 65 && e.charCode <= 90)
    {
        // firefox 大写
    }
    else if (gIsNS)
    {
        if (e.charCode != 0) 
        {
            e.preventDefault();
            return false;
        }
    }
}


/// <summary>
/// 对于相同名字的复选框, 排斥其它的选择
/// </summary>
/// <param name="obj">当前复选框对象</param>
/// <param name="parent">容器对象</param>
function setOnlyOne(obj, parent)
{
    parent = (parent ? (parent.document ? parent.document : parent) : document);

    var name = obj.name;
    var controls = $N(name, parent);
    if(controls)
    {
        for(var i=0;i<controls.length;i++)
        {
            if(obj != controls[i])
            {
                controls[i].checked = false
            }
        }
    }
}

/// <summary>
/// 根据 checkbox 名称获取, 选中的值
/// </summary>
/// <param name="name">复选框名称</param>
/// <param name="parent">容器对象</param>
/// <returns>第一个选中的复选框的值</returns>
function getOnlyValue(name, parent)
{
    parent = (parent ? (parent.document ? parent.document : parent) : document);
    var ret = "";
    var controls = $N(name, parent);
    if(controls)
    {
        for(var i=0;i<controls.length;i++)
        {
            if(controls[i].checked)
            {
                ret = controls[i].value;
                break;
            }
        }
    }
    return ret;
}

/// <summary>
/// 把所有选中的复选框的值Tag标志的方式
/// </summary>
/// <param name="name">复选框名称</param>
/// <param name="parent">容器对象</param>
/// <returns>所有选中的框值</returns>
function getAllValue(name, parent)
{
    parent = (parent ? (parent.document ? parent.document : parent) : document);
    var ret = 0;
    var controls = $N(name, parent);
    if(controls)
    {
        for(var i=0;i<controls.length;i++)
        {
            if(controls[i].checked)
            {
                ret = ret | parseInt(controls[i].vaue);
            }
        }
    }
    return ret;
}

/// <summary>
/// 在对应的div里显示信息
/// </summary>
function OK(div)
{
   div.className = "divright";
   div.innerHTML = "填写正确";
   div.style.display = "";
}
function Error(div,html)
{
   div.className = "diverror";
   div.innerHTML = html;
   div.style.display = "";
}

//trim()去掉字串两边的空格  
function trim(str)  
{ 
  return str.replace(/(^\s*)|(\s*$)/g,"");
  //或者return(rTrim(lTrim(str)));
}

//判断Email的JS程序
//是合法Email返回TRUE，不是返回false, 空是合法的email
function CheckEmail(a) 
{
	var i=a.length;
	if (i == 0)
	{
		return true;
	}
	var temp = a.indexOf('@'); 
	var tempd = a.indexOf('.'); 
	if (temp > 1) 
	{ 
		if ((i-temp) > 3)
		{ 
			if ((i-tempd)>0)
			{ 
				return true; 
			} 
		} 
	} 
	return false; 
} 
//判断输入的是否全为数字的JS程序
//是判断num是否都是strTemp的一部分
function CheckNum(NUM,strTemp) 
{ 
	var i,j,strTemp; 
	//strTemp="0123456789-、|,"; 
	if (NUM.length==0) 
	return false 
	for (i=0;i<NUM.length;i++) 
	{ 
		j=strTemp.indexOf(NUM.charAt(i)); 
		if (j==-1) 
		{ 
		//说明有字符不是数字 
			return false; 
		} 
	} 
	//说明是数字 
	return true; 
} 

//AJAX删除单条记录
//tb表名
//id对应表的id
function delInfo(tb,id)
{
	//alert("fff");
	 var url="adminajax.php?menu=delinfo&id="+id+"&tb="+tb;
	 //var p = "tr"+id;
	 //$("myhint").style.display= '';
	 var ajax=createAjax();
		ajax.open("GET",url,true);
		ajax.onreadystatechange=function()
		{
			if(ajax.readyState==4)
			{
				if(ajax.status==200)
				{
					var info = ajax.responseText;
					//alert(info);
					info = info.split("^");
					var p = "tr"+trim(info[0]);
					if(trim(info[1]) == "ok")
					{
						
						$(p).style.display='none';
						//$("myhint").style.display= 'none';
					}
					else if(trim(info) == "sorry")
					{
						alert("对不起,您不能删除它");
						//$("myhint").style.display= 'none';
					}
				}
			}
		}
		ajax.send(null);
}

//AJAX修改单条0，1记录，是0就变1，是1就变0
//tb表名
//id对应表的id
function changeinfo(tb,id,zd)
{
	 var url="../ajaxprocess.php?menu=changeinfo&id="+id+"&tb="+tb+"&zd="+zd;
	 var p = "img"+id;
	 $("myhint").style.display= '';
	 var ajax=createAjax();
		ajax.open("GET",url,true);
		ajax.onreadystatechange=function()
		{
			if(ajax.readyState==4)
			{
				if(ajax.status==200)
				{
					var info = ajax.responseText;
					if(trim(info) == "yes")
					{
						$(p).src="images/no.gif";
						$(p).alt = "已欠费";
						$("myhint").style.display= 'none';
					}
					else if(trim(info) == "no")
					{
						$(p).src="images/yes.gif";
						$(p).alt = "未欠费";
						$("myhint").style.display= 'none';
					}
				}
			}
		}
		ajax.send(null);
}

///审核文章列表
function changeinfoa(tb,id,zd)
{
	 var url="../ajaxprocess.php?menu=changeinfo&id="+id+"&tb="+tb+"&zd="+zd;
	 var p = "img"+id;
	 $("myhint").style.display= '';
	 var ajax=createAjax();
		ajax.open("GET",url,true);
		ajax.onreadystatechange=function()
		{
			if(ajax.readyState==4)
			{
				if(ajax.status==200)
				{
					var info = ajax.responseText;
					//alert(info);
					if(trim(info) == "yes")
					{
						$(p).src="images/yes.gif";
						$(p).alt = "已审核";
						$("myhint").style.display= 'none';
					}
					else if(trim(info) == "no")
					{
						$(p).src="images/no.gif";
						$(p).alt = "未审核";
						$("myhint").style.display= 'none';
					}
					else if(trim(info) == "sorry")
					{
						$("myhint").style.display= 'none';
						alert("操作失败,可能是您没有权限");
					}
				}
			}
		}
		ajax.send(null);
}
//JS替换换行为<br/>
function replaceTextarea1(str){
    var reg=new RegExp("\r\n","g");
    var reg1=new RegExp(" ","g");
    
    str = str.replace(reg,"<br>");
    str = str.replace(reg1,"<p>");
    
    return str;
}

//JS替换<br/>为换行
function replaceTextarea2(str){
    var reg=new RegExp("<br>","g");
    var reg1=new RegExp("<p>","g");
    
    str = str.replace(reg,"\r\n");
    str = str.replace(reg1," ");
    
    return str;
}