/*			*/

	// getAnchorPosition(anchorname)
	//   This function returns an object having .x and .y properties which are the coordinates
	//   of the named anchor, relative to the page.
	function getAnchorPosition(anchorname) {
		// This function will return an Object with x and y properties
		var useWindow=false;
		var coordinates=new Object();
		var x=0,y=0;
		// Browser capability sniffing
		var use_gebi=false, use_css=false, use_layers=false;
		if (document.getElementById) { use_gebi=true; }
		else if (document.all) { use_css=true; }
		else if (document.layers) { use_layers=true; }
		// Logic to find position
	 	if (use_gebi && document.all) {
			x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
			y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
			}
		else if (use_gebi) {
			var o=document.getElementById(anchorname);
			x=AnchorPosition_getPageOffsetLeft(o);
			y=AnchorPosition_getPageOffsetTop(o);
			}
	 	else if (use_css) {
			x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
			y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
			}
		else if (use_layers) {
			var found=0;
			for (var i=0; i<document.anchors.length; i++) {
				if (document.anchors[i].name==anchorname) { found=1; break; }
				}
			if (found==0) {
				coordinates.x=0; coordinates.y=0; return coordinates;
				}
			x=document.anchors[i].x;
			y=document.anchors[i].y;
			}
		else {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		coordinates.x=x;
		coordinates.y=y;
		return coordinates;
	}

	// getAnchorWindowPosition(anchorname)
	//   This function returns an object having .x and .y properties which are the coordinates
	//   of the named anchor, relative to the window
	function getAnchorWindowPosition(anchorname) {
		var coordinates=getAnchorPosition(anchorname);
		var x=0;
		var y=0;
		if (document.getElementById) {
			if (isNaN(window.screenX)) {
				x=coordinates.x-document.body.scrollLeft+window.screenLeft;
				y=coordinates.y-document.body.scrollTop+window.screenTop;
				}
			else {
				x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
				y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
				}
			}
		else if (document.all) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else if (document.layers) {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		coordinates.x=x;
		coordinates.y=y;
		return coordinates;
	}

	// Functions for IE to get position of an object
	function AnchorPosition_getPageOffsetLeft (el) {
		var ol=el.offsetLeft;
		while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
		return ol;
	}
	
	function AnchorPosition_getWindowOffsetLeft (el) {
		return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
	
	function AnchorPosition_getPageOffsetTop (el) {
		var ot=el.offsetTop;
		while((el=el.offsetParent) != null) { ot += el.offsetTop; }
		return ot;
	}
	
	function AnchorPosition_getWindowOffsetTop (el) {
		return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}
	
/*		*/

	function genGetObjOffset(objName,e) {
		var result = new Object();
		var resultObj= new Object();

		result.x = 0;		result.y = 0;
		resultObj.x = 0;	resultObj.y = 0;
		theObj  = document.getElementById(objName);
		if (theObj)
		{	
			if (isMSIE)
			{
			      x = window.event.clientX;
			      y = window.event.clientY;
			}	else	{
				x = e.clientX;
				y = e.clientY;
			}
					
			/* Rileva scroll */
					
			var scrollX, scrollY;
      
			if (document.all)
			{
			   if (!document.documentElement.scrollLeft)
			      scrollX = document.body.scrollLeft;
			   else
			      scrollX = document.documentElement.scrollLeft;
					         
			   if (!document.documentElement.scrollTop)
			      scrollY = document.body.scrollTop;
			   else
			      scrollY = document.documentElement.scrollTop;
			}   
			else
			{
			   scrollX = window.pageXOffset;
			   scrollY = window.pageYOffset;
			}					
					  
			resultObj = getAnchorPosition(objName)

			horiz = x + scrollX - parseInt(resultObj.x);
			vert  = y + scrollY- parseInt(resultObj.y);
					
			result.x = horiz;
			result.y = vert;
		}
		return result;
	}
		
/*	----------	*/
	var prevLat = 0;
	var prevLon = 0;

	function getcoords(nomeDiv,e)  
	{				
		var point, coords;
		if (omap == null)
			return;
		point = new Object();
		point = genGetObjOffset("map",e);
		var latLon = omap.fromContainerPixelToLatLng(new GPoint(point.x,point.y));
		if (prevLat != latLon.lat() || prevLon != latLon.lng())					
			if (!(isNaN(latLon.lat()) || isNaN(latLon.lng())))
			{
				latitude  = latLon.lat();
				longitude = latLon.lng();

				if (longitude < -180)	longitude = 360 + longitude;
				if (longitude > 180)	longitude = longitude - 360;

				setInnerHTML(nomeDiv, "<center><b> N: " + (Math.round(latitude * 1000000) / 1000000) + ", E: " + (Math.round(longitude * 1000000) / 1000000) + "</b></center>");
				prevLat = latitude;
				prevLon = longitude;
			}
		point = null;
	}
	
	function gettimes(nomeDiv,e)  
	{				
		var point, coords;
		if (omap == null)
			return;
		point = new Object();
		point = genGetObjOffset("map",e);
		var latLon = omap.fromContainerPixelToLatLng(new GPoint(point.x,point.y));
		if (prevLat != latLon.lat() || prevLon != latLon.lng())					
			if (!(isNaN(latLon.lat()) || isNaN(latLon.lng())))
			{
				latitude  = latLon.lat();
				longitude = latLon.lng();

				if (longitude < -180)	longitude = 360 + longitude;
				if (longitude > 180)	longitude = longitude - 360;
/*				
				var now = new Date();
				var DSTIndicator = ""; // month is 0 based. April to late oct 3..9
				var month = now.getMonth();
				if (month >= 3 && month <= 9) // early april to late oct is DST (approx)
					DSTIndicator = "<img src='css/daylight_savings.gif' height='9' width='12' title='Daylight Savings Warning'/>";
				now = now - now.getTimezoneOffset(); // to Greenwich
				now = now + 20; // Math.floor((12 * 60 * longitude) / 180);
				D.setHours(D.getHours()+9)
				now.setMinutes(now.getMinutes() + now.getTimezoneOffset());
				var hOffset = 0;
				if (longitude < -7.5 || longitude > 7.5)
				{
					hOffset = Math.floor(12 * (longitude + 7.5) / 180);
					now.setHours(now.getHours() + hOffset);
				}
				var timeStr;
				var half;
				var hour = now.getHours();
				if (hour >= 12)
				{
					half = "PM";
					hour = hour - 12;
				}
				else
					half = "AM";
				if (hour == 0)
					hour = 12;
				timeStr = "<a href='http://www.timeanddate.com/worldclock/' target='_blank' title='Check World Cities'>" + twoDigits(hour) + ":" + twoDigits(now.getMinutes()) + " " + half + "<\/a>" + DSTIndicator;
				setInnerHTML(nomeDiv,timeStr)
*/
			}
		point = null;
	}
