﻿
/*页面加载*/
$(document).ready(
        function() {
            /*防止弹出层移位*/
            if (getOs() == "MSIE") {
                document.body.style.width = document.documentElement.clientWidth;
                document.body.style.paddingleft = parseInt(document.documentElement.clientWidth - 960) / 2;
            }
            else {
                document.body.style.width = document.documentElement.clientWidth + "px";
                document.body.style.paddingleft = parseInt(document.documentElement.clientWidth - 960) / 2 + "px";
            }
            /*加载时间*/
            loadtime();
            $("#loading #loadtip").animate({ width: "80px" });

            /*加载天气信息*/
            //loadweather();
            $("#loading #loadtip").animate({ width: "100px" });
            $("#loading").fadeOut();
            window.history.forward(1);/*禁用后退*/
        }
);

/*加载天气*/
function loadweather() {
    var weaiframe = $("#weaiframe");
    if (weaiframe.attr("src") == "about:blank") {
        weaiframe.attr("src", "http://m.weather.com.cn/m/360/weather.htm");
    }
};

/*显示邮箱*/
function showmail() {
    if ($("#mailBody").css("display") == "none") {
        var top = $("#mailform").offset().top + $("#mailform").height();
        var left = $("#mailform").offset().left;
        var mailform = $("#mailBody");
        if (getOs() == "MSIE") {
            if (checkIE() == "8") {
                top = top + 33;
            }
        }
        else {
            top = top + 33;
        }
        mailform.css("top", top);
        mailform.css("left", left - 1);
        mailform.show(500);
        if ($("#ifmail").attr("src") == "about:blank")
            $("#ifmail").attr("src", "mails.htm");
    }
    else {
        $("#mailBody").hide(500);
    }
};
/*隐藏邮箱*/
function hidemail() {
    $("#mailBody").hide(500);
};

/*登陆*/
function loginOK() {
    $("#showmsg").css("display", "none");
    var strError = "";
    if (String($("#txt_UserName").val()).length == 0)
        strError += "账号 ";
    if (String($("#txt_Pwd").val()).length == 0)
        strError += "密码 ";
    if (String(strError).length > 0) {
        strError += "不能为空";
        Dialog.alert(strError);
        return;
    }
    $("#divTips").css("display", '');
    var txt = $("#navTop");
    var left = txt.offset().left;
    var top = txt.offset().top + txt.height();    
    $("#divTips").css("top", top + 35);
    $("#divTips").css("left", left + 140);
    ShowTips("提示:正在验证登陆，请稍等...");
    //$("#divTips").html("提示:正在验证登陆，请稍等...");
    
    loginAjax($("#txt_UserName").val(), $("#txt_Pwd").val());
}


function loginAjax(userName, pwd) {
    /*添加ajax添加方法*/
    var json_data = { "Username": userName,"Pwd":pwd};
    $.ajax({
        type: "get",
        url: "handler/login.ashx",
        cache: false,
        global: false, // 禁用全局Ajax事件.
        data: json_data,
        beforeSend: function(XMLHttpRequest) {
        },
        success: function(data, textStatus) {
            if (String(data).length > 0) {
                HideTips();
                $("#divTips").html("提示:" + data);
            }
            else {
                HideTips();
                window.location.href = "index.htm";
            }
        },
        complete: function(XMLHttpRequest, textStatus) {
        },
        error: function() {
            //请求出错处理
            Dialog.alert("提示：调用文件路径出错");
        }
    });
};

/*回车提交*/
function EnterSubmit(event) {
    var key = event.keyCode;
    if (key == 13)
        loginOK();
};

function EnterSubmit2(event) {
    var key = event.keyCode;
    if (key == 13)
        loginOK();
};

function show_error(obj) {
    var str = obj.value;
    if (String(str).length < 6) {
        $("#u_reg_default").css("display", "none");
        $("#tipName").css("display", "");
        $("#tipName").html("提示:账号长度必须大于等于6位");
        $("#txt_isPass1").val("0");      
    }
    else {
        $("#tipName").css("display", "");
        $("#tipName").html("提示:正在检测用户名..");      
        var json_data = { "Username": str};
        $.ajax({
            type: "get",
            url: "handler/nameExist.ashx",
            cache: false,
            global: false, // 禁用全局Ajax事件.
            data: json_data,
            beforeSend: function(XMLHttpRequest) {
            },
            success: function(data, textStatus) {
                if (String(data).length > 0) {
                    $("#u_reg_default").css("display", "");
                    $("#tipName").css("display", "");
                    $("#tipName").html("提示:" + data);
                    $("#txt_isPass1").val("0");
                }
                else {
                    $("#u_reg_default").css("display", "");
                    $("#tipName").css("display", "");
                    $("#tipName").html("提示:用户名可用");
                    $("#txt_isPass1").val("1");
                }
            },
            complete: function(XMLHttpRequest, textStatus) {
            },
            error: function() {
                //请求出错处理
                Dialog.alert("提示：调用文件路径出错");
                $("#txt_isPass1").val("0");
            }
        });
    }
};

function show_error2(obj) {
    var str = obj.value;
    if (String(str).Trim().length < 6) {
        $("#p_reg_default").css("display", "none");
        $("#tippwd").css("display", "");
        $("#tippwd").html("提示:密码长度必须大于等于6位");
        $("#txt_isPass2").val("0");
    } else {
        $("#p_reg_default").css("display", "");
        $("#tippwd").css("display", "none");
        $("#tippwd").html("");
        $("#txt_isPass2").val("1");
    }
};

function show_error3(obj) {
    var str = obj.value;
    if (String(str).Trim().length < 6) {
        $("#r_reg_default").css("display", "none");
        $("#tiprepwd").css("display", "");
        $("#tiprepwd").html("提示:密码长度必须大于等于6位");
        $("#txt_isPass3").val("0");
    }
    else {
        if (String($("#p_reg").val()).Trim() != String(str).Trim()) {
            $("#r_reg_default").css("display", "none");
            $("#tiprepwd").css("display", "");
            $("#tiprepwd").html("提示:两次输入密码不一致");
            $("#txt_isPass3").val("0");
        }
        else {
            $("#r_reg_default").css("display", "");
            $("#tiprepwd").css("display", "none");
            $("#tiprepwd").html("");
            $("#txt_isPass3").val("1");
        }
    }
};

function show_error4(obj) {
    var str = obj.value;
    if (str.search("^(?:\\w+\\.?)*\\w+@(?:\\w+\\.?)*\\w+$") != 0) {
        $("#tipemail").css("display", "");
        $("#tipemail").html("提示:email格式不正确");
        $("#txt_isPass4").val("0");
    }
    else {
        $("#tipemail").css("display", "none");
        $("#tipemail").html("");
        $("#txt_isPass4").val("1");
    }
};


function show_error5(obj) {
    var str = obj.value;
    if (String(str).length == 0) {
        $("#tipCode").html("提示:请输入验证码");
        $("#tipCode").css("display", "");
        $("#txt_isPass5").val("0");
    } else if (String(str).length < 5 || String(str).length > 5) {
        $("#tipCode").html("提示:请输入验证码长度为5位");
        $("#tipCode").css("display", "");
        $("#txt_isPass5").val("0");
    }
    else {

        $("#tipCode").css("display", "none");
        $("#tipCode").html("");
        $("#txt_isPass5").val("1");
    }

};        


/*注册*/
function regOK() {
    if ($("#txt_isPass1").val() == "1" && $("#txt_isPass2").val() == "1" && $("#txt_isPass3").val() == "1" && $("#txt_isPass4").val() == "1" && $("#txt_isPass5").val() == "1") {
        var json_data = { "Username": String($("#u_reg").val()).Trim(), "Pwd": String($("#p_reg").val()).Trim(), "Emial": String($("#e_reg").val()).Trim(), "VerifyCode": String($("#v_code").val()).Trim() };
        ShowTips("提示:正在验证登陆，请稍等...");
        $.ajax({
            type: "get",
            url: "handler/reg.ashx",
            cache: false,
            global: false, // 禁用全局Ajax事件.
            data: json_data,
            beforeSend: function(XMLHttpRequest) {
            },
            success: function(data, textStatus) {
            if (String(data).length > 0) {
                    HideTips();
                    Dialog.alert(data);                  
                }
                else {
                    HideTips();
                    Dialog.alert("注册成功",function(){ window.location.href="index.htm";}); 
                }
            },
            complete: function(XMLHttpRequest, textStatus) {
            },
            error: function() {
                //请求出错处理
                Dialog.alert("提示：调用文件路径出错");                
            }
        });
    }
    else {
        Dialog.alert("提示：请输入注册有误");   
        return;
    }

    
    
}




