//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------
function set_status(sb_text) { self.status = sb_text; }
function clear_status() { self.status = 'Done'; }

function getContainerWith(node, tagName, className) 
{
  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.
	try
	{
		while (node != null) 
		{
			if (node.tagName != null && node.tagName == tagName &&
					hasClassNameLike(node, className))
				return node;
			node = node.parentNode;
		}
		return null
		;
	}
	catch(e) { alert(e); return null; }
}

function getAnyContainerWith(node, className) 
{
  // Starting with the given node, find the nearest containing element
  // with the specified style class.
	try
	{
		//alert("looking for: " + className);
		//alert("node: " + node);
		while (node != null) 
		{
			if( hasClassNameLike(node, className))
			{
				//alert("found: " + className)
				return node;
			}
			node = node.parentNode;
		}
		return null;
	}
	catch(e) { alert(e); return null; }
}

function hasClassNameLike(el, name) 
{
  var i, list;

  // Return true if the given element currently has the a class
  // name that starts with the given name string
	try
	{
		if(el.className)
		{
		list = el.className.split(" ");
		for (i = 0; i < list.length; i++)
			if (list[i].indexOf(name)==0)
				return true;
		}
  return false;
	}
	catch(e) { alert(e); return false; }
}

function hasClassName(el, name) 
{
  var i, list;

  // Return true if the given element currently has the given class
  // name.
	try
	{
		if (el.className)
		{
			list = el.className.split(" ");
			for (i = 0; i < list.length; i++)
			{
				//alert("classname evaled to: " + list[i]);
				if (list[i] == name)
					return true;
			}
		}
		return false;
	}
	catch(e) { alert(e); return false; }
}

function removeClassName(el, name) 
{
  var i, curList, newList;

	// Remove the given class name from the element's className property.
	try
	{
		if (el.className)
		{
			//alert("diming new string");
			new_classname = "";
			//alert("diming new array");
			newList = new Array();
			//alert("splitting array");
			curList = el.className.split(" ");
			for (i = 0; i < curList.length; i++)
				if (curList[i] != name)
				{
					if (new_classname.length > 0)
						new_classname += " " + curList[i];
					else
						new_classname += curList[i];
				}
		//
		//		{
		//			alert("pushing to array?");
		//			newList.push(curList[i]);
		//			alert("pushed!");
		//		}
		//	alert("joining array");
		//	el.className = newList.join(" ");
		
			el.className = new_classname;
			//alert("done");
		}
	}
	catch(e) { alert(e); return; }
}

function getPageOffsetLeft(el) 
{
  var x;

  // Return the x coordinate of an element relative to the page.
	try
	{
		x = el.offsetLeft;
		if (el.offsetParent != null)
			x += getPageOffsetLeft(el.offsetParent);
	
		return x;
	}
	catch(e) { alert(e); return 0; }
}

function getPageOffsetTop(el) 
{
  var y;

  // Return the x coordinate of an element relative to the page.
	try
	{
		y = el.offsetTop;
		if (el.offsetParent != null)
			y += getPageOffsetTop(el.offsetParent);
	
		return y;
	}
	catch(e) { alert(e); return 0; }
}
