﻿var curObjectID
function printContent(strid) {
    var prtContent = document.getElementById(strid);
    var WinPrint =
        window.open('', '', 'left=0,top=0,width=1,height=1,t oolbar=0,scrollbars=0,status=0');
    WinPrint.document.write("<html><head><link rel='stylesheet' type='text/css' href='GeneralStyleSheet.css' /></head><body>" + prtContent.innerHTML + "</body></html>");

    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    WinPrint.close();
}
function SetTextValue(obj, TextToSet) {
    if (obj.value == "") {
        obj.value = TextToSet;
    }
}

function RemoveTextValue(obj, TextToCompare) {
    if (obj.value == TextToCompare) {
        obj.value = "";
    }
}

function handleKeyPress(e,buttonid) {
    //alert("key down e.keyCode = " + e.keyCode + "  e.which = " + e.which);
    var key = e.keyCode || e.which;
   // alert("key = " + key)
    if (key == 13) {
        //alert(" __doPostBack('" + buttonid.replace("_", "$") + "', '')")
  //    document.getElementById(buttonid).click();
        __doPostBack(buttonid, '');
    }
}

/******************** Document Types Control *************************/

function onDocTypeCBoxClick(cBoxObj) {
    selectAllCBoxes(cBoxObj.parentNode.parentNode, cBoxObj.checked, cBoxObj);
    if (cBoxObj.checked) {
        
        selectParents(cBoxObj);
    } else {
        deselectParents(cBoxObj);
     }
    
}
function selectAllCBoxes(obj, checked, rootObj) {
    for (var i = 0; i < obj.childNodes.length; i++) {
        if (obj.childNodes[i] != rootObj && obj.childNodes[i].checked != null) {
            //obj.childNodes[i].disabled = !checked;
            obj.childNodes[i].checked = checked;
        }
        selectAllCBoxes(obj.childNodes[i], checked, rootObj);
    }
}
function selectParents(cBoxObj) {
    if (cBoxObj.parentNode.parentNode.parentNode.getAttribute("id") == "docTypeFilterContainer")
        return
    
    var parent = getParentCBox(cBoxObj);
    parent.checked = true;
    selectParents(parent);

}
function deselectParents(cBoxObj) {
    if (cBoxObj.parentNode.parentNode.parentNode.getAttribute("id") == "docTypeFilterContainer")
        return
    if(allDeselected(cBoxObj.parentNode.parentNode.parentNode)){
        var parentCBox = getParentCBox(cBoxObj);
        parentCBox.checked = false;
        deselectParents(parentCBox);
    }
    
}
function allDeselected(obj) {
    if (obj.tagName != null && obj.tagName.toLowerCase() == "input" && obj.getAttribute("type").toLowerCase() == "checkbox") {
        if (obj.checked)
            return false;
    }
    for (var i = 0; i < obj.childNodes.length; i++) {
        if (!allDeselected(obj.childNodes[i])) {
            return false;
        }
    }
    return true;
}
function getParentCBox(child){
    return child.parentNode.parentNode.parentNode.parentNode.firstChild.firstChild;
}
/******************** End of Document Types Control ******************/

/************************** Navigation Tabs **************************/
var curObjectID;
var ddfocus_Array = new Array();

function setBlur(obj) {
    ddfocus_Array.push(obj);
}

document.onclick = function(e) {
for (var i = 0; i < ddfocus_Array.length; i++) {
        if (clickedOutsideElement(ddfocus_Array[i].id, e)) ddLostFocus(ddfocus_Array[i]);
    }
}
document.onmouseover = function(e) {
for (var i = 0; i < ddfocus_Array.length; i++) {
 
        if (clickedOutsideElement(ddfocus_Array[i].id, e)) ddLostFocus(ddfocus_Array[i]);
    }
}

function clickedOutsideElement(elemId, e) {

    evt = e || window.event

    var theElem = getEventTarget(evt);

    while (theElem != null) {
        if (theElem.id == elemId) {
            
            return false;
        }
        theElem = theElem.parentNode;
      
    }
  
    return true;
}

function getEventTarget(evt) {
    var targ = (evt.target) ? evt.target : evt.srcElement;

    if (targ != null) {
        if (targ.nodeType == 3)
            targ = targ.parentNode;
    }
    return targ;
}

function ddLostFocus(obj) {
    //obj.style.display = "none"
    //obj.style.visibility = "hidden"
    try {
        //hideElementByID(curObjectID);
        chkNavigation()
    }
    catch (Error)
    { }
    updateFocusArray(obj);
}

function updateFocusArray(obj) {
    for (var i = 0; i < ddfocus_Array.length; i++) {
        if (ddfocus_Array[i] == obj) {
            ddfocus_Array.splice(i, 1);
        }
    }
}

    function callNavigation(tabID) {
       // alert(curObjectID)
        if (curObjectID != tabID) {
            hideElementByPartialIds('divPullDown')
            curObjectID = tabID;
            setTimeout('openPullDown()', 100)
            setBlur(document.getElementById('tab' + tabID))
        }
    }

    function openPullDown() {
            //setBlur(document.getElementById('divPullDown' + curObjectID));
            showElementByID('divPullDown' + curObjectID);
           // curObjectID = 'divPullDown' + curObjectID;
        }

    function chkNavigation(tabID) {
    
        if (tabID != curObjectID) {
            hideElementByPartialIds('divPullDown')
            curObjectID = "";
         }
     }

    function resetNavigation() {
        hideElementByPartialIds('divPullDown')
        curObjectID = "";
    }
     

     function showElementByID(element_id) {
    if (document.getElementById && document.getElementById(element_id) && document.getElementById(element_id).style) {
        document.getElementById(element_id).style.visibility = "visible";
        document.getElementById(element_id).style.display = "";
        //document.getElementById(element_id).style.left = "10px";
        setNavPullDownValue("1");
        
    }
}

function hideElementByID(element_id) {
    if (document.getElementById && document.getElementById(element_id) && document.getElementById(element_id).style) {
        document.getElementById(element_id).style.visibility = "hidden";
        document.getElementById(element_id).style.display = "none";
        setNavPullDownValue("0");
    }
}

function hideElementByPartialIds(partialid) {
        var re = new RegExp(partialid, 'g');
        var elems = document.getElementsByTagName('div'), i = 0, el;
        while (el = elems[i++]) {
            if (el.id.match(re)) {
                hideElementByID(el.id);
            }
        }
    }

    function hideAllNavigation() {
    
     }
     /********************* End of Navigation Tabs ************************/
    
     /******************** Footer *************************/
     function resizeCaller() {
         try {
             if (document.getElementById('mainContent')) {
                 var screenHeight = screen.height;
                 var baseHeight = 527;
                 var mainContentHeight = document.getElementById('mainContent').offsetHeight;
                 var curDocumentHeight = baseHeight + mainContentHeight;
                 //alert("curDocumentHeight: " + curDocumentHeight + " < " + "screenHeight: " + screenHeight);
                 //alert(document.getElementById('mainContent').offsetHeight);
                 if (curDocumentHeight < screenHeight) {
                     var tmpHeight = screenHeight - curDocumentHeight;
                     var newHeight = mainContentHeight + tmpHeight;
                     document.getElementById('mainContent').style.height = newHeight + "px";
                 }
                 
             }
         }
         catch (Error)
         {
             alert("Problem " + Error.toString())
         }
     }





/********************************** Questionnaire ************************/
     function onAnswerChosen(answerIndex, submit_bool) {
         var totalAnswers = document.getElementById("totalAnswers").value;
         var correctIndex = document.getElementById("correctIndex").value;
        for (var i = 0; i < totalAnswers; i++) {
            hideElement("radioBtn_" + i)
            
            if (i == answerIndex || i == correctIndex)
                showElement("correctImg_" + i)
        }
        document.getElementById("optionalAnswerTd_" + correctIndex).bgColor = "#e6f0ab"
        if(arguments.length < 2 || submit_bool == true)
            submitAnswer(answerIndex);
    }
    
     
     
 function hideElement(id){
    document.getElementById(id).style.visibility = "hidden";
    document.getElementById(id).style.display="none";
 }
 function showElement(id){
    document.getElementById(id).style.visibility = "visible";
    document.getElementById(id).style.display="";
 }
/********************************** end of  Questionnaire ****************/