//drjs.ui.wizardbox.js - Dependencies: ui xml FloatBox
//WindowBox

var WindowBox = Class.Extends(FloatBox);
WindowBox.AddMethods({
	maincontent: "",
	objcontent: null,
	contentParent:null,
	title: "",
	_constructor: function() {
	},
	CreateWindow: function(id, style, width, height) {
		if($(id)!=false) {
			WindowBoxFunctions.RemoveContent(id);
		}
		this.Create(id, style, width, height);
		var html = "";
		html += "<div id=\"%id_windowtop\" class=\"%style_top\" onmousedown=\"UI.DragObj.StartDrag('%id');\">";
			html += "<span id=\"%id_windowtitle\" style=\"float:left;\" class=\"%style_toptitle\"></span>";
			html += "<span id=\"%id_windowclosebtn\" style=\"float:right;\" class=\"%style_closebtn\" onclick=\"WindowBoxFunctions.WindowClose('%id');\">x</span>";
		html += "</div>";
		html += "<div id=\"%id_windowcontent\" class=\"%style_maincontent\">";
			html += "";
		html += "</div>";
		html = html.replace(/%id/g, this.Id);
		html = html.replace(/%style/g, this.Style);
		this.SetContent(html);
	},
	CloseWindow: function() {
		this.RemoveContent();
		this.Close();
	},
	GetWindowContentID: function() {
		return this.Id + "_windowcontent";
	},
	RemoveContent: function() {
		if(this.objcontent!=null) {
			this.objcontent.Hide();
			this.contentParent.appendChild(this.objcontent);
		}
	},
	SetTitle: function(title) {
		this.title = title;
		$(this.Id+"_windowtitle").innerHTML = title;
	},
	SetMainContent: function(content) {
		if(typeof(content)=="string") {
			this.maincontent = content;
			$(this.Id+"_windowcontent").innerHTML = content;
		} else {
			content.Show();
			this.contentParent = content.parentNode;
			$(this.Id+"_windowcontent").appendChild(content);
			this.objcontent = content;
		}
	},
	ShowWindow: function() {
		this.Show();
		this.Center();		
	}
});

var WindowBoxFunctions = {
	RemoveContent: function(id) {
		FloatBoxFunctions.GetBox(id).RemoveContent();
	},
	WindowClose: function(id) {
		try {
			eval(id+"_onClose();");
		} catch(e) {}
		FloatBoxFunctions.GetBox(id).CloseWindow();
	},
	ShowWindow: function(id) {
		FloatBoxFunctions.GetBox(id).ShowWindow();
	}
};

drjs.loadComplete(drjs.files.uiWindowBox);