// ----------------------------------------------------------------------------
// HasClassName
//
// Description : returns boolean indicating whether the object has the class name
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function HasClassName(objElement, strClass)
   {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // we found it
            return true;

            }

         }

      }

   // if we got here then the class name is not there
   return false;

   }
   
/*

Function to grab URL passed vars

usage: var projecttype_param = gup( 'projecttype' );

*/

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "index";
  else
    return results[1];
}

/*

	== PHP FILE TREE JAVASCRIPT EXTENSION ==
		
		Based on the Expandable Listmenu Script by Daniel Nolan
		http://www.bleedingego.co.uk/webdev.php
		
		Modified by Cory S.N. LaViska
		http://abeautifulsite.net/
		
	== WHAT IT DOES ==
	
		This script makes the nested lists created by PHP File Tree expand and 
		collapse dynamically.
		
	== USAGE ==
	
		Include the script into the <head></head> section of the appropriate 
		page(s) as shown below:
	
			<script src="php_file_tree.js" type="text/javascript"></script>
			
		All file trees generated by PHP File Tree will automatically collapse to 
		the top level (as specified by $directory) and become dynamic.

	== FAQS ==
	
		Q Can I have more than one file tree on one page?
		A Yes.  You can have as many as you want and they will all function as expected.
		
*/

function init_php_file_tree() {
	if (!document.getElementsByTagName) return;
	
	var projecttype_param = gup( 'projecttype' );
	
	var aMenus = document.getElementsByTagName("LI");
	for (var i = 0; i < aMenus.length; i++) {
		var mclass = aMenus[i].className;
		if (mclass.indexOf("pft-directory") > -1) {
			var submenu = aMenus[i].childNodes;
			for (var j = 0; j < submenu.length; j++) {
				if ((submenu[j].tagName == "A") && (j>0) && (mclass.indexOf(projecttype_param) <= -1)){
					
					submenu[j].onclick = function() {
						var node = this.nextSibling;
											
						while (1) {
							if (node != null) {
								if (node.tagName == "UL") {
									var d = (node.style.display == "none")
									node.style.display = (d) ? "block" : "none";
									this.className = (d) ? "open" : "closed";
									return false;
								}
								node = node.nextSibling;
							} else {
								return false;
							}
						}
						return false;
					}
					
					submenu[j].className = (mclass.indexOf("open") > -1) ? "open" : "closed";
				}

				if (submenu[j].tagName == "UL") {
					if (mclass.indexOf(projecttype_param) > -1) {
					submenu[j].style.display = (mclass.indexOf("open") > -1) ? "none" : "block";}
					else {
					submenu[j].style.display = (mclass.indexOf("open") > -1) ? "block" : "none";}
				}
							
			}
		}
	}
}