//**********************************************************************************************************
// addRowToTable - Add Dynamic Rows to table with appropriate elements based on table name
//**********************************************************************************************************
function addRowToTable(tblName)
{
	var tbl = document.getElementById(tblName);
	var lastRow = tbl.rows.length;

	 // if there's no header row in the table, then iteration = lastRow + 1
	var iteration = lastRow;
	var row = tbl.insertRow(lastRow);

	// Number cell
	var cellLeft = row.insertCell(0);
	cellLeft.className = "tableCell";
	var textNode = document.createTextNode(iteration);
	cellLeft.appendChild(textNode);
	

	// Date with Calendar Control
	// spanWrapper
	var span = document.createElement("span");
	span.style.padding=2;
	// Anchor
	var a = document.createElement("a");
	var str = "javascript:show_calendar('theform.dtVisit" + iteration + "');"; 
	a.href=str;
	// Calendar Image
	var img = document.createElement("img");
	img.src = "images/calendar.gif";
	img.border = 0;
	a.appendChild(img);
	span.appendChild(a);

	var cellDate = row.insertCell(1);
	cellDate.className = "tableCell";
	var el = document.createElement('input');
	el.type = 'text';
	el.name = 'dtVisit' + iteration;
	el.id = 'dtVisit' + iteration;
	el.className = "employeebox";
	el.size = 10;
	el.setAttribute("maxLength", "10");
	el.onkeypress = DtFieldkeyPress;
	cellDate.appendChild(el);
	cellDate.appendChild(span);

	// Name
	var cellName = row.insertCell(2);
	cellName.className = "tableCell";
	var el = document.createElement('input');
	el.type = 'text';
	el.name = 'txtName' + iteration;
	el.id = 'txtName' + iteration;
	el.className = "employeebox";
	el.size = 22;
	cellName.appendChild(el);


	// Address
	var cellAddr = row.insertCell(3);
	cellAddr.className = "tableCell";
	var el = document.createElement('TEXTAREA');
	el.name = 'txtAddress' + iteration;
	el.id = 'txtAddress' + iteration;
	el.className = "employeebox";
	el.cols = 30;
	el.rows = 5;
	cellAddr.appendChild(el);

	// Code Select Box
	var cellCodeSel = row.insertCell(4);
	cellCodeSel.className = "tableCell";
	var sel = document.createElement('select');
	sel.name = 'code' + iteration;
	sel.options[0] = new Option('I/C', 'I/C');
	sel.options[1] = new Option('F/C', 'F/C');
	sel.options[0].selected = true;
	sel.className = "employeebox";
	cellCodeSel.appendChild(sel);

	// Comments
	var cellComments = row.insertCell(5);
	cellComments.className = "tableCell";
	var el = document.createElement('TEXTAREA');
	el.name = 'txtComments' + iteration;
	el.id = 'txtComments' + iteration;
	el.className = "employeebox";
	el.cols = 35;
	el.rows = 5;
	cellComments.appendChild(el);
}
//**********************************************************************************************************
// removeRowFromTable - Removes dynamic rows from tables based on the tablename
//**********************************************************************************************************
function removeRowFromTable(tblName)
{
  var tbl = document.getElementById(tblName);
  var lastRow = tbl.rows.length;
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}
//**********************************************************************************************************

