
/**********************************************************************
Statistieken teller. De stats zijn in webbeheer uit te lezen.
**********************************************************************/
function pageHit(){
	p = escape(document.location.href);
	rfr = escape(document.referrer);
	if (rfr == "undefined"){ rfr = "";}
	sx = screen.width;
	sy = screen.height;
	sc = (navigator.appName.indexOf("Microsoft") > -1) ? screen.colorDepth : screen.pixelDepth;
	src = 'stats.php?p=' + p + '&rfr=' + rfr + '&sx=' + sx + '&sy=' + sy + '&sc=' + sc;
	src = '<img style="position:absolute;left:-10px;top:-10px;" src="' + src + '" width="1" height="1" border="0" alt="" />';
	document.getElementById('counter').innerHTML = src;
}

window.addEvent('domready', function() {
    pageHit();
});


function overColor(id) {
	document.getElementById(id).className = "hoverstate";
}

function outColor(id) {
	document.getElementById(id).className = "";
}

/**********************************************************************
Deze functie toont of sluit een div

sDivId = naam van de hoofdgroep

De div die open of dicht wordt geklapt heeft als id: sDivId + 'Items' (bijvoorbeeld: hg1Items)
**********************************************************************/
function toggleCat(sDivId){

	if(document.getElementById(sDivId + 'Items')){
		if(document.getElementById(sDivId + 'Items').style.display == 'block'){
			document.getElementById(sDivId + 'Items').style.display = 'none';
			document.getElementById(sDivId + 'Link').className = 'dossierCatOff';
		} else {
			document.getElementById(sDivId + 'Items').style.display = 'block';
			document.getElementById(sDivId + 'Link').className = 'dossierCatOn';
		}
	}
}


function toggleCatThumb(sDivId){
	if(document.getElementById('thumbOff' + sDivId)){
		if(document.getElementById('thumbOn' + sDivId).style.display == 'block'){
			document.getElementById('thumbOn' + sDivId).style.display = 'none';
			document.getElementById('thumbOff' + sDivId).style.display = 'block';
		} else {
			document.getElementById('thumbOn' + sDivId).style.display = 'block';
			document.getElementById('thumbOff' + sDivId).style.display = 'none';
		}
	}
}

/*******************************************
Divje openklappen
*******************************************/
function showMore(id){
	document.getElementById('item'+id).style.display = 'block';
	document.getElementById('link'+id).style.display = 'none';
}

/*******************************************
Agenda functies
*******************************************/


// initCalendar function
function initCalendars() {
    var aCalendars = $(document).getElements('.calendarModule');
    if (aCalendars != null) {
        var i = aCalendars.length;
        while (i--) {
            var oMonthSpan = aCalendars[i].getElements('.month');

            oMonthSpan[0].onmouseover = function () {
                chooseMonthCalendar(this);
            }

            oMonthSpan[0].onmouseout = function () {
                if (window.oTimeoutCalenderChooseMonthPopup !== undefined) {
                    clearTimeout(oTimeoutCalenderChooseMonthPopup);
                }

                oTimeoutCalenderChooseMonthPopup = setTimeout (function () { closeChooseMonthPopup(); }, 500);
            }

            oMonthSpan[0].onclick = function () {
                return false;
            }

            buildCalendar(aCalendars[i]);
        }
    }
}

// buildCalendar function
function buildCalendar(oCalendar) {
    var aDls = oCalendar.getElementsByTagName('dl');

    var i = aDls.length;
    while (i--) {
        var aChildNodes = aDls[i].childNodes;

        var oDt = null;
        var oDd = null;
        for (var y = 0; y < aChildNodes.length; y++) {
            if (aChildNodes[y].tagName == 'DT') {
                oDt = aChildNodes[y];
            } else if (aChildNodes[y].className == 'calendarInfobox') {
                oDd = aChildNodes[y];
            }

            if (oDt != null && oDd != null) {
                oDt.contents = oDd.innerHTML;
                oDt.onmouseover = function () {
                    if (window.oTimeoutCalenderPopup !== undefined) {
                        clearTimeout(oTimeoutCalenderPopup);
                    }
                    closeCalendarPopup();

                    var oBody = document.getElementsByTagName("body").item(0);

                    var oCalendarInfobox = document.createElement("div");
                    oCalendarInfobox.setAttribute('id','calendarInfobox');
                    oCalendarInfobox.innerHTML = this.contents;
                    oBody.appendChild(oCalendarInfobox);

                    var oCalendarInfoboxArrow = document.createElement("div");
                    oCalendarInfoboxArrow.setAttribute('id','calendarInfoboxArrow');
                    oBody.appendChild(oCalendarInfoboxArrow);

                    var aPos = findPos(this);

                    oCalendarInfobox.style.left = aPos[0] - oCalendarInfobox.clientWidth - 18 - 5 + "px";
                    oCalendarInfobox.style.top = aPos[1] - (oCalendarInfobox.clientHeight / 2) + "px";

                    oCalendarInfoboxArrow.style.left = aPos[0] - 5 - 9 + "px";
                    oCalendarInfoboxArrow.style.top = aPos[1] + 4  + "px";

                    oCalendarInfobox.onmouseover = function () {
                        if (window.oTimeoutCalenderPopup !== undefined) {
                            clearTimeout(oTimeoutCalenderPopup);
                        }
                    }

                    oCalendarInfobox.onmouseout = function () {
                        oTimeoutCalenderPopup = setTimeout (function () { closeCalendarPopup(); }, 500);
                    }
                }

                oDt.onmouseout = function () {
                    if (window.oTimeoutCalenderPopup !== undefined) {
                        clearTimeout(oTimeoutCalenderPopup);
                    }

                    oTimeoutCalenderPopup = setTimeout (function () { closeCalendarPopup(); }, 500);
                }

                oDt.onclick = function () {
                    return false;
                }

                // Reset
                oDt = null;
                oDd = null;
            }
        }
    }
}

// closeCalendarPopup function
function closeCalendarPopup () {
    var oBody = document.getElementsByTagName("body").item(0);

    var oCalendarInfobox = document.getElementById('calendarInfobox');

    if (!oCalendarInfobox) {
        return false;
    }

    var oCalendarInfoboxArrow = document.getElementById('calendarInfoboxArrow');

    oBody.removeChild(oCalendarInfobox);
    oBody.removeChild(oCalendarInfoboxArrow);
}

// chooseMonthCalendar function
function chooseMonthCalendar (oMonthSpan) {
    if (window.oTimeoutCalenderChooseMonthPopup !== undefined) {
        clearTimeout(oTimeoutCalenderChooseMonthPopup);
    }
    closeChooseMonthPopup();

    var oBody = document.getElementsByTagName("body").item(0);

    var oCalendarMonthBox = document.createElement("div");
    oCalendarMonthBox.setAttribute('id','calendarMonthBox');
    oCalendarMonthBox.innerHTML = oMonthSpan.lastChild.innerHTML;
    oCalendarMonthBox.style.display = "block";

    oBody.appendChild(oCalendarMonthBox);

    var aPos = findPos(oMonthSpan);

    oCalendarMonthBox.style.left = aPos[0] - 22 + "px";
    oCalendarMonthBox.style.top = aPos[1] + 13 + "px";

    oCalendarMonthBox.onmouseover = function () {
        if (window.oTimeoutCalenderChooseMonthPopup !== undefined) {
            clearTimeout(oTimeoutCalenderChooseMonthPopup);
        }
    }

    oCalendarMonthBox.onmouseout = function () {
        oTimeoutCalenderChooseMonthPopup = setTimeout (function () { closeChooseMonthPopup(); }, 500);
    }

    oMonthSpan.onclick = null;
}

// closeChooseMonthPopup function
function closeChooseMonthPopup () {
    var oBody = document.getElementsByTagName("body").item(0);

    var oCalendarMonthBox = document.getElementById('calendarMonthBox');

    if (!oCalendarMonthBox) {
        return false;
    }

    oBody.removeChild(oCalendarMonthBox);
}

// findPos function
function findPos(obj) {
    var curleft = curtop = 0;

    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }

    return [curleft,curtop];
}
