/*
See yak-for-wordpress.php for information and license terms
*/

var className = ''

function getElement(id) {
    if (document.getElementById != null) {
        return document.getElementById(id)
    }
    else {
        return document.all[id]
    }
}

function toggleDisplay(cell) {
    row = cell.parentNode;
    nextRow = row.parentNode.rows[row.rowIndex+1];
    nextRow.className = className;
    if (className == '') {
        className = 'hidden';
    }
    else {
        className = '';
    }
}

function copyRow(tableName) {
	table = document.getElementById(tableName);
	cells = table.rows[table.rows.length-1].cells;
	var newrow = document.createElement('tr');
	for (var i = 0; i < cells.length; i++) {
		cell = document.createElement('td');
		cell.innerHTML = cells[i].innerHTML;
		newrow.appendChild(cell);
	}
	table.appendChild(newrow);
}

function findInput(cell) {
    row = cell.parentNode;
    for (var i = cell.cellIndex-1; i >= 0; i--) {
        var sibling = row.cells[i];
        if (sibling.firstChild.nodeName.toLowerCase() == 'input') {
            return sibling.firstChild;   
        }
    }
    return null;
}

function startsWith(str, prefix) {
    return str.substring(0, prefix.length) == prefix;
}

function selectAllCheckboxes(form, checkbox, prefix) {
    var checked = false;
    if (checkbox.checked) {
        checked = true;
    }
    
    var inputs = document.forms[form].getElementsByTagName('input');
    
    for (i = 0; i < inputs.length; i++) {
        if (inputs[i].type == 'checkbox' && startsWith(inputs[i].name, prefix)) {
            inputs[i].checked = checked;
        }
    }
}
