window.onload = function(){checkBrowser();}

function showMessage(id, obj)
{
	var message = document.getElementById(id);
	var balloon = document.getElementById('Baloon');
	var balloonInner = document.getElementById('BaloonInner');
	//message.className = "show";
	balloonInner.innerHTML = message.innerHTML;
	balloon.className = "show";
	var winHeight = getWindowHeight() + document.body.scrollTop;		
	var nodePosY = findPosY(obj);
	var nodePosX = findPosX(obj) + obj.offsetWidth + 10;	
	var nodeBottom = balloon.offsetHeight + nodePosY;
	var nodeRight = nodePosX + balloon.offsetWidth;
	var diff = nodeBottom - winHeight;

	if(nodeBottom > winHeight)
	{
		if(nodePosY - diff > 0)
		{
			balloon.style.top = nodePosY - diff - 5;
		}
		else
		{
			balloon.style.top = 0 + document.body.scrollTop;
			//alert(document.body.scrollTop);
		}
	}
	else
	{
		balloon.style.top = nodePosY;			
	}
	
	if(nodeRight > getWindowWidth())
	{
		balloon.style.left = findPosX(obj) - balloon.offsetWidth - 10;
	}
	else
	{
		balloon.style.left = nodePosX;
	}
	
}

function hideMessage(id)
{
	document.getElementById('Baloon').className = "hide";
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function getWindowHeight()
{
	var height = 0;
	if(typeof (window.innerWidth)=="number")
	{
		height =window.innerHeight;
	}
	else
	{
		if(document.documentElement&&document.documentElement.clientHeight)
		{
			height=document.documentElement.clientHeight;
		}
		else
		{
			if(document.body&&document.body.clientHeight)
			{
				height=document.body.clientHeight;
			}
		}
	}
	return height;
}

function getWindowWidth()
{
	var width = 0;
	if(typeof (window.innerWidth)=="number")
	{
		width =window.innerWidth;
	}
	else
	{
		if(document.documentElement&&document.documentElement.clientWidth)
		{
			width=document.documentElement.clientWidth;
		}
		else
		{
			if(document.body&&document.body.clientWidth)
			{
				width=document.body.clientWidth;
			}
		}
	}
	return width;
}

function checkBrowser()
{
	//if(checkIt('msie'))alert('IE');
	if(checkIt('firefox'))
	{
		var link = document.getElementById('balloonStyle');
	//	alert(link.getAttribute('href'));
		link.setAttribute('href', 'CSS/balloonFF.css');
	//	alert(link.getAttribute('href'));
	}
}

function checkIt(string)
{
	var detect = navigator.userAgent.toLowerCase();
	place = detect.indexOf(string) + 1;
	return place;
}

/*function showMessage(id, obj)
{
	var message = document.getElementById(id);
	message.className = "show";
	message.style.top = findPosY(obj);		
	message.style.left = findPosX(obj) + 100;	
}*/
