﻿function getNextSibling(obj)
{
	if(typeof(obj) == 'string')
		obj = document.getElementById(obj)

	var obj = obj.nextSibling
	while(obj != null && obj.tagName == undefined)
	{
		obj = obj.nextSibling
	}
	
	return obj
}

function getPreviousSibling(obj)
{
	if(typeof(obj) == 'string')
		obj = document.getElementById(obj)

	var obj = obj.previousSibling
	while(obj != null && obj.tagName == undefined)
	{
		obj = obj.previousSibling
	}
	
	return obj
}

function Show(obj)
{
	if(typeof(obj) == 'string')
		obj = document.getElementById(obj)
	
	obj.style.display = ''
}

function Hide(obj)
{
	if(typeof(obj) == 'string')
		obj = document.getElementById(obj)
	
	obj.style.display = 'none'
}

function ShowHide(obj)
{
	if(typeof(obj) == 'string')
		obj = document.getElementById(obj)
	
	if (obj.style.display == 'none')
	{
		obj.style.display = ''
	}
	else
	{
		obj.style.display = 'none'
	}
}

function abrePopup(url, largura, altura)
{
	pTop  = (window.screen.height / 2) - (altura / 2);
	pLeft = (window.screen.width / 2) - (largura / 2);
	window.open(url, 'popup', 'width=' + largura + ', height=' + altura + ', top=' + pTop + ', left=' + pLeft + ', scrollbars=yes');
}

function GetElementPosition(element)
	{
		if (typeof(element) == 'string')
			element = document.getElementById(element);
		
		var result = new Object();
		result.x = 0;
		result.y = 0;
		result.width = 0;
		result.height = 0;
		if (element.offsetParent) {
				result.x = element.offsetLeft;
				result.y = element.offsetTop;
				var parent = element.offsetParent;
				while (parent) {
						result.x += parent.offsetLeft;
						result.y += parent.offsetTop;
						var parentTagName = parent.tagName.toLowerCase();
						if (parentTagName != "table" &&
								parentTagName != "body" && 
								parentTagName != "html" && 
								parentTagName != "div" && 
								parent.clientTop && 
								parent.clientLeft) {
								result.x += parent.clientLeft;
								result.y += parent.clientTop;
						}
						parent = parent.offsetParent;
				}
		}
		else if (element.left && element.top) {
				result.x = element.left;
				result.y = element.top;
		}
		else {
				if (element.x) {
						result.x = element.x;
				}
				if (element.y) {
						result.y = element.y;
				}
		}
		if (element.offsetWidth && element.offsetHeight) {
				result.width = element.offsetWidth;
				result.height = element.offsetHeight;
		}
		else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {
				result.width = element.style.pixelWidth;
				result.height = element.style.pixelHeight;
		}
		return result;
	}
