function VeilDialog() {
    var veilZ = 10000;
    var isShown = false;
    var showWait = false;
    this.initialize = initialize;
    this.abstop = abstop;
    this.absleft = absleft;
    this.show = show;
    this.hide = hide;
    this.moveTo = moveTo;
    this.moveToCenter = moveToCenter;
    this.addListener = addListener;
    this.setVeilWidth = setVeilWidth;

/**
 * Modal dialog class
 */
function initialize( pTitle )
{
	// veil technology
	this.veilOverlay = document.getElementById('dialogBoxVeil');
	if (this.veilOverlay == null)
	{
	   this.veilOverlay = document.createElement('div');
	   this.veilOverlay.id = 'dialogBoxVeil';
	   this.veilOverlay.className = "cbDialogVeil";
	   this.veilOverlay.style.zIndex = VeilDialog.veilZ;
		//this.veilImage = document.createElement('div');
		//this.veilImage.id = 'ajax_wait';
	   //this.veilImage.className = "ajaxwaitbox";
		//this.veilImage.innerHTML = '<img name="AJAX_WAIT_IMG" title="Please wait..." src="/module/jscript/veil/ajax-loader.gif" width="16" height="16"/>';
	   //this.veilOverlay.appendChild(this.veilImage);
	   this.setVeilWidth();
	   this.addListener(window, "resize", this.setVeilWidth);
	   document.body.appendChild(this.veilOverlay);
	}
		
	// the main container
	this.container 				= null;	// the content
}


//TODO
function abstop(i)
{ 
	return (i.offsetParent) ? i.offsetTop+this.abstop(i.offsetParent) : i.offsetTop; 
}

function absleft(i)
{ 
	return (i.offsetParent) ? i.offsetLeft+this.absleft(i.offsetParent) : i.offsetLeft; 
}

/**
 * Shows the modal dialog window
 */
function show(pContainerName)
{
	this.isShown							= true;
	this.veilOverlay.style.display	= 'block';
	if (null != pContainerName) {
		this.container = document.getElementById(pContainerName);
		this.container.style.display			= 'block';
		this.container.style.zIndex 			= VeilDialog.veilZ + 1;
	}
}

/**
 * Hides the modal dialog window
 */
function hide(pContainerName)
{
	this.isShown = false;
	this.container.style.display = 'none';
	if (null != pContainerName) {
		document.getElementById(pContainerName).style.display = 'none';
	}
	this.veilOverlay.style.display = 'none';
}

/**
 * (Re-)positions the dialog to the given x,y position relative 
 * to the given object (HTML element)
 *
 * @param top pixels from top (related to given object)
 * @param left pixels from left (related to given object)
 * @param relativeObj the object, the dialog should be oriented at
 */
function moveTo(top, left, relativeObj)
{
   if(relativeObj)
   {
      this.container.style.left = (this.absleft(relativeObj)+left) + "px";
	   this.container.style.top = (this.abstop(relativeObj)+top) + "px";
	}
}

function moveToCenter(centerObj)
{
	tLeft = (document.body.scrollWidth / 2) - 32;
   tTop = (document.body.scrollHeight / 2) - 32;
   this.container.style.left = tLeft + "px";
	this.container.style.top = tTop + "px";
}

/**
 * "Static" functions and members
 */

function addListener(obj, eventType, func)
{
	if (obj.addEventListener)
	{
  		obj.addEventListener(eventType, func, false);
		return true;
	} else if (obj.attachEvent)
	{
		return obj.attachEvent('on' + eventType, func);
	}
	
	return false;
}
  
function setVeilWidth()
{
	if (null == this.veilOverlay) {
		this.veilOverlay = document.getElementById('dialogBoxVeil');
	}
	if (null != this.veilOverlay) {
		try {
			if (browser.isIE) {
				this.veilOverlay.style.width 	= document.body.scrollWidth;
				this.veilOverlay.style.height = document.body.scrollHeight;
			} else {
				this.veilOverlay.style.width 	= document.body.scrollWidth + "px";
				this.veilOverlay.style.height = document.body.scrollHeight + "px";
				this.veilImage.style.left = ((document.body.scrollWidth / 2) - 8) + "px";
				this.veilImage.style.top = ((document.body.scrollHeight / 2) - 8) + "px";
			}
		} catch (e) {
			//alert("setVeilWidth: " + e);
		}
	} else {
		alert("VeilOverlay is null");
	}
}

} //end class


function Browser() {

var ua, s, i;

this.isIE = false; // Internet Explorer
this.isNS = false; // Netscape
this.version = null;

ua = navigator.userAgent;

s = "MSIE";
if ((i = ua.indexOf(s)) >= 0) {
this.isIE = true;
this.version = parseFloat(ua.substr(i + s.length));
return;
}

s = "Netscape6/";
if ((i = ua.indexOf(s)) >= 0) {
this.isNS = true;
this.version = parseFloat(ua.substr(i + s.length));
return;
}

// Treat any other "Gecko" browser as NS 6.1.

s = "Gecko";
if ((i = ua.indexOf(s)) >= 0) {
this.isNS = true;
this.version = 6.1;
return;
}
}

var browser = new Browser();





/////////////////////////////////////////////////
/////////////////////////////////////////////////
//AJAX Wait dialog
/////////////////////////////////////////////////
/////////////////////////////////////////////////

//pShowDialog = boolean whether to show the block
//pContainerName = string containing the div to focus on, or null if no focus, just wait
function showAjaxWaitDialog(pShowDialog, pContainerName)
{
   if (null == gAjaxWaitDialog) {
	   gAjaxWaitDialog = new VeilDialog(); // modal dialog object   
		gAjaxWaitDialog.initialize("");
		//gAjaxWaitDialog.veilZ = 10000;
		//gAjaxWaitDialog.isShown = false;
   }
   if (pShowDialog) {
	   gAjaxWaitDialog.show(pContainerName);
	} else {
	   gAjaxWaitDialog.hide(pContainerName);
	}
}

var gAjaxWaitDialog = null;
