﻿$(function () {

    var url = GetHost() + "ArticlesHandler.ashx";
    $.post(url, { Action: 'Latest' }, ProcessActicle, "json");

    //按钮智能定位
    if (!$("#divVercode").length) {
        //显示空div
        $(".divEmpty").show();
    }
    else {
        //隐藏空div
        $(".divEmpty").hide();
    }
    if ($(".warnInfo").text()) {
        $(".warnInfoP").show();
        $("#hidloginErrorStatu").val(1);
        $(".vercode").show();
    }
    $("html").bind
         (
           "keydown", function (e) {
               var myCode = e.keyCode;
               if (myCode == 13) {
                $("#lbLogin").focus();
                $("#lbLogin").click();
               }
           }
      );
    });

//处理返回数据
function ProcessActicle(data) {
    var index = 1;
    $.each(data, function (key, val) {
        //绑定html显示
        var className = ".noticeItem" + index;
        index = index + 1;
        var url = GetHostName() + "tps/tpArticle/article.aspx?id=" + val.a_Id;
        $(className).text(val.a_Title);
        $(className).attr("href", url).attr("target", "_blank");
    });
}
function ChangeCaptchImage() {
    var imgCaptch = document.getElementById("imgCaptch");
    var imgSrc = "../../Captcha.ashx?t=" + Math.random();
    imgCaptch.src = imgSrc;
    if (navigator.userAgent.indexOf("; MAXTHON") != -1 || navigator.userAgent.indexOf("; CIBA") != -1)
        alert("您的图形校验码已经更换！");
    setTimeout("clearCaptchText()", 0);
}

function clearCaptchText() {
    var txtCaptch = document.getElementById("tbCaptcha");
    if (txtCaptch != null) {
        txtCaptch.value = "";
        txtCaptch.focus();
    }
}



function CheckInput() {
    var account = $("#txtUserName").val();
    var code = $("#txtPass").val();
    if (account == "") {
        $(".warnInfo").text("请输入帐号");
        $(".warnInfoP").show();
        $("#hidloginErrorStatu").val(1);
        $(".vercode").show();
        return false;
    }
    if (code == "") {
        $(".warnInfo").text("请输入密码");
        $(".warnInfoP").show();
        $("#hidloginErrorStatu").val(1);
        $(".vercode").show();
        return false;
    }
    if (/[,]/.test(account)) {
        $(".warnInfo").text("不允许含，的用户名.");
        $(".warnInfoP").show(); $("#txtUserName").val("");
        $("#txtPass").val("");
        return false;
    }
    if (/[,]/.test(code)) {
        $(".warnInfo").text("不允许含，的密码.");
        $(".warnInfoP").show();
        $("#txtPass").val("");
        return false;
    }
    if (code.length < 6) {
        $(".warnInfo").text("密码长度少于6位.");
        $(".warnInfoP").show();
        $("#hidloginErrorStatu").val(1);
        $(".vercode").show();
        return false;
    }
    return true;
}



