﻿/*
    File: WireFrame.js  02-08-2006 Brian Timmer
    Base JavaScript file for application
*/


// Sets the row highlighting
function RollOverHighlight(classname) {
    if (document.getElementById) {
	    var t, i, rows;
	    var ts = document.getElementsByTagName("table");
	    for (t in ts) {
	        if (ts[t].className == classname) {
	            rows = ts[t].getElementsByTagName("tr");
	            for (i in rows) {
		            rows[i].onmouseover = function() { rollOver(this); };
		            rows[i].onmouseout = function() { rollOut(this); };
	            }
	        }
	    }
	}
}

function rollOver(elm) {
    if (!/selecteditem/.test(elm.className))
	    elm.className = "hovereditem";
}

function rollOut(elm) {
    if (!/selecteditem/.test(elm.className)) {
	    elm.className = "";
	}
}


// Highlights a selected row
function HighlightRow(cbk) {
    if (document.getElementById) {
        var row = cbk.parentNode.parentNode;
        row.className = (cbk.checked) ? "selecteditem" : "";
    }
}

// Checks/Unchecks all checkboxes in a form
function ToggleCheck() {
   if (document.getElementById){
        var inputs, i;
        inputs = document.getElementsByTagName('input');
        for(i in inputs) {
            if(/checkbox/.test(inputs[i].type)) {
                inputs[i].checked = (inputs[i].checked) ? false : true;
                HighlightRow(inputs[i]);
            }
        }
    }
}

// Sets all of the checkboxes for the permission system to whatever
// the checkbox the user if clicking is set to.
function CheckSubCheckBoxes(elm) {
    if (document.getElementById) {
        var inputs, i, parentDl;
        parentDl = elm.parentNode.parentNode;
        inputs = parentDl.getElementsByTagName('input');
        for(i in inputs) {
            if(/checkbox/.test(inputs[i].type)) {
                inputs[i].checked = elm.checked;
            }
        }
    }
    else elm.style.display = "none";
}
