﻿var ajaxurl = "/ZYWJAjax.ashx";
/******Get方法 begin*********/
var p_spanUser;
function GetSpanUser() {
    if (p_spanUser == null) {
        p_spanUser = $("#lblUser");
    }
    return p_spanUser;
}
var p_divUser;
function GetDivUser() {
    if (p_Username == null) {
        p_divUser = $("#divUser");
    }
    return p_divUser;
}
var p_txtUser;
function GetTxtUser() {
    if (p_txtUser == null) {
        p_txtUser = $("#txtUsername");
    }
    return p_txtUser;
}
var p_txtPass;
function GetTxtPass() {
    if (p_txtPass == null) {
        p_txtPass = $("#txtPassword");
    }
    return p_txtPass;
}
var p_spMsg;
function GetMsg() {
    if (p_spMsg == null) {
        p_spMsg = $("#spMsg");
    }
    return p_spMsg;
}

//获取cookie里的用户名
function GetUsername() {
    $.post(ajaxurl, "action=GetUsername",
            function (data) {
                if (data != "") {
                    $("#divLog").hide();
                    $("#divUser").show();
                    $("#lblUser").css('visibility', 'hidden');
                    $("#lblUser").html(data);
                    $("#lblUser").css('visibility', 'visible');
                }
                else {
                    $("#divUser").hide();
                    $("#divLog").show();
                }
            });
}

function EnterLogin(e) {
    var e = window.event ? window.event : e;
    if (e.keyCode == 13) {
        Login();
    }
}

//用户登录
function Login() {
    $("#spUsername").html("");
    $("#spPassword").html("");
    GetMsg().html("");
    if (GetTxtUser().val() == "") {
        $("#spUsername").html("用户名不能为空");
    }
    else if (GetTxtPass().val() == "") {
        $("#spPassword").html("密码不能为空");
    }
    else {
        var username = GetTxtUser().val();
        var password = GetTxtPass().val();
        GetTxtUser().val("");
        GetTxtPass().val("");
        $.post(ajaxurl, "action=Login&username=" + username + "&passwpord=" + password,
            function (data) {
                if (data) {
                    window.location.href = location.href;
                    //$("#divLog").hide();
                    //$("#divUser").show();
                    //$("#lblUser").css('visibility', 'hidden');
                    //$("#lblUser").html(data);
                    //$("#lblUser").css('visibility', 'visible');
                }
                else {
                    $("#divUser").hide();
                    $("#divLog").show();
                    GetMsg().html("用户名或密码错误");
                }
            });
    }
}
function CookieCancer() {
    $.post(ajaxurl, "action=CookieCancer",
        function (data) {
            if (data) {
                window.location.href = "/";
            }
        });
}
function Register() {
    window.open("Register.html");
}

$(document).ready(function () {
    $("input.sitesearch").bind("click", function () {
        var text = $(this).prev("input[type='text']").val();
        if (text) {
            window.open("http://www.baidu.com/baidu?q=&si=www.zhuanyewanjia.com&cl=3&ct=2097152&tn=baidulocal&ie=gb2312&word=" + UrlEncode($.trim(text)));
        }
    });
});
