﻿//判断浏览器 true是IE false是ff
var isIe = (document.all) ? true : false;


//弹出方法 弹出DIV
function showMessageBox(DivId, wTitle, mContent, wHeight, wWidth, contentType, showback) {
    closeWindow(DivId);
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }


    var bWidth = parseInt(myWidth);
    var bHeight = parseInt(myHeight) > parseInt(document.documentElement.scrollHeight) ? parseInt(myHeight) : parseInt(document.documentElement.scrollHeight);
    if (isIe) { setSelectState('hidden'); }
    var Content = (contentType == 1 ? "<iframe id='mIframe' src='' frameborder='0' width='100%' scrolling='no' height='" + (wHeight - 10) + "'>正在加载...</iframe>" : mContent);
    var styleStr = (showback == 0 ? ("position:absolute;background:#000;width:" + (wWidth + 36) + "px;height:" + (wHeight + 60) + "px;left:" + (myWidth - wWidth - 20) / 2 + "px;top:" + (myHeight - wHeight - 20) / 2 + "px;z-index:999;") : ("top:0px;left:0px;position:absolute;background:#666;width:" + "100%" + ";height:" + bHeight + "px" + ";z-index:999;"));
    styleStr += (isIe) ? "filter:alpha(opacity=40);" : "opacity:0.40;";
    if (document.getElementById('back') == null) {
        var back = document.createElement("div");
        back.id = "back";
        back.style.cssText = styleStr;
        document.body.appendChild(back);
    } else {
        var back = document.getElementById('back');
        back.style.cssText = styleStr;
        back.style.visibility = "visible";
    }


    styleStr = "position:absolute;width:" + wWidth + "px;left:" + (myWidth - wWidth) / 2 + "px;top: " + (myHeight - wHeight) / 2 + "px;z-index:1000;";
    if (document.getElementById(DivId) == null) {
        var mesW = document.createElement("div");
        mesW.id = DivId;
        mesW.className = "mesWindow";
        mesW.innerHTML = "<div class='mesWindowTop'><div class='mesWindowtitle'>" + wTitle + "</div><div class='mesWindowclose'><a href=\"javascript:void(0);\" onclick=\"closeWindow('" + DivId + "')\"></a></div></div>" + Content + "";
        mesW.style.cssText = styleStr;
        document.body.appendChild(mesW);
    } else {
        var mesW = document.getElementById(DivId);
        mesW.style.visibility = "visible";
        mesW.style.cssText = styleStr;
    }
    if (contentType == 1) document.getElementById('mIframe').src = mContent;
}
//弹出DIV后的背影
function showBackground(obj, endInt) {
    obj.filters.alpha.opacity += 5;
    if (obj.filters.alpha.opacity < endInt) {
        setTimeout(function() { showBackground(obj, endInt) }, 8);
    }
}

//关闭弹出窗口
function closeWindow(s) {
    if (document.getElementById('back') != null) {
        //document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
        document.getElementById('back').style.visibility = "hidden";
    }
    if (document.getElementById(s) != null) {
        //document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
        document.getElementById(s).style.visibility = "hidden";
    }
    if (document.getElementById('mIframe') != null) {
        document.getElementById('mIframe').src = "";
    }
    if (isIe) { setSelectState(''); }
}

//设置select的可见状态 
function setSelectState(state) {
    var objl = document.getElementsByTagName('select');
    for (var i = 0; i < objl.length; i++) {
        objl[i].style.visibility = state;
    }
}

function setCookie(name, value) {
    var Days = 30; //此 cookie 将被保存 30 天
    var exp = new Date();
    exp.setTime(exp.getTime() + 1000);
    if (value == "" || value == "null" || value == "null" || value == " ") { } else {
        document.cookie = name + "=" + escape(value) + ";expires=Sun, 17-Jan-2038 19:14:07 GMT";
    }
}
function getCookie(sName) {
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++) {
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0]) {
            return aCrumb[1];
        }
    }
    return null;
}

//弹出纠错
function SubErrorBox(errTitle, errUrl) {
    //alert(Errtype+"--"+poiID+""+poiName+"--"+poiAddress+"--"+poiTel+"--"+cityname);
    var iframeurl = "/errorsubmit.html?" + encodeURI(errTitle) + "&&" + encodeURI(errUrl) + "&&" + Math.random();
    showMessageBox("correctErr", '提交错误', iframeurl, 350, 480, 1, 0);
}
