// JavaScript Document
//  The functions have been adapted from various sources
//  and re-written to provide maximum flexibility
//  and compatability with various browsers.

//Global Declarations
var ie = (document.all) ? true : false;

function toggleClass(objClass){
//  This function will toggle obj visibility of an Element
//  based on Element's Class
//  Works with IE and Mozilla based browsers

  if (getElementByClass(objClass).style.display=="none"){
    showClass(objClass)
  }else{
    hideClass(objClass)
  }
}

function hideClass(objClass){
//  This function will hide Elements by object Class
//  Works with IE and Mozilla based browsers

var elements = (ie) ? document.all : document.getElementsByTagName('*');
  for (i=0; i<elements.length; i++){
    if (elements[i].className==objClass){
      elements[i].style.display="none"
    }
  }
}

function showClass(objClass){
//  This function will show Elements by object Class
//  Works with IE and Mozilla based browsers
var elements = (ie) ? document.all : document.getElementsByTagName('*');
  for (i=0; i<elements.length; i++){
    if (elements[i].className==objClass){
      elements[i].style.display="block"
    }
  }
}

function toggleID(objID){
//  This function will toggle obj visibility of an Element
//  based on Element's ID
//  Works with IE and Mozilla based browsers
var element = (ie) ? document.all(objID) : document.getElementById(objID);
  if (element.style.display=="none"){
    showID(objID)
  }else{
    hideID(objID)
  }
}

function hideID(objID){
//  This function will hide Elements by object ID
//  Works with IE and Mozilla based browsers
var element = (ie) ? document.all(objID) : document.getElementById(objID);
  element.style.display="none"
}

function showID(objID){
//  This function will show Elements by object ID
//  Works with IE and Mozilla based browsers
var element = (ie) ? document.all(objID) : document.getElementById(objID);
  element.style.display="block"
}

function getElementByClass(objClass){
//  This function is similar to 'getElementByID' since there
//  is no inherent function to get an element by it's class
//  Works with IE and Mozilla based browsers
var elements = (ie) ? document.all : document.getElementsByTagName('*');
  for (i=0; i<elements.length; i++){
    //alert(elements[i].className)
    //alert(objClass)
    if (elements[i].className==objClass){
    return elements[i]
    }
  }
}



var oColl; //Collection for children.
var oRow, oCell; //Use for row and cell.
function fnCollection(){
    oColl = oParentDIV.children;

	//Call function to create cells for the top parent object.
	getChildren(oColl, oParentDIV);

	/*Call function to create cells for the child within the parent object
        containing its own child.*/
	oColl = oChildDIV.children;
	getChildren(oColl, oChildDIV);
}
/*****************************************************************************
In:
	oColl - Collection of children.
	oCollection - Parent object.
Out: 
	Output to screen.
******************************************************************************/
function getChildren(oColl, oCollection){
	for(x=0;x<oColl.length;x++){
	        //Create new row.
        	oRow = oTable.insertRow();
        
	        //Create cell with the array index of current child.
        	oCell = oRow.insertCell();
	        oCell.align = 'center';
        	oCell.style.color = '#0000FF';
	        oCell.innerText = x;
	
        	//Create cell with the tagName of current child.          
	        oCell = oRow.insertCell();
        	oCell.align = 'center';
	        oCell.innerText = oCollection.children.item(x).tagName;

	        //Create cell with ID / name of current child.            
	        oCell = oRow.insertCell();
        	oCell.align = 'center';
	        if(oCollection.children.item(x).name != null){
        	    oCell.innerText = oCollection.children.item(x).name;
	        }else{
        	    oCell.innerText = oCollection.children.item(x).id;
	        }
		
		//Create cell with applicable Parent object to the child.
		oCell = oRow.insertCell();
		oCell.align = 'center';
		oCell.innerText = oCollection.id;
	}
}
