/*	Takes the provided sDivId and turns it into a Dialogue (a floating overlay) wrapped with a success/info/failure header.
	Optionally attaches an "OK" button to close the dialogue.
	
	sDivId - The id of the div to be turned into a dialogue
	sHeader - The string that should be inserted as the title of the dialogue
	oCss: An associative array that applies css classes to the tabs. Keys to the array are:
          header, header_text, close_link, ok_button
	sHeaderBGColor - e.g. #0C0
	iWidth - The width of the dialogue (in pixels)
	bShowOk - Whether or not an "OK" button should be centered at the bottom of the dialogue.
	fOnShow/fOnHide - The functions to be executed when the dialogue is made visible or hidden
*/
function Dialogue(oDiv, sHeader, oCss, sHeaderBGColor, iWidth, bShowOk, fOnShow, fOnHide)
{
	var oThis = this;
	
	var dialogue = document.createElement('div');
	
	// Remove div from the document (we'll re-insert it as part of an overlay)
	var the_div = Util.Get(oDiv);
	this.the_div = the_div.parentNode.removeChild(the_div);
	
	var header_wrapper = document.createElement('div');
	var header = document.createElement('table');
	var header_body = document.createElement('tbody');
	var header_row = document.createElement('tr');
	var header_text = document.createElement('td');
	
	dialogue.style.width = iWidth + 'px';
	header.style.width = '100%';
	
	// Build header
	header.className = oCss.header; header.style.background = sHeaderBGColor;
	header.cellPadding = 0; header.cellSpacing = 0;
	header_text.innerHTML = sHeader; header_text.className = oCss.header_text;
	header_row.appendChild(header_text); header_body.appendChild(header_row);
	header.appendChild(header_body);
	header_wrapper.appendChild(header);
	
	if (bShowOk) {
		var ok_div = document.createElement('div');
		ok_div.style.textAlign = 'center'; ok_div.style.padding = '15px 5px 5px';
		
		var ok = document.createElement('input'); ok.setAttribute('type', 'button'); ok.setAttribute('value', 'OK'); ok.className = oCss.ok_button; ok.style.width = '35px';
		Util.AddEvent(ok, 'click', function() { oThis.Hide(); if (oThis.fOnOk) oThis.fOnOk(); } );
		ok_div.appendChild(ok);
		
		this.the_div.appendChild(ok_div);
	}
	
	dialogue.appendChild(header_wrapper);
	dialogue.appendChild(this.the_div);
	
	this.overlay = new Overlay(dialogue, fOnShow, fOnHide);
	Nifty.RoundedTop(header_wrapper, 'transparent', sHeaderBGColor, 'small');
	Nifty.RoundedBottom(dialogue, 'transparent', 'white', 'small');
};

Dialogue.prototype.Show = function()
{
	this.the_div.style.display = 'block';
	this.overlay.Show();
};

Dialogue.prototype.Hide = function()
{
	this.the_div.style.display = 'none';
	this.overlay.Hide();
};