/* Add zebra stripes to tables generated by the scheduling system */

function zebraSchedule() {
    for (var ti = 0; ti < 10; ti ++) {
	var table = document.getElementById ("zebra" + ti)

	if (table != null) {
	    table.border = "0";
	    table.className = "grid";
	    zebraStripes (table.id);

	    var rows = table.rows;

	    for (var ri = 0; ri < rows.length; ri ++) {
		var cells = rows [ri].cells;

		for (ci = 0; ci < cells.length; ci ++)
		    cells [ci].innerHTML =
			cells [ci].innerHTML.replace (/ \(/g, "<br />(");
	    }
	}
    }
}


/* We have some pages that are not directly referenced by the directory
   navigation in the left hand column, but we want a certain navigation
   structure to be displayed.  This function lets us turn on the sublists
   based on a URL. */

function turnOnDirectoryNav (link) {
    var anchors = document.getElementsByTagName ("A");

    for (var i = 0; i < anchors.length; i ++) {
	if (anchors [i].href.indexOf (link) != -1) {
	    var parent = anchors [i].parentNode;

	    while (parent != document) {
		if (parent.nodeName == "LI")
		    parent.className = parent.className + " on";
		parent = parent.parentNode;
	    }
	}
    }
}


/* Add an explicit link to the stylesheet for printing so that users
   will get a decent-looking page without having to switch to the
   printer-friendly view.  Since we don't want to accidently mess
   things up, we only do this on browsers that we know will work. */

function addPrintStyleSheet ( ) {
    var supported = 0;
    var agent = navigator.userAgent;
    var browser = navigator.appName;
    var version = parseFloat (navigator.appVersion);

    if (agent.indexOf ("MSIE 6") != -1 || agent.indexOf ("MSIE 7") != -1)
	supported = 1;
    else if (navigator.appName == "Netscape" && version >= 5.0)
	supported = 1;
    else if (navigator.appName == "Opera" && version >= 8.0)
	supported = 1;

    if (supported) {
	var link = document.createElement ("link");
	var node = document.getElementsByTagName ("head") [0];

	link.href = "/style/template-print.css";
	link.rel = "stylesheet";
	link.media = "print";
	node.appendChild (link);

	link = document.createElement ("link");
	node = document.getElementsByTagName ("head") [0];

	link.href = "/engineering/cse/upload/print.css";
	link.rel = "stylesheet";
	link.media = "print";
	node.appendChild (link);
    }
}


/* Set the selected option in a drop-down list of links to default to the
   document's url. */

function setSelectedOption ( ) {
    var options = document.getElementsByTagName ("OPTION");

    for (var i = 0; i < options.length; i ++)
	if (document.URL.indexOf (options [i].value) != -1)
	    options [i].selected = "true";
}

