/**
 * QLIB 1.0 Progress Control
 * Serge Dolgov (C) 2002
 * studio.quazzle.com
 */

function QProgress_update() {
    with (this) {
        var z;
        var delta = (high - low) / size;
        var p0 = res.list[0].src;
        var p1 = res.list[1].src;
        for (var j=0; j<size; j++) {
            z = low + j * delta;
            document.images["$p_" + name + j].src = (z < value) ? p1 : p0;
        }
    }
}

function QProgress_set(value) {
    this.value = value - 0;
    this.update();
}

function QProgress_setBounds(low, high) {
    this.low = Math.min(low, high);
    this.high = Math.max(low, high);
    this.update();
}
 
function QProgress(parent, name, res, size, style) {
    this.init(parent, name);
    if (res) {
        this.res = res;
        this.value = 0;
        this.low = 0;
        this.high = 100;
        this.size = size || 10;
        this.style = style || 0;
        this.set = QProgress_set;
        this.update = QProgress_update;
        this.setBounds = QProgress_setBounds;
        with (res) {
            var hor = this.style < 2;
            var rev = this.style % 2;
            var out = '<table class="progress" border="0"  cellspacing="0" cellpadding="0" ';
            out += hor ? 'width="' + (this.size * width) + '" height="' + height + '"><tr>\n' : 'width="' + width + '" height="' + (this.size * height) + '">\n';
            for (var j=0; j<this.size; j++) {
                out += hor ? '' : '<tr>';
                out += '<td width="' + width + '" height="' + height + '">';
                out += '<img name="$p_' + this.name + (rev ? this.size - j - 1 : j) + '" src="' + list[0].src + '" border="0" width="' + width + '" height="' + height + '"></td>';
                out += hor ? '\n' : '</tr>\n';
            }
            document.writeln(out + (hor ? '</tr>' : '') + '</table>');
        }
    } else {
        document.write("invalid resource");
    }
}
QProgress.prototype = new QControl();

QProgress.NORMAL  = 0;  // progress styles
QProgress.REVERSE = 1;
QProgress.FALL    = 2;
QProgress.RISE    = 3;