// variables:
// ------------------------------------------------------------------

var z = 1;
var x = 0;
var y = 0;
var h = 0;
var a = 0;

// Help:
// -------------------------------------------------------------------------------------------------------------------------------------
function ShowHelp(){
	wi = window.open("help.htm","Fenster1", "width=500 height=440,screenX=0,screenY=0");
}

// enable/disable buttons:
// --------------------------------------------------------------------------------------------------------------------------------------

function SetDisabled(theVar, z){

	if ( theVar == 0 ) {
		a = 0;
		document.images['Attribut'].src = "images/bd_info.gif";
		document.ControlForm.Att.value = 0;
		h=0;
		document.images['Hotlink'].src = "images/bd_hot.gif";
		document.ControlForm.Hot.value = 0;
		theVar = 'X'};
	if ( theVar == 1 ) {
		a = 0;
		document.images['Attribut'].src = "images/bd_info.gif";
		document.ControlForm.Att.value = 0;
		h=1;
		document.images['Hotlink'].src = "images/ba_hot.gif";
		document.ControlForm.Hot.value = 1;
		theVar = 'X'};
	if ( theVar == 2 ) {
		a = 1;
		document.images['Attribut'].src = "images/ba_info.gif";
		document.ControlForm.Att.value = 1;
		h=0;
		document.images['Hotlink'].src = "images/bd_hot.gif";
		document.ControlForm.Hot.value = 0;
		theVar = 'X'};
	if ( theVar == 3 ) {
		a = 1;
		document.images['Attribut'].src = "images/ba_info.gif";
		document.ControlForm.Att.value = 1;
		h=0;
		document.images['Hotlink'].src = "images/bi_hot.gif";
		document.ControlForm.Hot.value = 0;
		theVar = 'X'};

	if ( z < parseInt(parent.document.theForm.Zooms.value) )   {document.images['ZoomIn'].src = "images/bi_zoomin.gif"};
	if ( z == parseInt(parent.document.theForm.Zooms.value) ) {document.images['ZoomIn'].src = "images/bd_zoomin.gif"};
	if ( z == 1 ) {document.images['ZoomOut'].src = "images/bd_zoomout.gif"};
	if ( z > 1 )   {document.images['ZoomOut'].src = "images/bi_zoomout.gif"};
}

// change buttons:
// -----------------------------------------------------------------------------------------------------------------------------------

function ChangeImage(theVar){

	z = parseInt(parent.document.theForm.CurrentZ.value);

	if (z == 1)		{ bd = parseInt(parent.document.theForm.Zoom1i.value);
	} else if (z == 2)	{ bd = parseInt(parent.document.theForm.Zoom2i.value);
	} else if (z == 3)	{ bd = parseInt(parent.document.theForm.Zoom3i.value);
	} else		{ bd = parseInt(parent.document.theForm.Zoom1i.value) };

	if ( a == 0 && theVar == 'A') {
		if ( bd == 2 || bd == 3 ) {
			a = 1;
			document.images['Attribut'].src = "images/ba_info.gif";
			document.ControlForm.Att.value = 1;
			h = 0;
			if ( bd == 3 ) {
				document.images['Hotlink'].src = "images/bi_hot.gif";
				document.ControlForm.Hot.value = 0;
			}
			theVar = 'X';
		}
	}
	
	if ( a == 1 && theVar == 'A') {		
		if ( bd == 2 || bd == 3 ) {
			a = 0;
			document.images['Attribut'].src = "images/bi_info.gif";
			document.ControlForm.Att.value = 0;
			theVar = 'X';
		}
	}

	if ( h == 0 && theVar == 'H') {
		if ( bd == 1 || bd == 3 ) {
			h = 1;
			document.images['Hotlink'].src = "images/ba_hot.gif",
			document.ControlForm.Hot.value = 1;
			a = 0;
			if ( bd == 3 ) {
				document.images['Attribut'].src = "images/bi_info.gif";
				document.ControlForm.Att.value = 0;
			}
			theVar = 'X';
		}
	}

	if ( h == 1 && theVar == 'H') {		
		if ( bd == 1 || bd == 3 ) {
			h = 0;
			document.images['Hotlink'].src = "images/bi_hot.gif";
			document.ControlForm.Hot.value = 0;
			theVar = 'X';
		}
	}
}		


// get xin and 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};
}


// change map:
// ------------------------------------------------------------------

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 * 3 ; 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  / 3); 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);
}


// Tooltip:
// ------------------------------------------------------------------

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='FFF8DC';
	document.layers['Beschriftung'].fontSize='xx-small';
 	}
}


// Move Extent-Box on mouse click:
// ------------------------------------------------------------------------------------------------------

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;

}

// move extentbox on button click:
// -----------------------------------------------------------------------------------------------------------------

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';
	}

}

// Hotlinks: 
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	function GetExt(theHotlink, theAttributs){
		
		if (parseInt(parent.theControl.document.ControlForm.Hot.value) == 1 && theHotlink !='None') {

		if (theHotlink.substr(0,4).toLowerCase() == 'http'){
			F1 = window.open(theHotlink,"_blank", "scrollbars=yes, width=500 height=440");
		} else if  (theHotlink.indexOf("@") > 0){
			parent.document.location.href = "mailto:" + theHotlink;
		 } else if (theHotlink.lastIndexOf("htm") > -1)
			F1 = window.open("../hotlink/" + theHotlink,"_blank");

		 else {

			if ( document.all) {
					F1 = open("../hotlink/"+theHotlink+".htm","Fenster1","width=40,height=40,screenX=0,screenY=0, menubar=no resizeable=yes"); 
				} else {
					F1 = open("../hotlink/"+theHotlink+".htm","_blank","menubar=no, resizeable=yes"); 	
				}	
			}
		}

		if (parseInt(parent.theControl.document.ControlForm.Att.value) == 1&& theAttributs != 'None' ) {
			confirm(theAttributs);
		}
	}




