if (typeof(PHP2Controls) == 'undefined') PHP2Controls = new Object();
PHP2Controls.hWindow = function(wHandle, wTitle, wCSSBaseClass, wContentElement, canClose)
{
this.wHandle= ((wHandle) ? wHandle : 'aWindow');
this.wTitleCaption= ((wTitle) ? wTitle : 'System Messages');
this.wCSSBaseClass= ((wCSSBaseClass) ? wCSSBaseClass : 'aWindow');
this.wContentElement= ((wContentElement) ? wContentElement : null);
this.canClose = ((canClose) ? canClose : true);
}
PHP2Controls.AWindow = function(hWindow)
{
this.id = hWindow.wHandle;
this.wHandle= hWindow.wHandle;
this.wTitleCaption= hWindow.wTitleCaption;
this.wCSSBaseClass= hWindow.wCSSBaseClass;
this.wContentElement= hWindow.wContentElement;
this.canClose = hWindow.canClose;

if (!document.getElementById(this.id))
{
createWindowHtmlCode = '<div id="' + this.id + '" class="aWindow"><div id="' + this.id + '_wHeader" class="wHeader"><span id="' + this.id + '_wTitle" class="wHText">Window Title</span><span class="rHButtons"><div id="' + this.id + '_wBtnHide" class="wBtnHide">&nbsp;</div><div id="' + this.id + '_wBtnClose" class="wBtnClose">&nbsp;</div></span></div><div id="' + this.id + '_wBody" class="wBody"></div></div>';
document.body.insertAdjacentHTML("afterBegin", createWindowHtmlCode);
}
this.aWindow= document.getElementById(this.id);
this.wHeader= document.getElementById(this.id + '_wHeader');
this.wTitle = document.getElementById(this.id + '_wTitle');
this.wBtnHide = document.getElementById(this.id + '_wBtnHide');
this.wBtnClose= document.getElementById(this.id + '_wBtnClose');
this.wBody= document.getElementById(this.id + '_wBody');
this.aWindow.className = this.wCSSBaseClass;
this.wBtnClose.currentWinObject= this;
this.wBtnHide.currentWinObject = this;
this.wHeader.currentWinObject= this;
this.wBtnClose.onclick = function(){this.currentWinObject.close();};
this.wBtnHide.onclick= function(){this.currentWinObject.hide();};
this.wHeader.ondblclick= function(){this.currentWinObject.hide();};
this.wTitle.innerHTML= this.wTitleCaption ? this.wTitleCaption : 'System Messages';
if (this.wContentElement) this.attachContent(this.wContentElement);
this.protectFrameId = null;
}
PHP2Controls.AWindow.prototype.close = function()
{
this.aWindow.style.display = 'none';
if (this.protectFrameId && (document.all.item(this.protectFrameId) != null)) document.all.item(this.protectFrameId).style.display= 'none';
HTMLWindow.unsetDraggable(this.aWindow, this.wHeader);
}
PHP2Controls.AWindow.prototype.display = function()
{
this.aWindow.style.display = 'inline';
this.protectFrameId = HTMLElement.protectIEDiv(this.id);
}
PHP2Controls.AWindow.prototype.hide = function()
{
if (typeof(this.wBody) == undefined) return true;
headerHeight = this.wHeader.offsetHeight;
this.wBody.style.display = 'none';
this.aWindow.oldHeight = this.aWindow.height;
this.wHeader.height= headerHeight + 'px';
this.aWindow.height= headerHeight + 'px';
this.wBtnHide.onclick= function(){this.currentWinObject.show()};
this.wHeader.ondblclick= function(){this.currentWinObject.show();};
this.protectFrameId = HTMLElement.protectIEDiv(this.id);
}
PHP2Controls.AWindow.prototype.show = function()
{
if (typeof(this.wBody) == undefined) return true;

if (typeof(this.aWindow.oldHeight) != "undefined") this.aWindow.height = this.aWindow.oldHeight;

this.wBody.style.display = '';
this.wBtnHide.onclick= function(){this.currentWinObject.hide()};
this.wHeader.ondblclick= function(){this.currentWinObject.hide();};
this.protectFrameId = HTMLElement.protectIEDiv(this.id);
}
PHP2Controls.AWindow.prototype.initScreenPosition = function()
{
var leftPos= (HTMLElement.getBrowserWidth() - HTMLElement.getWidth(this.id)) / 2;
var topPos = (HTMLElement.getBrowserHeight() / 2) - 200;
this.aWindow.style.left= ((leftPos > 0) ? leftPos : '') + "px";
this.aWindow.style.top = ((topPos > 0) ? topPos : '') + "px";
this.protectFrameId = HTMLElement.protectIEDiv(this.id);
}
PHP2Controls.AWindow.prototype.attachContent = function(contentsNodeId)
{
var contentsNode = document.getElementById(contentsNodeId);

if (contentsNode.parentNode == this.wBody) return true;

this.wBody.innerHTML = '';
this.wBody.style.width = contentsNode.offsetWidth+ 'px';
this.wBody.style.height= contentsNode.offsetHeight+ 'px';
this.aWindow.style.height= this.wBody.offsetHeight + this.wHeader.offsetHeight + 'px';
this.aWindow.style.width = this.wBody.offsetWidth + 'px';
this.aWindow.style.left= HTMLElement.findPosX(contentsNode) + 'px';
this.aWindow.style.top = HTMLElement.findPosY(contentsNode) + 'px';
contentsNode.style.padding = 0;
contentsNode.style.margin= 0;

if (typeof(document.importNode) == "function")
{
var tmpNode = document.importNode(contentsNode, true);
this.wBody.appendChild(tmpNode);
}
else
{
var nodeHTML = (contentsNode.xml || contentsNode.outerHTML);
this.wBody.innerHTML = nodeHTML;
}
contentsNode.parentNode.removeChild(contentsNode);
}
PHP2Controls.AWindow.prototype.onMove = function()
{
this.protectFrameId = HTMLElement.protectIEDiv(this.id);
}
PHP2Controls.AWindow.prototype.initDragAndDrop = function()
{
this.aWindow.onMove = this.onMove;
HTMLWindow.setDraggable(this.aWindow, this.wHeader, null, false);
}
PHP2Controls.Alert = function (alertMessage)
{
this.id = 'pageSystemAlert';
this.hWindow= new PHP2Controls.hWindow(this.id, 'System Messages', 'aAlertWindow', null, true);
this.aWindowObject= new PHP2Controls.AWindow(this.hWindow);

var alertBody = '<div id="' + this.id + '_wAlertBody" class="wAlertBody"><div id="' + this.id + '_wAlertMessageBody" class="wAlertMessageBody">' + alertMessage + '</div><div class="wAlertFooter"><center><input id="' + this.id + '_wBtnAClose" type="button" class="button" value="Ok" /></center></div></div>';
this.aWindowObject.wBody.innerHTML = alertBody;
this.aWindowObject.wHeader.style.cursor = 'move';
this.aWindowObject.display();
this.aWindowObject.show();

this.wBtnAClose = document.getElementById(this.id + '_wBtnAClose');
this.wBtnAClose.currentWinObject= this.aWindowObject;
this.wBtnAClose.onclick = function(){this.currentWinObject.close()};
this.aWindowObject.initScreenPosition();
this.aWindowObject.initDragAndDrop();
}
PHP2Controls.MessageBox = function ()
{
this.id = 'pageSystemMessageBox';
this.hWindow= new PHP2Controls.hWindow(this.id, 'System Messages', 'aMessageBoxWindow', null, true);
this.aWindowObject= new PHP2Controls.AWindow(this.hWindow);
this.aWindowObject.wHeader.style.cursor = 'move';
this.messages = new Array();
}
PHP2Controls.MessageBox.prototype.add = function (message)
{
this.messages[this.messages.length] = message;
}
PHP2Controls.MessageBox.prototype.clear = function (message)
{
this.messages = new Array();
}
PHP2Controls.MessageBox.prototype.show = function (message)
{
messagesCount = this.messages.length;
if (messagesCount)
{
var messageboxBody = '<div id="' + this.id + '_wMessageBoxBody" class="wMessageBoxBody"><div id="' + this.id + '_wMessageBoxMessageBody" class="wMessageBoxMessageBody">';
for (i = 0; i < messagesCount; i++)
{
messageboxBody+= '<div class="wMessageBoxMessage"><span class="messageNumber">' + (i + 1) + '.</span><span class="messageBody">' + this.messages[i] + '</span></div>';
}
messageboxBody+= '</div><div class="wMessageBoxFooter"><center><input id="' + this.id + '_wBtnAClose" type="button" class="button" value="Ok" /></center></div></div>';
this.aWindowObject.wBody.innerHTML = messageboxBody;
this.aWindowObject.display();
this.aWindowObject.show();
this.wBtnAClose = document.getElementById(this.id + '_wBtnAClose');
this.wBtnAClose.currentWinObject= this.aWindowObject;
this.wBtnAClose.onclick = function(){this.currentWinObject.close()};
this.aWindowObject.initScreenPosition();
this.aWindowObject.initDragAndDrop();
}
}