//show a popup
function showPopup(title, content, centerEl)
{
	setInnerHTML('popup_title',	title);
	setInnerHTML('popup_content',content);
	
	showEl('popup');
	showEl('popupfader');
	
	if(centerEl == true)
	{
		centerElement('popupfader');
		centerElement('popup');
		
		updateToPageHeight('popupfader');
		updateToPageHeight('popup');
	}

	hideSelectBoxen(1);
	$('popupfader').style.height = $('popup').offsetHeight+"px";
	$('popupfader').style.width = $('popup').offsetWidth+"px";
}

//et an attribute for an element with a value
function setElAttrib(elID, elAttrib, elValue)
{
	switch(elAttrib.toUpperCase())
	{
		case "SRC":
			document.getElementById(elID).src = elValue;
		break;
		
		case "CLASS":
			document.getElementById(elID).className = elValue;
		break;
		
		case "HREF":
			document.getElementById(elID).href = elValue;
		break;
	}
}

//show an element
function showEl(elID)
{
	$(elID).style.display = "block";
}

//hide an element
function hideEl(elID)
{
	hideSelectBoxen();
	$(elID).style.display = "none";
}

//check if a div is visible
function isVisible(elID)
{
	if($(elID).style.display == "block" || $(elID).style.visibility == "visble")
		return true;
	else
		return false;
}

/**
Function to show or hide a div
*/
function showOrHide(divID, status)
{
	if($(divID))
	{
		if(status == 1){
			showEl(divID);
		}
		
		if(status == 0){
			hideEl(divID);
		}
	}
}

//set innerhtml of an element with a value
function setInnerHTML(elID, value)
{
	if($(elID)){
		$(elID).innerHTML = value;
	}
}

//set's the position of the div in the center of a page
function centerElement(elID)
{

	elWidth = $(elID).offsetWidth;

	var marginLeft = Math.round(elWidth /2);

	$(elID).style.left 			= "50%";
	$(elID).style.width 		= elWidth+"px";
	$(elID).style.marginLeft 	= "-"+marginLeft+"px";
}

/**
 * Function to do an ajaxrequest to a URI, which shows the result in a popup
 */
function popupAjaxRequest(sURI)
{
	new Ajax.Request(sURI,
		{
			method:'get',
			asynchronous:false,
			onSuccess:function(response)
			{
				/* Work-around specific for Wonion:
				*	if a zigPopup is called from another zigPopup, the semi-transparent
				*	background layer is dubble created. In this way we check and eventually
				*	remove the already created background-layer.
				*/
				if($('popupLayerBg'))
				{
					$('popupLayerBg').remove();
				}
				var oInfo = { title: '', content: response.responseText };
				showAlertPopup(oInfo);
			},
			onFailure:function(response)
			{
				var oInfo = { title: 'Systeemfout', content: 'Request is mislukt met code: ' + response.status };
				showAlertPopup(oInfo);
			}
		}
	);
}

function updateToPageHeight(elID)
{
	var currentTop = 150;

	var browser = getIEBrowser();
	
	if(browser)
	{
		if(browser == 6){
			scrollTop = document.body.scrollTop;
		}
		else{
			scrollTop = document.documentElement.scrollTop;
		}
	}
	else{
		scrollTop = window.pageYOffset;
	}
	
	var newTop = currentTop + scrollTop;

	$(elID).style.top = newTop + 'px';
}

function getIEBrowser()
{
	var result;
	var isIE = (navigator.appName=="Microsoft Internet Explorer");
	
	if(isIE) 
	{
		var IEversion = navigator.appVersion;
		result = parseInt(IEversion.substr(IEversion.indexOf("MSIE")+4));
	} 
	else 
	{
		result = false;
	}
	return result;
}

/**
*	Called during the building of the navigation menu, this function resizes the margin left
*	of the first colunmn of the subsection to let shift all items to the left.
*	@param integer iInt Section position to analize [1, 2, 3, 4]
*/
function readaptColumnsMenu(iInt)
{
	var aItems = $$( 'li.theme' + iInt + ' div.dropdown div.column');
	
	var iTotCols = aItems.length;
	
	if(iInt > 1 && iTotCols < 5)
	{
		// The first section doesn't need any operation because it disposes of all the needed space
		if( iTotCols > (4 - iInt + 1) )
		{
			var sStrID		= 'column_first' + iInt;
			var oObj = $( sStrID );
			var iOrigMargLx = 206 * (iInt-1);
			
			// Calculate howmany columns shift to the left
			var DeltaCols = iTotCols - (4 - iInt + 1);
			
			sOrigMargLx = (iOrigMargLx - (DeltaCols*206) );
			oObj.style.marginLeft = sOrigMargLx + 'px';
		}
	}
}
