| /* Multiline script */ |
| |
| var names = new Array; |
| var count; |
| |
| function addRow(elem){ |
| tableObj=findParent(elem,'TABLE') |
| if (!tableObj.processed) { |
| recursive(tableObj,'save') |
| tableObj.processed=true |
| } |
| tableObj.tBodies[0].insertBefore(tableObj.rows[1].cloneNode(true),tableObj.rows[tableObj.rows.length-1]) |
| recursive(tableObj.rows[tableObj.rows.length-2], 'clear') |
| setIndex(tableObj) |
| } |
| |
| function remRow(elem){ |
| tableObj=findParent(elem,'TABLE') |
| if (tableObj.rows.length>3){ |
| trObj=findParent(elem,'TR') |
| tableObj.deleteRow(trObj.sectionRowIndex) |
| } |
| } |
| |
| function findParent(childObj,parentTag){ |
| try {while (childObj.parentNode.tagName!=parentTag) childObj = childObj.parentNode} catch(childObj){return null} |
| return childObj.parentNode |
| } |
| |
| function setIndex(tableObj){ |
| for (i=1;i<tableObj.rows.length;i++){ |
| count=0 |
| recursive(tableObj.rows[i], 'set', i) |
| } |
| } |
| |
| function recursive(parentObj, mode, row){ |
| var i, childObj, mode; |
| childObj=parentObj.childNodes |
| for (i=0; i<childObj.length; i++){ |
| if (childObj[i].tagName=='INPUT' || childObj[i].tagName=='SELECT' || childObj[i].tagName=='TEXTAREA') |
| switch (mode){ |
| case "save": |
| names[tableObj,names.length]=childObj[i].name |
| break |
| case "set": |
| childObj[i].id=childObj[i].name=names[tableObj,count]+row.toString() |
| count++ |
| break |
| case "clear": |
| if (childObj[i].tagName=='INPUT' && childObj[i].type=='file'){ |
| // |
| } |
| else childObj[i].value='' |
| break |
| } |
| if (childObj[i].childNodes.length>0) recursive(childObj[i], mode, row) |
| } |
| } |