﻿WaitingMessageClass = function(targetNodeId) {
    this._domNode = null;
    this._domNodeId = targetNodeId;
    this._position = null;
    this._labAttr = "_waiting_label_attr";
    this.width = 150;
    this.height = 30;

    this.getDomNode = function() {
        if (this._domNode == null) {
            this._domNode = document.getElementById(this._domNodeId);
        }

        return this._domNode;
    };

    this.getTargetNodePosition = function() {
        var n = this.getDomNode();
        if (n == null) return null;

        var node = n.offsetParent;
        var coord = { left: n.offsetLeft, top: n.offsetTop };
        while (node != null) {
            coord = { left: coord.left + node.offsetLeft, top: coord.top + node.offsetTop };
            node = node.offsetParent;
        }
        coord.width = n.offsetWidth;
        coord.height = n.offsetHeight;

        return coord;
    };

    this.showWaiting = function() {
        var loc = this.getTargetNodePosition();
        if (loc == null) return;
        var cover = document.createElement("DIV");
        cover.setAttribute(this._labAttr, this._labAttr);
        cover.zIndex = 500;

        this.hideWaiting();

        var msgSrc = new Array();
        msgSrc.push("<div style='");
        msgSrc.push("position: absolute;");
        msgSrc.push("left:" + loc.left + "px;top:" + loc.top + ";");
        msgSrc.push("width:" + loc.width + "px;height:" + loc.height + ";");
        msgSrc.push("z-index:600;");
        msgSrc.push("-moz-opacity:0;filter:alpha(opacity:0);opacity:0;");
        msgSrc.push("'>&nbsp;");
        msgSrc.push("</div>");
        msgSrc.push("<div ");
        msgSrc.push(" style='left:" + Math.round(loc.left + loc.width / 2 - this.width / 2) + "px;");
        msgSrc.push("top:" + Math.round(loc.top + loc.height / 2 - this.height / 2) + "px;z-index:500;");
        msgSrc.push("text-align: center; border: solid 1px black;");
        msgSrc.push("opacity: 1;");
        msgSrc.push("position: absolute;width: " + this.width + "px; height: " + this.height + "px;z-index:700;");
        msgSrc.push("padding-left: 5px; padding-right: 5px; padding-top:2px; padding-bottom:2px;");
        msgSrc.push("background-color: #eeeeee; font-family: Tahoma; font-size: 8pt; font-weight: bold; color: #00498b;");
        msgSrc.push("' >");
        msgSrc.push("<div><img alt='Please wait' src='images/Intro.gif' width='16px' height='16px' /></div>");
        msgSrc.push("<div>Please wait</div>");
        msgSrc.push("</div>");
        cover.innerHTML = msgSrc.join("");

        document.body.appendChild(cover);
    };

    this.hideWaiting = function() {
        var nodes = document.body.childNodes;
        var len = nodes.length;

        for (var i = 0; i < len; i++) {
            if (typeof (nodes[i].getAttribute) != 'undefined' && nodes[i].getAttribute(this._labAttr) != null) {
                document.body.removeChild(nodes[i]);
                break;
            }
        }
    };
}

