/*
2012/10/20
*/

var IsIE = document.all ? true : false; //是否为IE浏览器

var _loadingimg1 = "/Images/loading/loading16x16b.gif";
var solution = {
    utility: {
        isIE: document.all ? true : false
    },
    isolution: {
        get: function (a, b) {
            /// <summary>
            /// 获取参数
            /// </summary>
            /// <param name="a">参数1</param>
            /// <param name="b">参数2</param>
            alert(a);
        }
    },
    status: {
        loadPage: {
            load: function () {
                this.start();
                window.onload = function () { document.getElementById("_pageLoadStatus").style.display = "none"; };
            },
            start: function () {
                /// <summary>
                /// 加载状态
                /// </summary>
                //                var obj = document.createElement("div");
                //                obj.className = "_pageLoadStatus";
                //                obj.style.cssText = "position:fixed;border:1px blue solid;width:200px;top:0px;left:0px;background-color:blue;";
                //                obj.innerHTML = "<img src=\"" + _loadingimg1 + "\" alt=\"loading\"/>加载中......";
                ////                if (document.all)
                ////                    document.body.appendChild(obj);
                //                //                else
                //                document.documentElement.appendChild(obj);
                var ct = "position:fixed;border:1px blue solid;width:200px;top:0px;left:0px;background-color:#FFF;";
                document.write("<div style=\"" + ct + "\" id=\"_pageLoadStatus\" class=\"_pageLoadStatus\"><img src=\"" + _loadingimg1 + "\" alt=\"loading\"/>加载中......</div>")
            },
            end: function () {
                /// <summary>
                /// 状态结束
                /// </summary>
                document.getElementById("_pageLoadStatus").style.display = "none";
                //   window.document.write('<style type=\"text/css\">._pageLoadStatus{display:none;}</style>');
            }
        },
        click: function () {
            /// <summary>
            /// 单击状态
            /// </summary>
            var obj = document.createElement("div");
            obj.className = "_pageLoadStatus";
            obj.style.cssText = "position:fixed;border:1px blue solid;width:200px;top:0px;left:0px;background-color:#FFF;";
            obj.innerHTML = "<img src=\"" + _loadingimg1 + "\" alt=\"loading\"/>加载中......";
            if (document.all)
                document.body.appendChild(obj);
            else
                document.documentElement.appendChild(obj);
        }
    },
    request: {
        queryString: function (key) {
            /// <summary>
            /// 获取HTTP查询字符串变量集合
            /// </summary>
            /// <param name="key">键值项</param>
            var _search = window.location.search.substring(window.location.search.lastIndexOf('?') + 1);
            var _searchArray = _search.split('&');
            var _searchKeyValue;
            if (_search != "") {
                for (var i = 0; i < _searchArray.length; i++) {
                    _searchKeyValue = _searchArray[i].split('=');
                    if (_searchKeyValue.length == 2) {
                        if (_searchKeyValue[0] == key)
                            return _searchKeyValue[1];
                        else
                            continue;
                    }
                }
                return "";
            }
            else {
                return "";
            }
        },
        url: {
            directory: function (index) {
                /// <summary>
                /// 获取目录名称
                /// </summary>
                /// <param name="index">索引</param>
                var _pathArray = window.location.pathname.split('/');
                if (_pathArray[index + 1] == undefined)
                    return "";
                else
                    return _pathArray[index + 1];
            },
            fileinfo: function () {
                /// <summary>
                /// 获取URL文件信息,返回一维数组
                /// </summary>
                var _pathArray = window.location.pathname.split('/');
                var _returnValue = new Array();
                _returnValue.push(""); _returnValue.push(""); _returnValue.push("")
                if (_pathArray[_pathArray.length - 1].indexOf('.') != -1) {
                    _returnValue[0] = _pathArray[_pathArray.length - 1]; //全文件名
                    _returnValue[1] = _pathArray[_pathArray.length - 1].substring(0, _pathArray[_pathArray.length - 1].lastIndexOf('.')); //文件名
                    _returnValue[2] = _pathArray[_pathArray.length - 1].substring(_pathArray[_pathArray.length - 1].lastIndexOf('.')); //扩展名
                }
                return _returnValue;
            }
        }
    },
    popup: {
        messageBox: function (params) {
            /// <summary>
            /// Div消息窗口
            /// </summary>
            /// <param name="params">参数集合</param>
            if (params == null) {
                return;
            }
            if (params.background != null && params.background == true) {
                jspopup.createBackground();
            }
            if (params.style == null || params.style == "1") {//默认风格
                var vContent = "<div class=\"window-skin-1\" style=\"padding: 5px;\"><div class=\"window-outer-1\"><div class=\"window-inner-1\" style=\"width:auto; height:auto; overflow: auto;\">{$text}</div></div><div title=\"关闭\" onclick=\"jspopup.closeWindow();\" class=\"window-close-1\"></div></div>";
                jspopup.show({ "content": vContent.replace("{$text}", params.text == null ? "" : params.text) });
            }
            else if (params.style == "2") {
                var vContent = "<div class=\"window-skin-2\"><div class=\"window-title-2\" onmousedown=\"jspopup.onMoveWindow(event);\"><a href=\"javascript:\" class=\"window-close-2\" onclick=\"jspopup.closeWindow()\">x</a></div><div class=\"window-content-2\">{$text}</div><div class=\"window-operition-2\">button</div></div>";
                jspopup.show({ "content": vContent.replace("{$text}", params.text == null ? "" : params.text) });
            }
            window.onresize = jspopup.onChangeWindowSize;
        },
        alert: function (params) {
            if (params == null) {
                return;
            }
            var wframe = "";
            wframe += "<div class=\"window-skin-4\">";
            wframe += "    <div class=\"window-title\"><input class=\"window-close\" type=\"button\" value=\"\" onclick=\"jspopup.closeWindow();\" />{title}</div>";
            wframe += "    <div class=\"window-content\"><p>{content}</p></div>";
            wframe += "    <div class=\"window-operition\">";
            wframe += "        <div class=\"window-operition-buttons\"><input class=\"window-operition-ok\" value=\"确定\" type=\"button\" onclick=\"jspopup.closeWindow();\" /></div>";
            wframe += "    </div>";
            wframe += "</div>";
            if (params.title != null)
                wframe = wframe.replace("{title}", params.title);
            else
                wframe = wframe.replace("{title}", "");
            wframe = wframe.replace("{content}", params.content);
            jspopup.createBackground();
            jspopup.show({ "content": wframe });
            window.onresize = jspopup.onChangeWindowSize;
        },
        window: function (params) {
            /// <summary>
            /// 空白窗口,参数text:自定义内容
            /// </summary>
            /// <param name="params">参数集合</param>
            if (params == null) {
                return;
            }
            if (params.background != null && params.background == true) {
                jspopup.createBackground();
            }
            jspopup.show({ "content": params.text });
            window.onresize = jspopup.onChangeWindowSize;
        },
        tips: function (params) {
            if (params == null) {
                return;
            }
            var fm = " <div class=\"window-skin-3\">";
            fm += "<div class=\"window-title-3\">&nbsp;</div>";
            fm += "<div class=\"window-content-3\">" + params.text + "</div>";
            fm += "<div class=\"window-operition-3\">&nbsp;</div>";
            fm += " </div>";
            jspopup.show({ "content": fm });
            window.setTimeout(function () {
                jspopup.closeWindow()
            }, 2000);
        },
        lazy: function (params) {
            $("#qbc").click();
        }
    }
};

var jspopup = {
    winObj: null,
    bgObj: null,
    winStyle: "position:fixed;_position:absolute;z-index:9999;", //窗口样式文本(部分),如果需窗口随滚动条滑动,position设置成相绝对值
    bjStyle: "top:0px;left:0px;position:absolute;background:#666;", //样式(部分)文本
    show: function (params) {
        /// <summary>
        /// 弹出窗口,参数:content=窗口内容,background=bool(是否显示背景层,默认否)
        /// </summary>
        //-----创建窗口-----
        var windowObj = document.createElement("div");
        //windowObj.id = "myWindow";
        //windowObj.className = "myWindow"; //类名(这里与ID同名)
        windowObj.innerHTML = params.content == null ? "" : params.content; //设置窗口的内容
        windowObj.style.cssText = this.winStyle; //设置窗口cssText样式(第一部分)
        //windowObj.style.width = params.width + "px";
        document.documentElement.appendChild(windowObj);
        this.winObj = windowObj;
        var vTop = this.getWindowLocation("top"); //获取窗口距顶部和左边的距离
        var vLeft = this.getWindowLocation("left");
        this.winObj.style.top = vTop + "px"; //第二部分样式(这样保证计算准确)
        this.winObj.style.left = vLeft + "px";
    },
    createBackground: function () {
        //-----创建背景---
        var vWidth = parseInt(document.documentElement.scrollWidth); //分别获取当前文档滚动条的宽度和高度并转换为整数型
        var vHeight = parseInt(document.documentElement.scrollHeight);
        var divObject = document.createElement("div");
        // divObject.id = aBackgroundID;

        //cssText属性:它是一组样式属性及其值的文本表示
        divObject.style.cssText = this.bjStyle + "width:" + vWidth + "px;height:" + vHeight + "px;" + (IsIE == true ? "filter:alpha(opacity=0)" : "opacity:0"); //透明值(IE与其它浏览的设置不同) 
        this.bgObj = divObject; //保存背景对象为全局对象

        document.body.appendChild(this.bgObj); //将建立的这个节点追加到当前body区域中
        this.changeBackground(this.bgObj, 30); //调用,背景变暗
    },
    changeBackground: function (divObj, opacityMaxValue) {
        if (document.all) {
            try {
                document.createElement("canvas").getContext("2d")
                if (divObj.style.opacity == false)//ie10
                    divObj.style.opacity = 0;

                var opa = parseFloat(divObj.style.opacity);
                opa += 0.1;
                divObj.style.opacity = opa; //设置透明值
                if (opa < (opacityMaxValue / 100)) {
                    setTimeout(function () { jspopup.changeBackground(divObj, opacityMaxValue) }, 5);
                }
            } catch (e) {
                divObj.filters.alpha.opacity += 10;
                if (divObj.filters.alpha.opacity < opacityMaxValue) {
                    setTimeout(function () { jspopup.changeBackground(divObj, opacityMaxValue); }, 5); //循环改变透明值
                }
            }
        }
        else {
            var opa = parseFloat(divObj.style.opacity);
            opa += 0.1;
            divObj.style.opacity = opa; //设置透明值
            if (opa < (opacityMaxValue / 100)) {
                setTimeout(function () { jspopup.changeBackground(divObj, opacityMaxValue) }, 5);
            }
        }
    },
    getWindowLocation: function (topLeft) {
        if (topLeft == "top") {
            //计算出窗口距离顶部的距离(body区域高度-窗口自身高度,再除2)
            var top = (document.documentElement.clientHeight - this.winObj.clientHeight) / 2;
            return top;
        }
        else if (topLeft == "left") {
            //距离左边的距离
            var left = (document.documentElement.clientWidth - this.winObj.clientWidth) / 2;
            return left;
        }
        else {
            return 0;
        }
    },
    onChangeWindowSize: function () {
        if (jspopup.bgObj != null) {
            jspopup.bgObj.style.width = parseInt(document.documentElement.scrollWidth) + "px"; //重新计算背景的宽度和高度
            jspopup.bgObj.style.height = parseInt(document.documentElement.scrollHeight) + "px"; ;

            jspopup.winObj.style.top = jspopup.getWindowLocation("top") + "px"; //重新计算左边和顶部的位置
            jspopup.winObj.style.left = jspopup.getWindowLocation("left") + "px";
        }
    },
    onMoveWindow: function (evt) {
        var evtObj = window.event ? event : evt;
        var X1 = evtObj.clientX; //获取当前事件距左边和顶部的距离
        var Y1 = evtObj.clientY;

        var L1 = this.winObj.style.left; //获取当前窗口距左边和顶部的距离
        L1 = L1.substring(0, L1.indexOf("px") != -1 ? L1.indexOf("px") : 0); //只取数字
        L1 = parseInt(L1);
        var T1 = this.winObj.style.top;
        T1 = T1.substring(0, T1.indexOf("px") != -1 ? T1.indexOf("px") : 0);
        T1 = parseInt(T1);

        var IsMove = true;
        //document.onmouseup = new Function("IsMove=false"); //与function相同效果
        document.onmouseup = function () {
            IsMove = false;
        }
        document.onmousemove = function (evt) {//需加上参数,否则FF不识别
            if (IsMove == true) {
                //当前距离-事件源=移动的距离,再加上窗口对象距离左边的距离就是当前窗口要显示的位置,
                var x = (L1 + (IsIE ? evtObj.clientX : evt.clientX) - X1);
                var y = (T1 + (IsIE ? evtObj.clientY : evt.clientY) - Y1);
                jspopup.winObj.style.left = x + "px";
                jspopup.winObj.style.top = y + "px";
                return false;
            }
        };
        return false;
    },
    closeWindow: function () {
        if (this.winObj != null) {
            this.winObj.parentNode.removeChild(this.winObj);
            this.winObj = null;
        }
        if (this.bgObj != null) {
            this.bgObj.parentNode.removeChild(this.bgObj);
            this.bgObj = null;
        }
        if (IsIE) { //如果是IE需要显示一部分(如之前隐藏的下拉框)

        }
    }
}

//var jpopup=function(){
//    winObj: null,
//    bgObj: null,
//    winStyle: "position:fixed;_position:absolute;z-index:9999;background:#fff;", //窗口样式文本(部分),如果需窗口随滚动条滑动,position设置成相绝对值
//    bjStyle: "top:0px;left:0px;position:absolute;background:#666;", //样式(部分)文本
//    show: function (params) {
//        /// <summary>
//        /// 弹出窗口,参数:content=窗口内容,width=窗口宽度,background=bool(是否显示背景层,默认否)
//        /// </summary>
//        //-----创建窗口-----
//        var windowObj = document.createElement("div");
//        //windowObj.id = "myWindow";
//        //windowObj.className = "myWindow"; //类名(这里与ID同名)
//        windowObj.innerHTML = params.content == null ? "" : params.content; //设置窗口的内容
//        windowObj.style.cssText = this.winStyle; //设置窗口cssText样式(第一部分)
//        //windowObj.style.width = params.width + "px";
//        document.documentElement.appendChild(windowObj);
//        this.winObj = windowObj;
//        var vTop = this.getWindowLocation("top"); //获取窗口距顶部和左边的距离
//        var vLeft = this.getWindowLocation("left");
//        this.winObj.style.top = vTop + "px"; //第二部分样式(这样保证计算准确)
//        this.winObj.style.left = vLeft + "px";
//    },
//    createBackground: function () {
//        //-----创建背景---
//        var vWidth = parseInt(document.documentElement.scrollWidth); //分别获取当前文档滚动条的宽度和高度并转换为整数型
//        var vHeight = parseInt(document.documentElement.scrollHeight);
//        var divObject = document.createElement("div");
//        // divObject.id = aBackgroundID;

//        //cssText属性:它是一组样式属性及其值的文本表示
//        divObject.style.cssText = this.bjStyle + "width:" + vWidth + "px;height:" + vHeight + "px;" + (IsIE == true ? "filter:alpha(opacity=0)" : "opacity:0"); //透明值(IE与其它浏览的设置不同) 
//        this.bgObj = divObject; //保存背景对象为全局对象

//        document.body.appendChild(this.bgObj); //将建立的这个节点追加到当前body区域中
//        this.changeBackground(this.bgObj, 50); //调用,背景变暗
//    },
//    changeBackground: function (divObj, opacityMaxValue) {
//        if (document.all) {
//            divObj.filters.alpha.opacity += 50;
//            if (divObj.filters.alpha.opacity < opacityMaxValue) {
//                setTimeout(function () { jspopup.changeBackground(divObj, opacityMaxValue); }, 5); //循环改变透明值
//            }
//        }
//        else {
//            var opa = parseFloat(divObj.style.opacity);
//            opa += 0.5;
//            divObj.style.opacity = opa; //设置透明值
//            if (opa < (opacityMaxValue / 100)) {
//                setTimeout(function () { jspopup.changeBackground(divObj, opacityMaxValue) }, 5);
//            }
//        }

//    },
//    getWindowLocation: function (topLeft) {
//        if (topLeft == "top") {
//            //计算出窗口距离顶部的距离(body区域高度-窗口自身高度,再除2)
//            var top = (document.documentElement.clientHeight - this.winObj.clientHeight) / 2;
//            return top;
//        }
//        else if (topLeft == "left") {
//            //距离左边的距离
//            var left = (document.documentElement.clientWidth - this.winObj.clientWidth) / 2;
//            return left;
//        }
//        else {
//            return 0;
//        }
//    },
//    onChangeWindowSize: function () {
//        if (jspopup.bgObj != null) {
//            jspopup.bgObj.style.width = parseInt(document.documentElement.scrollWidth) + "px"; //重新计算背景的宽度和高度
//            jspopup.bgObj.style.height = parseInt(document.documentElement.scrollHeight) + "px"; ;

//            jspopup.winObj.style.top = jspopup.getWindowLocation("top") + "px"; //重新计算左边和顶部的位置
//            jspopup.winObj.style.left = jspopup.getWindowLocation("left") + "px";
//        }
//    },
//    onMoveWindow: function (evt) {
//        var evtObj = window.event ? event : evt;
//        var X1 = evtObj.clientX; //获取当前事件距左边和顶部的距离
//        var Y1 = evtObj.clientY;

//        var L1 = this.winObj.style.left; //获取当前窗口距左边和顶部的距离
//        L1 = L1.substring(0, L1.indexOf("px") != -1 ? L1.indexOf("px") : 0); //只取数字
//        L1 = parseInt(L1);
//        var T1 = this.winObj.style.top;
//        T1 = T1.substring(0, T1.indexOf("px") != -1 ? T1.indexOf("px") : 0);
//        T1 = parseInt(T1);

//        var IsMove = true;
//        //document.onmouseup = new Function("IsMove=false"); //与function相同效果
//        document.onmouseup = function () {
//            IsMove = false;
//        }
//        document.onmousemove = function (evt) {//需加上参数,否则FF不识别
//            if (IsMove == true) {
//                //当前距离-事件源=移动的距离,再加上窗口对象距离左边的距离就是当前窗口要显示的位置,
//                var x = (L1 + (IsIE ? evtObj.clientX : evt.clientX) - X1);
//                var y = (T1 + (IsIE ? evtObj.clientY : evt.clientY) - Y1);
//                jspopup.winObj.style.left = x + "px";
//                jspopup.winObj.style.top = y + "px";
//                return false;
//            }
//        };
//        return false;
//    },
//    closeWindow: function () {
//        if (this.winObj != null) {
//            this.winObj.parentNode.removeChild(this.winObj);
//            this.winObj = null;
//        }
//        if (this.bgObj != null) {
//            this.bgObj.parentNode.removeChild(this.bgObj);
//            this.bgObj = null;
//        }
//        if (IsIE) { //如果是IE需要显示一部分(如之前隐藏的下拉框)

//        }
//    }
//}