/********************************************************
centers-institutes.js works in junction w/ ($global)/doctype-research.js
*********************************************************
*********************************************************
DEBUG Note: All debuging msgs are OFF, turn them ON by
find/replace //debug( with debug(
*********************************************************/
var itemData;
var collegeNarrow;
var	categoryNarrow;
var params = getParams();


//debug("JS starts running");
function updateContent(narrower) {
	
	
	//Reset all elements for updates
	$(".toggle-item").hide(0);
	$(".toggle-single").hide(0);
	$('#'+"category-formb").hide(0);
		
	if(narrower == "form"){
		collegeNarrow = document.categoryLista.college.value;
		categoryNarrow = document.categoryLista.category.value;
	}//end if
	
	else if(narrower == "url"){
			var collegeNarrow = params["college"];
			var	categoryNarrow = params["category"];
			
			if(collegeNarrow==null){ collegeNarrow = "allcunycolleges"; }//end if
			if(categoryNarrow==null){ categoryNarrow = "allcategories";}//end if
			
			document.getElementById(collegeNarrow).selected=true;
			
			document.getElementById(categoryNarrow).selected=true;
	}//end if
	else {
		collegeNarrow = "allcunycolleges";
		categoryNarrow = "allcategories";
	}//else

	try {
		document.getElementById("title-update").innerHTML="";
		document.getElementById("message-update").innerHTML="";
		
		//debug("Params: "+params.length);
		//debug("college from "+narrower+": "+collegeNarrow);
		//debug("Discipline from "+narrower+": "+categoryNarrow);
	
	    //variable to count elements to be shown, starts with all elements
		var showItems = $(".toggle-item").get();
		
			try { //params[id] might not be in url string
		
				if(params["id"].length>0) { //displays only one items information on the page and hides everything else
				
				$(".hp-view").hide(0);
				$(".moreinfo").hide(0);
				$('#'+"title-update").hide(0);
				$('#'+"category-forma").hide(0);
				$('#'+"category-formb").show(1);
				$("div.toggle-single").filter('#'+params["id"]).show(1);
				showItems = $(".toggle-single").filter('#'+params["id"]).get();
				
				}
		
				else { params["id"]=null; }
		
			}
		
			catch (e) {
		
		//check what to show and show it
		if(collegeNarrow == "allcunycolleges" && categoryNarrow == "allcategories") {
			//debug("allcunycolleges && allcategories");

			$(".toggle-item").show(1);
			showItems = $(".toggle-item").get();
			//debug("elements count "+showItems.length);
			
		}//if
		else if(collegeNarrow == "allcunycolleges"){
			//debug("allcunycolleges && "+ categoryNarrow);

			$(".categoryId").filter(":contains("+categoryNarrow+")").parent(".toggle-item").toggle(1);
			showItems = $(".categoryId").filter(":contains("+categoryNarrow+")").parent(".toggle-item").get();
			//debug("element count "+showItems.length);
			
		}//elseif
		else if(categoryNarrow == "allcategories"){
			
			//debug(collegeNarrow+" && allcategories");

			$(".collegeId").filter(":contains("+collegeNarrow+")").parent(".toggle-item").toggle(1);
			showItems = $(".collegeId").filter(":contains("+collegeNarrow+")").parent(".toggle-item").get();
			//debug("elements count "+showItems.length);

		}//elseif
		else {
			//debug(collegeNarrow+" && "+categoryNarrow);
			
			$(".toggle-item:has(.collegeId:contains("+collegeNarrow+")):has(.categoryId:contains("+categoryNarrow+"))").toggle(1);
			
			
			showItems = $(".toggle-item:has(.collegeId:contains("+collegeNarrow+")):has(.categoryId:contains("+categoryNarrow+"))").get();
			
			//debug("elements count "+showItems.length);
		
		}//else
		
	
		document.getElementById("title-update").innerHTML="";		
	
		var s1Tag = document.createElement("span");
		s1Tag.innerHTML =  colleges[collegeNarrow]+", ";
		var s2Tag = document.createElement("span");
		s2Tag.innerHTML =  categories[categoryNarrow];
		
		document.getElementById("title-update").appendChild(s1Tag);		
		document.getElementById("title-update").appendChild(s2Tag);
		
		//if no match, print message
		if(showItems.length==0){
			document.getElementById("message-update").innerHTML="There are no Centers or Institutes with those parameters.";
		}//if
		
		}//end of second catch
		
	}//end try
	

	catch(e){ //do  nothing
	}//end catch
	
}//end updateContent


/*
function debug(msg) {
	var pTag = document.createElement("p");
	pTag.innerHTML = msg;
	document.getElementById("debug").appendChild(pTag);
}
*/

//end debug