﻿
function windowOnload() {
    pageLoadFinished = true;
    RunOnLoadScripts();
}

var OnLoadScripts = [];
var scriptCount = 0;

window.onload = windowOnload;
var pageLoadFinished = false;

function RunOnLoadScripts() {
    for (var i = 0; i < OnLoadScripts.length; i++) {
        eval(OnLoadScripts[i]);
    }
}
        function swapClass(e, newClass) {

            e.className = newClass;
        }
        function cleardefault(clientID, defaultValue) {

            var e = document.getElementById(clientID);
            if (e.value == defaultValue) {
                e.value = "";
            }
            e.className = "searchtextactive";
        }
        function setdefault(clientID, defaultValue) {
            var e = document.getElementById(clientID);
            if (e.value == "") {
                e.value = defaultValue;
                e.className = "searchtext";
            }
        }
  
function AddOnloadScript(s, first) {
    if (first)
        OnLoadScripts.unshift(s);
    else
        OnLoadScripts.push(s);
}

function showHide(s) {
    var q = document.getElementById(s);
    if (q.style.display == '' || q.style.display == 'block')
        q.style.display = 'none';
    else
        q.style.display = '';
}

function GetQueryStringValue(name) {
    var url = window.location.toString();
    var search = name + "=";

    if (url.indexOf("?") > 0 & url.indexOf(search) > 0) {
        url = url.substring(url.indexOf(search) + search.length, url.length);
        if (url.indexOf("&") > -1) {
            url = url.substring(0, url.indexOf("&"));
        }

        return url;

    }
    else
        return "";

}

function SetAnchorOnloadScript(name, script) {
    //alert(window.location.hash.substring(1));
    if (window.location.hash.substring(1) == name)
        AddOnloadScript(script);
}



/*topics javascript*/

function setSelectedTopic(senderid, q) {

    //try {
    var header = document.getElementById("topics_headers_container");
    var topic_headers = header.getElementsByTagName("div");
    var content = document.getElementById("topics_contents_container");
    var topic_contents = content.childNodes;

    var positions = new Array("left", "center", "right");

    // turn off all topic tabs
    for (i = 0; i < topic_headers.length; i++) {
        if (topic_headers[i].className.indexOf("selected") > -1) {
            for (j = 0; j < positions.length; j++) {
                if (topic_headers[i].className.indexOf(positions[j]) > -1) {
                    topic_headers[i].className = "topic_header_" + positions[j];
                }
            }
        }
    }

    //hide selected content
    for (i = 0; i < topic_contents.length; i++) {
        topic_contents[i].className = "topic_content";
        //break;
    }

    // select sender tab 
    var child = document.getElementById(senderid).getElementsByTagName("div");
    for (i = 0; i < child.length; i++) {
        for (j = 0; j < positions.length; j++) {
            if (child[i].className.indexOf(positions[j]) > -1) {
                child[i].className = "topic_header_" + positions[j] + "_selected";
            }
        }
    }

    //now reappear proper content
    //alert(q);
    document.getElementById(q).className = "topic_content_selected";
    //    }
    //    catch (e) {
    //        alert(e.value);
    //    }
}

function setSelectedSubTopicEx(sender, container, q) {
    //try 
    //{    
    var contents = document.getElementById(container).getElementsByTagName("div");
    var headers = sender.parentNode.parentNode.getElementsByTagName("div");

    // hide all headers
    for (var i = 0; i < headers.length; i++) {
        if (headers[i].className.indexOf("subtopic_header") > -1)
            headers[i].className = "subtopic_header";
    }

    //hide all contents
    for (var i = 0; i < contents.length; i++) {
        if (contents[i].id.indexOf("_subtopiccontent") > -1) {
            //alert(contents[i].id);
            contents[i].className = "subtopic_content";
        }
    }

    // show selected
    sender.parentNode.className = "subtopic_header_selected";
    document.getElementById(q).className = "subtopic_content_selected";

    //}
    //catch (e) {
    //alert("setSelectedSubTopicEx: " + e.value);
    //}
}
var g_Modal = null;

function swapImageSRC(controlID1, newSrc) {
    var imageSRC = document.getElementById(controlID1);

    if (imageSRC != null)
        imageSRC.src = newSrc;

    return true;
}
function switchClass(sender, over) {

    try {
        var divs = sender.getElementsByTagName("div");
        var positions = new Array("tableft", "tabcenter", "tabright", "tabtext");
        if (divs[0].className.indexOf("selected") < 0) {
            for (i = 0; i < divs.length; i++) {
                for (j = 0; j < positions.length; j++) {
                    if (divs[i].className.indexOf(positions[j]) > -1) {
                        if (over == 'true') {
                            divs[i].className = positions[j] + "nav" + "hover";
                        }
                        else {
                            divs[i].className = positions[j] + "nav";
                        }
                    }
                }
            }
        }

    }
    catch (e) {
        alert("Hover Failed: " + e.value);
    }
}
function switchcontentClass(sender, over) {

    try {
        var divs = sender.getElementsByTagName("div");
        var positions = new Array("contentleft", "contentcenter", "contentright", "contenttext");
        if (divs[0].className.indexOf("selected") < 0) {
            for (i = 0; i < divs.length; i++) {
                for (j = 0; j < positions.length; j++) {
                    if (divs[i].className.indexOf(positions[j]) > -1) {
                        if (over == 'true') {
                            divs[i].className = positions[j] + "nav" + "hover";
                        }
                        else {
                            divs[i].className = positions[j] + "nav";
                        }
                    }
                }
            }
        }

    }
    catch (e) {
        alert("Hover Failed: " + e.value);
    }
}

function goToLink(link) {
    try {
        if (link != "" || link != null)
            document.location.href = link;
    }
    catch (e) {
        alert("goToLink: " + e.value);
    }
}