﻿/**************************************
* Copyright by Spring Studio(http://springstudio.org)
* 分页专用脚本
***************************************/

/*
* 检查跳转输入项是否正整数
*/
function Pagination_CheckIsNumber(str) {
    if (str.length == 0) {
        return false;
    }

    var isNumber = 0;

    for (i = 0; i < str.length; i++) {
        isNumber = 0; //先把isNumber置为0

        for (j = 0; j < 10; j++) {
            if (str.charAt(i) == "" + j)
                isNumber = 1; //找到匹配的数字项，则置为1
        }

        if (isNumber == 0)	//找不到匹配的数字，则返回false
            return false;
    }

    return true; //完成检查，返回true
}

/*
* 页面直接跳转
*/
function Pagination_Navigate() {
    var objPageIndex = document.getElementById("Pagination_PageIndex");
    var objPageCount = document.getElementById("Pagination_PageCount");

    if (!Pagination_CheckIsNumber(objPageIndex.value)) {
        alert("页码必须是正整数，并且不能为空！");
        objPageIndex.value = "";
        objPageIndex.focus();
        return;
    }

    if (objPageIndex.value - objPageCount.value > 0) {
        alert("页码必须不大于总页数！");
        objPageIndex.value = "";
        objPageIndex.focus();
        return;
    }

    if (objPageIndex.value == 0) {
        alert("页码必须大于零！");
        objPageIndex.value = "";
        objPageIndex.focus();
        return;
    }

    var url = document.location.href;

    if (url.search(/page=[0-9]*/) > -1) {
        url = url.replace(/page=[0-9]*/, "page=" + objPageIndex.value);
    }
    else {
        if (url.indexOf("?") > -1) {
            url += "&page=" + objPageIndex.value;
        }
        else {
            url += "?page=" + objPageIndex.value;
        }
    }

    document.location = url;
}
