// Script required for List Item Menu //
var sfHover = function() {
	if(document.getElementById("menu") != null) {
		var sfEls = document.getElementById("menu").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			if(sfEls[i] != null) {
				sfEls[i].onmouseover=function() {
					this.className+=" sfhover";
				}
				sfEls[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			}
		}
	}
}
if (window.attachEvent) {
	window.attachEvent("onload", sfHover);
}else if(document.all && document.getElementById) {
	window.onload = sfHover;
}
// Script required for List Item Menu //

//*** Load the clock functions ***//
var campusClock;

function StartClock()
{
    if (document.all||document.getElementById)
       setInterval("AddMinute()",1000 * 60);  // launches every minute
    //RefreshClock();
}

function SetTime(hours, minutes)
{
   campusClock = new Date(2007, 1, 1, hours, minutes);
}

function AddMinute()
{
    campusClock.setMinutes(campusClock.getMinutes() + 1);
    RefreshClock();
}

function RefreshClock()
{
var minutes = campusClock.getMinutes();
    var hours = campusClock.getHours();
    var tag = "a.m.";
    if (campusClock.getHours() >= 12)
    tag = "p.m.";
    if (hours > 12)
        hours = hours - 12;
    if (hours == 0)
        hours = 12;
    if ( minutes <= 9)
        minutes = "0" + minutes;

    document.getElementById("clock").innerHTML = hours + ":" + minutes + " " + tag;
}

//*** Page Onload adder function ***//
function AddLoadEvent(func) 
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
            window.onload = func;
    } else {
            window.onload = function() {oldonload();func();}
    }
}

function hasClass(obj) {
	var result = false;
	if (obj.getAttributeNode("class") != null) {
		result = obj.getAttributeNode("class").value;
	}
	return result;
}  

/* This set of functions are used to set alt row colors. */
	function setStripes(table) {
		var even = false;
		/* Look for color arguments, if not there set defaults. */
		var evenColor = arguments[1] ? arguments[1] : "#fff";
		var oddColor = arguments[2] ? arguments[2] : "#dedede";
		
		var tbodies = table.getElementsByTagName("tbody");
		
		for (var h = 0; h < tbodies.length; h++) {
			var trs = tbodies[h].getElementsByTagName("tr");

			for (var i = 0; i < trs.length; i++) {
                            // if tr attribute 'nohighlight=true', skip
                            if (trs[i].getAttribute("nohighlight") != null && trs[i].getAttribute("nohighlight") == "true")
                                continue;

                            if (trs[i].className.toLowerCase() == 'selected' || (!hasClass(trs[i]) && !trs[i].style.backgroundColor)) {
                                    var tds = trs[i].getElementsByTagName("td");

                                    for (var j = 0; j < tds.length; j++) {
                                            if(tds[j] != null) {
                                                    if (!hasClass(tds[j]) && !tds[j].style.backgroundColor) {
                                                            tds[j].style.backgroundColor = even ? evenColor : oddColor;
                                                    }
                                            }
                                    }
                            }
                            even =  ! even;
			}
		}
	}
	function loadStripes() {
		var x = document.getElementsByTagName('table');
		for(var i = 0;i<x.length;i++) {
			if(x[i].getAttribute != null) {
				if(x[i].getAttribute('striped')) {
					setStripes(x[i]);
				}
			}
		}
	}

function setTitle(){
	document.title = document.title + " North Dakota State College of Science - Wahpeton, ND 58076";
}

AddLoadEvent(loadStripes);
AddLoadEvent(setTitle);

function openPopUp(coursecode) {
	var x = 0;
	var y = 0;
	if (document.all){
		x = screenLeft + 400;
		y = screenTop + 270;
	}else{
		x = screenX + 400;
		y = screenY + 400;
	}

	if(coursecode != null && coursecode.length > 0) {
		window.open("/departments/courses/showcourse.jsp?coursecode=" + coursecode,"coursewindow","width=570,height=250,scrollbars=yes,left=" + x + ", top=" + y);
	} else {
		alert('Invalid course code!');
	}
}