/**
 * Javascript Utility File
 * This Javascript file is loaded by the main forms template files
 * generic_form.tpl and forms/lead.tpl
 * They contain Javascript functionality which is generic and can be applied as utilities
 * to the form elements.
 *
 * @author Dups <dups@mysql.com>
 */

/**
 * function gets a field id and calculates the length of what is entered
 * probably should be called on a onKeyUp event (or KeyPress). The function
 * will attempt to change the content of another span or div on the page with the
 * id of field_id_charlength and when it is over will attempt to change the color to
 * red (traditional warning colour)
 * @author Dups <dups@mysql.com>
 * @param string field_id the id of the field being monitored
 * @param int max_size maximum length in characters allowed on this field
 * @return void
 *
 */
function mysqlform_field_charlength(field_id, max_size)
{
    var inform_area_id = field_id + '_charlength';
    var check_field = document.getElementById(field_id);
    var inform_area = document.getElementById(inform_area_id);
    var char_length = parseInt(max_size - check_field.value.length);
    if (char_length < 0)
    {
        inform_area.style.color = "red";
    }
    else
    {
        inform_area.style.color = "";
    }
    inform_area.innerHTML = char_length;
}
