function EstateWeb_Objects_DialogManager(oid){
	this.id = oid;
	this.parentID = "body";
	this.parentMarginLeftOffset = 0;
	this.styleID = 1;
	this.browserWindowResizeTimer = null;
	this.browserWindowScrollTimer = null;
	this.dialogTypes = new EstateWeb_Objects_DialogManager_DialogTypes(this);
	this.controlLocations = new EstateWeb_Objects_DialogManager_ControlLocation(this);
	this.dialogOptions = new EstateWeb_Objects_DialogManager_DialogOptions(this);
	this.backgroundOptions = new EstateWeb_Objects_DialogManager_BackgroundOptions(this);
	this.events = new HttpManager.Browser.eventManager();
	//methods
	this.show = EstateWeb_Objects_DialogManager_Show;
	this.hide = EstateWeb_Objects_DialogManager_Hide;
	this.prevalidate = EstateWeb_Objects_DialogManager_PreValidate;
	this.createUniqueID = EstateWeb_Objects_DialogManager_CreateUniqueID;
	this.sizeElements = EstateWeb_Objects_DialogManager_SizeElements;
	//events
	this.onBrowserWindowResize = EstateWeb_Objects_DialogManager_OnBrowserWindowResize;
	this.onBrowserWindowScroll = EstateWeb_Objects_DialogManager_OnBrowserWindowScroll;
	//events for dialog specific types
	//progress bar
	this.onProgressBarChange = EstateWeb_Objects_DialogManager_OnProgressBarChange;
}

function EstateWeb_Objects_DialogManager_DialogTypes(o){
	this.parent = o;
	this.information = 0;
	this.confirm = 1;
	this.progress = 2;
	this.page = 3;
	this.panel = 4;
}

function EstateWeb_Objects_DialogManager_ControlLocation(o){
	this.parent = o;
	this.topLeft = 0;
	this.topMiddle = 1;
	this.topRight = 2;
	this.bottomLeft = 3;
	this.bottomMiddle = 4;
	this.bottomRight = 5;
}

function EstateWeb_Objects_DialogManager_BackgroundOptions(o){
	this.parent = o;
	this.opacity = 1;
	this.isVisible = true;
}

function EstateWeb_Objects_DialogManager_DialogOptions(o){
	this.parent = o;
	this.width = 300;
	this.height = 80;
	this.backgroundColour = "#000000";
	this.type = this.parent.dialogTypes.information;
	this.title = new EstateWeb_Objects_DialogManager_DialogOptions_Title();
	this.controls = new EstateWeb_Objects_DialogManager_DialogOptions_Controls(this);
	this.progressOptions = new EstateWeb_Objects_DialogManager_DialogOptions_ProgressOptions(this);
	this.confirmOptions = new EstateWeb_Objects_DialogManager_DialogOptions_ConfirmOptions(this);
	this.pageOptions = new EstateWeb_Objects_DialogManager_DialogOptions_PageOptions(this);
	this.panelOptions = new EstateWeb_Objects_DialogManager_DialogOptions_PanelOptions(this);
	this.isVisible = false;
	this.isSized = false;
	this.hideSelectControls = false;
	this.closeLocation = this.parent.controlLocations.topRight;
}

function EstateWeb_Objects_DialogManager_DialogOptions_PanelOptions(o){
	this.parent = o;
	this.contentID = "";
	this.contentData = null;
}

function EstateWeb_Objects_DialogManager_DialogOptions_ProgressOptions(o){
	this.parent = o;
	this.bar;
	this.barWidth = 200;
	this.barHeight = 5;
	this.barColour = "#45A945";
	this.barContainerColour = "";
	this.barContainerBorderColour = "#004F42";
	this.barContainerBorderWidth = "1";
	this.barContainer;
}

function EstateWeb_Objects_DialogManager_DialogOptions_ConfirmOptions(o){
	this.parent = o;
	this.text = "";
}

function EstateWeb_Objects_DialogManager_DialogOptions_PageOptions(o){
	this.parent = o;
	this.url = "";
	this.width = 200;
	this.height = 100;
	this.pageContainerBorderWidth = 0;
	this.pageContainerBorderColour = "#FFFFFF";
	this.allowScrolling = false;
}

function EstateWeb_Objects_DialogManager_DialogOptions_Controls(o){
	this.parent = o;
	this.ok = new EstateWeb_Objects_DialogManager_DialogOptions_Controls_Button(this,"ok");
	this.cancel = new EstateWeb_Objects_DialogManager_DialogOptions_Controls_Button(this,"cancel");
}

function EstateWeb_Objects_DialogManager_DialogOptions_Controls_Button(o,id){
	this.parent = o;
	this.id = id;
	this.imageSrc = "";
	this.imageOverSrc = "";
	this.enabled = false;
	this.render = EstateWeb_Objects_DialogManager_DialogOptions_Controls_Button_Render;
}

function EstateWeb_Objects_DialogManager_DialogOptions_Controls_Button_Render(){
	var obutton = document.createElement("img");
	with ( obutton ){
		src = this.imageSrc;
	}
	var tsrc = this.imageOverSrc;
	var tparent = this.parent;
	var tthis = this;
	obutton.onmouseover = function(){ HttpManager.Document.SwapImage( obutton, tsrc ) }
	obutton.onclick = function(){ tparent.parent.parent.events.raiseEvent("oncontrolbuttonclick", tthis, null);  }
	return obutton;
}

function EstateWeb_Objects_DialogManager_DialogOptions_Title(){
	this.text = "";
	this.fontFamily = "Calibri, Tahoma, Sans-serif";
	this.fontSize = "10pt";
	this.fontColour = "#FFFFFF";
	this.cssClass = "";
	this.backgroundColour = "";
	this.paddingLeft = 0;
	this.paddingRight = 0;
	this.paddingTop = 0;
	this.paddingBottom = 0;
	this.height = "15px";
}

function EstateWeb_Objects_DialogManager_SizeElements(){
	if ( this.dialogOptions.isVisible ){
		//calculate the correct offsets and dimensions for the parent object
		var idialogoffsetLeft = 0;
		var idialogoffsetTop = 0;
		var idialogwidth = 0;
		var idialogheight = 0;
		var ibackgroundoffsetLeft = 0;
		var ibackgroundoffsetTop = 0;
		var ibackgroundwidth = 0;
		var ibackgroundheight = 0;
		//calculate correct positioning for the background
		if ( this.parentID == "body" ){
			//relative to the body
			ibackgroundoffsetLeft = 0;
			ibackgroundoffsetTop = 0;
			ibackgroundwidth = document.body.offsetWidth;
			ibackgroundheight = document.documentElement.scrollHeight;
		}else{
			//relative to an object
			ibackgroundoffsetLeft = HttpManager.Document.GetObject(this.parentID).offsetLeft;
			ibackgroundoffsetTop = HttpManager.Document.GetObject(this.parentID).offsetTop;
			ibackgroundwidth = HttpManager.Document.GetObject(this.parentID).offsetWidth;
			ibackgroundheight = HttpManager.Document.GetObject(this.parentID).offsetHeight;			
		}
		//calculate the correct positioning for the dialog
		//if we in body mode then we use the current viewport
		//otherwise we the use the object's viewport
		var owindowdimensions = HttpManager.Browser.ViewableDimensions();
		if ( this.parentID == "body" ){
			idialogwidth = owindowdimensions[0];
			idialogheight = owindowdimensions[1];
			var oscrolloffset = HttpManager.Browser.ScrollOffset();
			idialogoffsetLeft = oscrolloffset[0];
			idialogoffsetTop = oscrolloffset[1];
		}else{
			idialogwidth = ibackgroundwidth;
			idialogheight = ibackgroundheight;
		}

		with ( HttpManager.Document.GetObject(this.createUniqueID("background")) ){
			if (! this.dialogOptions.isSized ){
				style.visibility = "hidden";
				style.display = ( this.backgroundOptions.isVisible ? "block" : "none" );
				style.backgroundColor = "#cdcdcd";
				style.position = "absolute";			
				switch ( HttpManager.Browser.Type() ){
					case HttpManager.Browser.Types.Mozilla:
						style.opacity = this.backgroundOptions.opacity;
						break;
					case HttpManager.Browser.Types.InternetExplorer4Plus, HttpManager.Browser.Types.InternetExplorer5Plus:
						style.filter = "alpha(opacity="+(this.backgroundOptions.opacity*100)+")";
						break;
				}
				style.visibility = "visible";			
			}
			style.top = ibackgroundoffsetTop + "px";
			style.left = ibackgroundoffsetLeft + "px";
			style.height = ibackgroundheight + "px";
			style.width = ibackgroundwidth + "px";
		}
		with ( HttpManager.Document.GetObject(this.createUniqueID("messagecontainer")) ){
			if (! this.dialogOptions.isSized ){
				style.visibility = "hidden";
				style.display = "block";		
				style.position = "absolute";
				style.visibility = "visible";
			}
			style.left = ( ( ( ibackgroundwidth / 2 ) - ( offsetWidth / 2 ) ) + ibackgroundoffsetLeft ) + "px";
			style.top = ( ( ( ( idialogheight / 2) + idialogoffsetTop ) - ( offsetHeight/2 ) ) + ibackgroundoffsetTop ) + "px";
			
		}
		this.dialogOptions.isSized = true;
	}
}

function EstateWeb_Objects_DialogManager_Hide(){
	HttpManager.Document.GetObject(this.createUniqueID("background")).style.display = "none";
	HttpManager.Document.GetObject(this.createUniqueID("messagecontainer")).style.display = "none";
	this.dialogOptions.isVisible = false;
	this.dialogOptions.isSized = false;
	if ( HttpManager.Browser.Type() != HttpManager.Browser.Types.Mozilla ){
		if ( this.dialogOptions.hideSelectControls ){
			HttpManager.Document.Forms.HtmlSelect.showAll();
		}
	}
	HttpManager.Browser.events.removeHandler("onresize", this);
}

function EstateWeb_Objects_DialogManager_Show(parentID){
	if ( parentID ){
		this.parentID = parentID;
	}
	if ( this.prevalidate() ){
		if ( HttpManager.Browser.Type() != HttpManager.Browser.Types.Mozilla ){
			var aSelectContainers = [];
			if ( this.dialogOptions.panelOptions.contentID.length > 0 ){
				aSelectContainers[0] = this.dialogOptions.panelOptions.contentID;
			}
			if ( this.dialogOptions.hideSelectControls ){
				HttpManager.Document.Forms.HtmlSelect.hideAll(aSelectContainers);
			}
		}
		var omessagecontainer;
		if ( HttpManager.Document.GetObject(this.createUniqueID("messagecontainer")) ){
			HttpManager.Document.RemoveObject(this.createUniqueID("messagecontainer"));
		}
		if ( HttpManager.Document.GetObject(this.createUniqueID("background")) ){
			HttpManager.Document.RemoveObject(this.createUniqueID("background"));
		}
		if (!HttpManager.Document.GetObject(this.createUniqueID("background")) ){
			var obackground = document.createElement("div");
			obackground.id = this.createUniqueID("background");	
			obackground.style.position = "absolute";
			obackground.style.display = "none";
			obackground.style.zIndex = 9998;
			omessagecontainer = document.createElement("div");
			omessagecontainer.id = this.createUniqueID("messagecontainer")
			omessagecontainer.style.zIndex = 9999;
			omessagecontainer.style.position = "relative";
			omessagecontainer.style.visibility = "hidden";
			omessagecontainer.style.width = Math.min(this.dialogOptions.width, HttpManager.Browser.ViewableDimensions()[0]) + "px";
			omessagecontainer.style.height = Math.min(this.dialogOptions.height, HttpManager.Browser.ViewableDimensions()[1]) + "px";
			//attach to body
			var odialogParentContainer = null;
			if ( this.parentID == "body" ){
				odialogParentContainer = document.getElementsByTagName("body")[0];
			}else{
				odialogParentContainer = document.getElementById( this.parentID ).parentNode;
			}
			odialogParentContainer.appendChild( obackground );
			odialogParentContainer.appendChild( omessagecontainer );
		}else{
			omessagecontainer = HttpManager.Document.GetObject(this.createUniqueID("messagecontainer"));
			//clear the contents
			HttpManager.Document.RemoveObject(this.createUniqueID("contenttable"));
		}

		var ocontents = document.createElement("table");
		var ocontents_tbody = document.createElement("tbody");
		var ocontents_row1 = document.createElement("tr");
		var ocontents_row1_cell1 = document.createElement("td");
		var ocontents_row1_cell2 = document.createElement("td");
		var ocontents_row1_cell3 = document.createElement("td");
		var ocontents_row2 = document.createElement("tr");
		var ocontents_row2_cell1 = document.createElement("td");
		var ocontents_row2_cell2 = document.createElement("td");
		var ocontents_row2_cell3 = document.createElement("td");
		var ocontents_row3 = document.createElement("tr");
		var ocontents_row3_cell1 = document.createElement("td");
		var ocontents_row3_cell2 = document.createElement("td");
		var ocontents_row3_cell3 = document.createElement("td");
		//appending
		ocontents.appendChild( ocontents_tbody );
		ocontents_row1.appendChild( ocontents_row1_cell1 );
		ocontents_row1.appendChild( ocontents_row1_cell2 );
		ocontents_row1.appendChild( ocontents_row1_cell3 );
		ocontents_row2.appendChild( ocontents_row2_cell1 );
		ocontents_row2.appendChild( ocontents_row2_cell2 );
		ocontents_row2.appendChild( ocontents_row2_cell3 );
		ocontents_row3.appendChild( ocontents_row3_cell1 );
		ocontents_row3.appendChild( ocontents_row3_cell2 );
		ocontents_row3.appendChild( ocontents_row3_cell3 );
		ocontents_tbody.appendChild( ocontents_row1 );
		ocontents_tbody.appendChild( ocontents_row2 );
		ocontents_tbody.appendChild( ocontents_row3 );
		//
		ocontents.id = this.createUniqueID("contenttable");
		with ( ocontents ){
			style.width = Math.min(this.dialogOptions.width, HttpManager.Browser.ViewableDimensions()[0]) + "px";
			style.height = Math.min(this.dialogOptions.height, HttpManager.Browser.ViewableDimensions()[1]) + "px";
			cellPadding = "0";
			cellSpacing = "0";
		}
		ocontents_row1.style.fontSize = "7px";
		//
		with ( ocontents_row1_cell1 ){
			style.width = "11px";
			style.height = "10px";
			if ( HttpManager.Browser.Type() == HttpManager.Browser.Types.InternetExplorer5Plus ){
				style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/controls/dialogs/style"+this.styleID +"/topLeft.png')";
			}else{
				style.backgroundImage = "url('/images/controls/dialogs/style"+this.styleID +"/topLeft.png')";
			}
			appendChild( EstateWeb_Objects_DialogManager_Show_CreateSpacer(11,9) );
		}
		with ( ocontents_row1_cell2 ){
			style.width = "8px";
			style.height = "10px";
			style.backgroundImage = "url('/images/controls/dialogs/style"+this.styleID +"/top.gif')";
			style.backgroundRepeat = "repeat";
			appendChild( EstateWeb_Objects_DialogManager_Show_CreateSpacer(11,9) );
		}
		with ( ocontents_row1_cell3 ){
			style.width = "16px";
			style.height = "10px";
			if ( HttpManager.Browser.Type() == HttpManager.Browser.Types.InternetExplorer5Plus ){
				style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/controls/dialogs/style"+this.styleID +"/topRight.png')";
			}else{
				style.backgroundImage = "url('/images/controls/dialogs/style"+this.styleID +"/topRight.png')";
			}
			appendChild( EstateWeb_Objects_DialogManager_Show_CreateSpacer(16,9) );
		}
		with ( ocontents_row2_cell1 ){
			style.width = "11px";
			style.backgroundImage = "url('/images/controls/dialogs/style"+this.styleID +"/left.gif')";
			style.backgroundRepeat = "repeat-y";
			appendChild( EstateWeb_Objects_DialogManager_Show_CreateSpacer(11,8) );
		}
		with ( ocontents_row2_cell2 ){
			style.height =  "100%";
			style.width = "100%";
			style.paddingBottom = "5px";
			style.paddingRight = "5px";
			style.backgroundColor = this.dialogOptions.backgroundColour;
		}
		with ( ocontents_row2_cell3 ){
			style.width = "11px";
			if ( HttpManager.Browser.Type() == HttpManager.Browser.Types.InternetExplorer5Plus ){
				style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/controls/dialogs/style"+this.styleID +"/right.png', sizingMethod='scale')";
			}else{
				style.backgroundImage = "url('/images/controls/dialogs/style"+this.styleID +"/right.png')";
			}
			style.backgroundRepeat = "repeat-y";
			appendChild( EstateWeb_Objects_DialogManager_Show_CreateSpacer(11,8) );
		}
		with ( ocontents_row3_cell1 ){
			style.width = "11px";
			style.height = "15px";
			if ( HttpManager.Browser.Type() == HttpManager.Browser.Types.InternetExplorer5Plus ){
				style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/controls/dialogs/style"+this.styleID +"/bottomLeft.png')";
			}else{
				style.backgroundImage = "url('/images/controls/dialogs/style"+this.styleID +"/bottomLeft.png')";
			}
			appendChild( EstateWeb_Objects_DialogManager_Show_CreateSpacer(11,15) );
		}
		with ( ocontents_row3_cell2 ){
			style.height = "15px";
			if ( HttpManager.Browser.Type() == HttpManager.Browser.Types.InternetExplorer5Plus ){
				style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/controls/dialogs/style"+this.styleID +"/bottom.png', sizingMethod='scale')";
			}else{
				style.backgroundImage = "url('/images/controls/dialogs/style"+this.styleID +"/bottom.png')";
			}
			style.backgroundRepeat = "repeat-x";
			appendChild( EstateWeb_Objects_DialogManager_Show_CreateSpacer(8,15) );
		}
		with ( ocontents_row3_cell3 ){
			style.width = "16px";
			style.height = "15px";
			if ( HttpManager.Browser.Type() == HttpManager.Browser.Types.InternetExplorer5Plus ){
				style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/controls/dialogs/style"+this.styleID +"/bottomRight.png')";
			}else{
				style.backgroundImage = "url('/images/controls/dialogs/style"+this.styleID +"/bottomRight.png')";
			}
			appendChild( EstateWeb_Objects_DialogManager_Show_CreateSpacer(16,15) );
		}
		//add contents to dialog
		omessagecontainer.appendChild( ocontents );
		//set the inner content height
		var icell2maxheight = ((omessagecontainer.offsetHeight + ( HttpManager.Browser.Type() == HttpManager.Browser.Types.InternetExplorer5Plus ? 40 : 60 ) )- 100);
		var icell2maxwidth = (omessagecontainer.offsetWidth - 25);
		ocontents_row2_cell2.style.height = icell2maxheight + "px";
		ocontents_row2_cell2.appendChild( EstateWeb_Objects_DialogManager_Show_CreateContent(this,icell2maxwidth,icell2maxheight) );
		//size elements
		this.dialogOptions.isVisible = true;
		this.sizeElements();	
	}
}


function EstateWeb_Objects_DialogManager_Show_CreateSpacer(w,h){
	var oimg = document.createElement("img");
	with ( oimg ){
		style.width = w + "px";
		style.height = h + "px";
		src = "/images/structure/trans.gif";
	}
	return oimg;
}

function EstateWeb_Objects_DialogManager_Show_CreateContent(o,maxWidth,maxHeight){
	var ocontent = document.createElement("table");
	var ocontent_tbody = document.createElement("tbody");
	var ocontent_row1 = document.createElement("tr");
	var ocontent_row1_cell1 = document.createElement("td");
	var ocontent_row1_cell2 = document.createElement("td");
	var ocontent_row2 = document.createElement("tr");
	var ocontent_row2_cell1 = document.createElement("td");
	var ocontent_row3 = document.createElement("tr");
	var ocontent_row3_cell1 = document.createElement("td");
	
	ocontent_row1.appendChild( ocontent_row1_cell1 );
	ocontent_row1.appendChild( ocontent_row1_cell2 );
	ocontent_row2.appendChild( ocontent_row2_cell1 );
	ocontent_row3.appendChild( ocontent_row3_cell1 );
	
	ocontent_tbody.appendChild( ocontent_row1 );
	ocontent_tbody.appendChild( ocontent_row2 );
	ocontent_tbody.appendChild( ocontent_row3 );
	
	ocontent.appendChild( ocontent_tbody );
	

	with ( ocontent_row1_cell1 ){
		innerHTML = o.dialogOptions.title.text;
		style.height = o.dialogOptions.title.height;
		if ( o.dialogOptions.title.fontFamily.length > 0 ){
			style.fontFamily = o.dialogOptions.title.fontFamily;
		}
		if ( o.dialogOptions.title.fontSize.length > 0 ){
			style.fontSize = o.dialogOptions.title.fontSize;
		}
		if ( o.dialogOptions.title.fontColour.length > 0 ){
			style.color = o.dialogOptions.title.fontColour;
		}
		if ( o.dialogOptions.title.backgroundColour.length > 0 ){
			style.background = o.dialogOptions.title.backgroundColour;
		}
		if ( o.dialogOptions.title.cssClass.length > 0 ){
			className = o.dialogOptions.title.cssClass;
		}
		style.padding = o.dialogOptions.title.paddingTop + " " + o.dialogOptions.title.paddingRight + " " + o.dialogOptions.title.paddingBottom + " " + o.dialogOptions.title.paddingLeft;
	}
	
	var ocontentrow = null;
	switch ( o.dialogOptions.closeLocation ){
		case o.controlLocations.topRight:
			ocontentrow = ocontent_row1_cell2;
			break;
		case o.controlLocations.bottomRight:
			ocontentrow = ocontent_row3_cell1;
			break;
	}
	
	with ( ocontentrow ){
		valign = "top";
		align = "right";
		var ocloseimg = document.createElement("img");
		ocloseimg.src = "/images/controls/dialogs/style"+o.styleID +"/close.gif";
		ocloseimg.style.cursor = "pointer";
		appendChild( ocloseimg );
		className = o.dialogOptions.title.cssClass;
		ocloseimg.onclick = function(){
			o.hide();
		}
		ocontentrow.style.height = "25px";
	}
	
	ocontent_row2_cell1.colSpan = "2";
	ocontent_row3_cell1.colSpan = "2";
	ocontent_row2_cell1.style.height = "100%";
	
	
	with ( ocontent ){
		cellSpacing = 0;
		cellPadding = 0;
		style.width = maxWidth + "px";
		style.height = maxHeight + "px";
		style.paddingBottom = "0px";
	}
	
	switch ( o.dialogOptions.type  ){
		case o.dialogTypes.progress:
			//progress bar
			var oprogressbar = document.createElement("table");
			var oprogressbar_tbody = document.createElement("tbody");
			var oprogressbar_trheading = document.createElement("tr");
			var oprogressbar_tdheading = document.createElement("td");
			var oprogressbar_trcontent = document.createElement("tr");
			var oprogressbar_tdcontent = document.createElement("td");
			var oprogressbar_trfooter = document.createElement("tr");
			var oprogressbar_tdfooter = document.createElement("td");
			
			//create progress bar
			var oprogressbar_container = document.createElement("div");
			var oprogressbar_bar = document.createElement("div");
			
			//set styles
			with ( oprogressbar_container ){
				style.backgroundColor = o.dialogOptions.progressOptions.barContainerColour;
				style.width = "100%";
				style.height = o.dialogOptions.progressOptions.barHeight + "px";
				style.border = "solid "+o.dialogOptions.progressOptions.barContainerBorderWidth + "px " +  o.dialogOptions.progressOptions.barContainerBorderColour;
			}
			o.dialogOptions.progressOptions.barContainer = oprogressbar_container;
			with ( oprogressbar_bar ){
				style.backgroundColor = o.dialogOptions.progressOptions.barColour;
				style.width = "0px";
				style.height = o.dialogOptions.progressOptions.barHeight + "px";
				//alert(style.height);
				//style.position = "absolute";
			}
			o.dialogOptions.progressOptions.bar = oprogressbar_bar;
			with ( oprogressbar ){
				style.width = "100%";
			}
			
			
			oprogressbar_container.appendChild( oprogressbar_bar);
			oprogressbar_tdcontent.appendChild( oprogressbar_container );
			oprogressbar_trheading.appendChild( oprogressbar_tdheading );
			oprogressbar_trcontent.appendChild( oprogressbar_tdcontent );
			oprogressbar_trfooter.appendChild( oprogressbar_tdfooter );
			
			oprogressbar_tbody.appendChild( oprogressbar_trheading );
			oprogressbar_tbody.appendChild( oprogressbar_trcontent );
			oprogressbar_tbody.appendChild( oprogressbar_trfooter );
			
			oprogressbar.appendChild( oprogressbar_tbody );
			ocontent_row2_cell1.appendChild( oprogressbar );
			break;
		case o.dialogTypes.confirm:
			ocontent_row2_cell1.innerHTML = o.dialogOptions.confirmOptions.text;
			break;
		case o.dialogTypes.page:
			var oframe = document.createElement("iframe");
			oframe.scrolling = ( o.dialogOptions.pageOptions.allowScrolling ? "yes" : "no" );
			oframe.frameBorder = "no";
			oframe.style.width = "100%";
			oframe.style.height = "100%";
			if ( o.dialogOptions.pageOptions.pageContainerBorderWidth > 0 ) {
				oframe.style.border = "solid " + o.dialogOptions.pageOptions.pageContainerBorderWidth + "px " + o.dialogOptions.pageOptions.pageContainerBorderColour;
			}
			ocontent_row2_cell1.appendChild( oframe );
			oframe.src = o.dialogOptions.pageOptions.url.replace(/&amp;/g, "&");
			oframe.id = o.createUniqueID("iframe");
			oframe.name = o.createUniqueID("iframe");
			break;
		case o.dialogTypes.panel:
			if ( o.dialogOptions.panelOptions.contentData == null ){
				o.dialogOptions.panelOptions.contentData = HttpManager.Document.GetObject(o.dialogOptions.panelOptions.contentID).cloneNode(true);
				HttpManager.Document.GetObject(o.dialogOptions.panelOptions.contentID).parentNode.removeChild( HttpManager.Document.GetObject(o.dialogOptions.panelOptions.contentID) );
			}
			ocontent_row2_cell1.appendChild( o.dialogOptions.panelOptions.contentData );
			o.dialogOptions.panelOptions.contentData.style.display = "block";
			break;
	}
	
	return ocontent;
}

function EstateWeb_Objects_DialogManager_CreateUniqueID(id){
	//creates a unique id based on the id of the object
	return HttpManager.Strings.Format("{0}_{1}", this.id, id)
}

function EstateWeb_Objects_DialogManager_PreValidate(){
	//before creating the object, ensure that all parameters are set correctly
	if ( this.id.length == 0 ){
		HttpManager.Document.Errors.add("Dialog Manager", "Required property 'id' not set");
	}else if ( this.parentID.length == 0 ){
		HttpManager.Document.Errors.add("Dialog Manager", "Required property 'parentID' not set");
	}else if ( !HttpManager.Document.GetObject(this.parentID) && this.parentID != "body" ){
		HttpManager.Document.Errors.add("Dialog Manager", "Unable to find object provided in 'parentID', verify you have spelt its name correctly");
	}
	
	if ( HttpManager.Document.Errors.errors.length > 0 ){
		HttpManager.Document.Errors.show();
		HttpManager.Document.Errors.clear("Dialog Manager");
		return false;
	}
	
	HttpManager.Browser.events.removeHandler("onscroll", this);
	HttpManager.Browser.events.addHandler("onscroll", this, this.onBrowserWindowScroll );
	HttpManager.Browser.events.removeHandler("onresize", this);
	HttpManager.Browser.events.addHandler("onresize", this, this.onBrowserWindowResize );
	return true;
}

//event handling

function EstateWeb_Objects_DialogManager_OnBrowserWindowScroll(creator,sender,eventArgs){
	//to prevent laggyness, only execute after the window has stopped being scrolled
	if ( creator.dialogOptions.isVisible ){
		if (creator.browserWindowScrollTimer) { clearTimeout(creator.browserWindowScrollTimer) }
		creator.browserWindowScrollTimer = setTimeout(function(){ creator.sizeElements(); }, 200);
	}
}

 function EstateWeb_Objects_DialogManager_OnBrowserWindowResize(creator,sender,eventArgs){
	//to prevent laggyness, only execute after the window has stopped being resized
	if ( creator.dialogOptions.isVisible ){
		if (creator.browserWindowResizeTimer) { clearTimeout(creator.browserWindowResizeTimer) }
		creator.browserWindowResizeTimer = setTimeout(function(){ creator.sizeElements(); }, 50);
	}
 }
 
 function EstateWeb_Objects_DialogManager_OnProgressBarChange(creator,sender,eventArgs){
	creator.dialogOptions.progressOptions.bar.style.width = (( 100 / eventArgs.total ) * ( eventArgs.index + 1)) + "%";
	if ( eventArgs.total == ( eventArgs.index + 1) ){
		setTimeout( function(){ creator.events.raiseEvent("onprogressbarcomplete", creator, null); },500);
	}
 }
 