var datenbank = new Array();	//Das Karten Array
var maptop;
var mapleft;

function initialisierung() {
//Wenn die Seite geladen wird, wird das Datenbankarray gebaut,
//Die Daten müssen als Javascript Array vorliegen, jeder Datensatz wird eindeutig durch seine
//Indexposition im Daten-Array identifiziert
         machObjekt(daten);
		 verstecke();
}


function machObjekt(arr) {
//Hier machen wir aus jedem einzelnen Zeilen-Datenssätzen des Arrays arr ein
//Objekt namens arrds mit den Feldern vorname, nachname, alter, tag, monat, jahr
//und sammeln alle arrds in dem global verfügbaren Array datenbank
//Zugriff auf ein Feld ist dann mit zB datenbank[5].land_name möglich
//
	var anzahlds = arr.length;

	for (i = 0; i < anzahlds; i++) {
		//splitte den Datensatzstring in das array arrds:
		arrds = arr[i].split("*");
		//fülle array datenbank[i] auf mit den Objekt-Eigenschaften land_id, land_name etc
                 datenbank[i] = {land_id:arrds[0], land_name:arrds[1], land_link:arrds[2], land_proj:arrds[3], land_vol:arrds[4], land_fk:arrds[5], land_stips:arrds[6], land_x:arrds[7], land_y:arrds[8]};
         }
}



function zeige(was) {
	var mt = getRawObject("meintext");
	var hoehe;
	var zeile1, zeile2, zeile3, zeile4, zeile5, zeile6;
	var i;
	var sonstigertext;	//inhalt des untersten Textfelds
	
	var anzahlds = datenbank.length;
	
	//Höhe des Info-Fensterchens
	hoehe = 130;
	

	for (i = 0; i< anzahlds; i++) {
		if (datenbank[i].land_id == was) {
			break;
		}
	}
	if (datenbank[i] != undefined) {
		show("meldung");
		shiftTo("meldung", (datenbank[i].land_x), (datenbank[i].land_y - hoehe) );
		
		//Zeilendaten ermitteln
		zeile1 = datenbank[i].land_name;
		
		if (datenbank[i].land_proj != "") {
			if (datenbank[i].land_proj == "1") {
				zeile2 = "<div style='background-color:#FDF0D3;padding-left:2px;width:100%;line-height:18px'>" + 
							datenbank[i].land_proj + texte[0] + "</div>";
			}
			else {
				zeile2 = "<div style='background-color:#FDF0D3;padding-left:2px;width:100%;line-height:18px'>" + 
							datenbank[i].land_proj + texte[1] + "</div>" 
			}

		} 
		else {
			zeile2 = "";
		}
		
		if (datenbank[i].land_vol != "") {
			zeile3 = "<div style='background-color:#FDF0D3;padding-left:2px;width:100%;line-height:18px'>" +
							datenbank[i].land_vol + texte[2] + "<div>" ;
		} 
		else {		
			zeile3 = "";
		}		

		if (datenbank[i].land_fk != "") {
			if (datenbank[i].land_fk == "1" ) {
				zeile4 = "<div style='background-color:#F9D995;padding-left:2px;width:100%;line-height:18px'>" + datenbank[i].land_fk + texte[3] +"</div>";	
			}
			else {
				zeile4 = "<div style='background-color:#F9D995;padding-left:2px;width:100%;line-height:18px'>" + datenbank[i].land_fk + texte[4] + "</div>";
			}
		} 
		else {		
			zeile4 = "";
		}
		
		if (datenbank[i].land_stips != "") {
			if (datenbank[i].land_stips == "1") {
				zeile5 = "<div style='background-color:#F9D995;padding-left:2px;width:100%;line-height:18px'>"+ datenbank[i].land_stips + texte[5] +"</div>";				
			}
			else {
				zeile5 = "<div style='background-color:#F9D995;padding-left:2px;width:100%;line-height:18px'>" + datenbank[i].land_stips + texte[6] + "</div>";
			}
		} 
		else {		
			zeile5 = "";
		}
	
		//unterste Zeile: sonstiger Text. 
		//Struktur in Excel zB: 
		//"EED in Südafrika | www.eed.de/sa" 
		//oder Irgendein Text ohne "|"
		//Falls ein | drin steht, dann wird ein a href und linktext erzeugt, ansonsten geht der Text
		//unverändert durch.
		if (datenbank[i].land_link != "") {
			
			sonstigertext = datenbank[i].land_link;		
			
			//splitte den string von Excel beim | 
			sonstigertextarray = sonstigertext.split("|");
			//Ist das ergebnis-array nur 1 Feld lang, dann lass sonstigertext einfach stehen:
			if (sonstigertextarray.length == 1) {
				sonstigertext = sonstigertext;
			}
			//wenn wir mehr als 1 Teil haben:
			else {
				//Leerzeichen in der URL löschen:
				sonstigertextarray[1] = sonstigertextarray[1].replace(/ /g,""); 
				//und Link schneidern:
				sonstigertext = "<a href=\"javascript:opener.location.href=\'http://" + sonstigertextarray[1] + "\';self.close()\">"  + sonstigertextarray[0] + "</a>";
			}
		
	
		zeile6 = "<div style='background-color:#F8BA36;padding-left:2px;width:100%;line-height:18px'>" + 
						sonstigertext + 
			   "</div>"	;		
		} 
		else {		
			zeile6 = "";
		}	
	

		
		//text schreiben
		mt.innerHTML = "<div style='position:absolute;padding-left:2px;width:100%;line-height:10px'>" + "<a href='javascript:verstecke()'><img src='ausdiemaus.gif' border='0'></a>" + "</div>" +
						"<div style='background-color:#f0b40f;padding-left:2px;color:#ffffff;width:100%;line-height:18px'><strong>" + 
							zeile1 + "</strong></div>" + 
							zeile2 +
							zeile3 +  
							zeile4 +
							zeile5 + 
							zeile6 ;
	}
	else {
		verstecke;
	}
}

function verstecke() {
	hide("meldung");
}


// Global variables
var isCSS, isW3C, isIE4, isNN4;


// initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
		//bau die Datenbank auf
		initialisierung();
    }
}
// set event handler to initialize API
window.onload = initDHTMLAPI;

// Seek nested NN4 layer from string name
function seekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
	
    return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }	
	if(theObj){
	} 	
    return theObj;
}

// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0;
            theObj.left = x + units;
            theObj.top = y + units;
        } else if (isNN4) {
            theObj.moveTo(x,y)
        }	
    }
}


// Set the z-order of an object
function setZIndex(obj, zOrder) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.zIndex = zOrder;
    }
}

// Set the background color of an object
function setBGColor(obj, color) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isNN4) {
            theObj.bgColor = color;
        } else if (isCSS) {
            theObj.backgroundColor = color;
        }
    }
}

// Set the visibility of an object to visible
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "visible";
    }
}

// Set the visibility of an object to hidden
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}









