/* $Id: lib.js,v 1.2 2002/03/02 14:06:30 cholewo Exp $ */
function mod(obj) {
    obj.parentNode.className = 'input-changed';
}

/* submit only modified controls */
function disunmod(form) {
    for (var i = 0; i < form.elements.length; i++) {
        e = form.elements[i];
        epc = e.parentNode.className;
        if (epc != 'input-changed' && epc != 'input-error') {
/*            if (e.type != 'hidden' && e.type != 'submit') { */
            if (e.type != 'hidden' && e.type != 'submit' && e.type != 'radio') {
                e.disabled = true;
            }
        } else if (e.type == 'checkbox' && e.checked == false) {
            e.value = 'No';
            e.checked = true;                   // always send something if changed
        }
    }
}

function popup(e) {
    window.open(e.href, '_blank', 'width=750,height=550,menubar=no,toolbar=no,status=no,resizable=yes,scrollbars=yes');
    return false;
}

function popup_txt(title, txt) {
    w = window.open('', '_blank', 'width=800,height=400,menubar=no,toolbar=no,status=no,resizable=yes,scrollbars=yes');
    w.document.write(txt);
    w.document.write('&nbsp;<br><input type="button" value="Close Window" onClick="window.close()">');
    w.document.title = title;
    return false;
}


function getkey(e) {
    if (window.event)
        return window.event.keyCode;
    else if (e)
        return e.which;
    else
        return null;
}

function getaltkey(e) {
    if (window.event && window.event.altKey)
        return window.event.keyCode;
    else if (e && (e.modifiers & Event.ALT_MASK))
        return e.which;
    else
        return null;
}

function capitalize(e, field) {
    var key = getkey(e);
    /*    alert(key + ' ' + field.value);*/
    if (key == 126) {
        var lowwords = ' for but so or nor and a an the in of by at with to on due as ';
        var ws = field.value.split(/\s+/);
        for (var i in ws) {
            var w = ws[i];
            if (i == 0 || (w.match(/^[a-z\-]+$/) && !lowwords.match(' ' + w + ' '))) {
                ws[i] = w.substring(0, 1).toUpperCase() + w.substring(1);
            }
        }
        field.value = ws.join(' ');
        mod(field);
        return false;
    }
    return true;
}

function toggle_vis(id) {
    e = document.getElementById(id);
    e.style.display = (!e.style.display || e.style.display == "none") ? "inline" : "none";
    //    echo('a:' + e.style.display);
    return false;
}
