function DialogBox(name)
{
	//alert('CONSTRUCTOR');
	this.name    = name;	
	this.left    = 0;
	this.top     = 0;
	this.init();
}

DialogBox.prototype.init = function()
{	
	var i = 0;
	this.div                       = document.createElement('div');
	this.div.id                    = this.name;
	this.div.style.display         = 'none';
	this.div.style.position        = 'absolute';
	this.div.style.backgroundColor = '#FEF9EB';	
	this.div.style.border          = 'solid 5px #8CA5F2';
	this.div.style.zIndex          = 900;						   
	document.body.appendChild(this.div);
	//alert('INIT: ' + this.div);
}

DialogBox.prototype.reposition = function()
{
	//alert('REPOSITION');
	this.getDiv().style.top  = this.top;
	this.getDiv().style.left = this.left;
}

DialogBox.prototype.resize = function()
{
	//alert('RESIZE');
	this.getDiv().style.width  = this.width + 'px';
	//this.getDiv().style.height = this.height + 'px';
}

DialogBox.prototype.moveTo = function(left,top,override)
{
	//alert('MOVETO');
	if ( !override ) {
		var page_top = this.getPageTop();
		this.left    = left - parseInt(this.width /2);
		this.top     = top + page_top - this.height;
		this.reposition();
	} else {
		this.left    = left;
		this.top     = top;
		this.reposition();
	}
}

DialogBox.prototype.setSize = function(width,height)
{
	//alert('SIZE');
	this.width  = width;
	this.height = height;
	this.resize();
}

DialogBox.prototype.getDiv = function()
{
	return this.div;
}

DialogBox.prototype.show = function()
{
	//alert('SHOW');
	blackScreen(true);
	this.getDiv().style.display = 'inline';
}

DialogBox.prototype.hide = function()
{
	blackScreen(false);
	this.getDiv().style.display = 'none';
}

DialogBox.prototype.setContents = function(html)
{
	//alert('CONTENTS');
	this.getDiv().innerHTML = html;
}

DialogBox.prototype.setErrorMessage = function(message, overrideDiv)
{
	var errorMessageDiv = overrideDiv || 'flag_error_message'; // default
	document.getElementById(errorMessageDiv).innerHTML = message;
}

DialogBox.prototype.getPageTop = function()
{
	if ( document.all ) {
		return document.body.scrollTop;
	} else {
		return window.pageYOffset;
	}
}


var currentOpacity = 0;

function blackScreen(vis) {
	var options = options || {};
	var zindex = options.zindex || 50;
	var opacity = options.opacity || 60;
	var opaque = (opacity / 100);
	var fadebgDiv = document.getElementById('fadebg');

	if (!fadebgDiv) {
		var tbody = document.getElementsByTagName("body")[0];
		var fadebgDiv = createDiv(tbody, {'top':'0px','left':'0px','id':'fadebg'});
	}

	// show fade background
	if (vis) {
		var sizes = new getDimensions;
		var pageWidth = sizes.Width;
		var pageHeight = sizes.Height;
		
		window.onresize = window.onload = function () {
			var sizes = new getDimensions;
			var pageWidth = sizes.Width;
			var pageHeight = sizes.Height;
			fadebgDiv.style.width = pageWidth;
			fadebgDiv.style.height = pageHeight;
		}
		
		//alert(document.body.scrollHeight + "\\\n" + document.body.offsetHeight + "\\\n" + pageHeight + "..." + document.height);
		
		//fadebgDiv.style.opacity = opaque;
		//fadebgDiv.style.MozOpacity = opaque;
		// reset currentOpacity so it creates the fade
		currentOpacity = 0;
		createFade('fadebg', opacity);

		fadebgDiv.style.zIndex = zindex;
		fadebgDiv.style.backgroundColor = '#000000';
		fadebgDiv.style.width = pageWidth;
		fadebgDiv.style.height = pageHeight;
		fadebgDiv.style.display = 'block';
	// hide fade background
	} else {
		fadebgDiv.style.filter = 'alpha(opacity=0)';
		fadebgDiv.style.display = 'none';
		
		window.onresize = function () {}
	}
}

function getDimensions() {
	//Fix for IE7 (at then end)
	if (window.innerHeight && window.scrollMaxY ) { // Firefox
		//alert("first");
		var pageWidth = window.innerWidth + window.scrollMaxX+'px';
		var pageHeight = window.innerHeight + window.scrollMaxY+'px';
	} else if (document.body.scrollHeight > document.body.offsetHeight) {        // all but Explorer Mac
		//alert("second");
		var pageWidth = document.body.scrollWidth+'px';
		var pageHeight = document.body.scrollHeight+'px';
	} else {        // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		//alert("third");
		var pageWidth ='100%';
		var pageHeight ='100%';
	}

	this.Width = pageWidth;
	this.Height = pageHeight;
}

function createFade(sam, opacity) {
	currentOpacity += 15;
	var opaque = (currentOpacity / 100);
	
	document.getElementById(sam).style.opacity = opaque;
	document.getElementById(sam).style.MozOpacity = opaque;
	document.getElementById(sam).style.filter = 'alpha(opacity='+currentOpacity+')';
	
	if (currentOpacity < opacity) {
		setTimeout('createFade(\'' + sam + '\', ' + opacity + ');', 1);
	}
}

function createDiv(parent, options) {
	var thisDiv = document.createElement('div');
	
	thisDiv.id = options.id;
	thisDiv.style.position = 'absolute'; // Position absolutely
	thisDiv.style.top = options.top;     // In the top
	thisDiv.style.left = options.left;   // Left corner of the page
	thisDiv.style.overflow = 'hidden';   // Try to avoid making scroll bars
	thisDiv.style.display = 'none';      // Start out Hidden
	
	parent.appendChild(thisDiv);
	return thisDiv;
}