var theCounter = new Object();
function DeleteRow(theFormName, theElement) {
  var theDoc = document.getElementById('TABLE_' + theFormName);  

  for(var i = 0; i <= 10; i ++ ) {
    theElement = theElement.parentNode;
    if(theElement.tagName == 'TR') break;
  }
  if(theElement.tagName == 'TR') {
    theDoc.deleteRow(theElement.rowIndex);
  }  
}

function AddRow(theFormName) {
  var theID = theCounter[theFormName]+ 0;
  if(isNaN(theCounter[theFormName])) {
    theCounter[theFormName] = 0;
    theID = 0;
  }
  theID++;
  theCounter[theFormName] = theID;  
  var theDoc = document.getElementById('TABLE_' + theFormName);  
  var theRow = document.getElementById('TR_' + theFormName);
  var TR = document.createElement('TR', theRow);
  var rowIndex = theRow.rowIndex+1;
  var InsertTR = document.getElementById('TR_' + theFormName + '_Insert');  
  if(InsertTR && InsertTR.rowIndex) rowIndex = InsertTR.rowIndex;
  var Row = theDoc.insertRow(rowIndex);
  
  //getChildElements(theRow.cells[0]);
  //if(!document.all) theRow.cells = getChildElements(theRow);
  for(i=0; i < theRow.cells.length; i++) {
    var TheCell  = Row.insertCell(i);    
    var theHTML  = theRow.cells[i].innerHTML;         
    theHTML = theHTML.replace('\n',' ');
    theHTML = theHTML.replace(/SLNO/g, theID);		
    TheCell.innerHTML = theHTML;
    TheCell.className = theRow.cells[i].className;    
    TheCell.colSpan   = theRow.cells[i].colSpan;
    TheCell.width     = theRow.cells[i].width;
    TheCell.noWrap    = theRow.cells[i].noWrap;
    TheCell.vAlign    = theRow.cells[i].vAlign;

  }
  //-- ok set the lastid inserted of the qFORM
  if(document.forms['qEditForm']) {
    var Obj = document.forms['qEditForm'][theFormName + "_LastID"]; 
    if(Obj) Obj.value = theID;
  } 
}
 
function getChildElements(theObj) {
  var msg = '';
  var theValue;
  for(i in theObj) {
    theValue = theObj[i] + '';
    theValue = theValue.replace(/</g, '\n&lt;');
    theValue = theValue.replace(/>/g,'&gt;');
    msg = msg +
    '<tr><td>' + i + '</td><td>' + theValue +  '&nbsp;</td></tr>\n'
  }
  document.getElementById('DocumentInfo').innerHTML = 
  '<table border="1">' + msg + '</table>';
}
function InitRow(theFormName) {
  var theRow = document.getElementById('TR_' + theFormName);
  if(theRow) theRow.style.display = 'none';
}