﻿/*
 * Create Object Box
 */
function CreateBoxStandard(util, pathImgSpacer, myName, headerText, content, style)
{
	this.util = util;
	this.myName = myName;
	this.style = style;
	this.headerText = headerText;
	this.content = content;
	this.elContent = null;
	this.pathImgSpacer = pathImgSpacer;
};

CreateBoxStandard.prototype =
{
	createMain: function(w) {
		var oTable = this.util.createEl("TABLE");
		oTable.id = this.myName;
		oTable.className = "box_content" + this.style;
		if (typeof (w) != "undefined") {
			oTable.style.width = w + "px";
		}
		oTable.cellPadding = 0;
		oTable.cellSpacing = 0;
		oTable.border = 0;
		var oTbody = this.util.createEl("TBODY");
		// Create header
		oTbody.appendChild(this.createHeader());
		// Create body
		oTbody.appendChild(this.createBody());
		// Create footer
		oTbody.appendChild(this.createFooter());
		oTable.appendChild(oTbody);
		this.oOut = oTable;
		return oTable;
	},

	changeStyleNow: function(style) {
		if (this.style == style) return;
		this.util.changeStyleAll(this.oOut, this.style, style, "box");
		this.style = style;
	},

	createHeader: function() {
		var oTD = this.util.createEl("TD");
		oTD.colSpan = "3";
		var oDivC = this.util.createEl("DIV");
		oDivC.className = "box_header_C" + this.style;
		oTD.appendChild(oDivC);

		var oDivL = this.util.createEl("DIV");
		oDivL.className = "box_header_L" + this.style;
		oDivC.appendChild(oDivL);

		var oDivR = this.util.createEl("DIV");
		oDivR.className = "box_header_R" + this.style;
		oDivL.appendChild(oDivR);

		oDivR.appendChild(this.createHeaderContent());

		var oTR = this.util.createEl("TR");
		oTR.appendChild(oTD);
		return oTR;
	},

	createBody: function() {
		var oTR = this.util.createEl("TR");
		var oTD = this.util.createEl("TD");
		oTD.colSpan = "3";
		oTD.appendChild(this.createTableBody());
		oTR.appendChild(oTD);
		return oTR;
	},

	createTableBody: function() {
		var oTable = this.util.createEl("TABLE");
		oTable.style.width = "100%";
		oTable.cellPadding = 0;
		oTable.cellSpacing = 0;
		oTable.border = 0;
		var oRow = oTable.insertRow(0);
		var oCell = oRow.insertCell(0);
		oCell.className = "box_body_L" + this.style;
		var oDiv = this.util.createEl("DIV");
		oDiv.className = "box_body_L" + this.style;
		oCell.appendChild(oDiv);

		oCell = oRow.insertCell(1);
		oCell.className = "box_body_C" + this.style;
		oCell.appendChild(this.createContent());

		oCell = oRow.insertCell(2);
		oCell.className = "box_body_R" + this.style;
		oDiv = this.util.createEl("DIV");
		oDiv.className = "box_body_R" + this.style;
		oCell.appendChild(oDiv);
		return oTable;
	},

	createFooter: function() {
		var oTR = this.util.createEl("TR");
		oTR.className = "box_footer" + this.style;
		var oTD = this.util.createEl("TD");
		oTD.className = "box_footer_L" + this.style;
		oTR.appendChild(oTD);
		oTD = this.util.createEl("TD");
		oTR.appendChild(oTD);
		oTD = this.util.createEl("TD");
		oTD.className = "box_footer_R" + this.style;
		oTR.appendChild(oTD);
		return oTR;
	},

	createHeaderContent: function() {
		var oTable = this.util.createEl("TABLE");
		oTable.cellPadding = 0;
		oTable.cellSpacing = 0;
		oTable.border = 0;
		oTable.style.width = "100%";
		var oTbody = this.util.createEl("TBODY");
		oTbody.appendChild(this.createHeaderText());
		//oTbody.appendChild(this.createHeaderLine());
		oTable.appendChild(oTbody);
		return oTable;
	},

	createHeaderText: function() {
		var oTR = this.util.createEl("TR");
		// Create img right
		var oTD = this.util.createEl("TD");
		var oDiv = this.util.createEl("DIV");
		this.oHeader = oDiv;
		oDiv.className = "titleBlock";
		oDiv.innerHTML = this.headerText;
		oTD.appendChild(oDiv);
		oTR.appendChild(oTD);
		return oTR;
	},

	createHeaderLine: function() {
		var oTR = this.util.createEl("TR");
		// Create img right
		var oTD = this.util.createEl("TD");
		oTD.style.textAlign = "center";
		oTD.style.fontSize = "1px";
		var img = this.createImgSpacer(this.pathImgSpacer, "box_line" + this.style);
		oTD.appendChild(img);
		oTR.appendChild(oTD);
		return oTR;
	},

	createContent: function() {
		var o = this.util.createEl("DIV");
		o.className = "box_body_C" + this.style;
		o.innerHTML = this.content;
		this.elContent = o;
		return o;
	},

	createImgSpacer: function(path, className) {
		var o = this.util.createEl("IMG");
		o.className = className;
		o.src = path;
		return o;
	},

	/*****************************************************************************
	Set Content Start
	*****************************************************************************/
	setTextBox: function(textHeader, textContent) {
		this.setTextHeader(textHeader);
		this.setContent(textContent);
	},

	setTextHeader: function(text) {
		this.oHeader.innerHTML = text;
		this.headerText = text;
	},

	setContent: function(content) {
		this.elContent.innerHTML = content;
		this.content = content;
	}
	/*****************************************************************************
	Set Content End
	*****************************************************************************/

};