/* get element */
function el(sId)
{
	if(document.getElementById(sId))
	{
		return document.getElementById(sId);
	}
	return null;
}

/* show a popup */
function showPopup(sTitle, sContent, bCenterEl)
{
	if(!el('popup_title') || !el('popup_content') || !el('popup') || !el('popupfader'))
	{
		//alert('showPopup: Conditions are NOT satsified!!! ');
		return;
	}
	
	setInnerHTML('popup_title',	sTitle);	
	setInnerHTML('popup_content', sContent);
	
	showEl('popup');
	showEl('popupfader');
	
	if(bCenterEl == true)
	{
		centerElement('popupfader');
		centerElement('popup');
		
		updateToPageHeight('popupfader');
		updateToPageHeight('popup');
	}

	hideSelectBoxen(1);
	el('popupfader').style.height = el('popup').offsetHeight+"px";
	el('popupfader').style.width = el('popup').offsetWidth+"px";
}

/* hide the popup */
function hidePopup()
{
	hideEl('popupfader');
	hideEl('popup');
}

/* set an attribute for an element with a value */
function setElAttrib(sId, sElAttrib, sElValue)
{
	if(!el(sId))
	{
		return;
	}	

	switch(sElAttrib.toUpperCase())
	{
		case "SRC":
			document.getElementById(sId).src = sElValue;
		break;
		
		case "CLASS":
			document.getElementById(sId).className = sElValue;
		break;
		
		case "HREF":
			document.getElementById(sId).href = sElValue;
		break;
	}
}

/* show an element */ 
function showEl(sId)
{
	if(el(sId))
	{
		el(sId).style.display = "block";
	}	
}

/* hide an element */ 
function hideEl(sId)
{
	if(el(sId))
	{
		el(sId).style.display = "none";
	}	
	hideSelectBoxen();
}

/* check if a div is visible */ 
function isVisible(sId)
{
	if( el(sId) && (el(sId).style.display == "block" || el(sId).style.visibility == "visible") )
	{
		return true;
	}
	else
	{
		return false;
	}
}

/**
Function to show or hide a div
*/
function showOrHide(sId, iShow)
{
	if(el(sId))
	{
		if(iShow == 1)
		{
			showEl(sId);
		}
		else
		{
			hideEl(sId);
		}
	}
}

/* set innerhtml of an element with a value */
function setInnerHTML(sId, sValue)
{
	if(el(sId))
	{
		el(sId).innerHTML = sValue;
	}
}

/* set's the position of the div in the center of a page */
function centerElement(sId)
{
	if(!el(sId))
	{
		return;
	}

	var iElWidth = el(sId).offsetWidth;
	var iMarginLeft = Math.round(iElWidth /2);

	el(sId).style.left 			= "50%";
	el(sId).style.width 		= iElWidth+"px";
	el(sId).style.marginLeft 	= "-"+iMarginLeft+"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(oRequestResult)
			{
				var sResponse = oRequestResult.responseText;

				//request is gelukt
				showPopup('', sResponse, true);
			},
			onFailure:function(oRequestResult)
			{
				//request is mislukt
				showPopup('Systeemfout','Request is mislukt met code: ' + oRequestResult.status, true);
			}
		}
	);
	
}

function updateToPageHeight(sId)
{
	if(!el(sId))
	{
		return;
	}

	var iCurrentTop = 150;
	var browser = getIEBrowser();
	
	if(browser)
	{
		if(browser == 6)
		{
			iScrollTop = document.body.scrollTop;
		}
		else
		{
			iScrollTop = document.documentElement.scrollTop;
		}
	}
	else
	{
		iScrollTop = window.pageYOffset;
	}
	
	var iNewTop = iCurrentTop + iScrollTop;
	el(sId).style.top = iNewTop + 'px';
}

function getIEBrowser()
{
	var mResult;
	var bIsIE = (navigator.appName=="Microsoft Internet Explorer");
	
	if(bIsIE) 
	{
		var sIEversion = navigator.appVersion;
		mResult = parseInt(sIEversion.substr(sIEversion.indexOf("MSIE")+4));
	} 
	else 
	{
		mResult = false;
	}
	return mResult;
}

 /**
  * Functie om de selectboxen te hidden als de toplayer er is.
  * Alleen nodig in IE omdat daar de selectboxen altijd ontop zitten.
  *
  */

function hideSelectBoxen(iHide)
{
	//Alleen in IE6 komen de select boxen boven de layer te staan dus alleen daar verwijderen en weer tonen
	if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match("^.*?(MSIE 6.0).*?$"))
	{
		var aTagSelect = document.getElementsByTagName('select');
		for(i=0; i<aTagSelect.length; i++)
		{
			if(iHide == 1)
			{
				aTagSelect[i].style.visibility = 'hidden';
			}
			else
			{
				aTagSelect[i].style.visibility = 'visible';
			}
		}		
	}
}


