var gradexml = new ActiveXObject("Microsoft.XMLDOM");
gradexml.async = false;
gradexml.load("../" + examid + "/grade.xml");
var gradeNode = gradexml.selectSingleNode("grade");

var examxml = new ActiveXObject("Microsoft.XMLDOM");
examxml.async = false;
examxml.load("../" + examid + "/infor.xml");
window.onload = function () {
    Pagers(pageCount + 1, curPage + 1)
var useLevelForResultNode = examxml.selectSingleNode("/examInfor/useLevelForResult");

    var tbody = scoreList.tBodies.item(0);
    if (useLevelForResultNode.text == "1") {
        document.getElementById("c4").style.display = "none";

        document.getElementById("c5").style.display = "block"
    }
    else {
        document.getElementById("c5").style.display = "none";

        document.getElementById("c4").style.display = "block"
    }
}
function getResult(score) {
    var classNode = gradeNode.selectSingleNode("gradename[" + score + " $ge$ @minvalue]");
    if (classNode != null) document.write(classNode.text);


}

function paper(userId) {
    if (userId == null) return;
    userId = encodeURIComponent(userId);

    var url = "../" + examid;
    if (random == "0")
        url += "/testpaper.xml?ek=" + userId + "&ei=" + examid;
    else
        url += "/stukey/" + userId + ".xml?ek=" + userId + "&ei=" + examid;
    window.open(url, "paper")

}

function printExcel(scoreList) {
    var oXL
    try
     { oXL = new ActiveXObject("Excel.Application"); }
    catch (Err) {
        alert("无法创建Excel对象，请参照打印word格式试卷的帮助文件");
        window.location = "../../../help/active.htm";

        return
    }
    oXL.Visible = true;
    var oWB = oXL.Workbooks.Add();
    var oSheet = oWB.ActiveSheet;
    var omxh = scoreList;

    for (i = 0; i < omxh.rows[0].cells.length; i++) {
        oSheet.Cells(2, i + 1).Value = omxh.rows[0].cells[i].innerText;
    }
    oSheet.Range("A1", "AA2").Font.Bold = true;
    oSheet.Columns("A:A").NumberFormatLocal = "@";
    oSheet.Columns("C:C").NumberFormatLocal = "@";
    for (i = 0; i < omxh.rows.length; i++) {

        for (j = 0; j < omxh.rows[i].cells.length; j++) {
            oSheet.Cells(i + 2, j + 1).Value = omxh.rows[i].cells[j].innerText;
        }
        oSheet.Cells(i + 2, 2).NumberFormat = "@";
    }


    //设置样式
    var oSelection = oSheet.Range("A2:B" + (omxh.rows.length + 1));
    oSelection.Borders(9).LineStyle = -4119;
    oSelection.Borders(9).Weight = 4;
    oSelection.Borders(5).LineStyle = 0
    oSelection.Borders(6).LineStyle = 0

    oSelection.Borders(7).LineStyle = 1
    oSelection.Borders(7).Weight = 2
    oSelection.Borders(7).ColorIndex = -4105


    oSelection.Borders(8).LineStyle = 1
    oSelection.Borders(8).Weight = 2
    oSelection.Borders(8).ColorIndex = -4105


    oSelection.Borders(9).LineStyle = 1
    oSelection.Borders(9).Weight = 2
    oSelection.Borders(9).ColorIndex = -4105

    oSelection.Borders(10).LineStyle = 1
    oSelection.Borders(10).Weight = 2
    oSelection.Borders(10).ColorIndex = -4105

    oSelection.Borders(11).LineStyle = 1
    oSelection.Borders(11).Weight = 2
    oSelection.Borders(11).ColorIndex = -4105
    oSelection.Borders(12).LineStyle = 1
    oSelection.Borders(12).Weight = 2
    oSelection.Borders(12).ColorIndex = -4105

    /*
    Excel自动换行
    var xls=new ActiveXObject("Excel.Application")
    xls.Visible = true;
    var x1Workbook=xls.Workbooks.Add();
    var xlSheet=x1Workbook.Worksheets(1);
    for(var i=1;i<10;i++){
    xlSheet.Cells(1,i).WrapText = true;
    }

  
  
    var newWin=window.open("","","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
  
    newWin.document.write("<body leftmargin=0 topmargin =0></body>")
  
    if (typeof(newWin.EXPORT_OBJECT)!="object")
    {
    newWin.document.write("<OBJECT style='display:block' classid=clsid:0002E510-0000-0000-C000-000000000046 id=EXPORT_OBJECT width=100% height=100% codebase='down/msowc.cab#version=9,0,0,2710'></Object>");
    }
  
    var oWB=newWin.EXPORT_OBJECT;
    var oSheet = oWB.ActiveSheet;
    alert(oSheet.Cells)
  
    return
    with (newWin.EXPORT_OBJECT)
    {
    DataType = "HTMLData";
    var htm=scoreList.outerHTML
	
    HTMLData =htm;
    try{
    ActiveSheet.Export("C:\\Excel.xls", 0);
    alert('保存完毕');
    }
    catch (exception){if(exception.description!="")
    alert('汇出Excel表失败，请确定已安装Excel2000(或更高版本),并且没打开同名xls文件。错误描述：'+exception.description);
    }
    }*/
}


var preBackgroundColor = "";
var preColor = "";
function mouseover(tr) {
    preBackgroundColor = tr.style.backgroundColor;
    preColor = tr.style.color;
    tr.style.backgroundColor = 'blue'; tr.style.color = 'white'


}
function mouseout(tr) {
    tr.style.backgroundColor = preBackgroundColor;
    tr.style.color = preColor;

}

function Pagers(pageCount, curPage) {
if (pageCount<=1)return
    var minPage = curPage - 7;
    if (minPage <= 0) minPage = 1;
    var maxPage = minPage + 14;
    if (maxPage > pageCount) maxPage = pageCount;
    var js = " <a href='scoreList_0.xml' title='转到首页'><font face='webdings'>9</font></a>";
    js += " <a href='scoreList_" + (curPage - 2) + ".xml' title='上一页'><font face='webdings'>7</font></a>";
    for (i = minPage-1; i < maxPage; i++) {
        if (i == curPage-1) {
            js += " <u>" + (i + 1) + "</u>";
        }
        else {
            js += " <a href='scoreList_" + i + ".xml'>" + (i+1) + "</a>";
        }
    }
    js += " <a href='scoreList_" + curPage+ ".xml' title='下一页'><font face='webdings'>8</font></a>";
    js += " <a href='scoreList_" + (pageCount-1) + ".xml' title='转到末尾'><font face='webdings'>:</font></a>";
    js += " [共计" + pageCount + "页]";
    document.getElementById("td_pagers").innerHTML = js;
}
