//find the elements descended from an element which are of the specified class
function getElementsByClass(parent, className)
{
	var arrEmts=new Array();
	var curChild;
	if(parent.hasChildNodes())
	{
		for(curChild=parent.firstChild; curChild; curChild=curChild.nextSibling)
		{
			arrEmts=getElementsByClassRecurse(curChild, className, arrEmts);
		}
	}
	return arrEmts;
}

//the recursive step of getElementsByClass
function getElementsByClassRecurse(curNode, className, arrEmts)
{
	var curChild;
	if(isClass(curNode, className)) arrEmts.push(curNode);
	if(curNode.hasChildNodes())
	{
		for(curChild=curNode.firstChild; curChild; curChild=curChild.nextSibling)
		{
			arrEmts=getElementsByClassRecurse(curChild, className, arrEmts);
		}
	}
	return arrEmts;
}

//is the specified class one of the classes used by the specified element?
function isClass(emt, className)
{
	var classes, i, cls;
	if(emt.nodeType==1) //only if this node is an element
	{
		cls=emt.getAttribute("class");
		if(cls) 
		{	
			classes=cls.split(" ");
			for(i=0; i<classes.length; i++)
			{
				if(classes[i]==className)
				{
					return true;
				}
			}
		}
	}
	return false;
}

//replace one style class with another in this element
function replaceClass(emt, oldClass, newClass)
{
	var cls, classes, i;
	if(emt.nodeType==1) //only if this node is an element
	{
		cls=emt.getAttribute("class");
		if(cls)
		{
			classes=cls.split(" ");
			for(i=0; i<classes.length; i++)
			{
				if(classes[i]==oldClass)
				{
					classes[i]=newClass;
				}
			}
			cls=classes.join(" ");
			emt.setAttribute("class", cls);
		}
	}
}

//remove a style class from this element
function removeClass(emt, className)
{
	var cls, classes, i;
	if(emt.nodeType==1) //only if this node is an element
	{
		cls=emt.getAttribute("class");
		if(cls)
		{
			classes=cls.split(" ");
			for(i=0; i<classes.length; i++)
			{
				if(classes[i]==className)
				{
					classes.splice(i, 1);
					i--;
				}
			}
			cls=classes.join(" ");
			emt.setAttribute("class", cls);
		}
	}
}

//add a style class to this element
function addClass(emt, className)
{
	var cls;
	if(emt.nodeType==1)
	{
		cls=emt.getAttribute("class");
		if(cls&&cls!="")
		{
			//this element has classes defined
			classes=cls.split(" ");
			for(i=0; i<classes.length; i++)
			{
				if(classes[i]==className)
				{
					//already has this class
					return;
				}
			}
			//not already in this class
			cls=cls+" "+className;
		}
		else
		{
			//this element doesn't have classes defined
			cls=className;
		}
		emt.setAttribute("class", cls);
	}
}




//find the distance of the specified element from the left edge of the window
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

//find the distance of the specified element from the top edge of the window
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//select a value from a list control
function SelectByValue(ctl, val)
{
	var i;
	var numItems=ctl.options.length;
	for(i=0; i<numItems; i++)
	{
		if(val==ctl.options[i].value)
		{
			ctl.selectedIndex=i;
			return;
		}
	}
}

//remove weird floating point nonsense by rounding off to nearest thousandth
function roundOff(amt)
{
	return (Math.round(amt*1000))/1000;
}

//set the text contents of an element
function setTextNode(emt, str)
{
	var curChild, nextChild;
	for(curChild=emt.firstChild; curChild; curChild=nextChild)
	{
		nextChild=curChild.nextSibling;
		emt.removeChild(curChild)
	}
	emt.appendChild(document.createTextNode(str));
}

//delete all the children of an element
function deleteChildren(parent)
{
	var nd, ndNext;
	nd=parent.firstChild;
	while(nd)
	{
		ndNext=nd.nextSibling;
		parent.removeChild(nd);
		nd=ndNext;
	}
}

function Trim(str)
{
	return str.replace(/^\s*|\s*$/g,"");
}


     
function linkto(str)
{
	window.location=str;
}

function AddToLoad(newFunction)
{
	var olde=window.onload;
	var newe= function()
	{
		if(olde) olde();
		newFunction();
	}
	window.onload=newe;
}