///////////////////////////////////////////////////////////////////////////////////////////////////
//	DIALOG OBJECT
//	Provides unified control of a modal or modeless dialog with dynamic content
//
function DialogObject() {
	this.Destroy = Dialog_Destroy;
	
	this.ShowModal = Dialog_ShowModal;
	this.ShowModeless = Dialog_ShowModeless;
	
	this.InsertHeading = Dialog_InsertHeading;
	this.InsertPara = Dialog_InsertPara;
	this.InsertCode = Dialog_InsertCode;
	this.InsertTable = Dialog_InsertTable;
	this.InsertRow = Dialog_InsertRow;
	this.InsertCell = Dialog_InsertCell;
	this.InsertList = Dialog_InsertList;
	this.InsertListItem = Dialog_InsertListItem;
	
	this.CallbackFunction = null;
	this.CallbackArguments = null;
	this.Callback = Dialog_Callback;
	this.Nullify = Dialog_Nullify;
	this.Reset = Dialog_Reset;
	this.Nullify();
}
function Dialog_Destroy() {
	try { this.Document.parentWindow.close() }
	catch(e) { }
}
function Dialog_Nullify() {
	this.Document = null;
	this.Reset();
}
function Dialog_Reset() {
	this.CurrentTable = null;
	this.CurrentRow = null;
	this.CurrentList = null;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//	SHOW FUNCTIONS
//	The caller optionally provides a reference to their callback function and a callback argument
//	or array of arguments. The callback function is responsible for generating the content in the
//	dialog, usually via the methods on this object.
//
function Dialog_ShowModal( fCallback, aArguments ) {
	try {
		this.CallbackFunction = fCallback;
		this.CallbackArguments = aArguments;
		window.showModalDialog( 'Dialog/Dialog.htm', this, 'dialogWidth:600px;dialogHeight:400px;help:no;resizable:yes;' );
		return true;
	}
	catch(e) {
		return false;
	}
}
function Dialog_ShowModeless( fCallback, aArguments ) {
	try {
		this.CallbackFunction = fCallback;
		this.CallbackArguments = aArguments;
		window.showModelessDialog( 'Dialog/Dialog.htm', this, 'dialogWidth:600px;dialogHeight:400px;help:no;resizable:yes;' );
		return true;
	}
	catch(e) {
		return false;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//	CALLBACK FUNCTION
//	Sets a reference to the HTML document in the dialog
//	Calls the callback (if provided) with the following arguments:
//		- aArguments a provided by the caller in the Show method
//		- a reference to this object
//		- a reference to the HTML document
//
function Dialog_Callback( oDocument ) {
	try {
		this.Document = oDocument;
		if( this.CallbackFunction != null ) this.CallbackFunction( this.CallbackArguments, this, this.Document );
		return true;
	}
	catch(e) {
		return false;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//	HTML INSERT FUNCTIONS
//
function Dialog_InsertHeading( sText ) {
	try {
		this.Reset();
		var oTABLE = this.Document.createElement( "TABLE" );
		oTABLE.className = "heading";
		var oTR = oTABLE.insertRow();
		var oTD = oTR.insertCell();
		oTD.innerHTML = "<IMG SRC='Icon.gif'>"
		oTD.style.width = "1%";
		var oTD = oTR.insertCell();
		oTD.innerText = sText;
		this.Document.body.appendChild( oTABLE );
		return true;
	}
	catch(e) {
		return false;
	}
}
function Dialog_InsertPara( sText ) {
	try {
		this.Reset();
		var oP = this.Document.createElement( "P" );
		oP.innerText = sText;
		this.Document.body.appendChild( oP );
		return true;
	}
	catch(e) {
		return false;
	}
}
function Dialog_InsertCode( sText ) {
	try {
		this.Reset();
		var oPRE = this.Document.createElement( "PRE" );
		oPRE.innerText = sText;
		this.Document.body.appendChild( oPRE );
		return true;
	}
	catch(e) {
		return false;
	}
}
function Dialog_InsertTable() {
	try {
		this.Reset();
		var oTABLE = this.Document.createElement( "TABLE" );
		this.CurrentTable = this.Document.body.appendChild( oTABLE );
		return true;
	}
	catch(e) {
		return false;
	}
}
function Dialog_InsertRow() {
	try {
		this.CurrentList = null;
		if( this.CurrentTable == null ) this.InsertTable();
		this.CurrentRow = this.CurrentTable.insertRow();
		return true;
	}
	catch(e) {
		return false;
	}
}
function Dialog_InsertCell( sText, bHeader ) {
	try {
		this.CurrentList = null;
		if( this.CurrentRow == null ) this.InsertRow();
		var oTD = this.CurrentRow.insertCell();
		oTD.innerText = sText;
		if( bHeader == true ) oTD.className = "header";
		return true;
	}
	catch(e) {
		return false;
	}
}
function Dialog_InsertList() {
	try {
		this.Reset();
		var oOL = this.Document.createElement( "OL" );
		this.CurrentList = this.Document.body.appendChild( oOL );
		return true;
	}
	catch(e) {
		return false;
	}
}
function Dialog_InsertListItem( sText ) {
	try {
		this.CurrentTable = null;
		this.CurrentRow = null;
		if( this.CurrentList == null ) this.InsertList();
		var oLI = this.Document.createElement( "LI" );
		oLI.innerText = sText;
		oLI = this.CurrentList.appendChild( oLI );
		oLI.scrollIntoView( false );
		return true;
	}
	catch(e) {
		return false;
	}
}
