/* 
 Javascript functions common to all iCopyright services
 Copyright 2005-2006 iCopyright, Inc. All rights reserved.
 */

// Limit the characters in a window
function limitTextarea(field, count, max) {
    if (field.value.length > max) {
        field.value = field.value.substring(0, max);
    } else {
        count.value = max - field.value.length;
    }
}

// Submits a command to a command form
function command(cmd, id) {
    if ('delete' == cmd && !confirm("Are you sure?")) {
        return;
    }
    document.commandform.cmd.value = cmd;
    document.commandform.id.value = id;
    document.commandform.submit();
}

// A version of the above with three args
function commandthree(cmd, id, xinfo) {
    document.commandform.cmd.value = cmd;
    document.commandform.id.value = id;
    document.commandform.xinfo.value = xinfo;
    document.commandform.submit();
}

// Prevent double-submission of forms
var isFormSubmitted = false;
function submitForm() {
    if (isFormSubmitted)
        return false;

    isFormSubmitted = true;
    return true;
}

// Clear any existing data
function initInput(input) {
    input.style.color = '#000';
    input.style.fontStyle = 'normal';
    input.value = '';
}

function popWindow(url, name, width, height) {
    try {
        var popup = (window.open(url, name, 'width=' + width + ',height=' + height +
                                            ',scrollbars=yes,resizable=yes'));
        popup.focus();
    } catch (e) {
        alert(e);
    }
    return false;
}
/* via http://brondsema.net/blog/index.php/2007/06/06/100_height_iframe */
function resizeIframe(eid) {
    var height = document.documentElement.clientHeight;
    height -= document.getElementById(eid).offsetTop;
    height -= 25;
    document.getElementById(eid).style.height = height + "px";
}

//  Find the selected value of a radio group
function getRadioValue(obj) {
    var length = obj.length;
    if (length == undefined)
        if (obj.checked)
            return obj.value; else
            return "";
    for (var i = 0; i < length; i++) {
        if (obj[i].checked) {
            return obj[i].value;
        }
    }
    return "";
}

