/*
用途：	检查输入字符串是否符合正整数格式

输入：	s：字符串
返回：	如果通过验证返回true,否则返回false	
*/
function aw_isNumber(s) {
    var regu = "^[0-9]+$";
    var re = new RegExp(regu);
    if (s.search(re) != -1) {
        return true;
    } else {
        return false;
    }
}

function aw_swapImgRestore() { //v3.0
    var i, x, a = document.aw_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function aw_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.aw_p) d.aw_p = new Array();
        var i, j = d.aw_p.length, a = aw_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.aw_p[j] = new Image; d.aw_p[j++].src = a[i]; }
    }
}
function aw_findObj(n, d) { //v4.0
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = aw_findObj(n, d.layers[i].document);
    if (!x && document.getElementById) x = document.getElementById(n); return x;
}

function aw_swapImage() { //v3.0
    var i, j = 0, x, a = aw_swapImage.arguments; document.aw_sr = new Array; for (i = 0; i < (a.length - 2) ; i += 3)
        if ((x = aw_findObj(a[i])) != null) { document.aw_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function aw_GotoPage(str, inpagecount) {
    var pageCount;
    var pageSize;
    var CurrentPage;
    var tempPage;
    pageCount = pg_total_page_count;
    CurrentPage = pg_current_page;

    switch (str) {
        case "first":
            if (CurrentPage == 1 || CurrentPage == 0) {
                alert('对不起，已经是第一页了.');
                return
            }
            else
                tempPage = 1;

            break;
        case "before":
            if (CurrentPage == 1 || CurrentPage == 0) {
                alert('对不起，已经是第一页了,不能继续向前翻页了.');
                return
            }
            else
                tempPage = CurrentPage - 1;

            break;
        case "next":
            if (CurrentPage >= pageCount) {
                alert('对不起，已经是最后一页了，不能继续向后翻页了.');
                return
            }
            else
                tempPage = CurrentPage + 1;

            break; ut
        case "last":
            if (CurrentPage == pageCount) {
                alert('对不起，已经是最后一页了.');
                return
            }
            else
                tempPage = pageCount;

            break;
        case "input":
            if (!aw_isNumber(document.getElementById("pageSize").value)) {
                alert("每页显示记录数，请输入一个合法的数字！");
                document.getElementById('pageSize').focus();
                return false;
            }
            //检查inpagecount是否数字
            if (inpagecount == "") {
                inpagecount = "1";
                //return false;
            }

            if (inpagecount == 0)
                inpagecount = 1;

            if (!aw_isNumber(inpagecount)) {
                alert("请输入一个合法的数字！");

                //return false;
            }

            if (inpagecount > pageCount) {
                alert("请输入一个 1 到 " + pageCount + " 之间的数字！");
                return;
            }
            else
                tempPage = inpagecount;
            break;
        default:
            tempPage = 1;
            break;
    }

    aw_SelectPage(tempPage);
    return;
}

function aw_SelectPage(currPage) {
    var url = pg_url + "&page=" + currPage + "&page_size=" + document.getElementById("pageSize").value;
    //alert(url);
    document.location.href = url;
}

//全选
var aw_bSelected_ALL = false;
function aw_SelectAllRows() {
    for (var i = 0; i < aw_myData.length; i++) {
        if (aw_myData[i][0] != "") {
            obj.setRowSelected(!aw_bSelected_ALL, i);
        }
    }
    aw_bSelected_ALL = !aw_bSelected_ALL;
}
//得到所选行
function aw_GetSelectRows(column) {
    var arr = aw_arrGridSelections;
    var results = [];
    if (arr != null) {
        for (var i = 0; i < arr.length; i++) {
            var text = aw_myData[arr[i]][column];
            results.push(text);
        }
    }
    return results;
}
//刷新整个Grid
function aw_Refresh(){
	obj.setRowIndices('');
	obj.refresh();
}
