//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';

//Side Nav 
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 openlegal (){
    window.open('/legal_standalone.aspx','legal','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=640,height=400');
}

function openagreelegal (){
    window.open('https://campus.ctuonline.edu/schools/6/pdf/enrollment_agreement.pdf','agreelegal','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=640,height=440');
}



//used from education and referral pages
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	function autoTab(input,len, e) 
	{
		var keyCode = (isNN) ? e.which : e.keyCode; 
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

		if(input.value.length >= len && !containsElement(filter,keyCode)) 
		{
			input.value = input.value.slice(0, len);
			input.form[(getIndex(input)+1) % input.form.length].focus();
		}

		function containsElement(arr, ele) 
		{
			var found = false, index = 0;
			while(!found && index < arr.length)

			if(arr[index] == ele)
				found = true;
			else
				index++;

			return found;
		}

		function getIndex(input) 
		{
			var index = -1, i = 0, found = false;
			while (i < input.form.length && index == -1)
			if (input.form[i] == input)
				index = i;
			else 
				i++;
			return index;
		}

	return true;
	}