// Allgemeine Setzungen:
// ------------------------------------------------------------------

var z = 1;
var x = 0;
var y = 0;
var h = 0;
var a = 0;

// Funktion zum Aufruf der Hilfeseite:
// -------------------------------------------------------------------------------------------------------------------------------------
function ShowHelp(){
	wi = window.open("help.htm","Fenster1", "width=600 height=550,screenX=0,screenY=0");
}


// Bestimmen der Werte für xin und yin::
// ------------------------------------------------------------------

function GetValues(){

if (z == 1)		{ xin = parent.document.theForm.Zoom1x.value; yin = parent.document.theForm.Zoom1y.value;
} else if (z == 2)	{ xin = parent.document.theForm.Zoom2x.value; yin = parent.document.theForm.Zoom2y.value;
} else if (z == 3)	{ xin = parent.document.theForm.Zoom3x.value; yin = parent.document.theForm.Zoom3y.value;
} else		{ xin = parent.document.theForm.Zoom1x.value; yin = parent.document.theForm.Zoom1y.value};
}


// Funktion zum Wechsel des Kartenausschnitts:
// ------------------------------------------------------------------

function ChangeMap(theVar){

	GetValues();

	z = parseInt(parent.document.theForm.CurrentZ.value);
	x = parseInt(parent.document.theForm.CurrentX.value);
	y = parseInt(parent.document.theForm.CurrentY.value);

	theNrOfZooms = parseInt(parent.document.theForm.Zooms.value);

	if (isNaN(x)){x=0}; if (isNaN(y)){y=0}; if (isNaN(theNrOfZooms)){theNrOfZooms=1};

	if (theVar=='zoomin'){
		z = z + 1;
		if ( z <= theNrOfZooms){
			x = x * 2 ; y = y * 2 ;
			if (z  == 2){ x = x + 1; y = y + 1};
		} else {
			z = theNrOfZooms;
		}
		if ( z == 1 ) {bd = parseInt(parent.document.theForm.Zoom1i.value); SetDisabled(bd, z)};
		if ( z == 2 ) {bd = parseInt(parent.document.theForm.Zoom2i.value); SetDisabled(bd, z)};
		if ( z == 3 ) {bd = parseInt(parent.document.theForm.Zoom3i.value); SetDisabled(bd, z ) };

	}else if (theVar=='zoomout'){
		if ( z > 1 ) {
			z = z - 1;
			GetValues();
			if (isNaN(x)){x=0}; if (isNaN(y)){y=0};
			x = parseInt(x  / 2); y = parseInt(y  / 2);
			if (isNaN(x)){x=0}; if (isNaN(y)){y=0};
			if ( z == 1 ) { z = 1};
		}

		if ( x >= xin ) { x = xin-1 };
		if ( y >= yin ) { y = yin-1 };

		if ( z == 1 ) {bd = parseInt(parent.document.theForm.Zoom1i.value); SetDisabled(bd, z)};
		if ( z == 2 ) {bd = parseInt(parent.document.theForm.Zoom2i.value); SetDisabled(bd, z)};
		if ( z == 3 ) {bd = parseInt(parent.document.theForm.Zoom3i.value); SetDisabled(bd, z) };

	}else if (theVar=='up'){
		y = y - 1;
		if ( y < 0 ) { y = 0 };
	}else if (theVar=='down'){
		y = y + 1;
		if (y >= yin-1) {y = yin-1};
	}else if (theVar=='left'){
		x = x - 1;
		if ( x < 0 ) { x = 0 };
	}else if (theVar=='right'){
		x = x + 1;
		if (x >= xin-1) {x = xin-1};
	}
	
	parent.document.theForm.CurrentZ.value=z;
	parent.document.theForm.CurrentX.value=x;
	parent.document.theForm.CurrentY.value=y;

	theDocumentName = 'maps/' + z + '' + x + '_' + y + '.htm';
	parent.theMap.location.href=theDocumentName;
	MoveExtentValue(x,y);
}


// Funktion zur Anzeige des Tooltip-Textes:
// ------------------------------------------------------------------

function DrawTextBox(theVar,x,y,state) {

	if (state==0) 	{state='hidden';
	} else 		{state='visible'};

	if (document.all)
	{     
	if ( x > (parseInt(document.all['theMapImage'].style.width) - 100)) { x = x - 100 }
	document.all['Beschriftung'].style.visibility=state;
	document.all['Beschriftung'].style.left=parseInt(document.all['theMapImage'].style.left) + x;
	document.all['Beschriftung'].style.top=parseInt(document.all['theMapImage'].style.top) + y;
	document.all['Beschriftung'].innerHTML=theVar;
	}
	else
	{
	if ( x > (document.Form1.MapSize.value - 100)) { x = x - 100 }
 	document.layers['Beschriftung'].visibility=state;
	document.layers['Beschriftung'].left=document.layers['theMapImage'].x + x;
	document.layers['Beschriftung'].top=document.layers['theMapImage'].y + y;
	document.layers['Beschriftung'].document.write(theVar);
	document.layers['Beschriftung'].document.close();
	document.layers['Beschriftung'].bgColor='yellow';
	document.layers['Beschriftung'].fontSize='xx-small';
 	}
}


// Funktion zum Verschieben der Extent-Box in Übersichtskarte per Mausklick:
// ------------------------------------------------------------------------------------------------------

function MoveExtent(x,y) {

	z = parseInt(parent.document.theForm.CurrentZ.value);

	GetValues()

	if ( z == 1 ) {
		xx = parseInt(parent.document.theForm.BildX.value / xin);
		yy = parseInt(parent.document.theForm.BildY.value / yin);
		theXDiff = (parseInt(parent.document.theForm.BildX.value) - (xx * xin)) / xin ;
		theYDiff = (parseInt(parent.document.theForm.BildY.value) - (yy * yin)) / yin;
	} else {
		bx = parseInt(parent.document.theForm.BildX.value) + (parent.document.theForm.BildX.value / ( xin - 1));
		xx = parseInt( (bx / xin) + 0.5 );
		by = parseInt(parent.document.theForm.BildY.value) + (parent.document.theForm.BildY.value / ( yin - 1));
		yy = parseInt( (by / yin) + 0.5 );
		theXDiff = (bx - (xx * xin)) / xin;
		theYDiff = (by - (yy * yin)) / yin;
	}

	if (document.all){
		x=x-parseInt(document.all['theMapImage'].style.left);
		y=y-parseInt(document.all['theMapImage'].style.top);
	} else {
		x=x-parseInt(document.layers['theMapImage'].left);
		y=y-parseInt(document.layers['theMapImage'].top);
	}

	if (z == 1) {
		xClick=parseInt(x / xx); yClick=parseInt(y / yy);
	} else {	
		if ( x > parseInt(parent.document.theForm.BildX.value)-( xx / 2 )) { xClick  = xin-1;
		} else { xClick=parseInt( x / (parseInt(parent.document.theForm.BildX.value) / xin) ) };
		if ( y > parseInt(parent.document.theForm.BildY.value)-( yy / 2 )) { yClick = yin-1;
		} else { yClick=parseInt( y / (parseInt(parent.document.theForm.BildY.value) / yin) ) };
	}
	if (isNaN(xClick)){xClick=0}; if (isNaN(yClick)){yClick=0};
	if (xClick > xin) {xClick=xin}; if (yClick > yin) {yClick=yin};

	xNum = parseInt(xClick); yNum = parseInt(yClick);
	
	if (isNaN(xNum)){xNum=0}; if (isNaN(yNum)){yNum=0};

	x = xClick;	y = yClick;

	xCorrect = parseInt(x * theXDiff); yCorrect = parseInt(y * theYDiff);

	if (isNaN(xCorrect)){xCorrect=0}; if (isNaN(yCorrect)){yCorrect=0};

	if (z == 1)	{ x = x  * xx; y = y * yy;
	} else 	{ x = ( x * xx ) - parseInt( xx / 2 );	y = ( y * yy ) - parseInt( yy / 2 )};

	if ( theXDiff == 1 ) 		{ x = x;
	} else if ( theXDiff < 1 ) 	{ x = x + xCorrect;
	} else if ( theXDiff > 1 ) 	{ x = x - xCorrect};

	if ( theYDiff == 1 ) 		{ y = y;
	} else if ( theYDiff < 1 ) 	{ y = y + yCorrect;
	} else if ( theYDiff > 1 ) 	{ y = y - yCorrect};

	if (document.all)
	{
	document.theExtentImage.width=xx+2;
     	document.theExtentImage.height=yy+2;
	if ( xx >= 30 ) {document.theExtentImage.src="../../images/1px.gif"};
	if ( xx < 30 && xx >= 20 ) {document.theExtentImage.src="../../images/2px.gif"};
	if ( xx < 20 && xx >= 10 ) {document.theExtentImage.src="../../images/3px.gif"};
	if ( xx < 10 ) {document.theExtentImage.src="../../images/4px.gif"};
	document.all['theExtent'].style.width = xx+2;
	document.all['theExtent'].style.height = yy+2;
	document.all['theExtent'].style.top=y+parseInt(document.all['theMapImage'].style.top);
	document.all['theExtent'].style.left=x+parseInt(document.all['theMapImage'].style.left);
 	document.all['theExtent'].style.visibility='visible'
	}
	else
	{

	if ( xx >= 30 ) {document.layers['theExtent'].document.write("<img src='../../images/1px.gif' width=" + (xx+2) + " height=" + (yy+2) + ">")};	
	if ( xx < 30 && xx >= 20) {document.layers['theExtent'].document.write("<img src='../../images/2px.gif' width=" + (xx+2) + " height=" + (yy+2) + ">")};	
	if ( xx < 20 && xx >= 10) {document.layers['theExtent'].document.write("<img src='../../images/3px.gif' width=" + (xx+2) + " height=" + (yy+2) + ">")};	
	if ( xx < 10 ) {document.layers['theExtent'].document.write("<img src='../../images/4px.gif' width=" + (xx+2) + " height=" + (yy+2) + ">")};	
	document.layers['theExtent'].document.close();
	document.layers['theExtent'].width=xx+2;
	document.layers['theExtent'].height=yy+2;
	document.layers['theExtent'].top=y+parseInt(document.layers['theMapImage'].top);
	document.layers['theExtent'].left=x+parseInt(document.layers['theMapImage'].left);
 	document.layers['theExtent'].visibility='visible';
	}

	parent.document.theForm.CurrentX.value=xNum;
	parent.document.theForm.CurrentY.value=yNum;
	theDocumentName =  z + '' + xNum + '_' + yNum + '.htm';
	parent.theMap.location.href=theDocumentName;

}

// Funktion zum Verschieben der Extent-Box in Übersichtskarte über Richtungstasten:
// -----------------------------------------------------------------------------------------------------------------

function MoveExtentValue(x,y) {

	z = parseInt(parent.document.theForm.CurrentZ.value);

	if (z == 1){
		xin = parent.document.theForm.Zoom1x.value;
 		yin = parent.document.theForm.Zoom1y.value;
		bd = parseInt(parent.document.theForm.Zoom1i.value);
	}else if (z == 2){
		xin = parent.document.theForm.Zoom2x.value;
 		yin = parent.document.theForm.Zoom2y.value;
		bd = parseInt(parent.document.theForm.Zoom2i.value);
	}else if (z == 3){
		xin = parent.document.theForm.Zoom3x.value;
 		yin = parent.document.theForm.Zoom3y.value;
		bd = parseInt(parent.document.theForm.Zoom3i.value);
	}else{
		xin = parent.document.theForm.Zoom1x.value;
 		yin = parent.document.theForm.Zoom1y.value;
		bd = parseInt(parent.document.theForm.Zoom1i.value);
	}

	if ( z == 1 ) {
		xx = parseInt(parent.document.theForm.BildX.value / xin);
		yy = parseInt(parent.document.theForm.BildY.value / yin);
		theXDiff = (parseInt(parent.document.theForm.BildX.value) - (xx * xin)) / xin ;
		theYDiff = (parseInt(parent.document.theForm.BildY.value) - (yy * yin)) / yin;
	} else {
		bx = parseInt(parent.document.theForm.BildX.value) + (parent.document.theForm.BildX.value / ( xin - 1));
		xx = parseInt( (bx / xin) + 0.5 );
		by = parseInt(parent.document.theForm.BildY.value) + (parent.document.theForm.BildY.value / ( yin - 1));
		yy = parseInt( (by / yin) + 0.5 );
		theXDiff = (bx - (xx * xin)) / xin;
		theYDiff = (by - (yy * yin)) / yin;
	}

	xCorrect = parseInt(x * theXDiff); yCorrect = parseInt(y * theYDiff);
	if (isNaN(xCorrect)){xCorrect=0}; if (isNaN(yCorrect)){yCorrect=0};

	if (z == 1)	{ x = x  * xx; y = y * yy;
	} else 	{ x = ( x * xx ) - parseInt( xx / 2 );	y = ( y * yy ) - parseInt( yy / 2 )};

	if ( theXDiff == 1 ) 		{ x = x;
	} else if ( theXDiff < 1 ) 	{ x = x + xCorrect;
	} else if ( theXDiff > 1 ) 	{ x = x - xCorrect};

	if ( theYDiff == 1 ) 		{ y = y;
	} else if ( theYDiff < 1 ) 	{ y = y + yCorrect;
	} else if ( theYDiff > 1 ) 	{ y = y - yCorrect};

	if (document.all)
	{
	parent.theOverview.document.theExtentImage.width=xx+2;
     	parent.theOverview.document.theExtentImage.height=yy+2;
	if ( xx >= 30 ) {parent.theOverview.document.theExtentImage.src="../../images/1px.gif"};
	if ( xx < 30 && xx >= 20 ) {parent.theOverview.document.theExtentImage.src="../../images/2px.gif"};
	if ( xx < 20 && xx >= 10 ) {parent.theOverview.document.theExtentImage.src="../../images/3px.gif"};
	if ( xx < 10 ) {parent.theOverview.document.theExtentImage.src="../../images/4px.gif"};
	parent.theOverview.document.all['theExtent'].style.width = xx+2;
	parent.theOverview.document.all['theExtent'].style.height = yy+2;
	parent.theOverview.document.all['theExtent'].style.top=y +parseInt(parent.theOverview.document.all['theMapImage'].style.top);
	parent.theOverview.document.all['theExtent'].style.left=x +parseInt(parent.theOverview.document.all['theMapImage'].style.left);
 	parent.theOverview.document.all['theExtent'].style.visibility='visible'
	}
	else
	{
	if ( xx >= 30 ) {parent.theOverview.document.layers['theExtent'].document.write("<img src='../../images/1px.gif' width=" + (xx+2) + " height=" + (yy+2) + ">")};	
	if ( xx < 30 && xx >= 20) {parent.theOverview.document.layers['theExtent'].document.write("<img src='../../images/2px.gif' width=" + (xx+2) + " height=" + (yy+2) + ">")};	
	if ( xx < 20 && xx >= 10) {parent.theOverview.document.layers['theExtent'].document.write("<img src='../../images/3px.gif' width=" + (xx+2) + " height=" + (yy+2) + ">")};	
	if ( xx < 10 ) {parent.theOverview.document.layers['theExtent'].document.write("<img src='../../images/4px.gif' width=" + (xx+2) + " height=" + (yy+2) + ">")};	
	parent.theOverview.document.layers['theExtent'].document.close();
	parent.theOverview.document.layers['theExtent'].width=xx+2;
	parent.theOverview.document.layers['theExtent'].height=yy+2;
	parent.theOverview.document.layers['theExtent'].top=y+parseInt(parent.theOverview.document.layers['theMapImage'].top);
	parent.theOverview.document.layers['theExtent'].left=x+parseInt(parent.theOverview.document.layers['theMapImage'].left);
 	parent.theOverview.document.layers['theExtent'].visibility='visible';
	}

}


