// JavaScript Document

var userCount = 1;

function addRowToTable()
{
        userCount++;
		var tbl = document.getElementById('userTable');
        var row = tbl.insertRow(-1);
		row.setAttribute('id', 'rowID' + userCount);
        
        // firstName cell
        var cell = row.insertCell(0);
		cell.setAttribute('class', 'formfield');
        var el = document.createElement('input');
        el.setAttribute('type', 'text');
        el.setAttribute('name', 'firstName' + userCount);
        el.setAttribute('id', 'firstName' + userCount);
        el.setAttribute('size', '15');
		cell.appendChild(el);
		var el = document.createElement('input');
        el.setAttribute('type', 'hidden');
        el.setAttribute('name', 'rowIndex');
        el.setAttribute('id', 'rowIndex' + userCount);
        el.setAttribute('value', userCount);
        cell.appendChild(el);
		
		// lastName cell
        var cell = row.insertCell(1);
		cell.setAttribute('class', 'formfield');
        var el = document.createElement('input');
        el.setAttribute('type', 'text');
        el.setAttribute('name', 'lastName' + userCount);
        el.setAttribute('id', 'lastName' + userCount);
        el.setAttribute('size', '15');
        cell.appendChild(el);
		
		// userName cell
        var cell = row.insertCell(2);
		cell.setAttribute('class', 'formfield');
        var el = document.createElement('input');
        el.setAttribute('type', 'text');
        el.setAttribute('name', 'userName' + userCount);
        el.setAttribute('id', 'userName' + userCount);
        el.setAttribute('size', '15');
        cell.appendChild(el);
		
		// password cell
        var cell = row.insertCell(3);
		cell.setAttribute('class', 'formfield');
        var el = document.createElement('input');
        el.setAttribute('type', 'text');
        el.setAttribute('name', 'password' + userCount);
        el.setAttribute('id', 'password' + userCount);
        el.setAttribute('size', '15');
        cell.appendChild(el);
		
		// email cell
        var cell = row.insertCell(4);
		cell.setAttribute('class', 'formfield');
        var el = document.createElement('input');
        el.setAttribute('type', 'text');
        el.setAttribute('name', 'email' + userCount);
        el.setAttribute('id', 'email' + userCount);
        el.setAttribute('size', '15');
        cell.appendChild(el);
		
		// delete
		var cell = row.insertCell(5);
		cell.setAttribute('class', 'formlabel');
		var el = document.createElement('input');
        el.setAttribute('type', 'button');
        el.setAttribute('name', 'delete' + userCount);
        el.setAttribute('id', 'deleteRow' + userCount);
		el.setAttribute('alt', userCount);
		el.setAttribute('value', 'X');
		if(navigator.appName =="Microsoft Internet Explorer"){
			el.attachEvent("onclick",function(){removeRowFromTable(event.srcElement.alt);});}
		else{
			el.setAttribute('onclick', 'removeRowFromTable(' + userCount + ');');
		}
        
		cell.appendChild(el);	
}

function removeRowFromTable(row){	
		tbl = document.getElementById('userTable');
		removeRow = document.getElementById('rowID'+row);
		tbl.deleteRow(removeRow.rowIndex);
}