rebuilding table

see http://stackoverflow.com/questions/3950385/combining-rows-in-javascript

HTML

<table>
 <tbody>
        <tr> 
            <td colspan="3">
                <p>(Row 1) This Says Something</p>
            </td>
        </tr>
        <tr>
            <td> (Row 1a)
                <select option/>
            </td>
        </tr>
        <tr> 
            <td colspan="3">
                <p>(Row 2) This Says Something</p>
            </td>
        </tr>
        <tr>
            <td> (Row 2a)
                <select option/>
            </td>
        </tr>
        <tr>
            <td colspan="3"> 
                <p>(Row 3) This Says Something</p>
            </td>
        </tr>
        <tr>
            <td> (Row 3a)
                <select option/>
            </td>
        </tr>
    </tbody>
</table>

JavaScript

function fx(table)
 {
   var tmp=document.createElement('table');
       tmp.appendChild(document.createElement('tbody'));
   
   while(table.rows.length)
   {
     if(table.rows.length%2===0)
     {
       var wrapper=tmp.lastChild.appendChild(document.createElement('tr'));
       wrapper.appendChild(document.createElement('td'));
       wrapper.getElementsByTagName('TD')[0].appendChild(document.createElement('table'));
       wrapper.getElementsByTagName('TD')[0].lastChild.appendChild(document.createElement('tbody'));
     }
     
     wrapper.getElementsByTagName('TD')[0].lastChild.lastChild.appendChild(table.getElementsByTagName('TR')[0]);
   }
   table.parentNode.replaceChild(tmp,table);
   tmp.setAttribute('border',1);
 }

     
fx(document.getElementsByTagName('table')[0]);