function duplicateRow(tableID,e)
{
	// Determine what row the button clicked is on (we will insert the clone in the row above this)
	if (window.event) // IE 
	{
		insertBeforeRow = window.event.srcElement.parentNode.parentNode.rowIndex;
	}	
	else // Mozilla/Netscape
	{ 
		insertBeforeRow = e.parentNode.parentNode.rowIndex;
	}
   	
	// Clone and Insert new row
	table = document.getElementById(tableID);
	var newRow = table.tBodies[0].rows[insertBeforeRow-1].cloneNode(true);
	table.tBodies[0].insertBefore(newRow,table.tBodies[0].rows[insertBeforeRow]);	//Inserts row one row before the button
   
	// Set/Reset input attributes 
	var clonedRow = newRow.childNodes;
	for (var i=clonedRow.length-1;i>=0;i--)
	{
    for (z=0;z<clonedRow[i].childNodes.length;z++) // Loop through all children, incase there are multiple inputs in the cell
    {
      traverseDomTree_recurse(clonedRow[i].childNodes[z],0);  
  	}	
	} 
}

function traverseDomTree_recurse(curr_element) 
{
  var i;

  if(curr_element.childNodes.length <= 0) 
  {
    // This is a leaf node.
    if(curr_element.type=='text')
		{
			 curr_element.value="";
		}else if(curr_element.type=='button')
		{
			curr_element.value="";
		}else if(curr_element.type=='hidden')
		{
			curr_element.value="";
    }
    else if(curr_element.type=='select-one') // Edits select boxes
		{	// added to make the dropdown_menu.js script work	and also make sure any selected indexes are not copied
		 	if(curr_element.contentHTML)
		 	{
        curr_element.outerHTML = curr_element.contentHTML.replace("selected","");
      }
      else // this is for normal select boxes
      {
        curr_element.selectedIndex=0;
      }  
		}    
  } else 
  {
    // Expand each of the children of this node.
    for(i=0; curr_element.childNodes[i]; i++) 
    {
      traverseDomTree_recurse(curr_element.childNodes[i]);
    }
  }
}
