/**
 *  Function to handle opening a modal dialog
 *  fixes some display quirks when these steps are done in the init function
 *
 *  @param string el name of the dialog box to display
 */
var renderedDialogs={};
var modalMask=null;

function showModalDialog(el,w,h)
{
    if(renderedDialogs[el] === undefined) {
		renderedDialogs[el]=true;
		el=$(el);
		var c = document.createElement("div");
		var mask = document.createElement("div");
		mask.id="mask";
		document.body.appendChild(c);
		document.body.appendChild(mask);
		c.appendChild(el);
		var docHeight = document.documentElement.scrollHeight + document.documentElement.scrollTop + "px";
		Object.extend(mask.style,{height:docHeight});
	}
	Element.show($(el).parentNode);
	Element.show(modalMask=document.getElementById('mask'));
	
	if(w != null)
		$(el).style.left = ((document.innerWidth - $(el).offsetWidth)/2) + "px";
	else
		$(el).style.left = ((document.body.clientWidth - $(el).offsetWidth)/2) + "px";
	

}

/**
 *  Function to handle opening a modal dialog with an element to ajax into
 *
 *  @param string el name of the dialog box to display
 *  @param string url to ajax into el
 */
function showAjaxedModalDialog(el,url,w,h,params)
{
	if (typeof(params)!='undefined'&&params)
		var x = new Ajax.Updater(el,url,{evalScripts: true, method: 'POST',parameters: params, onComplete:function() {showModalDialog(el,w,h);initTooltips();}});
	else
		var x=new Ajax.Updater(el,url,{evalScripts: true, method: 'GET',onComplete:function() {showModalDialog(el,w,h);initTooltips();}});
}

/**
 *  Function to handle closing a modal dialog
 *
 *  @param string el name of the dialog box to close
 */
function closeModalDialog(el)
{
	el=$(el);
    Element.hide(el.parentNode);
	Element.hide(modalMask);
}

