/*-- this document should be added to the Control Panel as a custom page named "custom_page_functions.js"  --*/

/*--- remove padding from div "left_col" that contains the auto generated menus --*/

var left_col = document.getElementById("left_col");
var tables = left_col.getElementsByTagName('table');
for(i=0; i<tables.length; i++)
{
		tables[i].cellSpacing = 0;
		tables[i].cellPadding = 0;
}

/*--- end remove padding from div "left_col" that contains the auto generated menus --*/

/***********************************************
* Bookmark site script- &copy; Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

/*--- end script for "bookmark this page" --*/

/*

	All helper functions return element nodes.  Nodes with a nodeType == 1.
	These are the nodes representing html tags.  When traversing the DOM there are many types
	of nodes.  These functions filter through the respective section of the tree with concern
	for only element types.
*/


function traverseAllElementNodes(node,appendText)
{
	//loop through all the siblings of node recursively and be cross browser safe
	//write the output to the screen
	
	var lastChild = node.lastChild;
	var current = node.firstChild;
	var next = true;
	while(next)  //3 == text 8 == comment
	{
		if(current === lastChild)
			next = false;

		try {
		if(current.nodeType == 1)
		{
			document.write(appendText + current.tagName + " " +  current.nodeType + "<br>");
			//get a list of all nodes in this node
			traverseAllElementNodes(current,appendText + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
		}
		} catch (e) {
			return false;
		}
		if(next)
			current = current.nextSibling;
	}
}

function traverseOneElementNode(node)
{
	//loop through all of first depth siblings of node and be cross browser safe
	//write the output to the screen
	
	var lastChild = node.lastChild;
	var current = node.firstChild;
	var next = true;
	while(next)  //3 == text 8 == comment
	{
		if(current === lastChild)
			next = false;

		if(current.nodeType == 1)
			document.write(current.tagName + " " +  current.nodeType + "<br>");

		if(next)
			current = current.nextSibling;
	}
}

function getFirstElementNodeByTagName(node,tagname)
{
	//loop through all of the first depth siblings of node and be cross browser safe
	//return the first child element having the given tagname
	
	var lastChild = node.lastChild;
	var current = node.firstChild;
	var next = true;
	while(next)  //3 == text 8 == comment
	{
		if(current === lastChild)
			next = false;

		//return the first name we find
		if(current.nodeType == 1 && current.tagName == tagname)
			return current;

		if(next)
			current = current.nextSibling;
	}
	
	return null;
}

function getAllElementNodesByTagName(node,tagname)
{

	//returns all of the first depth siblings of node by the given tagname
	//ex if a table has 3 rows with nested tables, only the rows belonging to
	//the table indicated by node will be returned

	var nodes = new Array();

	//loop through all the siblings and be cross browser safe
	var lastChild = node.lastChild;
	var current = node.firstChild;
	var next = true;
	while(next)	{
		if(current === lastChild)
			next = false;

		//return the first name we find
		if(current.nodeType == 1 && current.tagName == tagname)
			nodes.push(current);

		if(next)
			current = current.nextSibling;
	}

	if(nodes.length > 0)	
		return nodes;
	return null;
}

function assignChildElementNodeId(parent,tagname,index,newid)
{
	//traverse the first depth of the parent node
	//finds the nth(index - 1) node given by tagname
	//assigns it the given newid
	
	//use helper function to get a list of first level nodes having this tagname
	var nodes = getAllNodesByTagName(parent,tagname);
	if(nodes == null)
		return false;	//return false if none are found
		
	//go to the index of the nodes array and assign the id
	nodes[index-1].id = newid;
	
	return true;	//return true on success
}

function removeAllElementNodes(node)
{

	//loop through all of the outer siblings and be cross browser safe
	var lastChild = node.lastChild;
	var current = node.firstChild;
	var next = true;
	while(next)  //3 == text 8 == comment
	{
		if(current === lastChild)
			next = false;

		if(current.nodeType == 1)
			if(next)	//save the next before deleting current
			{
				temp = current.nextSibling;
				node.removeChild(current);
				current = temp;
			}
			else
			{
				node.removeChild(current);
			}
		else
			if(next)
				current = current.nextSibling;
	}
}

var menu_links = document.getElementById('menu_links');
var firstTable = getFirstElementNodeByTagName(menu_links,"TABLE");
var firstTbody = getFirstElementNodeByTagName(firstTable,"TBODY");
var firstRow = getFirstElementNodeByTagName(firstTbody,"TR");
var firstTd = getFirstElementNodeByTagName(firstRow,"TD");
var nextTable = getFirstElementNodeByTagName(firstTd,"TABLE");
var nextTbody = getFirstElementNodeByTagName(nextTable,"TBODY");
var nextTr = getFirstElementNodeByTagName(nextTbody,"TR");

nextTbody.removeChild(nextTr);
