/* DEPENDENCIES
* HashTable.js
*/
var rowAdditionSequence = 0;
function addFilter(group, filterArray) {
var theTable = document.getElementById(group);
document.getElementById(group + "_size").value
= parseInt(document.getElementById(group + "_size").value) + 1;
if(noneSelected.get(group)){
theTable.tBodies[0].deleteRow(1);
noneSelected.remove(group)
noneSelected.put(group,false);
}
var row = document.createElement('tr');
row.id = "tr_" + group + "_" + rowAdditionSequence;
rowAdditionSequence++;
theTable.tBodies[0].appendChild(row);
for (var i = 0; i < filterArray.length; i++){
addTd(theTable, filterArray[i], i);
}
addRemoveButton(group,theTable,row.id);
window.focus();
}
function addTd(theTable, filterId, tdPosition){
var td = document.createElement('td');
var oFilter = document.getElementById(filterId);
theTable.tBodies[0].rows[theTable.tBodies[0].rows.length - 1].appendChild(td);
theTable.tBodies[0].rows[theTable.tBodies[0].rows.length - 1].cells[tdPosition].innerHTML =
"" + oFilter.options[oFilter.selectedIndex].text;
}
function addRemoveButton(group,theTable,rowId){
var td = document.createElement('td');
theTable.tBodies[0].rows[theTable.tBodies[0].rows.length - 1].appendChild(td);
td.align = "right";
td.innerHTML =
""
+ "remove"
+ "";
}
function remove(group, rowId){
var theTable = document.getElementById(group);
var row = document.getElementById(rowId);
theTable.tBodies[0].deleteRow(row.sectionRowIndex);
renameInputs(theTable);
document.getElementById(group + "_size").value -= 1;
if(theTable.tBodies[0].rows.length == 1){
addNoneSelectedRow(theTable)
noneSelected.remove(group);
noneSelected.put(group,true);
}
}
function removeAllFilters(group){
var theTable = document.getElementById(group);
document.getElementById(group + "_size").value = 0;
while (theTable.tBodies[0].rows.length > 1){
theTable.tBodies[0].deleteRow(1);
}
addNoneSelectedRow(theTable)
noneSelected.remove(group);
noneSelected.put(group,true);
}
function addNoneSelectedRow(theTable){
theTable.tBodies[0].appendChild(document.createElement('tr'));
for (var i=0; i < (theTable.tBodies[0].rows[0].cells.length - 1); i++){
addNoneSelectedTd(theTable);
}
var td2 = document.createElement('td');
td2.innerHTML = " ";
theTable.tBodies[0].rows[1].appendChild(td2);
}
function addNoneSelectedTd(theTable){
var td = document.createElement('td');
td.innerHTML = "All";
theTable.tBodies[0].rows[1].appendChild(td);
}
// loops through the table and reassigns the hidden input names based on row
function renameInputs(theTable){
for (var rowNo = 1; rowNo < theTable.tBodies[0].rows.length; rowNo++){
for (var cellNo = 0; cellNo < theTable.tBodies[0].rows[rowNo].cells.length - 1; cellNo++){
var oHiddenInput = theTable.tBodies[0].rows[rowNo].cells[cellNo].firstChild;
oHiddenInput.name = oHiddenInput.name.substring(0,oHiddenInput.name.length - 1) + (rowNo - 1);
}
}
}