// +++++++++++++++++++++++++++++++++++++++++++++++++++++
// +                                                   +
// + Saechsisches Landesamt fuer Umwelt und Geologie   +
// + 30.06.2003 - Referat 11 - fs                      +
// + Update 25.11.2004                                 +
// + Update 21.12.2004                                 +
// +                                                   +
// +++++++++++++++++++++++++++++++++++++++++++++++++++++

var nav_name = navigator.appName
var nav_version = parseInt(navigator.appVersion)
var browser = "";
var reddoturl = "";

if (nav_name == "Microsoft Internet Explorer" && nav_version >= 4) { browser ="ie4"; }

if (browser == "ie4")
{
	url = window.location + "";
	reddoturl = url.search(/reddot/i);
}

var xdiff, ydiff, enmvt, name, fx, cookieX, cookieY, zthide, docstr;
function setZoomSize()
{
	if ((browser == "ie4") && (reddoturl == -1))
	{
		docstr = "top.document";
		fx = parseFloat(getCookie("fxvalue"));
		if (isNaN(fx) == true) fx = 1;
		else fx = getCookie("fxvalue");

		eval(docstr + ".body.style.zoom = fx");
	}
}

function initZoomTool(name)
{
	if ((browser == "ie4") && (reddoturl == -1))
	{
		docstr = "top.document";
		fx = parseFloat(getCookie("fxvalue"));
		if (isNaN(fx) == true) fx = 1;
		else fx = getCookie("fxvalue");

		eval(docstr + ".body.style.zoom = fx");

		if (getCookie("layertop") == "")
			eval(docstr + ".cookie = 'layertop=65'");

		if (getCookie("layerleft") == "")
			eval(docstr + ".cookie = 'layerleft=18'");
		
		cookieY = getCookie("layertop");
		cookieX = getCookie("layerleft");		
		zthide	= getCookie("visible");

		if (!isNaN(cookieY) && !isNaN(cookieX))
		{
			if ((cookieY != "") && (cookieX != ""))	
			{
				eval("document.all." + name + ".style.pixelTop = cookieY");
				eval("document.all." + name + ".style.pixelLeft = cookieX");
			}
		}

		if (zthide == 'hidden' || zthide == 'visible') 
			eval("document.all." + name + ".style.visibility = \"" + zthide + "\"");
		else
		{
			eval("document.all." + name + ".style.visibility = \"visible\"");
			eval(docstr + ".cookie = 'visible=visible'");
		}
			
		eval("document.all." + name + ".oncontextmenu = function () {return false;}");
	}
}

function setEvents(lyr)
{
	document.onmousedown 	= setOnMouseDown;
	document.onmouseup 	= setOnMouseUp;
	document.onmouseout	= setOnMouseOut;
	document.onmousemove 	= setOnMouseMove;

	name = lyr;
}

function setOnMouseDown(e)
{
	var xcur = "" , ycur = "";
	if ((browser == "ie4") && (event.button==1))
	{
		layertop = "document.all." + name + ".style.pixelTop";
		layerleft = "document.all." + name + ".style.pixelLeft";
		xcur = window.event.x;
		ycur = window.event.y;
		xdiff = eval(xcur + " - " + layerleft + " * " + fx);
		ydiff = eval(ycur + " - " + layertop + " * " + fx);
	}

	enmvt = true;
}

function setOnMouseMove(e)
{
	if (enmvt)
	{
		if ((browser == "ie4") && (event.button==1))
		{
			layertop = "document.all." + name + ".style.pixelTop";
			layerleft = "document.all." + name + ".style.pixelLeft";
			xcur = window.event.x;
			ycur = window.event.y;
			xpos = (xcur - xdiff) / fx;
			ypos = (ycur - ydiff) / fx;
			eval(layertop + " = " + ypos);
			eval(layerleft + " = " + xpos);
			return false;
		}
	}
}

function setOnMouseOut()
{
	document.onmousedown 	= nothing;
	document.onmouseout	= nothing;	
	return;
}

function setOnMouseUp()
{
	document.onmousedown 	= nothing;
	document.onmouseup 	= nothing;
	document.onmouseout	= nothing;
	document.onmousemove 	= nothing;

	if (browser == "ie4")
	{
		layertop = "document.all." + name + ".style.pixelTop";
		layerleft = "document.all." + name + ".style.pixelLeft";
	
		eval(docstr + ".cookie = 'layertop=' + eval(layertop)");
		eval(docstr + ".cookie = 'layerleft=' + eval(layerleft)");
		
		enmvt = false;
	}
	
	return;
}

function nothing()
{
	return;
}

function hotKey(action, obj)
{
	if (browser == "ie4" && window.event.altKey)
	{
		zoomIt(action);
		eval(obj).blur();
	}
}

function hideLayer(name)
{
	if (browser == "ie4")
	{
		eval(docstr + ".cookie = 'visible=hidden'");
		eval("document.all." + name + ".style.visibility = \"hidden\"");
	}

	return;
}

function zoomIt(type)
{
	switch (type)
	{
		case "out":
		if (fx <= 5) fx *= 1.1;
			eval(docstr + ".body.style.zoom = fx");
		break;
		case "in":
		if (fx > .9) fx /= 1.1;
			eval(docstr + ".body.style.zoom = fx");
		break;
		case "1":
			fx = 1;
			eval(docstr + ".body.style.zoom = fx");
		break;
	}
	eval(docstr + ".cookie = 'fxvalue=' + fx");
}

function getCookie(name)
{
	if (eval(docstr + ".cookie.indexOf(name) != -1"))
	{
		var start 		= eval(docstr + ".cookie.indexOf(name) + name.length");
		var stop		= eval(docstr + ".cookie.substring(start, document.cookie.length).indexOf(';')");
		if (stop == -1)
			stop		= eval(docstr + ".cookie.substring(start, document.cookie.length).length");

		var cookieValue		= eval(docstr + ".cookie.substr(start+1, stop-1)");
		return cookieValue;
	} else
		return "";
}