(function() {
    function addHandler(element, type, handler) {
        if (!!element.addEventListener) {
            element.addEventListener(type, handler, false);
        } else if (!!element.attachEvent) {
            element.attachEvent("on" + type, handler);
        } else {
            element["on" + type] = handler;
        }
    }
    var sys = {},
        ua = navigator.userAgent;
    sys.iphone = ua.indexOf("iPhone") > -1;
    sys.ipod = ua.indexOf("iPod") > -1;
    sys.ipad = ua.indexOf("iPad") > -1;
    sys.nokiaN = ua.indexOf("NokiaN") > -1;
    /Win(?:dows )?([^do]{2})/.test(ua);
    sys.winMobile = /^CE|Ph$/.test(RegExp["$1"]);
    sys.ios = navigator.platform.indexOf("Mac") == 0 && ua.indexOf("Mobile") > -1;
    sys.android = ua.indexOf("Android") > -1;
    var isNoPC = sys.iphone || sys.ipod || sys.ipad || sys.nokiaN || sys.winMobile || sys.ios || sys.android;
    if (!isNoPC) {
        var body = document.body || document.getElementsByTagName("body")[0];
        var ifrWrap = document.createElement('div');
        ifrWrap.innerHTML = '
' +
            '' +
            '
正在处理,请稍后...
' +
            '
' +
            '
×' + // src="http://127.0.0.1:3006/login?debug=true" style="width:100%; height:100%;"
            '
 ';
        body.appendChild(ifrWrap.firstChild);
        body.appendChild(ifrWrap.lastChild);
        if("" != "1" && "0" =="1"){
            var css = '#J_Mark53645{display:none; position:fixed; margin:0; padding:0; top:0; left:0; width:100%; height:100%; background-color:#000; filter:alpha(opacity=30); opacity:0.3; z-index:1982;}' +
            '#J_LoginIframeWarp53645{position:fixed; border-radius: 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px; margin:0; padding:0; top:-9999px; left:-9999px; width:410px; margin-left:-245px; z-index:1984; display:block; font-size:12px; line-height:1; font-family: 微软雅黑,Tahoma,Helvetica,Arial,sans-serif; background:#fff;}' +
            '#J_LoginIframeWarp53645 p{position:absolute; margin:0; padding:0; top:40%; left:0; margin-top:55px; width:100%; font-size:24px; color:#444; text-align:center; z-index:1;}' +
            '#J_LoginClose53645{ position:absolute; top:5px; left:7px; background-color:#fff; width:33px; height:33px; color:#999; text-align:center; font-weight:400; text-decoration:none; outline:none; cursor:pointer; font-size:30px; line-height:30px; font-family: 微软雅黑,Tahoma,Helvetica,Arial,sans-serif; z-index:3;}';
        }else{
            var css = '#J_Mark53645{display:none; position:fixed; margin:0; padding:0; top:0; left:0; width:100%; height:100%; background-color:#000; filter:alpha(opacity=30); opacity:0.3; z-index:1982;}' +
            '#J_LoginIframeWarp53645{position:fixed; border-radius: 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px; margin:0; padding:0; top:-9999px; left:-9999px; width:410px; margin-left:-245px; z-index:1984; display:block; font-size:12px; line-height:1; font-family: 微软雅黑,Tahoma,Helvetica,Arial,sans-serif; background:#fff;}' +
            '#J_LoginIframeWarp53645 p{position:absolute; margin:0; padding:0; top:40%; left:0; margin-top:55px; width:100%; font-size:24px; color:#444; text-align:center; z-index:1;}' +
            '#J_LoginClose53645{ position:absolute; top:5px; left:370px; background-color:#fff; width:33px; height:33px; color:#999; text-align:center; font-weight:400; text-decoration:none; outline:none; cursor:pointer; font-size:30px; line-height:30px; font-family: 微软雅黑,Tahoma,Helvetica,Arial,sans-serif; z-index:3;}';
        }
        var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
        var style = document.createElement("style");
        style.type = "text/css";
        try {
            style.appendChild(document.createTextNode(css));
        } catch (e) {
            style.styleSheet.cssText = css;
        }
        head.insertBefore(style, head.firstChild);
        /*iframe 跨域传值处理 */
        if (!!window.postMessage) {
            addHandler(window, "message", function(evt) {
                evt = evt || window.event;
                var ifr = document.getElementById("loginIframe53645"),
                    ifrWin = ifr.contentWindow || ifr.contentDocument;
                var warp = document.getElementById("J_LoginIframeWarp53645");
                if (evt.source != ifrWin) {
                    return;
                }
                ifr.style.height = evt.data + "px";
                warp.style.height = evt.data + "px";
            });
        } else {
            setTimeout(function() {
                var _hash = location.hash;
                if (_hash != "") {
                    _hash = _hash.substr(1);
                    var hArrs = _hash.split("&"),
                        height;
                    for (var i = 0, len = hArrs.length; i < len; i++) {
                        var hArr = hArrs[i].split("=");
                        if (hArr[0] == "height") {
                            height = hArr[1];
                            break;
                        }
                    }
                    if (height != undefined) {
                        var ifr = document.getElementById("loginIframe53645");
                        var warp = document.getElementById("J_LoginIframeWarp53645");
                        var ifrHeight = parseInt(ifr.style.height);
                        if (height != ifrHeight) {
                            ifr.style.height = height + "px";
                            warp.style.height = height + "px";
                        }
                    }
                }
                setTimeout(arguments.callee, 100);
            }, 100);
        }
        addHandler(document.getElementById("J_LoginBtn"), "click", function() {
            var is_weixin = (function(){return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1})();
            if(is_weixin){
                $(function(){
                    window.location.href="https://passport.migu.cn/login?sourceid=100001&apptype=0&forceAuthn=false&isPassive=false&authType=MiguPassport&passwordControl=0&display=web&referer=null&logintype=1&qq=null&weibo=null&alipay=null&weixin=null&andPass=null&phoneNumber=&callbackURL=&relayState=&openPage=&hideRegister=&hideForgetPass=&sim=&needOneKey=0&hideps=0&hideqrc=0&hidetitle=0";
                });
            }else{
                $(function(){
                    var warp = document.getElementById("J_LoginIframeWarp53645"),
                        ifr = document.getElementById("loginIframe53645"),
                        mark = document.getElementById("J_Mark53645");
                    warp.style.top = "50%";
                    warp.style.left = "53%";
                    warp.style.marginTop = -230+ "px";
                    warp.style.display = "block";
                    mark.style.display = "block";
        
                    ifr.src = "https://passport.migu.cn/login?sourceid=100001&apptype=0&forceAuthn=false&isPassive=false&authType=MiguPassport&passwordControl=0&display=web&referer=null&logintype=1&qq=null&weibo=null&alipay=null&weixin=null&andPass=null&phoneNumber=&callbackURL=&relayState=&openPage=&hideRegister=&hideForgetPass=&sim=&needOneKey=0&hideps=0&hideqrc=0&hidetitle=0";
                });
            }
        });
        addHandler(document.getElementById("J_LoginClose53645"), "click", function() {
            var warp = document.getElementById("J_LoginIframeWarp53645"),
            ifr = document.getElementById("loginIframe53645"),
                mark = document.getElementById("J_Mark53645");
            warp.style.display = "none";
            mark.style.display = "none";
        });
    } else {
        addHandler(document.getElementById("J_LoginBtn"), "click", function() {
            top.location.href = "https://passport.migu.cn/login?sourceid=100001&apptype=0&forceAuthn=false&isPassive=false&authType=MiguPassport&passwordControl=0&display=web&referer=null&logintype=1&qq=null&weibo=null&alipay=null&weixin=null&andPass=null&phoneNumber=&callbackURL=&relayState=&openPage=&hideRegister=&hideForgetPass=&sim=&needOneKey=0&hideps=0&hideqrc=0&hidetitle=0";
        });
    }
})();