﻿function Progress(Id) {
    this.Id = Id;
    this.ProgressDiv = null;
    this.OnShow = new Event();
    this.OnHide = new Event();
    return this;
}
Progress.prototype.Show = function() {
    if (this.Id == '' || this.Id == undefined)
        return;
    if (this.ProgressDiv == null) {
        this.CreateHTML();
    }
    this.ProgressDiv.style.display = "block";
    Progress.Resize(this);
    var progressObj = this;

    addEvent(window, "resize", function() { Progress.Resize(progressObj) });

    this.OnShow.Execute();
}

Progress.prototype.CreateHTML = function() {
    var body = document.body;
    var pDiv = document.createElement('div');
    pDiv.id = 'Progress' + this.Id;
    pDiv.className = "Progress";

    var tDiv = document.createElement('div');
    var bDiv = document.createElement('div');
    var lDiv = document.createElement('div');
    var rDiv = document.createElement('div');

    var tlDiv = document.createElement('div');
    var trDiv = document.createElement('div');
    var blDiv = document.createElement('div');
    var brDiv = document.createElement('div');

    tDiv.className = "t"; pDiv.appendChild(tDiv);
    bDiv.className = "b"; tDiv.appendChild(bDiv);
    lDiv.className = "l"; bDiv.appendChild(lDiv);
    rDiv.className = "r"; lDiv.appendChild(rDiv);
    blDiv.className = "bl"; rDiv.appendChild(blDiv);
    brDiv.className = "br"; blDiv.appendChild(brDiv);
    tlDiv.className = "tl"; brDiv.appendChild(tlDiv);
    trDiv.className = "tr"; tlDiv.appendChild(trDiv);

    var pContent = document.createElement('div');
    pContent.className = "ProgressContent";
    trDiv.appendChild(pContent);

    var img = document.createElement('img');
    img.src = "/includes/images/framework/progress/loopLoader.gif";
    img.alt = "Progress";
    img.title = "Progress";

    pContent.appendChild(img);

    body.appendChild(pDiv);
    this.ProgressDiv = pDiv;
}


Progress.Resize = function(ProgressObject) {
    if (ProgressObject.ProgressDiv != null && ProgressObject.ProgressDiv != undefined && ProgressObject.ProgressDiv.style.display == "block") {
        var dim = GetWindowDimention();
        ProgressObject.ProgressDiv.style.left = (dim[0] - 130) / 2 + "px";
        ProgressObject.ProgressDiv.style.top = (dim[1] - 100) / 2 + "px";
    }
}


Progress.prototype.Hide = function() {
    if (this.Id == '' || this.Id == undefined || this.ProgressDiv == null)
        return;
    this.ProgressDiv.style.display = "none";
    this.OnHide.Execute();
}

/*
Progress.prototype.OnShow = function() {
this.Show.Execute();
}

Progress.prototype.OnHide = function() {
this.Hide.Execute();
}
*/

