//hide or show sub menu and change + to -
function toggleMenu(lID, aID){
	if (!document.getElementById){
		return;
	}

	var mHead = getElementsByClass("mHead"); //the mList headings
	var mList = getElementsByClass("mList", document, "div"); //the divs that contain the mLists
	var headText; //text to render
	var currTextNode; //store current text node
	var currIH; //store current inner HTML
	var s; //use to reference style property
	
	//hide all menus except the one whose id was passed in
	for(i = 0; i < mList.length; i++){
		s = mList[i].style;
		currIH = mHead[i].innerHTML; //save the current text 
		//alert(currTextNode.toString())
		if(mList[i].id != lID){
			headText = document.createTextNode('+ ' + right(currIH, currIH.length - 2));
			s.display = 'none';
		}
		else
		{
			if(s.display == 'inline'){
				headText = document.createTextNode('+ ' + right(currIH, currIH.length - 2));
				s.display = 'none';
			}
			else{	
				headText = document.createTextNode('- ' + right(currIH, currIH.length - 2));
				s.display = 'inline';
			}
		}
		currTextNode = mHead[i].childNodes[0];
		mHead[i].removeChild(currTextNode); //clear the current text 
		mHead[i].appendChild(headText);
	}
}

//returns an array of elements of a particular class
function getElementsByClass(searchClass,node,tag) {
  var classElements = new Array();
  if (node == null)
    node = document;
  if (tag == null)
    tag = '*';
  var els = node.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;
}

//return the left n chracters of a string
function left(str, n){
	if (n <= 0){
	    return "";
	}
	else if (n > String(str).length){
	    return str;
	}
	else{
	    return String(str).substring(0,n);
	}
}

//return the right n characters of a string
function right(str, n){
    if (n <= 0){
       return "";
	}
    else if (n > String(str).length){
       return str;
	}
    else{
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
