﻿$(document).ready(function() {
    $('#MessageLoginForm').ajaxForm(function(xml) {
        if (xml.substring(0, 4) == "True") {
            $("#spanUserInfo").html("<a href=\"/Friend/index\" >" + xml.replace("True", "") + "</a>,您好&nbsp;|&nbsp<a href=\"/Reg/exitLogin\" >退出</a>");
            CloseMessageBox();
        }
        else {
            $("#MessageLoginForm").clearForm();
            location.href = "/reg/login.html";
        }

    });
    $("input[type=button]").addClass("button_mouseout");
    $("button").addClass("button_mouseout");
    $("input[type=submit]").addClass("button_mouseout");
    $(function() {
        $("input[type=button]").hover(function() { $(this).addClass("button_mouseover"); },
                            function() {
                                $(this).removeClass("button_mouseover"); $(this).addClass("button_mouseout");
                            });
    })

    $(function() {
        $("input[type=submit]").hover(function() { $(this).addClass("button_mouseover"); },
                            function() {
                                $(this).removeClass("button_mouseover"); $(this).addClass("button_mouseout");
                            });
    })
    $(function() {
        $("button").hover(function() { $(this).addClass("button_mouseover"); },
                            function() {
                                $(this).removeClass("button_mouseover"); $(this).addClass("button_mouseout");
                            });
    })

    $("#EmailSubscribeAdd").click(function() {
        if ($("#EmailSubscribe").val() != "") {
            $.ajax({ type: "POST", url: "/EmailSubscribe/Create", data: "Email=" + $("#EmailSubscribe").val(), success: function(xml) {
                alert(xml);
            }
            });
        }
        else {
            alert('请输入正确的邮箱');
        }
    });

    $("#EmailSubscribeDelete").click(function() {
        $.ajax({ type: "POST", url: "/EmailSubscribe/Delete/" + $("#EmailSubscribe").val(), data: '', success: function(xml) {
            alert(xml);
        }
        });
    });
    $.ajax({ type: "POST", url: "/Home/GetMessageCount.html", data: '', success: function(xml) {
        var data = eval(xml);
        if (data > 0) {
            $("#MessageCount").html("<span style='color:red'>(" + xml + ")</span>");
        }

    }
    });
});

function isLogin() {
    var flag = true;
    $.ajax({ type: "POST", url: "/reg/IsLogin.html", data: '', async: false, success: function(xml) {
        if (!eval(xml)) {
            location.href = "/Reg/Login.html?ReturnUrl=" + location.href;
            // OpenMessageBox("control:MessageIslogin;width:600;height:250;title:用户登录");
            flag = false
        }
    }
    });
    return flag;
}

