var version = navigator.userAgent.substring(navigator.userAgent.lastIndexOf("MSIE") + 5, navigator.userAgent.lastIndexOf("MSIE") + 8);

if (navigator.appName.indexOf('Microsoft') == -1 || version < 7.0) {
    $("#cover_div").css("position", "absolute").css("height", $(window).height()).css("width", $(window).width());
    
}

function __message(message, callback) {
    $('#__msg').modal({
        closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
        position: ["20%", ],
        overlayCss:{ backgroundColor: "red" },
        overlayId: 'confirm-overlay',
        containerId: 'confirm-container',
        onShow: function (dialog) {
            $('p[class=\'message\']', dialog.data[0]).append(message);

            // if the user clicks "yes"
            $('div[class=\'yes\']', dialog.data[0]).click(function () {
                // call the callback
                if ($.isFunction(callback)) {
                    callback.apply();
                }
                // close the dialog
                $.modal.close();
            });
        }
    });
}
function playMP3(e, file) {
    var t = e.parentNode.style;
    var player = $("#mediaplayer_content");
    player.css("display", "block");
    player.css("top", parseInt(t.top) - 22);
    player.css("left", parseInt(t.left) + 20);

    $('#mediaplayer').media({
    flashvars: { autostart: 'true',bufferlength:10 }, 
    height: 30,width:200, autoplay: true, src: file
    });
   

};
function displayEmaineeKey(myKeyXML,displayMark) {
    var keyList = myKeyXML.selectNodes("/KeyList/StuKey")
    var keycount = keyList.length//得到试题数量

    for (var i = 0; i < keycount; i++) {
        var keynode = keyList.item(i)//得到一个答案节点
        var score = 0

        var testids = keynode.getAttribute("KeyId")//得到该答案id

        var mode = testids.substring(0, 1)//得到试题类型
        var mykey
        if (mode != "c") {
            //不是填空题,得到答案,显示分数
            mykey = keynode.text//得到考生答案

        }
        var _keyId = testids.substring(1);
        switch (mode) {
            case "a": //单选题

                _testFlags.initKeyFromServer(_keyId, [mykey]);

                var getByid = document.getElementById(testids);
                if ((getByid) && (getByid.tagName.toLowerCase() == "select")) { document.getElementById(testids).value = mykey } else {

                    switch (mykey.toLowerCase()) {
                        case "a":
                            document.getElementsByName(testids).item(0).checked=true
                            break
                        case "b":
                            document.getElementsByName(testids).item(1).checked=true
                            break
                        case "c":
                            document.getElementsByName(testids).item(2).checked=true
                            break
                        case "d":
                            document.getElementsByName(testids).item(3).checked=true
                            break
                        case "e":
                            document.getElementsByName(testids).item(4).checked=true
                            break
                        case "f":
                            document.getElementsByName(testids).item(5).checked=true
                            break
                    }
                };
                score = keynode.getAttribute("Point"); 
                break
            case "b": //多选题
                _testFlags.initKeyFromServer(_keyId, [mykey]);
                mykey = mykey.toLowerCase();
                if (mykey.indexOf('a') != -1 || mykey.indexOf('1') != -1)
                    document.getElementsByName(testids).item(0).checked=true
                if (mykey.indexOf('b') != -1 || mykey.indexOf('2') != -1)
                    document.getElementsByName(testids).item(1).checked=true
                if (mykey.indexOf('c') != -1 || mykey.indexOf('3') != -1)
                    document.getElementsByName(testids).item(2).checked=true
                if (mykey.indexOf('d') != -1 || mykey.indexOf('4') != -1)
                    document.getElementsByName(testids).item(3).checked=true
                if (mykey.indexOf('e') != -1 || mykey.indexOf('5') != -1)
                    document.getElementsByName(testids ).item(4).checked=true
                if (mykey.indexOf('f') != -1 || mykey.indexOf('6') != -1)
                    document.getElementsByName(testids).item(5).checked=true

                score = keynode.getAttribute("Point");
                break
            case "c": //填空题

                var fillObjs = document.getElementsByName(testids);

                for (var ii = 0; ii < keynode.childNodes.length; ii++) {
                    var myKeyNode = keynode.childNodes[ii]
                    var addr = parseInt(myKeyNode.getAttribute("Addr"))
                    addr = addr - 1

                    var myKey = myKeyNode.text;
                    //var fillScore=myKeyNode.getAttribute("Point")
                    //fillTotal+=parseFloat(fillScore)
                    fillObjs.item(addr).value = myKey
                    //fillObjs.item(addr).title="得分"+fillScore

                };
                var keysArr = new Array();
                for (var x = 0; x < fillObjs.length; x++) {
                    keysArr[keysArr.length] = fillObjs.item(x).value;
                };
                _testFlags.initKeyFromServer(_keyId, keysArr);
                score = keynode.getAttribute("Point");
                if (score == null) {
                    var subKeyNode = keynode.childNodes;
                    if (subKeyNode != null) {
                        score = "";
                        for (var i0 = 0; i0 < subKeyNode.length; i0++) {
                            score +=" "+ subKeyNode[i0].getAttribute("Point");

                        }
                    }
                }
                //document.getElementById("t" + testids).innerHTML="<font color=red><b>得分"+fillTotal+"</b></font>"
                break
            case "d": //判断题
                _testFlags.initKeyFromServer(_keyId, [mykey]); ;
                if (mykey == "1") {
                    document.getElementsByName(testids).item(0).checked = true;
                } else {
                    document.getElementsByName(testids).item(1).checked = true;

                }
                score = keynode.getAttribute("Point");
                break
            case "e": //问答题
                _testFlags.initKeyFromServer(_keyId, [mykey]);
                document.getElementsByName(testids).item(0).value=mykey
                score = keynode.getAttribute("Point");
                break
                /*case "f"://选项题
                var ele=p_keyQueue.pushData(testids,mykey);
                var sKey=new Array();
                sKey[0]=mykey;
                ele.setSKey(sKey);
                switch(mykey){
                case "a":
                eval("document.getElementsByName('"+testids+"').item(0).checked=true")
                break
                case "b":
                eval("document.getElementsByName('"+testids+"').item(1).checked=true")
                break
                case "c":
                eval("document.getElementsByName('"+testids+"').item(2).checked=true")
                break
                case "d":
                eval("document.getElementsByName('"+testids+"').item(3).checked=true")
                break
            
             } 
                break;
                case "k"://vr
                var ele=p_keyQueue.pushData(testids,mykey);
                var sKey=new Array();
                sKey[0]=mykey;
                ele.setSKey(sKey);
                document.getElementById(testids).innerHTML=mykey*100;
                break;
                case "l"://upload 
         
             uploadStatu(testids.substring(1),2,mykey)
                break;*/

        }



        
        if (displayMark) {
            //显示评分标记
            var judgeDiv = document.getElementById("judgeDiv" + _keyId);
            if (judgeDiv != null) judgeDiv.style.display = "block";
            var markImg = document.getElementById("markImg" + _keyId);
            var scoreDiv = document.getElementById("markScore" + _keyId);
            var sdandKeyDiv = document.getElementById("keyDiv" + _keyId);
            
            if (parseInt(score) > 0) {
                if (scoreDiv != null) scoreDiv.innerHTML = "+" + score;
                if (markImg != null) markImg.src = "/paperstyle/right.gif";

            }
            else {
                if (markImg != null) markImg.src = "/paperstyle/error.gif";
                if (scoreDiv != null) scoreDiv.innerHTML = score;
            }
        };
    }








};
$().ready(
        function () {


            if (navigator.appName.indexOf('Microsoft') == -1 || version < 7.0) {
                $("#cover_div").css("height", $(document).height()).css("width", $(document).width());
                $("#right_bottom,#right_top").css("position", "absolute");
                alert("您使用的浏览器可能无法正常显示本页，推荐使用IE8.0浏览器")
                window.onscroll = function () {
                    var t = (document.body.scrollTop || document.documentElement.scrollTop);
                    $("#right_top").css("top", t.toString() + "px");
                    $("#right_bottom").css("top", (t + $(window).height() - 305).toString() + "px");
                    $("#right_top").css("left", ($(window).width() - 160).toString() + "px");
                    $("#right_bottom").css("left", ($(window).width() - 160).toString() + "px");

                };
                window.onresize = function () {

                    window.onscroll();
                };
            }
            //w类型试卷初始化select控件
            $("select[id^='a'][v][t]").each(function () {
                var t = $(this).attr("t").split(","); var v = $(this).attr("v").split(",");
                for (var i = 0; i < t.length; i++) {
                    $(this).append("<option value='" + v[i] + "'>" + t[i] + "</option>");

                };

            });
           


            //---------------撤销radio选择--------start
            $(":radio").attr("title", "单击右键可以撤销当前选择")
            $(":radio").bind("contextmenu", function () { return false; });
            $(":radio").bind("mousedown", function (e) {
                if (e.button != 2) return;
                var radioStatus = $(this).attr('checked');
                if (radioStatus) { $(this).attr('checked', false); }
                _testFlags.setClientKey(e.target.name.substring(1), [""]);

            });
            //---------------撤销radio选择--------end

            $(".dragDiv").bind("contextmenu", function () { return false; });
            var loader = jQuery('<div id="loader"><img src="/paperStyle/images/loading2.gif" alt="loading..." /></div>')
			.appendTo("body")
			.hide();
            loader.ajaxStart(function () {

                loader.css({ zIndex: "9999", position: "absolute", top: $().scrollTop() + 5, left: $().scrollLeft() + 5 })
                loader.show();
            }).ajaxStop(function () {
                loader.hide();
            }).ajaxError(function (a, b, e) {
                loader.hide();
                if (b.status == 404) { alert("主机不支持ajax wcf服务或请求的服务不存在！错误代码:404"); }
                else alert(b.responseText);
            });
        });


function LRTrim(str) {
    if (str == null) return "";
    if (str == "") return "";
    while (str.substr(0, 1) == " ") {
        str = str.substr(1)

    }
    while (str.substr(str.length - 1, 1) == " ") {
        str = str.substr(0, str.length - 1)

    }
    return str;

}
function resetRadioKey(RadioName) {
    var r = document.getElementsByName(RadioName);
    for (var i = 0; i < r.length; i++) {
        var radio = r[i];
        if (radio.checked) radio.checked = false;


    }

}
//function window.onload(){document.forms[0].reset();}
function saveKeyToArr(testClass, keyObj) {
    //储存考生答案到队列中去
    if (keyObj == null) keyObj = event.srcElement;

    var keyName = keyObj.name.substring(1);
    var keyIndex = 0;
    switch (testClass) {
        case 0: //单项选择题
            var theKey = keyObj.value;

            _testFlags.setClientKey(keyName, [theKey]);

            //alert(ele.keys[0])       
            break;
        case 1: //多项选择题
            var nowKeyArr = new Array();
            $("input[name='" + keyObj.name + "']").each(function() {
                if (this.checked) { nowKeyArr[nowKeyArr.length] = this.value; };
            });
            nowKeyArr.sort();
            var selected=nowKeyArr.toString();
            var t = selected.replace(/,/g, "");
            _testFlags.setClientKey(keyName, [t]);
            
            break;
        case 2:
            var kk = keyObj.value; var nowKeyArr = new Array();
            $("input[name='" + keyObj.name + "']").each(function(i,n) {
                 nowKeyArr[nowKeyArr.length] = LRTrim(this.value);
            });

            _testFlags.setClientKey(keyName, nowKeyArr);
            break;
        case 3: //判断题 
            var theKey = keyObj.value;

            _testFlags.setClientKey(keyName, [theKey]);

            break;
        case 4: //问答题 
            var theKey = LRTrim(keyObj.value);
            keyObj.value = theKey;
            _testFlags.setClientKey(keyName, [theKey]);

            break;
        default:
            alert("unknown test class!");
            return;
            break;

    };

    //var k=p_keyQueue.add(keyName,keyIndex,key);
    //if(k!=null)calculate(k.keyName,k.keys);
}

