// JavaScript Document
function urlJump(selectMenu) {
	var i = selectMenu.selectedIndex;
	var c = selectMenu[i].className;	
	var href = selectMenu[i].value;
	//alert(c);
	if(i > 0){
		if(c == 'p')
			window.open(href,'new','width=600,height=600,resizable=yes,scrollbars=yes');
		else 
			window.location = href;
	} 
}

//MM Open Window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//loads copy right year
function loadYear(){
var d = new Date();
document.write(d.getFullYear());
//document.write(d.getYear());
}

function checkAccreditationDIV(){
	var items = document.getElementsByTagName("div");
	var i;
	for(i=0; i< items.length;i++){		
		if((items[i].className != null) && (items[i].className == "right_button")){
				accbttn_flag =  true;
			}
	}
}


/* onload function to call function */
function addLoadEvent(func){
	var oldonload = window.onload;
	 if(typeof window.onload != 'function'){
	 	window.onload = func;
	 } else {
	 	window.onload = function() {
			oldonload();
			func();
		}
	 }
}

/* reset form fields with default values */
function resetFields(whichform){
	for(var i=0;i<whichform.elements.length; i++){
		var element = whichform.elements[i];
			if(element.type == "submit") continue;
				if(!element.defaultValue) continue;
			element.onfucus = function(){
				if(this.value == this.defaultValue){
					this.value = "";
				}
			}
			element.onblur = function(){
				if(this.value == ""){
					this.value = this.defaultValue;
				}
			}
			
	}

}

/* check for empty form fields */
function isFilled(field){
	if(field.value.length < 1 || field.value == field.defaultValue){
		return false;
	} else {
		return true;
	}
}

/* check for basic valid email syntax */
function isEmail(field){
	if(field.value.indexOf("@") == -1 || field.value.indexOf(".") == -1){
		return false;
	} else {
		return true;
	}
}

/* get form object and loop through and validate form elements */
function validateForm(whichform){
	for(var i=0; i<whichform.elements.length; i++){
		var element = whichform.elements[i];
			if(element.className.indexOf("required") != -1){
				if(!isFilled(element)){
					displayName = element.name.replace(/_/," ");
				alert("Please fill in the " + displayName + " field.");
				return false;
				}
			}
		if((element.name.indexOf("email") != -1) || (element.name.indexOf("Email") != -1)){
			if(!isEmail(element)){
				displayName = element.name.replace(/_/," ");
				alert("The " + displayName + " field must be a valid email address.");
				return false;
			}
		}
	}
	
	return true;
}

/* get form object on submit */
function prepareForms(){
	for(var i=0;i < document.forms.length; i++){
		var thisform = document.forms[i];
		resetFields(thisform);
		thisform.onsubmit = function() { return validateForm(this); }
	}
}


/***********************************************
* IFrame SSI script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
* dynammically resize iframe
***********************************************/
function dyniframesize() {
	var dyniframe=new Array()
	for (i=0; i<iframeids.length; i++){
		if (document.getElementById){ //begin resizing iframe procedure
		dyniframe[dyniframe.length] = document.getElementById(iframeids[i]);
		if (dyniframe[i] && !window.opera){
			dyniframe[i].style.display="block";
			if (dyniframe[i].contentDocument && dyniframe[i].contentDocument.body.offsetHeight) //ns6 syntax
				dyniframe[i].height = dyniframe[i].contentDocument.body.offsetHeight+FFextraHeight; 
			else if (dyniframe[i].Document && dyniframe[i].Document.body.scrollHeight) //ie5+ syntax
				dyniframe[i].height = dyniframe[i].Document.body.scrollHeight;
			}
		}
			//reveal iframe for lower end browsers? (see var above):
			if ((document.all || document.getElementById) && iframehide=="no"){
			var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
			tempobj.style.display="block";
		}
	}
}

/********************
* reset search field
*********************/
function resetField(form,field){
	eval("document." + form + "." + field + ".value=\"\"");
}

/*****************************************************
* show/hide
* used on News Page - can be used elsewhere
* if passed a link with name= "foo" will show/hide a div id= "foo_container"
*****************************************************/
function showHideDiv(whichlink) {
	if (!document.getElementById) return false;
	var num = whichlink.getAttribute("name");
	var story_id = num + "_container";
	var story_div = document.getElementById(story_id);
	if ( story_div.style.display == 'none') {
		story_div.style.display = 'block';
	}else{
		story_div.style.display = 'none';
	}
	return false;
}


/************************************************
* show / hide course descriptions
**************************************************/
function SwitchCourse(obj){
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementById("courselist").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="coursebody") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
				el.style.display = "block";
			}else{
				el.style.display = "none";
			}
		}
}

/************************************************
* show / hide generic elements, 
* set class on show / hide elements to 'box'
**************************************************/
function SwitchRegion(container,tag,obj){
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementById(container).getElementsByTagName(tag); //DynamicDrive.com change
		
		if(el.style.display != "block"){ //DynamicDrive.com change

			////for toggling open / close 'boxes'////

			/*for (var i=0; i<ar.length; i++){
				if (ar[i].className == 'box') //DynamicDrive.com change
					ar[i].style.display = "none";
				}*/
				
				el.style.display = "block";
			}else{
				el.style.display = "none";
			}
		}
}


/* generic pop up window with W/H parameters */
function openWindow(page,name,w,h){	
	var evalString = "window.open(";
								  
	if(page == ""){
		return false;
	} else {
		evalString += "'" + page + "'";
		
		if(name != ""){
			evalString += ",'" + name + "'";
		}	
		
		if(h != "" || w != ""){
		evalString += ",'";
			if(w != ""){
				evalString += "width = " + w + ",";
			}
			if(h != ""){
				evalString += "height = " + h;
			}
		evalString += "'";
		}
	}	
	
	evalString += ")";
	
	eval(evalString);
	}



/************************************
* return next element sibling node
*************************************/
function getNextSibling(startBrother){
  endBrother = startBrother.nextSibling;
  while(endBrother.nodeType != 1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
}


/************************************
* boolean: node not a comment
*************************************/
function notComment(e){
	if(e.nodeType != 8)
		return true;
	else
		return false;
	}
	

/************************************
* boolean: node is text node
*************************************/
function isText(e){
	if(e.nodeType == 3)
		return true;
	else
		return false;
}


/************************************
* hide element if no content
*************************************/
function hideRegion(element){
	var el = document.getElementsByTagName(element);
	var eCount = el.length;
	var kid;
	var test;
	var x;
	var keep = false;
	
	for(var i=0;i<eCount;i++){
	curr = el[i];
	kid = getNextSibling(curr);			
	test = kid.nodeName;
	keep = false;
	if(test == 'UL' || test == 'ul'){
		//alert(kid.nodeName);
		if(kid.hasChildNodes){
			var list = kid.childNodes;
			for(var j=0;j<list.length;j++){
				y = list[j];
				x = y.nodeName;
				if(x == 'LI' || x == 'li'){
					if(y.hasChildNodes){
						var s = y.childNodes;
							for(var k=0;k<s.length;k++){
									if(notComment(s[k]) && isText(s[k])){	
											keep = true;
										}
								}
						}
					

				}
				//alert(list[j].nodeName);
			}
		}
				
				if(!keep){//hide element if no <li> tags in <ul> sibling
					el[i].style.display = "none";						
				}	
										
		}
												
	}
				  
}

/******************************************
* print news link based on dept directory
*******************************************/
function printNewsLink(){
var id = document.getElementById("csldir");
var list = id.childNodes;
var kids = id.hasChildNodes;
var c = list.length;
var reg = new RegExp("hum");		

if(kids){
	for(var i=0;i<c;i++){	
		x = list[i].nodeValue;
			if(x.match(reg)){
				document.write("<p><strong><a href=\"/csl/hum/announcements/\">More News &raquo;</a></strong></p>");
			}
	}
}
}


/********* TEST 01.11.08 TT ********************/


function getTextNode(e){	
	var x = e.childNodes;
	var c = e.length;
	var t;
	var textValue = "";	
		for(var i=0;i<c;i++){
			t = x[i];
				if((notComment(t)) && (isText(t))){
						textValue = t;	
					}
			}						
			return textValue;			
	}



function swapNavHeader(e){
	var aTags = document.getElementsByTagName(e);
	//var navRoot = document.getElementById('cssnavtree');
	var count = aTags.length;
	var aTags;
	var list;
	var value;
	var url;
	var newNode;
	
	/*******
	* have to find way to swap nodes.....
	**********/
	for(var i=0;i<count;i++){												
	//value = list[j].nodeValue;								
	
		list = aTags[i].childNodes;//list of child nodes of anchor tag
		
			for(var j=0;j<list.length;j++){		
			
				if( (notComment(list[j])) && (isText(list[j])) ){//check that textNode is not a comment and is text
					
					value = list[j].nodeValue;//text value in anchor tag
					url = aTags[i].href;//href value in anchor
					
						if(value != 'undefined'){
							if(url == 'http://www.iit.edu/'){
									
									newNode = document.createTextNode(value);//create a new text node
									alert(newNode.nodeValue);
									//aTags.replaceChild(newNode,aTags[i]);//alert(newNode.nodeValue);
								}			
							}
						//alert("Href of this a element is : " + aTags[i].href + "\nValue is: " + value);		
				}
		}
		}

	}
	

/********************************************/






