function addBaris() {
var tbl = document.getElementById("ItemTable");
var row = tbl.insertRow(tbl.rows.length);
var td0 = document.createElement("td");
var td1 = document.createElement("td");
var td2 = document.createElement("td");
var td3 = document.createElement("td");
var td4 = document.createElement("td");
var td5 = document.createElement("td");
var td6 = document.createElement("td");
td0.appendChild(genIndex(row.rowIndex));
td1.appendChild(genCheckBox(row.rowIndex));
td2.appendChild(genCompany(row.rowIndex));
td3.appendChild(genPeriod(row.rowIndex));
td4.appendChild(genYear(row.rowIndex));
td5.appendChild(genRole(row.rowIndex));
td6.appendChild(genRespon(row.rowIndex));
row.appendChild(td0);
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
row.appendChild(td4);
row.appendChild(td5);
row.appendChild(td6);
}
function genIndex(index) {
var idx = document.createElement("input");
idx.type = "hidden";
idx.name = "index[ ]";
idx.id = "index["+index+"]";
idx.value = index;
return idx;
}
function genCheckBox(index) {
var check = document.createElement("input");
check.type = "checkbox";
check.name = "check2[ ]";
check.id = "check2["+index+"]";
return check;
}
function genCompany(index) {
var idx = document.createElement("input");
idx.type = "text";
idx.name = "fCompany[ ]";
idx.id = "fCompany["+index+"]";
idx.size = "20";
return idx;
}
function genPeriod(index) {
var idx = document.createElement("input");
idx.type = "text";
idx.name = "fPeriod[ ]";
idx.id = "fPeriod["+index+"]";
idx.size = "15";
return idx;
}

function genYear(index) {
var idx = document.createElement("input");
idx.type = "text";
idx.name = "fYear2[ ]";
idx.id = "fYear2["+index+"]";
idx.size = "4";
idx.setAttribute('maxLength',2);
return idx;
}
function genRole(index) {
var idx = document.createElement("textarea");
idx.name = "fRole[ ]";
idx.id = "fRole["+index+"]";
idx.cols="30";
idx.rows="5";
return idx;
}
function genRespon(index) {
var itemName = document.createElement("textarea");
itemName.name = "fRespon[ ]";
itemName.id = "fRespon["+index+"]";
itemName.cols = "30";
itemName.rows = "5";
return itemName;
}
function AllClick() {
var checked = false;
if (document.getElementById("checkMaster2").checked == true)
checked = true;
var tbl = document.getElementById("ItemTable");
var rowLen = tbl.rows.length;
for (var idx=1;idx<rowLen;idx++) {
var row = tbl.rows[idx];
var cell = row.cells[1];
var node = cell.lastChild;
node.checked = checked;
}
}
function AllDelete() {
var tbl = document.getElementById("ItemTable");
var rowLen = tbl.rows.length - 1;
for (var idx=rowLen;idx > 0;idx--) {
tbl.deleteRow(idx)
}
}
function RowBuffer(table) {
var tbl = document.getElementById("ItemTable");
var rowLen = tbl.rows.length;
for (var idx=1;idx<rowLen;idx++) {
var row = tbl.rows[idx];
var cell = row.cells[1];
var node = cell.lastChild;
if (node.checked == false) {
var rowNew = table.insertRow(table.rows.length);
var td0 = document.createElement("td");
var td1 = document.createElement("td");
var td2 = document.createElement("td");
var td3 = document.createElement("td");
var td4 = document.createElement("td");
var td5 = document.createElement("td");
var td6 = document.createElement("td");
td0.appendChild(row.cells[0].lastChild);
td1.appendChild(row.cells[1].lastChild);
td2.appendChild(row.cells[2].lastChild);
td3.appendChild(row.cells[3].firstChild);
td4.appendChild(row.cells[4].lastChild);
td5.appendChild(row.cells[5].lastChild);
td6.appendChild(row.cells[6].lastChild);
rowNew.appendChild(td0);
rowNew.appendChild(td1);
rowNew.appendChild(td2);
rowNew.appendChild(td3);
rowNew.appendChild(td4);
rowNew.appendChild(td5);
rowNew.appendChild(td6);
}
}
}
function reIndex2(table) {
var tbl = document.getElementById("ItemTable");
var rowLen = table.rows.length;
for (var idx=0;idx < rowLen;idx++) {
var row = table.rows[idx];
var rowTbl = tbl.insertRow(tbl.rows.length);
var td0 = document.createElement("td");
var td1 = document.createElement("td");
var td2 = document.createElement("td");
var td3 = document.createElement("td");
var td4 = document.createElement("td");
var td5 = document.createElement("td");
var td6 = document.createElement("td");
td0.appendChild(row.cells[0].lastChild);
td1.appendChild(row.cells[1].lastChild);
td2.appendChild(row.cells[2].lastChild);
td3.appendChild(row.cells[3].firstChild);
td4.appendChild(row.cells[4].lastChild);
td5.appendChild(row.cells[5].lastChild);
td6.appendChild(row.cells[6].lastChild);
rowTbl.appendChild(td0);
rowTbl.appendChild(td1);
rowTbl.appendChild(td2);
rowTbl.appendChild(td3);
rowTbl.appendChild(td4);
rowTbl.appendChild(td5);
rowTbl.appendChild(td6);
}
}
function RowDelete() {
var tbl = document.getElementById("ItemTable");
var error = false;
if (document.getElementById("checkMaster2").checked == false)
error = true;
var tbl = document.getElementById("ItemTable");
var rowLen = tbl.rows.length;
for (var idx=1;idx<rowLen;idx++) {
var row = tbl.rows[idx];
var cell = row.cells[1];
var node = cell.lastChild;
if (node.checked == true) {
error = false;
break;
}
}
if (error == true) {
alert ("You didn't check anything, please check the checkbox and try again");
return;
}
if (document.getElementById("checkMaster2").checked == true) {
AllDelete();
document.getElementById("checkMaster2").checked = false;
} else {
var table = document.createElement("table");
RowBuffer(table);
AllDelete();
reIndex2(table);
}
}
