var tableName = "";//表名
var pageno = "1";//当前页数
var allrows = "";//一共多少页
var filter = "";//过滤条件
var pagename = "";//显示页名
var sFilter = "";

function LoadListData()//读取数据
{
    clearall();
    var xmlData="<action>LoadListData</action><PAGENO>"+ pageno +"</PAGENO><FILTER>"+ filter +"</FILTER><tableName>"+ tableName +"</tableName>";

    xmlData=formatXmlData("",xmlData);
    result=sendXmlData(xmlData,"service/service.jsp");
    if(!checkResult(result))
    {
        alert(getErrorMessage(result));
        return false;
    }
    else
    {
        var oDiv = document.createElement("DIV");
	oDiv.innerHTML = getErrorMessage(result);
        if(oDiv.childNodes[0].getAttribute("repeat") == "0"){
            oDiv = oDiv.childNodes[0];
            var rowCount = oDiv.getAttribute("iRowCount");
            var count = oDiv.getAttribute("iPageRowCount");
            var pagecount = oDiv.getAttribute("pagecount");
//                        alert(oDiv.getAttribute("rtFilter"));
            document.all('txt_FILTER').value = oDiv.getAttribute("rtFilter");
            var listno = pageno*10-10;
            allrows = pagecount;

            if(window.ActiveXObject){
                document.getElementById('span_TOTAL').innerText = pagecount;
                document.getElementById('span_PAGENO').innerText = pageno;
            }else if(window.XMLHttpRequest){
                document.getElementById('span_TOTAL').textContent = pagecount;
                document.getElementById('span_PAGENO').textContent = pageno;
            }
            PageNoList();
            var i = 0;
            for(;i<count;i++){
                document.getElementById('tr_LIST' + i).style.display = "";
                document.getElementById('span_OID'+i).title = oDiv.childNodes[i].getAttribute("type");
                document.getElementById('span_TITLE'+i).title = replaceClientValue(oDiv.childNodes[i].getAttribute("name"));
                if(window.ActiveXObject){
                    document.getElementById('span_LIST'+i).innerText = (pageno - 1) * 10 + i + 1;
                    document.getElementById('span_OID'+i).innerText = replaceClientValue(oDiv.childNodes[i].getAttribute("oid"));
                    document.getElementById('span_TITLE'+i).innerText = cutString(replaceClientValue(oDiv.childNodes[i].getAttribute("name")),70);
                    document.getElementById('span_TIME'+i).innerText = replaceClientValue(oDiv.childNodes[i].getAttribute("time"));
                }else if(window.XMLHttpRequest){
                    document.getElementById('span_LIST'+i).textContent = (pageno - 1) * 10 + i + 1;
                    document.getElementById('span_OID'+i).textContent = replaceClientValue(oDiv.childNodes[i].getAttribute("oid"));
                    document.getElementById('span_TITLE'+i).textContent = cutString(replaceClientValue(oDiv.childNodes[i].getAttribute("name")),70);
                    document.getElementById('span_TIME'+i).textContent = replaceClientValue(oDiv.childNodes[i].getAttribute("time"));
                }
            }
//            OtherList(i);
        }
    }
}
//function OtherList(iNow)
//{
//    for(i=6;i<=15;i++){
//        document.getElementById('span_LIST'+i).innerText = iNow + (pageno-1)*16 + i - 5;
//    }
//}
function clearall()
{
    for(i=0;i<10;i++){
        document.getElementById('tr_LIST' + i).style.display = "none";
//        document.getElementById('span_LIST'+i).innerText = "";
//        document.getElementById('span_TITLE'+i).innerText = "";
//        document.getElementById('span_TIME'+i).innerText = "";
    }
}
function PageNoList()//数字页数显示
{
    var list = "";
    var count = parseInt(pageno / 7) * 7;
    for(i=count;i<=allrows;i++){
        if(i== count + 8){
            break;
        }else if(i==0){
            continue;
        }
        if(i == pageno){
            list += "| <font color='#FC650D'>";
            list += i + "</font> ";
        }else{
            list += "| <span style='Cursor:pointer' onclick='ChangePage("+ i +")'>";
            list += i + "</span> ";
        }
    }
    document.getElementById('span_PAGES').innerHTML = list.substring(1);
}
function ChangePage(NO)//页数选择
{
    if(NO != pageno){
        location.href = 'index.html?'+NO+"filter="+replaceValue(sFilter);
//        clearall();
//        LoadListData();
    }
}
function ProPage()//上一页
{
    if(pageno > 1 ){
        pageno--;
        location.href = 'index.html?'+pageno+"filter="+replaceValue(sFilter);
    }
}
function NextPage()//下一页
{
    if(pageno < allrows ){
        pageno++;
        location.href = 'index.html?'+pageno+"filter="+replaceValue(sFilter);
    }
}
function ChangeSelect()//页数添入下拉列表
{
    var oSelect = document.getElementById('select_PAGENO');
    for(i=oSelect.options.length-1;i>=0;i--)
    {
        oSelect.options.remove(i);
    }
    var oOption;
    for(i=1;i<=allrows;i++)
    {
        oOption = document.createElement("OPTION");
        oSelect.options.add(oOption);
        if(window.ActiveXObject){
            oOption.innerText = i;
        }else if(window.XMLHttpRequest){
            oOption.textContent = i;
        }
        oOption.value = i;
    }
    oSelect.selectedIndex = pageno - 1;
}
function ClickList(NO)//选择内容
{
    var sOid = "";
    if(window.ActiveXObject){
        sOid = document.getElementById('span_OID'+NO).innerText;
    }else if(window.XMLHttpRequest){
        sOid = document.getElementById('span_OID'+NO).textContent;
    }
    var type = document.getElementById('span_OID'+NO).title;
    if(type == "1"){
        location.href = sOid;
    }else{
        location.href = 'newsdetaile.jsp?oid=' + sOid + "&page="+pageno+"filter="+replaceValue(sFilter);
    }
}
function SelectPage()//下拉列表选择页
{
    var oSelect = document.getElementById('select_PAGENO');
    pageno = oSelect.options[oSelect.selectedIndex].value;
    location.href = 'index.html?'+pageno+"filter="+replaceValue(sFilter);
}
function RowFilter()//过滤条件
{
    sFilter = returnValue('txt_FILTER');
    if(sFilter == ""){
        filter = "";
    }else{
//        filter = "TITLE LIKE '%"+ replaceValue(sFilter) +"%'";
        filter = replaceValue(sFilter);
    }
//    LoadListData();
    location.href = 'index.html?1filter='+replaceValue(sFilter);
//    pageno=1;
//    clearall();
//    LoadListData();
//    ChangeSelect();
}
function cutString(str, outputLen)//截取长度
{
    var strLen,tLen, charCode;
    if(str==undefined){ return ""; }
    strLen=str.length;
    tLen=0;
    for(var i=0;i<strLen;i++){
       charCode=str.charCodeAt(i);
       if(charCode<0||charCode>255){ tLen+=2 }else{ tLen++ }
       if(tLen>=outputLen){ return str.substr(0,i)+"..."; }
    }
    return str;
}
function returnValue(NAME)//返回值
{
    var value = trim(document.getElementById(NAME).value);
    return replaceValue(value);
}
