function getControl(controls, id)
{
	for (var i = 0; i < controls.length; i++)
	{
		var control = controls[i];
		if (control.id != null && control.id != "undefined")
		{
			if (control.id.indexOf(id) >= 0)
			{
				return control;
			}
		}
	}
	
	return null;
}

function getLeft(element)
{
	var left = 0;
	
	var parent = element.offsetParent;
	while (parent != null)
	{
		left += parseInt(parent.offsetLeft);
		parent = parent.offsetParent;
	}
	
	if (document.all)
	{
		left += parseValue(element.currentStyle.borderLeftWidth);
		left += parseValue(element.currentStyle.marginLeft);
		left += parseValue(element.currentStyle.paddingLeft);
	}
	else
	{
		left += parseValue(element.style.borderLeftWidth);
		left += parseValue(element.style.marginLeft);
		left += parseValue(element.style.paddingLeft);
	}
	
	left += parseValue(element.offsetLeft);
	
	return left;
}

function getMouseLeft(event)
{

    var posx = 0;
	
	if (event.pageX) 	
	{
		posx = event.pageX;
	}
	else if (event.clientX) 	
	{	    
		posx = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;

	}
	
	return posx;

}

function getTop(element)
{
	var top = 0;
	
	var parent = element.offsetParent;
	while (parent != null)
	{
		top += parseInt(parent.offsetTop);
		parent = parent.offsetParent;
	}
	
	if (document.all)
	{
		top += parseValue(element.currentStyle.borderTopWidth);
		top += parseValue(element.currentStyle.marginTop);
		top += parseValue(element.currentStyle.paddingTop);
	}
	else
	{
		top += parseValue(element.style.borderTopWidth);
		top += parseValue(element.style.marginTop);
		top += parseValue(element.style.paddingTop);
	}
	
	top += parseValue(element.offsetTop);
	
	return top;
}


function getMouseTop(event)
{
	var posy = 0;
	
	if (event.pageY) 	
	{
		posy = event.pageY;
	}
	else if (event.clientY) 	
	{	    
		posy = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	
	return posy;
}


function getHeight(element)
{
	var height = 0;
	
	height += parseValue(element.clientHeight);
	
	if (document.all)
	{
		height -= parseValue(element.currentStyle.borderTopWidth);
		height -= parseValue(element.currentStyle.borderBottomWidth);
	}
	else
	{
		height -= parseValue(element.style.borderTopWidth);
		height -= parseValue(element.style.borderBottomWidth);
	}
	
	return height;
}

function getWidth(element)
{
	var width = 0;
	
	width += parseValue(element.clientWidth);
	
	if (document.all)
	{
		width -= parseValue(element.currentStyle.borderLeftWidth);
		width -= parseValue(element.currentStyle.borderRightWidth);
	}
	else
	{
		width -= parseValue(element.style.borderLeftWidth);
		width -= parseValue(element.style.borderRightWidth);
	}
	
	return width;
}

function parseValue(value)
{
	var intValue = parseInt(value);
	if (isNaN(intValue))
	{
		return 0;
	}
	else
	{
		return intValue;
	}
}

function getText(control)
{
	if (document.all)
	{
		return control.innerText;
	}
	else
	{
		return control.textContent;
	}
}

function setText(control, value)
{
	if (document.all)
	{
		control.innerText = value;
	}
	else
	{
		control.textContent = value;
	}
}

function getSourceElement(event)
{
	if (document.all)
	{
		return event.srcElement;
	}
	else
	{
		return event.target;
	}
}

function fireClickEvent(control)
{
	if (document.all)
	{
		//control.fireEvent("onclick");
		control.click();
	}
	else
	{
		var clickEvent = window.document.createEvent("MouseEvent");
		clickEvent.initEvent("click", false, true);
		control.dispatchEvent(clickEvent);
	}
}


function getWindowHeight()
{

	if (document.all)
	{
		return document.body.offsetHeight;
	}
	else
	{
		return window.innerHeight;
	}
}

function getWindowWidth()
{
    
	if (document.all)
	{
		return document.body.offsetWidth;
	}
	else
	{
		return window.innerWidth;
	}
}
