﻿function InlineWindow(x,y , windowName) {
    this.oTable = document.getElementById(windowName + "table")
    this.oTable.style.position = "absolute";
    this.oTable.style.display = 'block';
    this.oTable.style.left = x + "px";
    this.oTable.style.top = y + "px";
    this.oTable.InlineWindow = this;
    this.oTable.onmousedown = InlineWindow.prototype.onBringToFront;
    var oTR = this.oTable.insertRow(0);
    var oTD = document.getElementById(windowName + "title")
    oTD.InlineWindow = this;
    oTD.onmousedown = InlineWindow.prototype.tdOnMouseDown;
    return this;
}

InlineWindow.prototype.onBringToFront = function()
{ this.InlineWindow.bringToFront(); }
InlineWindow.prototype.bringToFront = function() {
//    if (document.body.childNodes[document.body.childNodes.length - 1] !== this.oTable)
//    { document.body.appendChild(this.oTable); } 
}
InlineWindow.prototype.tdOnMouseDown = function()
{ this.InlineWindow.onMouseDown(); }
InlineWindow.prototype.onMouseDown = function()
{ this.bDown = true; document.body.InlineWindow = this; this.saveMouseMove = document.body.onmousemove; this.saveMouseUp = document.body.onmouseup; document.body.onmousemove = InlineWindow.prototype.bodyOnMouseMove; document.body.onmouseup = InlineWindow.prototype.bodyOnMouseUp; }
InlineWindow.prototype.bodyOnMouseMove = function(evt)
{ var e = window.event ? window.event : evt; this.InlineWindow.onMouseMove(e); }
InlineWindow.prototype.onMouseMove = function(evt) {
    if ((document.all) && !(evt.button & 1))
    { this.onMouseUp(); return; }
    if (this.bDown)
    { this.dx = parseInt(this.oTable.style.left, 10) - evt.clientX; this.dy = parseInt(this.oTable.style.top, 10) - evt.clientY; this.bDown = false; }
    else {
        this.oTable.style.left = Math.max((this.dx + evt.clientX), 0) + "px"; this.oTable.style.top = Math.max((this.dy + evt.clientY), 0) + "px";
    } 
}
InlineWindow.prototype.bodyOnMouseUp = function()
{ this.InlineWindow.onMouseUp(); }
InlineWindow.prototype.onMouseUp = function()
{ document.body.onmouseup = this.saveMouseUp; document.body.onmousemove = this.saveMouseMove; document.body.InlineWindow = null; }
InlineWindow.prototype.onMinimize = function()
{ this.InlineWindow.minimize(); }
InlineWindow.prototype.minimize = function() {
    this.oContent.style.visibility = "hidden"; this.oContent.style.position = "absolute"; document.body.appendChild(this.oContent); this.oTable.deleteRow(1); this.saveX = this.oTable.style.left; this.saveY = this.oTable.style.top; if (!window.InlineWindowBar)
    { window.InlineWindowBar = document.createElement("span"); document.body.appendChild(window.InlineWindowBar); }
    window.InlineWindowBar.appendChild(this.oTable); this.oTable.style.position = "static"; this.oTable.style.left = "0px"; this.oTable.style.top = "0px"; this.oMinTD.innerHTML = "#"; this.oMinTD.onmousedown = InlineWindow.prototype.onMaximize;
}
InlineWindow.prototype.onMaximize = function()
{ this.InlineWindow.maximize(); }
InlineWindow.prototype.maximize = function()
{ document.body.appendChild(this.oTable); this.oTable.style.position = "absolute"; this.oTable.style.left = this.saveX; this.oTable.style.top = this.saveY; oTR = this.oTable.insertRow(1); oTD = oTR.insertCell(0); oTD.colSpan = 3; oTD.appendChild(this.oContent); this.oContent.style.position = "static"; this.oContent.style.visibility = "visible"; this.oMinTD.innerHTML = "_"; this.oMinTD.onmousedown = InlineWindow.prototype.onMinimize; }
InlineWindow.prototype.onMaximize = function()
{ this.InlineWindow.maximize(); }
InlineWindow.prototype.close = function() {
    this.oTable.style.display = 'none';
}
InlineWindow.prototype.onClose = function()
{ this.InlineWindow.close(); }