
onload = function(){
	pageHit();
	getNewWindowLinks();
	initFillColumns();
}

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;  
  
}


function openInNewWindow(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	// Abort if a modifier key is pressed
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {
		// Change "_blank" to something like "newWindow" to load all links in the same new window
	    var newWindow = window.open(this.getAttribute('href'), '_blank');
		if (newWindow) {
			if (newWindow.focus) {
				newWindow.focus();
			}
			return false;
		}
		return true;
	}
}

function getNewWindowLinks() {
	// Check that the browser is DOM compliant
	if (document.getElementById && document.createElement && document.appendChild) {
		// Change this to the text you want to use to alert the user that a new window will be opened
		var strNewWindowAlert = "";
		// Find all links
		var links = document.getElementsByTagName('a');
		var objWarningText;
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			// Find all links with a class name of "extLink"
			if (/\bextLink\b/.test(link.className)) {
				// Create an em element containing the new window warning text and insert it after the link text
				objWarningText = document.createElement("em");
				objWarningText.appendChild(document.createTextNode(strNewWindowAlert));
				link.appendChild(objWarningText);
				link.onclick = openInNewWindow;
			}
		}
		objWarningText = null;
	}
}

function openSearch(s) {

	document.getElementById('searchLink').style.display = 'none';
	
	switch(s) {
		case 'simple':
			document.getElementById('extendedSearch').style.display = 'none';
			document.getElementById('simpleSearch').style.display = 'block';
			break;
		case 'extended':
			document.getElementById('simpleSearch').style.display = 'none';
			document.getElementById('extendedSearch').style.display = 'block';
			break;
	}

}


function clearBerichtVeld(sBericht) {

	if(document.getElementById('bericht').value == sBericht) 
		document.getElementById('bericht').value = '';

}


function initBerichtVeld(sBericht) {

	if(document.getElementById('bericht').value == '') {
		document.getElementById('bericht').value = sBericht;
		
	}

}


function initFillColumns() {

	if(document.getElementById('mainContainer')) {
	
		var iTotalHeight = document.getElementById('mainContainer').offsetHeight;
		//console.log('iHeight : ', iTotalHeight);
		
		// Basis template
		if(document.getElementById('leftColumn') && document.getElementById('pageContent') && document.getElementById('rightColumn'))
			fillColumns(iTotalHeight, 'leftColumn', 'rightColumn', 'pageContent');
			
		// Basis template
		if(document.getElementById('leftColumn') && document.getElementById('pageContent') && !document.getElementById('rightColumn'))
			fillColumnsAlt(iTotalHeight, 'leftColumn', 'pageContent');
		
		// Home template
		else if(document.getElementById('intro') && document.getElementById('middleBanners') && document.getElementById('rightColumn'))
			fillColumns(iTotalHeight, 'intro', 'rightColumn', 'middleBanners');
			
	}	

}



function fillColumns(iTotalHeight, sLeftId, sRightId, sMiddleId) {

	iLeftHeight = document.getElementById(sLeftId).offsetHeight;
	iRightHeight = document.getElementById(sRightId).offsetHeight;
	iMiddleHeight = document.getElementById(sMiddleId).offsetHeight;
	
	if(iLeftHeight < iRightHeight || iLeftHeight < iMiddleHeight) {
		// Left filler
		iFillHeightLeft = iTotalHeight - iLeftHeight - 6;
		addElement(sLeftId, iFillHeightLeft);
	}
	
	if(iRightHeight < iLeftHeight || iRightHeight < iMiddleHeight) {
		// Right filler
		iFillHeightRight = iTotalHeight - iRightHeight - 6;
		addElement(sRightId, iFillHeightRight);
	}
	
	if(iMiddleHeight < iLeftHeight || iMiddleHeight < iRightHeight) {
		// Right filler
		iFillHeightMiddle = iTotalHeight - iMiddleHeight - 6;
		addElement(sMiddleId, iFillHeightMiddle);
	}

}


function fillColumnsAlt(iTotalHeight, sLeftId, sMiddleId) {

	iLeftHeight = document.getElementById(sLeftId).offsetHeight;
	iMiddleHeight = document.getElementById(sMiddleId).offsetHeight;
	
	if(iLeftHeight < iMiddleHeight) {
		// Left filler
		iFillHeightLeft = iTotalHeight - iLeftHeight - 6;
		addElement(sLeftId, iFillHeightLeft);
	}
	
	if(iMiddleHeight < iLeftHeight) {
		// Right filler
		iFillHeightMiddle = iTotalHeight - iMiddleHeight - 6;
		addElement(sMiddleId, iFillHeightMiddle);
	}

}


function addElement(sParent, iHeight) {
	
	var elParent = document.getElementById(sParent);

	var elFiller = document.createElement('div');
	elFiller.setAttribute('class','dBC');
	elFiller.setAttribute('className','dBC');
	elFiller.style.marginTop = '4px';
	elFiller.style.height = iHeight - 4 +'px';
	
	elParent.appendChild(elFiller);
	
}


function popUpWin(url, width, height, name) {
	width = width || 640;
	height = height || 520;
	name = name || 'leiden_popup';
	popupwin = window.open(url, name, 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1,width='+width+',height='+height);
	if (window.focus) {popupwin.focus()}
}


/*******************************************
Drie functie om cookies te gebruiken binnen javascript
********************************************/
function createCookie(name,value,days){
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}


