﻿/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: addAddresses                                                                                    ***/
/***                                                                                                        ***/
/// <summary>
/// Builds up a list of email addresses for checked items in a data grid
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function addAddresses(datagridID, txtID, index)
{
    var dataGrid = document.getElementById(datagridID);
    
    var emails = '';
    var i = 1;
    for (i=1;i<dataGrid.rows.length;i++)
    {
        var checked = false;
        for(j=0;dataGrid.rows[i].cells[0].childNodes.length;j++)
        {
            if  (dataGrid.rows[i].cells[0].childNodes[j].type == 'checkbox')
            {
                checked = dataGrid.rows[i].cells[0].childNodes[j].checked;
                break;
            }
        }
        
        if (checked == true)
        {
            if  (emails.length > 0)
            {
                emails = emails + ', ';
            }
            emails = emails + dataGrid.rows[i].cells[index].innerHTML
        }
    }

    /* Now set the email text */    
    var txtTxt = document.getElementById(txtID);
    if  (txtTxt.value == '')
    {
        txtTxt.value = emails;
    }
    else
    {
        txtTxt.value = txtTxt.value + ', ' + emails;
    }
}