/**
 * QLIB 1.0 Button Control
 * Serge Dolgov (C) 2002
 * studio.quazzle.com
 */

function QButton_update() {
    with (this) {
        document.images["$b_" + name].src = ((!enabled && res.imgD) ||
            (value ? res.imgP : res.imgN)).src;
    }
}

function QButton_doEvent() {
    with (this) {
        if (enabled) {
            if (res.style == 1) {
                this.value = value ? 0 : 1;
                update();
            }
            if (this.onClick) onClick(value, tag);
        }
    }
    return false;
}

function QButton_enable(state) {
    this.enabled = state || !this.res.imgD;
    this.update();
}

function QButton_set(value) {
    if (this.enabled) {
        this.value = value ? 1 : 0;
        this.update();
    }
    return true;
}

function QButton(parent, name, res) {
    this.init(parent, name);
    if (res) {
        this.res = res;
        this.enabled = true;
        this.value = 0;
        this.set = QButton_set;
        this.enable = QButton_enable;
        this.update = QButton_update;
        this.doEvent = QButton_doEvent;
        with (res) {
            var out = '<a href="#"';
            if (tip) out += ' title="' + tip + '"';
            out += ' onClick="return ' + this.name + '.doEvent()" onMouseOver="';
            if (style == 2) out += this.name + '.set(1);';
            out += 'window.top.status=' + this.name + '.res.tip;return true" onMouseOut="';
            if (!style || (style == 2)) out += this.name + '.set();';
            out += 'window.top.status=\'\'"';
            if (!style) out += ' onMouseDown="return ' + this.name + '.set(1)" onMouseUp="return ' + this.name + '.set()"';
            out += '><img name="$b_' + this.name + '" src="' + imgN.src + '" border="0" width="' + width + '" height="' + height + '"></a>';
            document.write(out);
        }
    } else {
        document.write("invalid resource");
    }
}
QButton.prototype = new QControl();
