﻿
function SetTimer(container) {
    var h = document.getElementById("ucHead_hdHour").value;
    var m = document.getElementById("ucHead_hdMinute").value;
    var s = document.getElementById("ucHead_hdSeconds").value;
    this.container = document.getElementById(container)
    this.localtime = new Date();
    this.localtime.setHours(h);
    this.localtime.setMinutes(m);
    this.localtime.setSeconds(s);
    this.updateTime()
    this.updateContainer()
}

SetTimer.prototype.updateTime = function () {
    var thisobj = this
    var s = document.getElementById("ucHead_hdSign").value;
    if (s == '-') {
        this.localtime.setSeconds(this.localtime.getSeconds() - 1)
    }
    else if (s == '+') {
        this.localtime.setSeconds(this.localtime.getSeconds() + 1)
    }
    else {
        this.localtime.setSeconds(this.localtime.getSeconds() + 0)
    }
    setTimeout(function () { thisobj.updateTime() }, 1000) //update time every second
}

SetTimer.prototype.updateContainer = function () {
    var thisobj = this
    var str = this.localtime.toTimeString();
    this.container.innerHTML = str.substring(0, 8);
    document.getElementById("ucHead_hfRemTime").value = str.substring(0, 8);
    setTimeout(function () { thisobj.updateContainer() }, 1000) //update container every second
}

function MarkAnswer(rd) {
    //alert(rd);
    var lbl = document.getElementById("ucHead_lblAnswered");
    var rID = rd.id;
    rID = rID.replace('dlQuestions_rdlAnswers_', '');
    var rID2 = rID.split('_');
    var aID = rID2[0];
    var hdAns = document.getElementById("dlQuestions_hdAnsID_" + aID);
    var hdQues = document.getElementById("dlQuestions_hdQuesID_" + aID);
    if (hdAns.value == "0") {
        var count = lbl.innerHTML
        count = Number(count) + 1;
        lbl.innerHTML = count;
    }
    hdAns.value = rd.value;
    UpdateTestAnswer(hdQues.value, hdAns.value);
}

function UpdateTestAnswer(QuesID, AnsID) {
    obj = GetXmlHttpRequestNew();
    if (obj != null) {
        var URL = "UpdateTestAnswers.aspx?QuesID=" + QuesID + "&AnsID=" + AnsID;
        //obj.onreadystatechange = ValidProcess;
        obj.open("GET", URL, true);
        obj.send(null);
    }
}

function GetXmlHttpRequestNew() {
    var xreq = null;
    if (window.XMLHttpRequest) {
        xreq = new XMLHttpRequest();
    }
    else if (typeof ActiveXObject != "undefined") {
        xreq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xreq;
}

function UpdateTestData() {
    obj = GetXmlHttpRequest();
    if (obj != null) {
        var ID = document.getElementById("ucHead_hfCanTestSecID").value;
        var hfRemTime = document.getElementById("ucHead_hfRemTime");
        var Time = document.getElementById("RemTime").innerHTML;
        hfRemTime.value = Time;
        var URL = "UpdateTestData.aspx?ID=" + ID + "&Time=" + Time;
        //obj.onreadystatechange = ValidProcess;
        obj.open("GET", URL, true);
        obj.send(null);
    }
    setTimeout(function () { UpdateTestData() }, 10000) //update time every 10 second
}

function GetXmlHttpRequest() {
    var xreq = null;
    if (window.XMLHttpRequest) {
        xreq = new XMLHttpRequest();
    }
    else if (typeof ActiveXObject != "undefined") {
        xreq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xreq;
}



