// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function remove_field(element, item) {
  element.up(item).remove();
}

function numbersonly(myfield, e, dec)
 {
    var key;
    var keychar;

    if (window.event) {
        key = window.event.keyCode;
    } else if (e) {
        key = e.which;
    } else {
        return true;
    }
    keychar = String.fromCharCode(key);

    if (isControlKey(e)) {
        return true;
    }

    // numbers
    if ((("0123456789").indexOf(keychar) > -1)) {
        return true;
    }

    // decimal point jump
    else if (dec && (keychar == "."))
    {
        myfield.form.elements[dec].focus();
        return false;
    }
    else {
        return false;
    }
}

function isControlKey(e) {
    var key;
    var keychar;

    if (window.event) {
        key = window.event.keyCode;
    } else if (e) {
        key = e.which;
    } else {
        return true;
    }

    if ((key == null) || (key == 0) || (key == 8) ||
    (key == 9) || (key == 13) || (key == 27) || (key == 114)) {
        return true;
    }
}

function withinParams(field_id, min, max) {
    val = parseInt(document.getElementById(field_id).value);
    if (val >= min && val <= max) {
        return;
    }
	
    alert("value must be within " + min + " and " + max);
}