//Add class jsOn to the html tag if the user has javascript enabled, then use it in front of a style to override
//For example: #basicstyle {display:block} followed by .jsOn #basicstyle {display: none;} will show by default and hide by default if js is on.
	document.getElementsByTagName('html')[0].className='jsOn';

function initPage()
{
	var n = document.getElementById("side-nav");
	if (n)
	{
		var lis = n.getElementsByTagName("li");
		for (var i = 0; i < lis.length; i++)
		{
			if (lis[i].getElementsByTagName("ul").length)
			{
				var a = lis[i].getElementsByTagName("a").item(0);
				if (a)
				{
				/* Doesn't work right
					a.onmouseover = function ()
					{	
						var p = this.parentNode;
						if (p.className.indexOf("active") != 1) 
						p.className += " active";
						return false;
					}
					
					a.onmouseout = function ()
					{	
						var p = this.parentNode;
						if (p.className.indexOf("active") != 1) 
						p.className = p.className.replace("active", "");
						return false;
					}
				*/	
					a.onclick = function ()
					{	
						var p = this.parentNode;
						if (p.className.indexOf("active") != -1) 
						{
							p.className = p.className.replace("active", "");
						}
						else {
							p.className += " active";
							window.open(this.href,this.target='_self');
						}
						return false;
					}
				}
			}
		}
	}
}

if (window.addEventListener)
    window.addEventListener("load", initPage, false);
else if (window.attachEvent)
    window.attachEvent("onload", initPage);

//Nav test


// PRINT PAGE	
// unobtrusive JavaScript for "Print This!" links
// http://perishablepress.com/press/2009/02/01/unobtrusive-javascript-for-print-this-links/

function printClick() {
    if (!document.getElementById) return false;
    if (!document.getElementById("print_this")) return false;

    var link = document.getElementById("print_this");
    link.onclick = function() {
        window.print();
        return false;
    }
    link.onkeypress = link.onclick;
}

// onload function (not needed if script called at the end of the page)
// replace with "printClick();" if script called at the end of the page

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
addLoadEvent(printClick);
// End PRINT PAGE

// BEGIN BOOKMARK CODE
function addBookmark() {
    var url = location.href;
    var title = document.title;

    if (url.indexOf("file:") > -1) // IE cannot bookmark pages saved on hd: use main URL
        url = "http://www.coloradotech.edu";

    if (window.sidebar && sidebar.addPanel) { // add to FF bookmarks  
        window.sidebar.addPanel(title, url, '');
    }
    else if (window.external) { // add IE favorite
        window.external.AddFavorite(url, title);
    }
    else { // unknown browser
        alert('Failed to recognize your browser, please bookmark the page manually.');
    }
}
// END BOOKMARK LINK

function toggleSelection(object, value) {
    var AllOption = (value == "-1");
    var cbL = document.getElementById('ctl00_Main_Container_Content_cbDegreeLevel');    //TODO
    toggleSelections(cbL, AllOption);
}

function toggleSelections(ListObject, AllIsSelected) {
    var options = ListObject.getElementsByTagName('input');
    var NoneSelected = true;

    if (AllIsSelected) {
        //All option is selected.  Uncheck every other option.
        for (i = 1; i < options.length; i++) {
            ListObject.getElementsByTagName('input')[i].checked = false;
        }
    } else {
        ListObject.getElementsByTagName('input')[0].checked = false;
    }

    for (i = 1; i < options.length; i++) {
        if (options[i].checked) {
            NoneSelected = false;
        }
    }

    if (NoneSelected) {
        //All options unchecked.  Check "All" option.
        ListObject.getElementsByTagName('input')[0].checked = true;
    } else {
        ListObject.getElementsByTagName('input')[0].checked = false;
    }

}

//APPLICATION PROCESS PAGES
/*function LaunchMyDocs(gentype) {
    window.open('/applicationprocess/MyDoc/default.aspx?gentype=' + gentype, 'blank', 'menubar=no,toolbar=no,resizable=yes');
    return false;
}*/

function TrackOmnitureConversion(s_account, folderType, frmType) {
    s.pageName = "";
    s.channel = folderType;
    s.linkTrackVars = 'prop1,prop2,eVar8,eVar9,events';
    s.linkTrackEvents = 'event1,event2';
    s.prop1 = "Request Info";
    s.prop2 = frmType;
    s.hier1 = "Business|Project Management|" + frmType; //Note: frmtype will be either “long form” or “short form"
    s.eVar8 = "Request Info";
    s.eVar9 = frmType;
    s.events = "event1";
    s.tl(this, 'o', 'Request Info Submit Button');
}


function OmnitureTracking_LiveChatClick(folderType, s_account) {
    var s = s_gi(s_account);
    s.pageName = "";
    s.channel = folderType;
    s.linkTrackVars = 'prop1,eVar8,events';
    s.linkTrackEvents = 'event1,event2';
    s.prop1 = "Live Chat Request";
    s.eVar8 = "Live Chat Request";
    s.events = "event2";
    s.tl(this, 'o', 'Live Chat Request');
    return true;
}

// Need to add a call to transmitErrorsToLP() statement somewhere!
function transmitErrorsToLP() {
    if (typeof (Page_Validators) != 'undefined') {
        var i;
        var j = 0;
        for (i = 0; i < Page_Validators.length; i++) {
            if (!Page_Validators[i].isvalid) {
                j += 1;
            }
        }
        if (j > 0) {
            lpAddVars('page', 'CTUErrorCounter', j);
        }
    }
}
