//*************************************************************************
//***	
//*************************************************************************

$(document).ready(function() {

    //tips en venn
    $("#Tips").click(function() {
        $("#TipFrame").toggle();
    });

    //menu stuff
    $(".ExpandBtn").click(function() {
        $(this).parent().find("ul").toggle(0, function() {
            $(this).parent().find(".ExpandBtn").toggleClass("Expand");
            $(this).parent().find(".ExpandBtn").toggleClass("Collapse");
        }
        );

        if ($(this).hasClass("Collapse")) {
            $(this).parent().addClass("Mid");
        } else {
            $(this).parent().removeClass();
        }

    });

    // calendar popup
    $(".sml").mouseover(function() {
        if ($(this).find(".PopupContainer").length) {
            var bHeight = $("#CalendarBox", window.parent.document).height();
            var content = $(this).find(".PopupContent").html();
            var popup = $("#Popup", window.parent.document);
            var xpos = $(this).offset().left - 157;
            var ypos = $(this).offset().top;
            ypos = bHeight - ypos - 35;
            popup.find("#Content").html(content);
            popup.css({ left: xpos + "px", bottom: ypos + "px" });
            popup.show();
        }
    });

    $(".sml").mouseout(function() {
        var popup = $("#Popup", window.parent.document);
        popup.hide();
    });


});


//*** GLOBAL VARIABEL
var blnDOM = false;

//*** FUNCTIONS	
//Advanced dthml check
if (document.getElementById && document.createElement) {
    blnDOM = true;
}

//default image switch
function fjsImgSwitch(id, imgsrc) {
    if (blnDOM == true) {
        if (document.getElementById(item)) {
            //Switch image	
            document.getElementById(item).src = imgsrc;
        }
    }
}

//Tool, strips away all path info
function fjsGetFileName(varName) {
    var re = /^.*\/(\S*\.\S*)$/;
    var tmp = new String(varName);
    tmp = tmp.match(re)[1];

    return tmp;
}

//Swap classes for any item
function fjsSwapClass(strId, class1, class2) {
    if (blnDOM == true) {
        //Check if element exists
        if (document.getElementById(strId)) {
            //Switch class
            if (document.getElementById(strId).className == class1) {
                document.getElementById(strId).className = class2;
            }
            else if (document.getElementById(strId).className == class2) {
                document.getElementById(strId).className = class1;
            }
        }
    }
}

//Change class for any item
function fjsChangeClass(strId, class1) {
    if (blnDOM == true) {
        //Check if element exists
        if (document.getElementById(strId)) {
            //Change class
            document.getElementById(strId).className = class1;
        }
    }
}

//Clear input boxes for default data 
function fjsClearBox(e) {
    e.value = "";
    e.focus();
}

//When IE creates a new element it gives the new element about 84 attributes inherited from IE's default DTD. Oh what fun.
//And when you try to change an attribute like "class", it actually creates a new attribute so you end up with 2 "class" attributes.
//So, this function checks your node for a given attribute, if it exists then it changes the attribute value with the one given.
//If the attribute doesnt exist, it creates a new one and sets its value.
function fjsToolBox_setAttribute(oNode, strAttribute, strValue) {
    if (oNode.getAttributeNode(strAttribute)) {
        for (var i = 0; i < oNode.attributes.length; i++) {
            var attrName = oNode.attributes[i].name.toUpperCase();
            if (attrName == strAttribute.toUpperCase()) {
                oNode.attributes[i].value = strValue;
            }
        }
    }
    else {
        //create a new attribute 
        oNode.setAttribute(strAttribute, strValue);
    }
}


//retrieves content from text nodes
function fjsToolBox_GetTextNodeContent(n) {
    var s = '';
    var children = n.childNodes;
    for (var i = 0; i < children.length; i++) {
        var child = children[i];
        if (child.nodeType == 3 /*Node.TEXT_NODE*/) {
            s += child.data;
        }
        else {
            s += getTextContent(child);
        }
    }
    return s;
}	

