//  this function is used to check for show or hide, and show all immediate child elements
function showOrHideItem(parentchild) {
	
	// get the parent and child based on the string 
	var brokenstring = parentchild.split("-");
	
	// assign the parent and child parts to specific ids
	parent_id = brokenstring[0];
	child_id = brokenstring[1];
		
	var contentDiv = document.getElementById("sidenav");
	
	//  if they are being hidden
	checkHide = document.getElementById("i" + child_id);
	if(checkHide.src == "http://www.nspd.net/images/menu_tree_minus.gif") {
		hideItem(parentchild);
	}
	//  if they are being shown
	else {
	
		// run through all contained elements
		var allContainedElements = contentDiv.getElementsByTagName("div");
		for (var i = 0; i < allContainedElements.length; i++) {
			var elem = allContainedElements[i];
			var catIDs = elem.id;
			if((catIDs != null) && (catIDs != "undefined")) {
				
				var anotherstring = catIDs.split("-");
				current_parent_id = anotherstring[0];
				current_child_id = anotherstring[1];
	
				//  show or hide all child immediate elements
				if(current_parent_id == child_id) {				
					current_child = document.getElementById(catIDs);
					current_child.style.display = "block";
				}
			}
		}
		
		//  changes the plus to minus
		var img_name = "i" + child_id;
		var theImg = document.getElementById(img_name);
		if(theImg != null) {
			theImg.src = "http://www.nspd.net/images/menu_tree_minus.gif";
		}
	}
}

//  this function is used to recursively hide child elements of the menu
function hideItem(parentchild) {
	// get the parent and child based on the string 
	var brokenstring = parentchild.split("-");
		
	var contentDiv = document.getElementById("sidenav");
	
	// run through all contained elements
	var allContainedElements = contentDiv.getElementsByTagName("div");
	for (var i = 0; i < allContainedElements.length; i++) {
		
		// assign the parent and child parts to specific ids
		parent_id = brokenstring[0];
		child_id = brokenstring[1];
		
		var elem = allContainedElements[i];
		var catIDs = elem.id;
	
		if((catIDs != null) && (catIDs != "undefined")) {
			
			var anotherstring = catIDs.split("-");
			current_parent_id = anotherstring[0];
			current_child_id = anotherstring[1];

			//  show or hide all child immediate elements
			if(current_parent_id == child_id) {				
				current_child = document.getElementById(catIDs);
				current_child.style.display = "none";
				hideItem(catIDs);
			}
		}
	}
	
	//  changes the minus back to plus
	var img_name = "i" + child_id;
	var theImg = document.getElementById(img_name);
	if(theImg != null) {
		theImg.src = "http://www.nspd.net/images/menu_tree_plus.gif";
	}
}

//  this function is used to send the user to the correct product page
function goToProductPage(mid) {
	window.location = "http://www.nspd.net/products.php?&mid=" + mid;
	
}