function dontBubble(e)
{
	if (!e && !window.event)
		return;
	if (!e)
		var e = window.event
	e.cancelBubble = true;
	if (e.stopPropagation)
		e.stopPropagation();
}

function confirmDelete(e,t)
{
	dontBubble(e);
	return confirm("Really delete this "+t+"?");
}

function changeSort(form,column,direction)
{
	var f=document.getElementById(form);
	if(column!=f.sc.value)
	{
		f.lsc.value=f.sc.value;
		f.lsd.value=f.sd.value;
	}
	f.sc.value=column;
	f.sd.value=direction;
	f.submit();
}

function getY( oElement )
{
	var iReturnValue = 0;
	while( oElement != null )
	{
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX( oElement )
{
	var iReturnValue = 0;
	while( oElement != null )
	{
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getPageSizeX()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
		
	var windowWidth, windowHeight;
	
	if (self.innerHeight)// all except Explorer
	{
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		}
		else
		{
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{
		pageWidth = xScroll;
	}
	else
	{
		pageWidth = windowWidth;
	}

	return pageWidth;
}

function createPopup(e,width,height,class_name,offset_type,offset_x,offset_y,mask)
{
	var popup;
	var x;
	var y;
	if(!class_name) class_name="defaultPopup";
	if(!offset_type) offset_type="relative";
	if(!offset_x) offset_x=0;
	if(!offset_y) offset_y=0;

	if(mask==true)
	{
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY)
		{
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		}
		else if (document.body.scrollHeight > document.body.offsetHeight)
		{ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}
		else
		{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
			
		var windowWidth, windowHeight;
		
		if (self.innerHeight)// all except Explorer
		{
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			}
			else
			{
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
		{
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight)
		{
			pageHeight = windowHeight;
		}
		else
		{
			pageHeight = yScroll;
		}
		
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth)
		{
			pageWidth = xScroll;
		}
		else
		{
			pageWidth = windowWidth;
		}

		//return pageWidth, pageHeight;
		
		var mdiv=document.createElement("DIV");
		mdiv.setAttribute("id","popupMaskBackground");
		mdiv.style.width=pageWidth+"px";
		mdiv.style.height=pageHeight+"px";
		document.body.appendChild(mdiv);
	}
	if(offset_type=="relative")
	{
		if (window.event)
		{
			x=window.event.clientX+document.documentElement.scrollLeft;
			y=window.event.clientY+document.documentElement.scrollTop;
		}
		else
		{
			if(e)
			{
				x=e.pageX;
				y=e.pageY;
			}
			else
			{
				x=getX(cell);
				y=getY(cell);
			}
		}
		x+=offset_x;
		y+=offset_y;
		x=Math.min(x,document.documentElement.clientWidth+document.documentElement.scrollLeft-width-50);
		y=Math.min(y,document.documentElement.clientHeight+document.documentElement.scrollTop-height-20);
	}
	else if(offset_type=="center")
	{
		x=document.documentElement.clientWidth/2+document.documentElement.scrollLeft-width/2;
		y=document.documentElement.clientHeight/2+document.documentElement.scrollTop-height/2;
	}
	else if(offset_type=="absolute")
	{
		x=offset_x;
		y=offset_y;
	}
	else
	{
		x=Math.min(x,document.documentElement.clientWidth+document.documentElement.scrollLeft-width-50);
		y=Math.min(y,document.documentElement.clientHeight+document.documentElement.scrollTop-height-20);
	}
	popup=document.createElement("div");
	popup.className=class_name;
	popup.style.height=height+"px";
	popup.style.width=width+"px";
	popup.style.top=Math.max(0,y)+"px";
	popup.style.left=Math.max(0,x)+"px";
	document.body.appendChild(popup);
	return popup;
}

function closePopup(popup)
{
	var mask=document.getElementById("popupMaskBackground");
	if(mask)
	{
		document.body.removeChild(mask);
		mask=null;
	}
	if(popup)
	{
		document.body.removeChild(popup);
		popup=null;
	}
	return null;
}

function browserIsIE()
{
	ua = navigator.userAgent;

	isOpera = window.opera && opera.buildNumber;
	isWebKit = /WebKit/.test(ua);
	isOldWebKit = isWebKit && !window.getSelection().getRangeAt;
	isIE = !isWebKit && !isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(navigator.appName);
	
	return isIE;
}

