﻿$(function () {
    var loginModel = "person";
    //登录表单验证
    var CheckForm = function () {
        if (loginModel == "company") {
            if ($.trim($(".companyLoginForm #account_c").val()) == "") {
                popAlertBox("用户名不能为空");
                $("#account_c").focus();
                return false;
            }
            else if ($.trim($(".companyLoginForm #password_c").val()) == "") {
                popAlertBox("密码不能为空");
                $("#password_c").focus();
                return false;
            }
        }
        else {
            if ($.trim($(".personLoginForm #account").val()) == "") {
                popAlertBox("用户名不能为空");
                $("#account").focus();
                return false;
            }
            else if ($.trim($(".personLoginForm #password").val()) == "") {
                popAlertBox("密码不能为空");
                $("#password").focus();
                return false;
            }
        }
        return true;
    };

    //登录功能
    $(".sbtn").click(function () {
        if (CheckForm()) {
            if (loginModel == "company") {//企业登录
                $.post("../Login/C_Login", { account: $.trim($(".companyLoginForm #account_c").val()), password: $.trim($(".companyLoginForm #password_c").val()), isAuto: false, autoLogin: $(".chbox:eq(1)").attr("checked") }, function (response) {
                    if (response == "true") {
                        isCompanyLogin = true;
                        window.location.href = "http://" + SiteConfig.COMPANYDOMAIN + "/Index.aspx";
                    }
                    else {
                        popAlertBox("登录失败，请检查用户名和密码是否正确。");
                    }
                });
            }
            else {//个人登录
                $.post("../Login/P_Login", { account: $.trim($(".personLoginForm #account").val()), password: $.trim($(".personLoginForm #password").val()), isAuto: false, autoLogin: $(".chbox:eq(0)").attr("checked") }, function (response) {
                    if (response == "true") {
                        isPersonLogin = true;
                        window.location.href = "http://" + SiteConfig.PERSONDOMAIN + "/Index.aspx";
                    }
                    else {
                        popAlertBox("登录失败，请检查用户名和密码是否正确。");
                    }
                });
            }
        }
        else {
            return false;
        }
    });

    //注册登录表单标签单击事件
    $(".loginTypeTab li").click(function () {
        $(".loginTypeTab li").removeClass("current");
        $(this).addClass("current");
        if ($.trim($(this).text()) == "个人") {
            $(".companyLoginForm").hide();
            $(".personLoginForm").show();
            $(".loginTypeText").text("个人登录");
            loginModel = "person";
            if ($.trim($(".personLoginForm .posrel input").val()) != "") {
                $(".personLoginForm .posrel span").hide();
            }
        }
        else if ($.trim($(this).text()) == "企业") {
            $(".personLoginForm").hide();
            $(".companyLoginForm").show();
            $(".loginTypeText").text("企业登录");
            loginModel = "company";
            if ($.trim($(".companyLoginForm .posrel input").val()) != "") {
                $(".companyLoginForm  .posrel span").hide();
            }
        }
    });

    $(".posrel input").focus(function () {
        $(this).next("span").hide();
    }).blur(function () {
        if ($.trim($(this).val()) == "") {
            $(this).next("span").show();
        }
    });

    if ($.trim($(".posrel input").val()) != "") {
        $(".posrel span").hide();
    }
    $(".posrel span").click(function () {
        $(this).hide();
        $(this).prev("input").trigger("focus");
    });

    //图片播放
    var player = $(".imgContainer").playImgs({
        imgCSS: { 'width': '554px', 'height': '145px' }, width: '554px', height: '145px', time: '5000', transition: 2, duration: 500
    }).start();
    //会员动态文字滚动
    $(".p_movement").textSlider({
        line: 2,
        speed: 500,
        timer: 4000
    });
    $(".c_movement").textSlider({
        line: 2,
        speed: 500,
        timer: 4000
    });

});
