/****************************************
	Overlay aanmaken
****************************************/
function showPrintOverlay(pData) {
    var version = parseFloat(vIE());

    if (version == '6') {
        window.open(pData, 'printWindow', 'scrollbars=yes,toolbar=no,location=no');
    } else {
        showOverlay(pData);
    }
}

function vIE() { return (navigator.appName == 'Microsoft Internet Explorer') ? parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]) : -1; }

function showOverlay(pData)
{
	// afmetingen div
	var divWidth = 600;
	var divHeight = 400;
	
	//divjes aanmaken
	createDiv('overlayContainer'); // achtergrond
	createDiv('overlayDataContainer'); // container div
	createDiv('overlayData', 'overlayDataContainer'); // data div maken binnen container div
	
	// hide select boxes
	hideAllByTag('SELECT');
	
	// Toetsenbord navigatie aanzetten 
	enableKeyboardNav();
	
		// variabelen
		var oCont = document.getElementById('overlayContainer'); // achtergrond
		var oData = document.getElementById('overlayDataContainer'); // main container
		var oShow = document.getElementById('overlayData'); // te tonen data
		
		// scherm informatie
		var pos = getPageScroll();
		var screen = getPageSize();

		// set container 
		oCont.style.visibility = "visible";
		
		//width fixen voor FF
		if(!document.all && (document.body.clientHeight > screen[3]))
			oCont.style.width = (screen[2] - 16) + "px";
		else
			oCont.style.width = screen[2] + "px";
		
		// height fixen voor IE
		if(document.all && (document.body.clientHeight > screen[3]))
			oCont.style.height = screen[1] + 30 + "px";
		else
			oCont.style.height = screen[1] + "px";
		
		// Data kader tonen
		var topSelect = Math.round(((screen[3] - divHeight) / 2 + pos[1]));
		var leftSelect = Math.round((screen[0] - divWidth) / 2);

		oData.style.top = topSelect - 40 + "px";
		oData.style.left = leftSelect + "px";
		oData.style.visibility = "visible";
		
		// divje + content plaatsen
		if(pData.substring(0,4) == 'http' || pData.substring(0,5) == 'popup') // data in iframe tonen
		{
			//scrollen van data div tegen gaan
			oShow.style.overflow = 'hidden';
			
			// spaties fixen in url
			pData = pData.replace(new RegExp(/%20/g),' ');
			
			// iframe aanmaken
			iFrame = document.createElement('IFRAME'); 
			iFrame.setAttribute('src', pData);
			if (pData.indexOf('scrolling=no')>0)
			    iFrame.setAttribute('scrolling', 'no');
			else
			    iFrame.setAttribute('scrolling', 'auto');
			iFrame.setAttribute('frameborder', 'no');
			iFrame.style.width = divWidth + 'px'; 
			iFrame.style.height = divHeight + 'px'; 
			oShow.appendChild(iFrame); 
		}else{ // string is waarschijnlijk content, dus tonen we het direct in de div
			oShow.innerHTML = pData;
			oShow.style.overflow = 'auto';
		}
		
		// aangemaakte content tonen
		oShow.style.visibility = "visible";
		
		// close button toevoegen aan container
		oData.innerHTML = oData.innerHTML + '<div id="divClose"><img src="../Styles/Default/include/close.gif" width="26" height="26" onclick="hideOverlay();return false;" /></div>';
}

/****************************************
	Overlay verwijderen
****************************************/
function hideOverlay()
{
	// show select boxes
	showAllByTag('SELECT');
	
	// Toetsenbord navigatie uitzetten 
	disableKeyboardNav();
	
	// overlay verstoppen
	HideSelectionView();
}


/****************************************
	Divje aanmaken
****************************************/
function createDiv(div, masterDiv)
{
	if(document.getElementById(div) == null) // data divje aanmaken
	{
		if(masterDiv == undefined)
			var d = document.getElementsByTagName('body')[0];
		else
			var d = document.getElementById(masterDiv);

		divContainer = document.createElement("DIV");
		divContainer.id = div;	
		divContainer.style.visibility = 'hidden';
		divContainer.innerHTML = '';
		
		d.appendChild(divContainer);
	}else{ // data divje legen
		document.getElementById(div).innerHTML = '';
	}
}

/****************************************************************
	Elementen verstoppen / tonen
	Bron: http://www.bytemycode.com/snippets/snippet/506/
****************************************************************/
function showAllByTag(tagName)
{
	var elements = document.getElementsByTagName(tagName);
	var i = 0;
	
	while (i < elements.length) 
	{
		elements[i].style.display = 'block';
		i++;
	}
}
function hideAllByTag(tagName)
{
	var elements = document.getElementsByTagName(tagName);
	var i = 0;
	while (i < elements.length)
	{
		elements[i].style.display = 'none';
		i++;
	}
}

/************************************************************************************
	Toetsen aanslagen 'bekijken'
	Originele code afkomstig van http://huddletogether.com/projects/lightbox2
************************************************************************************/

// toetsenbord navigatie aanzetten
function enableKeyboardNav()
{
	document.onkeydown = this.keyboardAction; 
}

// toetsenbord navigatie uitzetten 
function disableKeyboardNav()
{
	document.onkeydown = '';
}

// Kijken naar toetsenbord aanslagen 
function keyboardAction(e)
{
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // other
		keycode = e.which;
	}

	// code omzetten naar key 
	//key = String.fromCharCode(keycode).toLowerCase();
	switch(keycode)
	{
		case 27: // ESC 
			HideSelectionView();
		break;
	}
}

function HideSelectionView()
{
	var oData = document.getElementById('overlayDataContainer');
	
	if(oData != null)
	{
		oData.innerHTML = '';
		oData.style.visibility = 'hidden';
		document.getElementById('overlayContainer').style.visibility = 'hidden';
	}
	
	// Toetsenbord navigatie uitzetten 
	disableKeyboardNav();
	
	// verstopte items tonen
	showAllByTag('SELECT')
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll()
{

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
