//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 true;
					}
				}
			}
		}
	}
}

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.iadt.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;
    }

}


// 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', 'IADTErrorCounter', j);
        }
    }
}

function new_window(url) {
	newwindow = window.open(url, 'xczzxc', 'resizable=yes,scrollbars=yes');
	newwindow.focus();
}

/* Degree Page Tabs */
try {
	jQuery(document).ready(function(){
    if (document.getElementById('DegreeTabs') != null) {
        /* Product Page Product Tab */
        jQuery(function() {
            var tabContainers1 = jQuery('.DescriptionTab > div.tabContainer div.s1');

            jQuery('.DescriptionTab ul li a').click(function() {
                tabContainers1.hide().filter(this.hash).fadeIn('normal').show();
                jQuery('.DescriptionTab ul li').removeClass('selected');
                jQuery(this).parent().addClass('selected');
                return false;
            }).filter(':first').click();
            //}).filter(':first').click();
        });
    }
	});
}
catch(err) {}

/* Input Field Clear */
/*$(document).ready(function() {
			//$('input[type="text"]').addClass("idleField");
       		$('input[type="text"]').focus(function() {
       			//$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('input[type="text"]').blur(function() {
    			//$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});
		});	*/


/* Drop Down Menu JS */
$(document).ready(function() {
	
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}
 
 
	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 0, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 100, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};
 
	/*$("div.leftcol li .sub").css({'opacity':'0'});
	$("div.leftcol li").hoverIntent(config);
	
	$("div.rightcol .sub").css({'opacity':'0'});
	$("div.rightcol").hoverIntent(config);*/
 
});
