﻿function updateCharactersLeft(controlID, maxLength, charactersLeftControlID)
{   
    var control = $get(controlID);
    var charactersLeftControl = $get(charactersLeftControlID);
    
    if((control != null) && (charactersLeftControl != null))
    {
        var charactersUsed = control.value.length;
        charactersLeftControl.innerHTML = '(' + (maxLength - charactersUsed) + ')';
    }
}

function clickButton(button) 
{
    // process only the Enter key
    if (event.keyCode == 13) 
    {
        // cancel the default submit
        event.returnValue = false;
        event.cancel = true;
        
        // submit the form by programmatically clicking the specified button
        button.click();
    }
}

function getNumericValue(value)
{
    if((!isNaN(value)) && (value != ""))
    {
        return parseFloat(value);
    }
    else
    {
        return 0;
    }
}

function setUniqueRadioButton(nameregex, current) 
{
    for (i = 0; i < document.forms[0].elements.length; i++) 
    {
        elm = document.forms[0].elements[i]

        if (elm.type == 'radio') 
        {
            if (elm.id.indexOf(nameregex) != -1) 
            {
                elm.checked = false;
            }
        }
    }
    
    current.checked = true;
}

function clearChildCheckBoxes(nameregex, current) 
{
    if (current.checked == true) 
    {
        return;
    }
    
    for (i = 0; i < document.forms[0].elements.length; i++) 
    {
        elm = document.forms[0].elements[i];

        if (elm.type == 'radio') 
        {
            if (elm.id.indexOf(nameregex) != -1) 
            {
                elm.checked = false;
            }
        }
    }
}

function setParentCheckBox(parent, child) 
{
    if (child.checked == true) 
    {
        parent.checked = true;
    }
}
