﻿
//使用方法----引用“遮罩层”片段 然后在引用页添加以下代码   alert中写你需要显示的html内容 下面是个demo
//var obj = new sAlert();
//obj.style = { msgwidth: 300, msgheight: 60, msgbackground: "transparent" }
//obj.alert("<div><dl><img src='/images/loding.gif' /></dl><dl><font style='font-size:12px;'><strong>正在登录......</strong></font></dl>"); closeForm();
//修改方法请找作者
//////////////////////遮罩层 by robin /////////////////////
function sAlert() {
    this.style = { msgwidth: 300, msgheight: 200, msgbackground: "#777", bordercolor: "transparent", titlebgcolor: "#A8130F", formbordercolor: "transparent", titleheight: 25 }
    this.titles = null;

    var msgw, msgh, msgbackground, bordercolor, titlebgcolor, formbordercolor, borderwidth;
    msgw = this.style.msgwidth; //the form width
    msgh = this.style.msgheight; //the form height
    msgbackground = this.style.msgbackground;
    titleheight = this.style.titleheight //the form tilte height
    bordercolor = this.style.bordercolor; //the title bordercolor
    titlebgcolor = this.style.titlebgcolor;
    formbordercolor = this.style.formbordercolor; //the form title rcolor
    var sWidth, sHeight;
    sWidth = document.body.offsetWidth;
    sHeight = document.body.scrollHeight > window.screen.availHeight ? document.body.scrollHeight : window.screen.availHeight;
    this.alert = function(msinnerhtml) {
        msgw = this.style.msgwidth == null ? msgw : this.style.msgwidth;
        msgh = this.style.msgheight == null ? msgh : this.style.msgheight;
        msgbackground = this.style.msgbackground == null ? msgbackground : this.style.msgbackground;
        titleheight = this.style.titleheight == null ? titleheight : this.style.titleheight;
        bordercolor = this.style.bordercolor == null ? bordercolor : this.style.bordercolor == null;
        titlebgcolor = this.style.titlebgcolor == null ? titlebgcolor : this.style.titlebgcolor == null;
        formbordercolor = this.style.formbordercolor == null ? formbordercolor : this.style.formbordercolor;
        borderwidth = formbordercolor == "transparent" ? "0" : "1";

        var bgObj = document.createElement("div");
        bgObj.setAttribute('id', 'bgDiv');
        bgObj.style.position = "absolute";
        bgObj.style.top = "0";
        bgObj.style.background = "#ccc";
        bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
        bgObj.style.opacity = "0.6";
        bgObj.style.left = "0";
        bgObj.style.width = "100%";
        bgObj.style.height = sHeight + "px";
        bgObj.style.zIndex = "10000";
        document.body.appendChild(bgObj);
        var msgObj = document.createElement("div")
        msgObj.setAttribute("id", "msgDiv");
        msgObj.setAttribute("align", "center");
        msgObj.style.background = msgbackground;
        msgObj.style.border = borderwidth + "px solid " + formbordercolor;
        msgObj.style.position = "absolute";
        msgObj.style.display = "none";
        msgObj.style.left = "50%";
        msgObj.style.top = "50%";
        msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
        msgObj.style.marginLeft = (document.documentElement.scrollLeft - msgw) / 2 + "px";
        msgObj.style.marginTop = (document.documentElement.scrollTop) - (msgh / 2) + "px";
        msgObj.style.width = msgw + "px";
        msgObj.style.height = msgh + "px";
        msgObj.style.textAlign = "center";
        msgObj.style.zIndex = "10001";
        document.body.appendChild(msgObj);
        if (this.titles != null) {
            var title = document.createElement("div");
            title.setAttribute("id", "msgTitle");
            title.setAttribute("align", "left");
            title.style.margin = "0";
            title.style.textindent = "1em";
            title.style.background = titlebgcolor;
            title.style.filter = "progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
            title.style.opacity = "0.75";
            title.style.border = "1px solid " + bordercolor;
            title.style.height = "25px";
            title.style.font = "12px Verdana, Geneva, Arial, Helvetica, sans-serif";
            title.style.color = "white";
            // title.style.background="url('Resource/img/menu_bg1.gif')";
            title.style.cursor = "pointer";
            title.innerHTML = "<h2>" + this.title + "&nbsp;&nbsp;&nbsp;×关闭</h2>"; //title
            title.onclick = function() {
                $("#msgDiv").fadeOut("fast");
                setTimeout(function() {
                    document.body.removeChild(bgObj);
                    Cw$("msgDiv").removeChild(title);
                    document.body.removeChild(msgObj);
                }, 100);
            }
            Cw$("msgDiv").appendChild(titles);
        }
        var txt = document.createElement("div");
        txt.style.margin = "0"
        txt.setAttribute("id", "msgTxt");
        txt.innerHTML = msinnerhtml;
        Cw$("msgDiv").appendChild(txt);
        $("#msgDiv").show();
    }
    this.errreload = function(message) {

        setTimeout(function() {
            closeForm();
            alert(message);
            document.location.reload(true);
        }, 30000);
    }
}

function closeForm() {
    //勿改
    if (Cw$("bgDiv") != null) {
        document.body.removeChild(Cw$("bgDiv"));
        document.body.removeChild(Cw$("msgDiv"));
        return true;
    }
    return false;
}



//get  id  to  object
function Cw$() {
    var elements = new Array();

    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);

        if (arguments.length == 1)
            return element;

        elements.push(element);
    }

    return elements;
}
//////////////////////遮罩层结束/////////////////////


//set cookies  by robin
function SetCookie(Name, Expiresdays, Domain, Value) {
    var exp = new Date();
    exp.setTime(exp.getTime() + Expiresdays * 24 * 60 * 60 * 1000);
    var strdomian;
    if (Domain.toLowerCase(Domain).indexOf("localhost") < 0)
    { strdomian = ";domain=" + Domain; }
    document.cookie = Name + "=" + Value + ";expires=" + exp.toGMTString() + strdomian;
}
function SetCookiebySe(Name, Expires, Domain, Value) {
    var exp = new Date();
    exp.setTime(exp.getTime() + Expires * 1000);
    var strdomian;
    if (Domain.toLowerCase(Domain).indexOf("localhost") < 0)
    { strdomian = ";domain=" + Domain; }
    document.cookie = Name + "=" + Value + ";expires=" + exp.toGMTString() + strdomian;
}
//get cookies
function GetCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}

//object to string
function obj2str(o) {
    var r = []; if (typeof o == "string") return "\"" + o.replace(/([\'\"\\])/g, "\\$1").replace(/(\n)/g, "\\n").replace(/(\r)/g, "\\r").replace(/(\t)/g, "\\t") + "\"";
    if (typeof o == "undefined") return ""; if (typeof o == "object") {
        if (o == null) return "null"; else if (!o.sort) { for (var i in o) { r.push(i + ":" + obj2str(o[i])); } r = "{" + r.join() + "}"; }
        else { for (var i = 0; i < o.length; i++) { r.push(obj2str(o[i])); } r = "[" + r.join() + "]"; } return r;
    } return o.toString();
}
//get  id  to  object
function Jc$() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        if (arguments.length == 1)
            return element;
        elements.push(element);
    }
    return elements;
}


/*************************************Changjin添加开始******************************************/
/*
功能：弹出遮罩框
作者：Changjin
时间：2010/09/01
*/
function AlertMsg(msg) {
    var obj = new sAlert();
    obj.style = { msgwidth: 300, msgheight: 60, msgbackground: "transparent" }
    obj.alert("<div><dl><img src='../../front_images/loding.gif' /></dl><dl style='padding-top:10px;'><font style='font-size:12px;'><strong>" + msg + "</strong></font></dl></div>");
}
/*
功能：删除遮罩
作者：Changjin
时间：2010/09/01
*/
function CloseMsg(msg) {
    closeForm();
}
/*************************************Changjin添加结束******************************************/
