/*------------------------------------------------------------------------------
    addEmpRowSet
------------------------------------------------------------------------------*/
/**
 * Adds N new rows to the table of employees
 */
function addEmpRowSet()
{
    var	increment = 5;
    var table = document.getElementById('etable');
    var newRow;
     for (i = currentIndex; i < (currentIndex + increment); i++)
    {
	newRow = table.insertRow(-1);
	populateEmployee(newRow, i);
   }
 
    // update the current index
    currentIndex += increment;
    
    // update the form variable to pass the total rows back to the censusForm bean
    var totalRows = document.getElementById('totalRows');
    if (totalRows != null)
    {
	totalRows.value = currentIndex;
    }
}

/*------------------------------------------------------------------------------
    populateEmployee
------------------------------------------------------------------------------*/
/**
 * Creates an employee row in the given PARENT with the index of INDEX
 */
function populateEmployee(parent, index)
{
    var indexInput = document.createElement('input');
    indexInput.name = 'employees[' + index + '].index';
    indexInput.value = index;
    indexInput.type = 'hidden';

    var nameTD = document.createElement('td');
    var nameInput = document.createElement('input');
    nameInput.type = 'text';
    nameInput.name = 'employees[' + index + '].name';
    nameInput.maxLength = 254;
    nameTD.appendChild(nameInput);
    nameTD.appendChild(indexInput);

    var sexTD = document.createElement('td');
    var sexSelection = document.createElement('select');
    sexSelection.name = 'employees[' + index + '].sexId';
    var maleOption = document.createElement('option');
    maleOption.value='1';
    var text = document.createTextNode('Male');
    maleOption.appendChild(text);
    sexSelection.appendChild(maleOption);
    var femaleOption = document.createElement('option');
    femaleOption.value='2';
    var text = document.createTextNode('Female');
    femaleOption.appendChild(text);
    sexSelection.appendChild(femaleOption);
    sexTD.appendChild(sexSelection);

    var dobTD = document.createElement('td');
    var dobInput = document.createElement('input');
    dobInput.type = 'text';
    dobInput.name = 'employees[' + index + '].dob';
    dobInput.maxLength = 10;
    dobInput.size = 10;
    dobTD.appendChild(dobInput);

    var coverageTD = document.createElement('td');
    var coverageSelection = document.createElement('select');
    coverageSelection.name = 'employees[' + index + '].coverageId';

    var cOption;
    var text;

    for (j = 0; j < coverageCount; j++)
    {
	cOption = document.createElement('option');
	cOption.value = coverageList[j][0];
	text = document.createTextNode(coverageList[j][1]);
	cOption.appendChild(text);
	coverageSelection.appendChild(cOption);
    }

    coverageTD.appendChild(coverageSelection);

    var zipTD = document.createElement('td');
    var zipInput = document.createElement('input');
    zipInput.type = 'text';
    zipInput.name = 'employees[' + index + '].zip';
    zipInput.maxLength = 10;
    zipInput.size = 10;
    zipTD.appendChild(zipInput);

    parent.appendChild(nameTD);
    parent.appendChild(sexTD);
    parent.appendChild(dobTD);
    parent.appendChild(coverageTD);
    parent.appendChild(zipTD);

}


