﻿/*
This function is called at the base of the page it takes two paramaters
classToHide parameter: the name of the class which if a div element possesses will be hidden. It does this by calling the hide elements function.
shownElement paramter: the id of the div element you wish to show, or the array of id elements you wish to show.
*/
function defineDivSet()
{

}

function DefaultView(classToHide, shownElement){
    
    HideElements(classToHide);
    this.showElements = showElements;
    this.setTheClassToHide = classToHide;
    this.showElements(shownElement);
}


//This function hides div elements, it does this by taking in a parameter the parameter is the name of the class which the divs have.
function HideElements(classToHide) { 
    var documentDivs = document.getElementsByTagName("div");
    
    for (i = 0; i < documentDivs.length; i++){
        var div = documentDivs[i];
        if(div.className && (' ' + div.className + ' ').indexOf(' ' + classToHide + ' ') != -1)
        {
            div.style.display = "none";   
        }
    }
    
}

//This function takes in a parameter that parameter is used to determine which div elements you wish to show
function showElements(shownElement)
{
    
    //Hides the divs based on the global variable set earlier by the DefaultView function
    HideElements(this.setTheClassToHide);
    //Excecutes this code if the parameter is an array(i.e multiple divs to be shown)
    if(typeof shownElement == 'object')
    {
        for (i = 0; i < shownElement.length; i++)
        {
            element = shownElement[i];
            if(document.getElementById(element) != undefined)
            {
                document.getElementById(element).style.display = "block";
            }
        }
    }
    //excecutes this code if its just a single div, if the id does not exist then code will not excecute.
    else if(document.getElementById(shownElement) != undefined)
    {
        document.getElementById(shownElement).style.display = "block";
    }
}
function DisplayHeading(headingID, headingText)
{
    if(document.getElementById(headingID) != undefined)
    {
        document.getElementById(headingID).innerHTML = headingText;
    }
}
/*
function findTarget(e)
{
    var target;
    if(window.event && window.event.srcElement) {
        target = window.event.srcElement;
    }
    else if (e && e.target) {
        target = e.target;
    }
    if(!target) {
        return null;
    }
    while (target != document.getElementById('tabholder') && target.nodeName.toLowerCase() != 'a') {
        target = target.parentNode;
    }
    if(target.nodeName.toLowerCase() != 'a'){
        return null;
    }
    return target;
}
function onclick(e)
{
    var target = findTarget(e);
    if(!target) return;
    //alert(target.innerHTML);

}
*/