﻿function setFamilyImageCode()
{
    if ($("imgFamilyCodeImg").src.indexOf("/images/blank.gif") != -1)
    {
        refreshFamilyImageCode();
    }
}
function refreshFamilyImageCode()
{
    new Ajax("/Ajax/ImageCode.ashx", Math.random(), refreshFamilyImageCode_callback, "get", "");
}
function refreshFamilyImageCode_callback()
{
    var obj = eval(arguments[0]);
    if (obj.result)
    {
        $("hdnFamilyImgCode").value = obj.imgCode;
        $("imgFamilyCodeImg").src = "/ImageCode.aspx?" + $("hdnFamilyImgCode").value;
    }
}
function familyLogin()
{
    var ptId = $("txtFamilyPtId").value.trim();
    if(ptId.length == 0)
    {
        AlertDialog("请输入盛大通行证！");
        return;
    }
    var password = $("txtFamilyPassword").value.trim();
    if(password.length == 0)
    {
        AlertDialog("请输入登录密码！");
        return;
    }
    var imgCode1 = $("txtFamilyImgCode").value.trim();
    if (imgCode1.length == 0)
    {
        AlertDialog("请输入验证码！");
        return;
    }
    var imgCode2 = $("hdnFamilyImgCode").value.trim();
    
    Loading("系统处理中...");
    var params = "txtPtId=" + encodeURIComponent(ptId) + "&txtPassword=" + encodeURIComponent(password) + "&txtImgCode=" + encodeURIComponent(imgCode1) + "&hdnImgCode=" + encodeURIComponent(imgCode2);
    new Ajax(
                "/Ajax/NewLogin.ashx", 
                params, 
                function familyLogin_callback()
                {
                    var obj = eval(arguments[0]);
                    if(obj.result)
                    {
                        if(obj.result == 1)
                        {
                            location.reload(true);
                        }
                        else
                        {
                            location = obj.returnString;
                        }
                    }
                    else
                    {
                        LoadingClose();
                        AlertDialog(obj.returnString);
                        setTimeout("AlertDialogClose();", 3000);
                    }
                }, 
                "post", 
                "familyLogin"
            );
}
function familyLogout()
{
    Loading("系统处理中...");
    new Ajax(
                "/Ajax/Logout.ashx", 
                "", 
                function familyLogout_callback()
                {
                    location.reload(true);
                }, 
                "post", 
                ""
            );
}