var OffsetFactor = 0.001497177; // This is calculated from 20(measured factor) / 3.1415927 (PI) / 6378.2 (Earth radius in Km)
var LocImg="pics/USEN_";
var OldImgN;
var OldZmN;
var ct = 1;

function ChangeMapSz(i)
{
	gMapSize = i;
	onMapSize();
}

function oSzMouseOver(i)
{
	if (i.src.indexOf("Zd.gif")>=0)
		i.src="pics/Zm.gif";
	else if (i.src.indexOf("MapSzD.gif")>=0)
		i.src="pics/MapSzM.gif";
}

function oSzMouseOut(i)
{
	if (i.src.indexOf("Zm.gif")>=0)
		i.src="pics/Zd.gif";
	else if (i.src.indexOf("MapSzM.gif")>=0)
		i.src="pics/MapSzD.gif";
}
	
function oMouseOver(oImgN)
{
	MouseOver("pics/",oImgN);
}

function oMouseOverL(oImgN)
{
	MouseOver(LocImg,oImgN);
}

function oMouseOut()
{
	MouseOut("pics/");
}

function oMouseOutL()
{
	MouseOut(LocImg);
}

function MouseOver(i,oImgN)
{
	OldImgN = oImgN;
	document.MCForm[oImgN].src = i + oImgN + "m.gif";
	if (!gNavMaps)
	{
		document.MCForm[oImgN].style.cursor="hand";
	}
}

function MouseOut(i)
{
	document.MCForm[OldImgN].src = i + OldImgN + ".gif";
}

function oZMouseOver(oImgN)
{
	OldZmN = oImgN;
	if ("Z" + Zoom() != oImgN)
		document.MCForm[oImgN].src = "pics/zm.gif";
}

function oZMouseOut()
{
	if ("Z" + Zoom() != OldZmN)
		document.MCForm[OldZmN].src = "pics/zd.gif";
}

function oLegend()
{
/*
	var strLang = document.MCForm.MapForm_LangText.value;
	var LangStr = strLang;
	var Leg = "/MapLegend.htm";
	if ( -1 != LangStr.indexOf( "WLD" ) )
	{
		Leg="/WldMapLegend.htm";
	}
	else if ( -1 != LangStr.indexOf( "EUR" ) )
	{
		Leg="/EurMapLegend.htm";
	}
*/
	Leg = "http://www.mapblast.com/MapLegend.htm";
	var w = window.open( Leg, "Map_Legend", "width=300,height=490,scrollbars=yes,left=480,top=120,screenX=480,screenY=120" );
	w.focus();
}

function oCZoomInt(LT)
{
	document.MCForm.MapForm_TextZoom.value = LT;
	RepaintMap();
	SetZoom(LT);
}

function NewMapLink()
{
	window.scrollBy(0,1000);
	document.FindForm["FndControl:StreetText"].focus();
}

function FixZoom()
{
	SetZoom(Zoom());
}


function SetZoom(ndx)
{
	with(document)
	{
		var i;
		for( i = 0; i < 8; i++)
		{
			var CName = "Z" + i;
			MCForm[CName].src = "pics/Zd.gif";
			if (i<ndx)
				MCForm[CName].alt = "Zoom in";
			else
				MCForm[CName].alt = "Zoom out";
		}
		var CName = "Z" + ndx;
		MCForm[CName].src = "pics/Za.gif";
		MCForm[CName].alt="Current zoom";
		SetScaleImg()
		SetMapTT();
	}
}

function SetScaleImg()
{
	with(document.MCForm)
	{
		MapScale.src = "pics/"+gMapSize+Zoom()+".gif";
	}
}

function SetMapTT()
{
	with(document.MCForm)
	{
		var tt = (0==Zoom() || !ZmOnClk()) ? "Map - Click to center":"Map - Click to zoom in";
		if (MapImage.alt != tt)
			MapImage.alt = tt;
	}
}

function SphereClick(sX, sY, ZoomI)
{
	var R = (6378.2 * MapHeights[gMapSize]) / (Zooms[ZoomI] / 2.5);
	var vC = new Array(0.0, 0.0, 0.0);
	vC[0] = sX / R;
	vC[1] = - sY / R;
	if ( (vC[0]*vC[0] + vC[1]*vC[1]) > 1.0 )
		return;

	vC[2] = Math.sqrt( 1 - (vC[0]*vC[0] + vC[1]*vC[1]) );
	with(document.MCForm)
	{
		var fLat = document.MCForm.MapForm_TextLatitude.value;
		var fLong = document.MCForm.MapForm_TextLongitude.value;

		var CurLat = -( parseFloat(fLat) * 0.017453292 );
		var CurLon = ( parseFloat(fLong) * 0.017453292 );
		var m1 = new Array( Math.cos(CurLon), Math.sin(CurLat)*Math.sin(CurLon), Math.cos(CurLat)*Math.sin(CurLon) );
		var m2 = new Array( 0.0, Math.cos(CurLat), -Math.sin(CurLat) );
		var m3 = new Array( -Math.sin(CurLon), Math.sin(CurLat)*Math.cos(CurLon), Math.cos(CurLat)*Math.cos(CurLon) );
		var vF = new Array(0.0, 0.0, 0.0);
		for(i=0;i<3;i++)
		{
			vF[0] = vF[0] + vC[i]*m1[i];
		}
		for(i=0;i<3;i++)
		{
			vF[1] = vF[1] + vC[i]*m2[i];
		}
		for(i=0;i<3;i++)
		{
			vF[2] = vF[2] + vC[i]*m3[i];
		}
		var FinalLat = Math.asin( vF[1] );
		var FinalLon = Math.atan2( vF[2], vF[0] );
		MapForm_TextLatitude.value = FinalLat/0.017453292;
		var Lon = 90 - FinalLon/0.017453292;
		if ( Lon > 180 )
			Lon -= 360;
		MapForm_TextLongitude.value = Lon;
		if (ZmOnClk())
			oCZoomIn();
		else
			RepaintMap();
	}
}

function oCMap()
{
	if (bDisablePanning)
		return;

	var pX=window.event.offsetX-Math.floor(MapWidths[gMapSize]/2);
	var pY=window.event.offsetY-Math.floor(MapHeights[gMapSize]/2);
	SphereClick(pX, pY, Zoom());
}

function oCPan(iX, iY)
{
	if (bDisablePanning)
		return;

	var A = Zooms[Zoom()];
	PanLat( A * OffsetFactor * iY );
	PanLon( A * OffsetFactor * iX );
	RepaintMap();
}

function PanLat(Y)
{
	with(document.MCForm.MapForm_TextLatitude)
	{
		Y += parseFloat(value);
		if (Y > 90)
			Y = 90;
		if (Y < -90)
			Y = -90;
		value = Y;
	}
}

function PanLon(X)
{
	with(document.MCForm.MapForm_TextLongitude)
	{
		X += parseFloat(value);
		while(X > 180)
		{
			X -= 360;
		}
		while(X < -180)
		{
			X += 360;
		}
		value = X;
	}
}

function oCZoomIn()
{
	var A = Zoom() - 1;
	if (A < 0)
	{
		A = 0;
	}
	else
	{
		document.MCForm.MapForm_TextZoom.value = A;
		SetZoom(A); 
	}
	RepaintMap(); 
}

function oCZoomOut()
{
	var A = Zoom() + 1;
	if (A > 7)
	{
		A = 7;
	}
	else
	{
		document.MCForm.MapForm_TextZoom.value = A;
		SetZoom(A);
		RepaintMap();
	}
}

function RepaintMap()
{
	with(document.MCForm)
	{
		var ZoomKm = Zooms[Zoom()];

		var strSizeX = MapForm_TextMapX.value;
		var strSizeY = MapForm_TextMapY.value;

		var ImgParam = gMIM + "?Z=" + ZoomKm + "&S=" + strSizeX + "," + strSizeY;
		MapImage.src = ImgParam;
	}
}

function oZmOnClk(cb)
{
	StoreInCookie(eZoom,cb.checked?1:0); SetMapTT();
}

function ZmOnClk()
{
	return document.MCForm.MapForm_idZmOnClk.checked;
}

function Zoom()
{
	return parseInt(document.MCForm.MapForm_TextZoom.value);
}

function MapWHtoSize()
{
	for(i = 0; i < 3; i++)
	{
		if (document.MCForm.MapForm_TextMapX.value == MapWidths[i] && document.MCForm.MapForm_TextMapY.value == MapHeights[i])
			return i;
	}
	return 0;
}<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-4277916-3");
pageTracker._trackPageview();
} catch(err) {}</script>
