/**
 * @class Constructor of the GraphicalWindow object<br>
 * This one is used to build a window (or graphicalWindow)<br>
 * This one can be datasheet, messages, selectors, wizards...<br>
 *
 * @param {String} title Title of the graphicalWindow
 * @param {String} content HTML content of the graphicalWindow
 * @param {Int} width Width of the graphicalWindow (optional - 700 by default)
 * @param {Int} height Height of the graphicalWindow (optional - 600 by default)
 * @param {String} name Name of the graphicalWindow
 * @param {Boolean} noClose If true, close button is disabled
 * @return The created GraphicalWindow object
 * @constructor
 * @author Laurent Vergnaud
 */
function GraphicalWindow(title, content, width, height, name, noClose) {

	/**
	 * Start Title of the graphicalWindow
	 * @type String
	 */
	this.startTitle = title;

	/**
	 * Title of the graphicalWindow
	 * @type String
	 */
	this.title = title;
	
	/**
	 * HTML content of the graphicalWindow
	 * @type String
	 */
	this.content = content;

	/**
	 * Width of the graphicalWindow (optional - 700 by default)
	 * @type Int
	 */
	this.width = ((width)&&(width!=-1))?width:700;

	/**
	 * Height of the graphicalWindow (optional - 600 by default)
	 * @type Int
	 */
	this.height = ((height)&&(height!=-1))?height:600;

	/**
	 * Top position of the graphicalWindow
	 * @type Int
	 */
	this.top = 10;

	/**
	 * Left position of the graphicalWindow
	 * @type Int
	 */
	this.left = 10;

	/**
	 * Layered position of the graphicalWindow
	 * @type Int
	 */
	this.zindex = 0;

	/**
	 * Id of the graphicalWindow
	 * @type String
	 */
	this.id = name;

	/**
	 * Id of the graphicalWindow
	 * @type String
	 */
	this.noClose = (noClose)?noClose:false

	/**
	 * HTML content of the graphicalWindow
	 * @type Int
	 */
	this.innerHTML = "";
    



	/**
	 * Building the HTML content (principally the banner) of the graphicalWindow
	 */
	this.build = function () {
		var varHTML = "";
		varHTML += "<div id='" + this.id + "' name='" + this.id + "' class='graphicalWindowContainer'>";
		varHTML += "<table border='0' cellspacing='0' cellpadding='0' width='100%'>";
		varHTML += "<tr>";
			varHTML += "<td class='graphicalWindowTopLeft'></td>";
			varHTML += "<td class='graphicalWindowTop' colspan='2'></td>";
			varHTML += "<td class='graphicalWindowTopRight'></td>";
		varHTML += "</tr>";
		varHTML += "<tr>";
			varHTML += "<td class='graphicalWindowLeft'>&nbsp;</td>";
			varHTML += "<td class='graphicalWindowBannerTitle'><span id='graphicalWindowBannerTitle" + this.id + "'>" + this.title + "</span></td>";
			varHTML += "<td class='graphicalWindowBannerButtonClose'>";
			if (!noClose) {
				varHTML += "<a href='#' onClick='closeGraphicalWindow(\"" + this.id + "\");'><img src='images/window/croix.gif' border='0' /></a>";
			}
			varHTML += "</td>";
			varHTML += "<td class='graphicalWindowRight'>&nbsp;</td>";
		varHTML += "</tr>";
		varHTML += "<tr>";
			varHTML += "<td class='graphicalWindowLeft'>&nbsp;</td>";
			varHTML += "<td colspan='2' class='graphicalWindowSubContainer'>";
				varHTML += this.content;
			varHTML += "</td>";
			varHTML += "<td class='graphicalWindowRight'>&nbsp;</td>";
		varHTML += "</tr>";
		varHTML += "<tr>";
			varHTML += "<td class='graphicalWindowBottomLeft'>&nbsp;</td>";
			varHTML += "<td class='graphicalWindowBottom' colspan='2'>&nbsp;</td>";
			varHTML += "<td class='graphicalWindowBottomRight'>&nbsp;</td>";
		varHTML += "</tr>";
		varHTML += "</table>";
		varHTML += "</div>";
		this.innerHTML = varHTML;
		frameWidth = getWindowWidth();
		frameHeight = getWindowHeight();
		if (this.width > frameWidth - 20)
			this.width = frameWidth - 20;
		if (this.height > frameHeight - 20)
			this.height = frameHeight - 20;
		this.top = (frameHeight - this.height) / 2;
		this.left = (frameWidth - this.width) / 2;
		if (this.startTitle == "NewsLetter Subscription") {
			this.top = 295;
		}
	}

	/**
	 * Refresh position and size at screen for the graphicalWindow
	 */
	this.refresh = function() {
		var obj = document.getElementById(this.id);
		obj.style.width = this.width + "px";
		obj.style.height = this.height + "px";
		obj.childNodes[0].childNodes[0].childNodes[2].childNodes[1].childNodes[0].style.height = (this.height - obj.childNodes[0].childNodes[0].childNodes[0].clientHeight - obj.childNodes[0].childNodes[0].childNodes[1].clientHeight - obj.childNodes[0].childNodes[0].childNodes[3].clientHeight) + "px"; //content
		obj.childNodes[0].childNodes[0].childNodes[2].childNodes[1].childNodes[0].childNodes[0].style.height = (this.height - obj.childNodes[0].childNodes[0].childNodes[0].clientHeight - obj.childNodes[0].childNodes[0].childNodes[1].clientHeight - obj.childNodes[0].childNodes[0].childNodes[3].clientHeight - 10) + "px"; //content
		obj.childNodes[0].childNodes[0].childNodes[2].childNodes[1].childNodes[0].childNodes[0].style.width = (this.width - 35) + "px"; //content
		obj.style.top = this.top + "px";
		obj.style.left = this.left + "px";
		obj.style.zIndex = this.zindex;
	}
	
	/**
	 * Change title for the graphicalWindow
	 */
	this.setTitle = function(title) {
		this.title = title;
		document.getElementById("graphicalWindowBannerTitle" + this.id).innerHTML = this.title;
	}

	/**
	 * Change size for the graphicalWindow
	 */
	this.setSize = function(width, height) {
		this.width = width;
		this.height = height;
		frameWidth = getWindowWidth();
		frameHeight = getWindowHeight();
		if (this.width > frameWidth - 20)
			this.width = frameWidth - 20;
		if (this.height > frameHeight - 20)
			this.height = frameHeight - 20;
		this.top = (frameHeight - this.height) / 2;
		this.left = (frameWidth - this.width) / 2;
		if (this.startTitle == "NewsLetter Subscription") {
			this.top = 295;
		}
		this.refresh();
	}
}
