function stopPropagation(e){
	e=e||event;
	if (e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;  //IE
}



function getPosition(n,endNode){
	var left = 0;
	var top =0;
	var node = n;
	done=false;
	while(!done){
		if(node.offsetLeft!=null)
			left += node.offsetLeft;
		if(node.offsetTop!=null)
			top += node.offsetTop;
		if(node.offsetParent){
			node = node.offsetParent;
		}else{
			done = true;
		}
		if(node == endNode)
			done = true;
	}
	done=false;
	node = n;
	while(!done){
		if(document.all && node.style && parseInt(node.style.borderLeftWidth)){
			left += parseInt(node.style.borderLeftWidth);
		}
		if(document.all && node.style && parseInt(node.style.borderTopWidth)){
			top += parseInt(node.style.borderTopWidth);
		}

		if(node.scrollLeft){
			left -= node.scrollLeft;
		}
		if(node.scrollTop)
			top -= node.scrollTop;
		if(node.parentNode)
			node = node.parentNode;
		else
			done=true;
	}
	return new Array(left, top);
}



function changeOpacity (opacity, object) {

	object.style.opacity = (opacity / 100);
    object.style.MozOpacity = (opacity / 100);
    object.style.KhtmlOpacity = (opacity / 100);
    object.style.filter = "alpha(opacity=" + opacity + ")";

}

Array.prototype.append = function (obj, duplicates)
{
	var index = -1;
	if (duplicates || !this.contains (obj)){
		index = this.length;
		this [index] = obj;
	}
	return index;
}

Array.prototype.contains = function (obj)
{
	return (this.indexOf (obj) >= 0);
}

Array.prototype.indexOf = function (obj)
{
	var retval = -1;
	var length  = this.length;
		
	for (var i = 0; i < length; i++)
	{
		if (obj == this [i])
		{
			retval  = i;
			break;
		}
	}

	return retval;
}

Array.prototype.remove = function (obj)
{
	this.splice (this.indexOf(obj), 1);
}


function getScrollbarWidth()
{
	// calculate scrollbar width;
	var tmp = document.createElement("div");
	tmp.style.overflowY = "scroll";
	tmp.style.width = "100px";
	tmp.innerHTML = "z";
	document.body.appendChild( tmp );
	var scrollWidth = 100 - tmp.clientWidth;
	document.body.removeChild( tmp );
	tmp = null;

	return scrollWidth;
}


function fixAllPngs ()
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img.src+"',  sizingMethod='scale')";
			 img.src = "images/spacer.gif";
		  }
	   }
	}
}



function loadClass (className)
{
	if(!window [className])
	{
		var html_doc = document.getElementsByTagName('head').item(0);
		var js = document.createElement('script');
		js.setAttribute('language', 'javascript');
		js.setAttribute('type', 'text/javascript');
		js.setAttribute('src', className+".js");
		html_doc.appendChild(js);
	}
	else
	{
		eval("new " + className);
	}
}



loadData  = function (url, callbackMethod, context)
{
	var request;
	if (window.XMLHttpRequest)
		request = new XMLHttpRequest ();
	else if (window.ActiveXObject)
		request = new ActiveXObject ("Microsoft.XMLHTTP");
	else
		alert("Browser Not Supported.");

	if (request)
	{
		request.open ("GET", url, true);
		setTimeout( function (){ loadData_callback(request, callbackMethod, context) }, 100);
		request.send (null);
	}
}

function loadData_callback ( request, callbackMethod, context )
{
	if (request && request.readyState == 4)
	{
		if (request.status == 200 || request.state == 0)
			callbackMethod.call ( context, request.responseText );
		else
			alert("Error Loading Page.");
	}
	else if ( request )
	{
		var self = this;
		setTimeout( function (){ loadData_callback(request, callbackMethod, context) }, 100);
	}
}
