function doMouseOver(cell)
{
    try
    {
        if ((cell.className.indexOf('_Disabled') < 0) && (cell.className.indexOf('_Selected') < 0) && (cell.className.indexOf('_Expanded') < 0))
            cell.className = cell.className.replace('_Hover','').replace('_Disabled','').replace('_Selected','') + '_Hover';
    }
    catch(e) {}
}

function doMouseOut(cell)
{
    try
    {
        if ((cell.className.indexOf('_Disabled') < 0) && (cell.className.indexOf('_Selected') < 0) && (cell.className.indexOf('_Expanded') < 0))
            cell.className = cell.className.replace('_Hover','').replace('_Disabled','').replace('_Selected','');
    }
    catch(e) {}
}

function doMouseSelect(cell)
{
    try { cell.className = cell.className.replace('_Hover','').replace('_Disabled','').replace('_Selected','') + '_Selected'; }
    catch(e) {}
}

function doMouseUnselect(cell)
{
    try { cell.className = cell.className.replace('_Hover','').replace('_Disabled','').replace('_Selected',''); }
    catch(e) {}
}

function selectCheckboxCell(label)
{
    var row = (document.getElementById&&!document.all) ? label.parentNode.parentNode : label.parentElement.parentElement;
    var checkbox = row.getElementsByTagName('input')[0];
    checkbox.checked = !checkbox.checked;
}

function getXmlHttpObject()
{
	var xmlHttp = null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}


/****************************************************************
 *  COMMON HELPER FUNCTIONS
 ****************************************************************/
function removeQueryStringKey(string, key)
{
	var value = queryString(key,string);
	if (value == null) value = '';
	
	string = string.replace('?'+key+'='+value, '');
	string = string.replace('&'+key+'='+value, '');
	string = string.replace(key+'='+value, '');
		
	return string;
}

function queryString(key, querystring)
{
	if (querystring.indexOf('?') < 0)
		querystring = '?'+querystring;
    var re = new RegExp( "[?&]" + key + "=([^&$]*)", "i" );
    var offset = querystring.search( re );
    if ( offset == -1 ) return null;
    return RegExp.$1;
}
 
function replaceChars(find, replace, string)
{
	temp = "" + string; 

	while (temp.indexOf(find)>-1)
	{
		pos  = temp.indexOf(find);
		temp = "" + (temp.substring(0, pos) + replace + temp.substring((pos + find.length), temp.length));
	}
	return temp;
}	

function fixPageHeight()
{
	var holder = document.body;
	holder.style.display = '';
	try { holder.style.display = 'table-cell'; }
	catch(e) {}
	holder.style.display = '';
}

function getElementPosition(element)
{
	var x=0,y=0;
	if (navigator.userAgent.toLowerCase().indexOf('mac')!=-1)
	{
		while (element!=null)
		{
			try 
			{
				x+=element.offsetLeft;
				y+=element.offsetTop;
				element=element.offsetParent;
			}
			catch(exception) { return {x:0,y:0}; }
		}
	}
	else
	{
		while (element!=null)
		{
			try 
			{
				x+=element.offsetLeft-element.scrollLeft;
				y+=element.offsetTop-element.scrollTop;
				element=element.offsetParent;
			}
			catch (exception) { return {x:0,y:0}; }
		}
	}
	return {x:x,y:y};
}

function getElementSizeById(elementid)
{
	var height=0,width=0;
	
	try
	{
		if(document.defaultView) //mozilla
		{	
			docObj = document.getElementById(elementid);
			height = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("height");
			if(height.indexOf("p") >= 0)
				height = height.substring(0, height.indexOf("p"))
			
			width = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("width");
			if(width.indexOf("p") >= 0)
				width = width.substring(0, width.indexOf("p"))
		}
		else if (document.layers)
		{
			height = document.layers[elementid].document.height;
			width = document.layers[elementid].document.width;
		}
		else if (document.all)	// IE
		{
			height = document.all[elementid].offsetHeight;
			width = document.all[elementid].offsetWidth;
		}
	}
	catch(oExc){}
	
	return {height:height,width:width};
}

function getElementSize(element)
{
	var height=0,width=0;
	
	try
	{
	    var elementid = element.id;
	
		if(document.defaultView) //mozilla
		{	
			docObj = document.getElementById(elementid);
			height = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("height");
			if(height.indexOf("p") >= 0)
				height = height.substring(0, height.indexOf("p"))
			
			width = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("width");
			if(width.indexOf("p") >= 0)
				width = width.substring(0, width.indexOf("p"))
		}
		else if (document.layers)
		{
			height = document.layers[elementid].document.height;
			width = document.layers[elementid].document.width;
		}
		else if (document.all)	// IE
		{
			height = document.all[elementid].offsetHeight;
			width = document.all[elementid].offsetWidth;
		}
	}
	catch(oExc){}
	
	return {height:height,width:width};
}


function getElementPositionFromParent(element, parentElement)
{
	var x=0,y=0;
	if (navigator.userAgent.toLowerCase().indexOf('mac')!=-1)
	{
		while (element!=parentElement)
		{
			try 
			{
				x+=element.offsetLeft;
				y+=element.offsetTop;
				element=element.offsetParent;
			}
			catch(exception) { return {x:0,y:0}; }
		}
	}
	else
	{
		while (element!=parentElement)
		{
			try 
			{
				x+=element.offsetLeft-element.scrollLeft;
				y+=element.offsetTop-element.scrollTop;
				element=element.offsetParent;
			}
			catch (exception) { return {x:0,y:0}; }
		}
	}
	return {x:x,y:y};
}

function cursorOnElement(x, y, element)
{
    var size = getElementSize(element);
    var pos = getElementPosition(element);
    
    var startX = parseInt(pos.x);
    var endX = startX + parseInt(size.width);
    var startY = parseInt(pos.y);
    var endY = startY + parseInt(size.height);
    
    return (x >= startX && x<= endX && y >= startY && y <= endY);
}


function trimText(strValue, maxLength)
{
	if (strValue != null)
	{
		if (strValue.length <= maxLength)
			return strValue;
		else
			return strValue.substring(0,maxLength) + "...";
	}
	else
		return "";
}

function hideSubDivs(element)
{
	var subdivs = element.getElementsByTagName('div');
	if (subdivs != null)
	{
		if (subdivs.length)
		{
			for (i=0;i<subdivs.length;i++)
			{
				if (subdivs[i].getAttribute && subdivs[i].getAttribute('container') && subdivs[i].getAttribute('container') == "true")
					subdivs[i].style.display = 'none';
			}
		}
	}
}

function capitalize(inputString)
{

	var tmpStr, tmpChar, preString, postString, strlen;
	tmpStr = inputString.toLowerCase();
	stringLen = tmpStr.length;
	if (stringLen > 0)
	{
		for (i = 0; i < stringLen; i++)
		{
			if (i == 0)
			{
				tmpChar = tmpStr.substring(0,1).toUpperCase();
				postString = tmpStr.substring(1,stringLen);
				tmpStr = tmpChar + postString;
			}
			else
			{
				tmpChar = tmpStr.substring(i,i+1);
				if (tmpChar == " " && i < (stringLen-1))
				{
					tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
					preString = tmpStr.substring(0,i+1);
					postString = tmpStr.substring(i+2,stringLen);
					tmpStr = preString + tmpChar + postString;
				}
			}
		}
	}
	return tmpStr;
}

function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
}

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}