// specifieke functies

function initPage() {
    startList("root");
    TMLComenom("root", "li");
}

startList = function(elId) {
    if (document.all && document.getElementById) {
        navRoot = document.getElementById(elId);
        if (navRoot) {
            listElements = navRoot.getElementsByTagName("LI");
            for (i = 0; i < listElements.length; i++) {
                node = listElements[i];
                node.onmouseover = function() {
                    this.className += " over";
                }
                node.onmouseout = function() {
                    this.className = this.className.replace(" over", "");
                }
            }
        }
    }
}
//window.onload = initPage;



// TMLC library functies

TMLComenom = function(id, tag) {
    if (document.getElementById) {
        var even = false;
        var root = document.getElementById(id);
        if (!root) return;
        
        var childs = root.childNodes;
        
        for (var i = 0; i < childs.length; i++) {
            var node = childs[i];
            if (String(node.tagName).toUpperCase() == tag.toUpperCase()) {
                if (even) node.className += " even";
                else node.className += " odd";
                even = !even;
            }
        }
    }
}



function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, true);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}

function showLayer() {
    if (document.getElementById) { // IE5 & NN6
        res = showLayer.arguments;
        for (i = 0; i < res.length; i++) {
            if (document.getElementById(res[i])) document.getElementById(res[i]).style.visibility = "visible";
        }
    }
}

function hideLayer() {
    if (document.getElementById) { // IE5 & NN6
        res = hideLayer.arguments;
        for (i = 0; i < res.length; i++) {
            if (document.getElementById(res[i])) document.getElementById(res[i]).style.visibility = "hidden";
        }
    }
}

function displayBlock() {
    if (document.getElementById) { // IE5 & NN6
        res = displayBlock.arguments;
        for (i = 0; i < res.length; i++) {
            document.getElementById(res[i]).style.display = "block";
        }
    }
}

function displayInline() {
    if (document.getElementById) { // IE5 & NN6
        res = displayInline.arguments;
        for (i = 0; i < res.length; i++) {
            document.getElementById(res[i]).style.display = "inline";
        }
    }
}

function displayNone() {
    if (document.getElementById) { // IE5 & NN6
        res = displayNone.arguments;
        for (i = 0; i < res.length; i++) {
            document.getElementById(res[i]).style.display = "none";
        }
    }
}

function checkEmail(pValue) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(pValue)) {
        return (true)
    }
    return (false)
}

function initExternalLinks() {
    // Fetch all the a elements in the document.
    var links = document.getElementsByTagName('a');
    
    // Loop through the a elements in reverse order
    // for speed.
    for (var i = links.length; i != 0; i--) {
    
        // Pull out the element for this iteration.
        var a = links[i - 1];
        
        // If the element doesn't have an href, skip it.
        if (!a.href) continue;
        
        if ((a.href.indexOf("http://") == 0) && (a.href.indexOf("http://" + document.domain + "/") != 0)) {
            a.onclick = PopWin;
        }
    }
}

function PopWin(e) {
    // Accommodate IE's non-standard event handling.
    if (!e) var e = window.event;
    
    var a = e.target ? e.target : e.srcElement;
    
    if (a.tagName.toLowerCase() != "a") {
        a = YAHOO.util.Dom.getAncestorByTagName(a, "a");
    }
    
    // Open a new window with the link's href.
    var newwin = window.open(a.href);
    
    // The thought is that if the new window didn't
    // (popups blocked or whatever) we want to return
    // true so the link is follow normally. Not sure
    // if this works, but it doesn't seem to hinder.
    return !newwin;
}

YAHOO.util.Event.on(window, "load", initExternalLinks);

