var login = {
    method: "",
    CheckForm: function() {
        var email = $("email_text").value;
        var pwd = $("pwd_text").value;
        var msgStr = "";
        var bool = true;
        if (!IsEmail(email)) {
            msgStr += "邮箱格式错误<br>";
            bool = false;
        }
        if (pwd.length < 6 || pwd.length > 18) {
            msgStr += "密码长度应该在6-18位之间！";
            bool = false;
        }
        if (bool == false) {
            var msg = new Msgbox({ title: "", msg: msgStr }, 1, 1);
            return;
        }
        var check = 0;
        if (jQuery("#checkbox").attr("checked") == true) {
            check = 1;
        }


        jQuery.getJSON("http://api.yoho.cn/mobile/ismoved?mail=" + encodeURIComponent(email) + "&pass=" + jQuery.md5(pwd) + "&remember=" + check + "&callback=?", function(data) {
            if (data.status) {
                jQuery("#txt_newurl").val(data.url);
                $("login_btn_new").click();
            }
            else {
                $("login_btn").click();
            }
        });
        //$("login_btn").click();
    },
    CheckLand: function() {
        var email = $("email_text").value;
        var pwd = $("pwd_text").value;
        var ex = false;
        var msgStr = "";
        var bool = true;
        if (!IsEmail(email)) {
            msgStr += "邮箱格式错误<br>";
            bool = false;
        }
        if (pwd.length < 6 || pwd.length > 18) {
            msgStr += "密码长度应该在6-18位之间！";
            bool = false;
        }
        if (bool == false) {
            var msg = new Msgbox({ title: "", msg: msgStr }, 1, 1);
            return;
        }
        if ($("ex_cb").checked == true) {
            ex = true;
        }
        var url = "/MyYoho/ajax/login.aspx";
        var params = "m=4&email=" + email + "&pwd=" + pwd + "&ex=" + ex;
        var ajax = new Ajax.Request(url, { method: "post", parameters: params, onComplete: login.h_CheckLand });
    },
    h_CheckLand: function() {
        var obj = arguments[0].responseText;
        var re = obj.parseJSON();
        var flag = re.msg;
        if (flag == 1) {
            login.CloseDiv();
            eval(login.method);
        }
        else if (flag == 0) {
            var msg = new Msgbox({ title: "", msg: "邮箱或密码错误，请重试！" }, 1, 1);
        }
    },
    CloseDiv: function() {
        $("login_div").parentNode.removeChild($("login_div"));
        $("overlay").parentNode.removeChild($("overlay"));
    },
    CreateDiv: function() {
        this.method = arguments[0];
        var Body = document.getElementsByTagName("body").item(0);

        var Overlay = document.createElement("div");
        Overlay.setAttribute("id", "overlay");
        var p_s = getPageSize();
        Overlay.style.display = "";
        Overlay.style.position = "absolute";
        Overlay.style.top = "0";
        Overlay.style.left = "0";
        Overlay.style.zIndex = "10";
        Overlay.style.backgroundColor = "#666";
        Overlay.style.width = p_s[2] + "px";
        Overlay.style.height = p_s[1] + "px";
        if (Browser.isIE) {
            Overlay.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
        } else {
            Overlay.style.opacity = "0";
        }
        Body.appendChild(Overlay);

        var Main = document.createElement("div");
        Main.setAttribute("id", "login_div");
        Main.className = "floatwindow";
        var pa = getPageSize();
        Main.style.top = (pa[3] / 2 - 110 + parseInt(document.documentElement.scrollTop)) + "px";
        Main.style.left = (pa[0] / 2 - 230) + "px";
        Main.style.width = 310 + "px";
        Main.style.zIndex = "11";
        Body.appendChild(Main);

        Main.innerHTML = "<div class=\"shadow\"><div class=\"inner_floatwindow\"><h4>居民登录<a href=\"javascript:login.CloseDiv();\"><img src=\"/images/button_del.gif\" border=\"0\" class=\"windowcontrol\"></a></h4><div class=\"floatcontent\"><table width=\"100%\" border=\"0\" align=\"center\" cellspacing=\"8\" style=\"border-bottom:solid 1px #CCCCCC; margin:15px 0px;\"><tr><td width=\"80\" height=\"27\" align=\"right\" valign=\"middle\"><b>邮箱<br /></b><small class=\"font_gray\">E-MAIL</small><label></label></td><td width=\"256\" valign=\"top\"><input id=\"email_text\" name=\"email_text\" type=\"text\" class=\"biginput\" style=\"width:190px;\" padding-left:3px; border:solid #999 1px;\" /></td></tr><tr><td height=\"31\" align=\"right\" valign=\"top\"><b>密码<br /></b><small class=\"font_gray\">PASSWORD</small></td><td valign=\"top\"><input id=\"pwd_text\" name=\"pwd_text\" type=\"password\" class=\"biginput\"style=\"padding-left:3px;width:190px;border:solid #999 1px; font-weight:bold; \" /></td></tr><tr><td height=\"30\" valign=\"middle\">&nbsp;</td><td valign=\"top\"><button style=\"width:80px;\" onclick=\"login.CheckLand();\"><b>登 录</b></button> &nbsp;<input type=\"checkbox\" id=\"ex_cb\" />下一次自动登陆 </td></tr></table><p style=\"margin:8px 0px 0px 0px;\">还没有加入YOHO？ 立即<a href=\"http://www.yoho.cn/MyYoho/Login.aspx?" + location.href + "\"><strong> 注册>></strong></a></p></div></div></div>";
    }
}

//获取cookie
function getCookie(name) {
    var text = document.cookie;
    var index = text.indexOf(name + "=");
    if (index < 0)
        return (null);
    var start = index + name.length + 1;
    var end = text.indexOf(";", start);
    if (end < 0)
        end = text.length;
    var value = text.substring(start, end);
    return decodeURIComponent(value);
}
//设置cookie
function setCookie(name, value, expires, path, domain, secure) {
    var text = name + "=" + value;
    if (expires) {
        var currentDate = new Date();
        var expireDate = new Date(currentDate.getTime() + expires * 24 * 60 * 60 * 1000);
        text = text + ";expires=" + expireDate.toGMTString();
    }
    if (path)
        text = text + ";path=" + path;
    if (domain)
        text = text + ";domain=" + domain;
    if (secure)
        text = text + ";secure";
    document.cookie = text;
}
//移除cookie
function removeCookie(name) {
    setCookie(name, "", -1);
}
function CookieDataStore(name) {
    this.name = name; this.load();
}
CookieDataStore.prototype.load = function() {
    this.data = new Object();
    var text = getCookie(this.name);
    if (text == null)
        return;
    var data = text.split('&');
    for (var i = 0; i < data.length; i++) {
        var datum = data[i];
        var index = datum.indexOf('=');
        if (index > 0) {
            var key = datum.substring(0, index);
            var value = datum.substring(index + 1);
            this.data[key] = value;
        }
    }
}
CookieDataStore.prototype.save = function() {
    var text = "";
    for (var key in this.data) {
        var type = typeof (this.data[key]);
        if (type != "object" && type != "function") {
            var datum = key + "=" + encodeURIComponent(this.data[key]);
            text = text + datum + "&";
        }
    }
    var expires;
    try {
        if (this.data["expires"] == "1")
            expires = 2 * 365;
        else
            expires = false;
    } catch (e) {
        expires = false;
    }
    setCookie(this.name, text, expires, "/", ".yoho.cn");
}
CookieDataStore.prototype.clear = function() {
    this.data = new Object();
}
CookieDataStore.prototype.set = function(key, value) {
    this.data[key] = value;
}
CookieDataStore.prototype.get = function(key) {
    return (this.data[key]);
}
CookieDataStore.prototype.remove = function(key) {
    delete (this.data[key]);
}
CookieDataStore.prototype.count = function() {
    var i = 0;
    for (var key in this.data) {
        var type = typeof (this.data[key]);
        if (type != "object" && type != "function") {
            i++;
        }
    }
    return (i);
}
function outLand() {
    var yohoData = new CookieDataStore("yoho");
    yohoData.clear();
    yohoData.save();
    try {
        setCookie("yoho", "", -1, "/")
    } catch (e) {
    }
    $("#div_Login").show();
    $("#div_HasLogin").hide();
}

