//alert('foo');

//show the main body and hide the summary for a particular event
function ShowBody()
{
	document.getElementById("EventBody").style.display = "block";
	document.getElementById("EventSummary").style.display = "none";
	document.getElementById("EventContinue").style.display = "none";
}

//shows the selected newsletter
function DisplayNewsletter(id)
{
	if(id != 0)
	{
		window.location.href = "inform-newsletter.php?issue=" + id;
	}
}

//function for showing the details on the degrees page
function ShowDegreeDetail(lvl, grp, dgr)
{
	//alert("degree: " + dgr + "\ngroup: " + grp + "\nLevel: " + lvl);
	var level 	= document.getElementById('level_' + lvl);
	var group 	= document.getElementById('group_' + grp);
	var degree 	= document.getElementById(dgr);
	
	
	level.style.color = "#FF4000";
	group.style.color = "#FF4000";
	degree.style.color = "#FF4000";
	degree.getElementsByTagName('strong')[0].style.color = "#FF4000";
	
	
}
//function for showing the details on the degrees page
function HideDegreeDetail(lvl, grp, dgr)
{
	//alert(lvl);
	var level 	= document.getElementById('level_' + lvl);
	var group 	= document.getElementById('group_' + grp);
	var degree 	= document.getElementById(dgr);
	
	level.style.color = "#006699";
	group.style.color = "#006699";
	degree.style.color = "#8B8B8B";
	degree.getElementsByTagName('strong')[0].style.color = "#8b8b8b";
}

function ToggleDegreeSummary(id)
{
	var arySummaryRows = getElementsByClassName("degreeInfo","div");

	for(var i=0; i < arySummaryRows.length; i++)
	{
		//alert(arySummaryRows[i].style);
		arySummaryRows[i].style.display = "none";
	}
	
	var degreeDiv = document.getElementById('degreeInfo_' + id);
	degreeDiv.style.display = "block";
	
}

function ToggleGroupSummary(id)
{
	var arySummaryRows = getElementsByClassName("degreeInfo","div");

	for(var i=0; i < arySummaryRows.length; i++)
	{
		//alert(arySummaryRows[i].style);
		arySummaryRows[i].style.display = "none";
	}
	
	var degreeDiv = document.getElementById('groupInfo_' + id);
	degreeDiv.style.display = "block";
	
}
function getElementsByClassName(searchClass,tag) {

	var classElements = new Array();
	var i;
	var j;

	var els = document.getElementsByTagName(tag);

	var elsLen = els.length;
	
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

//function used to parse qstring for name value pairs by variable name
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return("");
}

//this function is used to control the state of whole rows or columns of degrees
//the value of type determines whether we're toggling state on a row of degrees by disc group or 
//a columns of degrees by level. typeId determines which row/col we're focusing on and 
//action is whether we're showing active or inactive state

function HighlightDegreesByType(type, typeId, action, el)
{
	var aryDegrees = getElementsByClassName("degree","a");
	var str = '';
	var aryTemp = new Array();
	var tester = '';
	var theLink = document.getElementById(el);
	
	//alert(el);
	theLink.style.color = (action == 'show') ? "#FF4000" : "#006699";
	for(var i=0; i<aryDegrees.length; i++)
	{
		str = aryDegrees[i].id;
		aryTemp = str.split("_");
		tester = aryTemp[type];
		//alert(tester);
		if(tester == typeId && action == 'show')
		{
			aryDegrees[i].style.color = "#FF4000";
			aryDegrees[i].getElementsByTagName('strong')[0].style.color = "#FF4000";
			//theLink.style.color = "#FF4000";
		}
		else
		{
			aryDegrees[i].style.color = "#8b8b8b";
			aryDegrees[i].getElementsByTagName('strong')[0].style.color = "#8b8b8b";
			//theLink.style.color = "#006699";
		}
	}
	//alert('done');
}

//show hides divs for display 
function ToggleDescription()
{
	//get the div, the link, and the summary
	var thelink	= document.getElementById("morelink");
	var desc	= document.getElementById("buildingDescription");
	var summary	= document.getElementById("buildingSummary");
	
	summary.style.display = "none";
	thelink.style.display = "none";
	desc.style.display = "block";	
	
}

//set the sort variables (querystring) for people pages
function DoSort(filter)
{
	//alert("sort");
	var aryNames = new Array("type","faculty","id");
	var theUrl = "people.php" + ReCreateQString(aryNames);
	theUrl += "&sortBy=" + filter;
	
	window.location.href = theUrl;
}
function SetRange(range)
{
	var aryNames = new Array("type","faculty","id","sortBy");
	var theUrl = "people.php" + ReCreateQString(aryNames);
	theUrl += "&range=" + range;
	
	window.location.href = theUrl;
}


//take an array of names, and recreate the name/val pairs are required
//attach to a string, trim the tailing ampresand and return
function ReCreateQString(aryNames)
{
	var retval = "?";
	for(var i=0; i<aryNames.length; i++)
	{
		var tempVal = getQueryVariable(aryNames[i]);

		if(tempVal != '')
		{
			retval += aryNames[i] + "=" + tempVal + "&";
		}
	}
	return (retval != "?") ? retval.substring(0,(retval.length - 1)) : "";
	
}
