//Scripts coded by Huaming Chen

function load_GEBD_MAP_IMG()
{
	imageYcoord = 0;
	imageXcoord = 0;
	var obj = document.AtG1001_MAP_IMG;

	imageYheight = obj.height;
	imageXwidth = obj.width;

	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			imageXcoord += obj.offsetLeft;
			imageYcoord += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else
	{
		imageXcoord += obj.x;
		imageYcoord += obj.y;
	}
}

function gh (help, ix, iy, on)
{
	if ( on == 0 )
	{
		document.getElementById('tailHelp').style.visibility = "hidden";
	}
	else
	{
		load_GEBD_MAP_IMG ();
		string = ""+help;
		var sTop = parseInt(document.getElementById("innerRight").scrollTop);
		var vPosn = imageYcoord+iy+24;
		if (sTop>0) vPosn = imageYcoord+iy+24-sTop;
		document.getElementById('tailHelp').style.top = vPosn.toString()+"px";

		if ( string.length > 50 ) tailHelpWidth = 360;
		else tailHelpWidth = (string.length)*5+20;

		var windowWidth = screen.width;
                if (typeof(window.innerWidth)=='number')
                        windowWidth = window.innerWidth;
                else if (document.documentElement && document.documentElement.clientWidth)
                        windowWidth = document.documentElement.clientWidth;
                else
                        windowWidth = document.body.clientWidth;

		if ((ix+tailHelpWidth+imageXcoord-parseInt(document.getElementById("innerRight").scrollLeft))>windowWidth)
		{
			vPosn = imageXcoord+ix-tailHelpWidth+20-parseInt(document.getElementById("innerRight").scrollLeft);
			document.getElementById('tailHelp').style.left = vPosn.toString()+"px";
		}
		else
		{
			vPosn = imageXcoord+ix+20-parseInt(document.getElementById("innerRight").scrollLeft);
			document.getElementById('tailHelp').style.left = vPosn.toString()+"px";
		}

		if ( string.length > 50 )
		{
			vPosn = (string.length+49)/50*15+15 ;
			document.getElementById('tailHelp').style.height = vPosn.toString()+"px";
			document.getElementById('tailHelp').style.width = "360px"; 
		}
		else
		{
			vPosn = (string.length+2)*6+35;
			document.getElementById('tailHelp').style.width = vPosn.toString()+"px";
			document.getElementById('tailHelp').style.height = "30px" ;
		}
		document.getElementById('tailHelp').innerHTML = "<table id='tailHelpTab' bgcolor=#6666AA border=0 cellpadding=1 cellspacing=0><tr><td ><table cellpadding=4 cellspacing=6 bgcolor=#CCDDFF  width=100%><tr><td><font size=1 color=#222288 face=\"Arial\">"+help+"</td></tr></table></td></tr></table>";
		document.getElementById('tailHelp').style.visibility = "visible";
	}
}

function followmouse (e)
{
	if (!e)
	{
		if ( window.event ) e = window.event;
		else
		{
			return;
		}
	}

	if (document.geView.View.value=="Text") return;

	load_GEBD_MAP_IMG();

	if (typeof(e.pageX) == 'number' )
	{
		xcoord = e.pageX;
		ycoord = e.pageY;
	}
	else if (typeof(e.clientX)=='number')
	{
		xcoord=e.clientX;
		ycoord=e.clientY;

		//var badOldBrowser = (window.navigator.userAgent.indexOf('Opera')+1 )||
		var badOldBrowser = (window.ScriptEngine && ScriptEngine().indexOf('InScript' )+1) || (navigator.vendor=='KDE')

		if (!badOldBrowser)
		{
			if (document.body && (document.body.scrollLeft || document.body.scrollTop))
			{
				xcoord += document.body.scrollLeft;
				ycoord += document.body.scrollTop;
			}
			else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
			{
				xcoord += document.documentElement.scrollLeft;
				ycoord += document.documentElement.scrollTop;
			}
		}
	}
	else
	{
		return;
	}

	var oLeft = parseInt (document.getElementById("innerRight").offsetLeft);
	var oTop = parseInt (document.getElementById("innerRight").offsetTop);
	var sLeft = parseInt (document.getElementById("innerRight").scrollLeft);
	var sTop = parseInt (document.getElementById("innerRight").scrollTop);

	var xLeft = imageXcoord - sLeft;
	if (xLeft < oLeft) xLeft=oLeft;
	var xTop = imageYcoord+imageYheight-sTop;
	if (xTop < oTop) xTop=oTop;
	var xRight = oLeft+parseInt(document.getElementById("innerRight").offsetWidth)-16;
	if (xRight > imageXcoord+imageXwidth-sLeft) xRight = imageXcoord+imageXwidth-sLeft;
	var xBottom = oTop+parseInt(document.getElementById("innerRight").offsetHeight)-16;

	if (xcoord<xLeft || ycoord<xTop || xcoord>=xRight || ycoord>xBottom) 
	{

		document.getElementById('topDown').style.visibility = "hidden";
		document.getElementById('tailPosition').style.visibility = "hidden";
	}
	else
	{
		var vPosn = xcoord+1;
		document.getElementById('topDown').style.left = vPosn.toString()+"px";
		vPosn = imageYcoord;
		if (sTop>0)
		{
			if (sTop<imageYcoord) vPosn -= sTop;
			else vPosn = oTop;
		}
		document.getElementById('topDown').style.top = vPosn.toString()+"px";

		vPosn = xBottom - oTop;
		if (sTop<imageYcoord) vPosn -= (imageYcoord-sTop-oTop);
		document.getElementById('topDown').style.height = vPosn.toString()+"px";

		Posn = parseInt(document.geView.Position.value)+(parseInt(document.geView.Zoom.value))*(xcoord-imageXcoord+sLeft);

		Posn = Math.round ( Posn );
		document.getElementById('tailPosition').innerHTML = Posn;

		var ln = Posn.toString();
		vPosn = ycoord-20;
		document.getElementById('tailPosition').style.top = vPosn.toString()+"px";
		vPosn = ln.length*6+4;
		document.getElementById('tailPosition').style.width = vPosn.toString()+"px";
		vPosn = xcoord-(ln.length*3)-2;
		document.getElementById('tailPosition').style.left = vPosn.toString()+"px";


		document.getElementById('topDown').style.visibility = "visible";
		document.getElementById('tailPosition').style.visibility = "visible";
	}
}
