﻿
//document.write("<script src='jquery-1.2.6.min.js' type='text/javascript'></script>");

function $(id) { return document.getElementById(id); }

//==============================================================================================
//  验证输入
//==============================================================================================

function ValidateTextIsNull(obj, msg)
{
    if (obj.value.length <= 0)
    {
        alert(msg);
        obj.focus();
        return false;
    }
    return true;
}

function ValidateTextIsNullByID(id, msg)
{
    var obj = $(id);
    return ValidateInputIsNull(obj, msg);
}

function ValidateTextLength(obj, minLen, maxLen, msg)
{
    if (obj.value.length < minLen)
    {
        alert(msg);
        obj.focus();
        return false;
    }
    if (obj.value.length > maxLen)
    {
        alert(msg);
        obj.focus();
        return false;
    }
    return true;
}

function ValidateTextLength(id, minLen, maxLen, msg)
{
    var obj = $(id);
    return ValidateTextLength(obj, minLen, maxLen, msg);
}

function ValidateTextIsNull(obj, msg, isAscii)
{
    var unlen
    if (isAscii == true)
    {
        unlen = obj.value.length;
    }
    else
    {
        unlen = obj.value.replace(/[^\x00-\xff]/g, "**").length;
    }

    if (unlen <= 0)
    {
        alert(msg);
        obj.focus();
        return false;
    }
    return true;
}

function ValidateTextIsNullByID(id, msg, isAscii)
{
    var obj = $(id);
    return ValidateTextIsNull(obj, msg, isAscii);
}

function ValidateTextLength(obj, minLen, maxLen, msg, isAscii)
{
    var unlen
    if (isAscii == true)
    {
        unlen = obj.value.length;
    }
    else
    {
        unlen = obj.value.replace(/[^\x00-\xff]/g, "**").length;
    }

    if (unlen < minLen)
    {
        alert(msg);
        obj.focus();
        return false;
    }
    if (unlen > maxLen)
    {
        alert(msg);
        obj.focus();
        return false;
    }
    return true;
}

function ValidateTextLengthByID(id, minLen, maxLen, msg, isAscii)
{
    var obj = $(id);
    return ValidateTextLength(obj, minLen, maxLen, msg, isAscii);
}

//function ValidateAllText(str)
//{
//    var strArr = str.split("|");
//}


//==============================================================================================
//  翻页控制
//==============================================================================================


function PageDown()
{
    var pageno = location.hash.length > 0 ? location.hash.substring(1) : 1;
    var pageTotal = 1;
    if ($("hdnPageTotal"))
    {
        pageTotal = $("hdnPageTotal").value;
    }
    else
    {
        return;
    }

    if (isNaN(pageno))
    {
        GoPage(pageTotal, 2);
        return;
    }
    var p = parseInt(pageno) + 1;
    if (p <= pageTotal)
    {
        GoPage(pageTotal, p);
    }
}

function PageUp()
{
    var pageno = location.hash.length > 0 ? location.hash.substring(1) : 1;
    var pageTotal = 1;
    if ($("hdnPageTotal"))
    {
        pageTotal = $("hdnPageTotal").value;
    }
    else
    {
        return;
    }

    if (isNaN(pageno))
    {
        GoPage(pageTotal, 1);
        return;
    }
    var p = parseInt(pageno) - 1;
    if (p > 0)
    {
        GoPage(pageTotal, p);
    }
}

function GoPage(pageTotal, pageNo)
{
    for (i = 1; i <= pageTotal; i++)
    {
        $("page_" + i).style.display = "none";
        $("pageno_" + i).style.color = "black";
    }

    $("page_" + pageNo).style.display = "block";
    $("pageno_" + pageNo).style.color = "red";

    var hash = location.hash.length > 0 ? location.hash.substring(1) : 1;

    if (pageNo > 1 || (!isNaN(hash) && parseInt(hash) <= pageTotal && parseInt(hash) > 0))
    {
        location.hash = pageNo;
    }

    if (pageTotal == 1)
    {
        $("PageUpID").style.visibility = "hidden";
        $("PageDownID").style.visibility = "hidden";
        $("pageno_1").style.visibility = "hidden";
    }
    else if (pageNo == 1)
    {
        $("PageUpID").style.visibility = "hidden";
        $("PageDownID").style.visibility = "visible";
    }
    else if (pageNo == pageTotal)
    {
        $("PageUpID").style.visibility = "visible";
        $("PageDownID").style.visibility = "hidden";
    }
    else
    {
        $("PageUpID").style.visibility = "visible";
        $("PageDownID").style.visibility = "visible";
    }

    document.documentElement.scrollTop = 0;
}

function PageInit()
{
    var pageno = location.hash.length > 0 ? location.hash.substring(1) : 1;

    var pageTotal = 1;
    if ($("hdnPageTotal"))
    {
        pageTotal = $("hdnPageTotal").value;
    }
    else
    {
        return;
    }

    if (isNaN(pageno) || parseInt(pageno) < 1 || parseInt(pageno) > parseInt(pageTotal))
    {
        pageno = 1;
    }
    GoPage(pageTotal, pageno);
}

//-------------------------------------------------------------------------------

function keyDown(e)
{
    if (window.event)
        e = window.event;
    var int_keycode = e.charCode || e.keyCode;
    if (int_keycode == '37')
    {
        PageUp();
    }
    if (int_keycode == '39')
    {
        PageDown();
    }

}

document.onkeydown = keyDown;

//-------------------------------------------------------------------------------



//var id = 0;
//var url = location.href;

//if (url.toLocaleLowerCase().indexOf(".html") > -1)
//{
//    var b = url.lastIndexOf("/");
//    var e = url.toLocaleLowerCase().lastIndexOf(".html");
//    id = url.substring(b + 1, e);
//}
//else if (url.toLocaleLowerCase().indexOf("articleid=") > -1)
//{
//    var b = url.toLocaleLowerCase().lastIndexOf("articleid=");
//    var e = url.indexOf("&amp;", b);
//    if (e > -1)
//    {
//        id = url.substring(b + 10, e);
//    }
//    else
//    {
//        id = url.substring(b + 10);
//    }
//}

//if (id > 0)
//{
//    document.write(unescape("%3Cscript src='/Stat/UpdateHits.rails?id=" + id + "' type='text/javascript'%3E%3C/script%3E"));
//}
