	imageTooltip=null;
	settlementJSONObj=null;
	document.onmousemove = getMouseCoordinates;

       function showImages(pid, aid){
           // OpenLayers.loadURL('http://geoworld.de/showNzImages.php5?pid=' + pid + '&aid=' + aid, '', this, callbackShowImages);      
       }
       function callbackShowImages(response){
	  // TODO: Umwandlung des Responses in ein JSON Objekt aller Callback Funktionen in einen Funktion auslagern
          var JSONObj = eval('(' + response.responseText + ')');
	  var txt='';
          if (JSONObj != null){     
             if (typeof JSONObj.error == "undefined") {
	        for(var i=0; i<JSONObj.records.length; i++){
		   txt += '<image src="' + JSONObj.records[i].bild + '" width="800">';
		}
		OpenLayers.Util.getElement('imageList').innerHTML = txt;
             } else {
                // Fehler in der Rueckgabe.
             }
          } else {
             alert("Fehler beim Aufruf");
          }
       }

/*
       function init(){
          // Pull Down mit der Uebersicht wird erstellt
          // sendXmlHttpCall(url, parameters, callback, mimetype, tagname, action, resultString, requestHeader);
	  sendXmlHttpCall("nz_summary.php5", "?", callbackNZSummary, null, "overviewSelector", null, "xml", null);
          
	  // Einblendung der allgemeinen Infos (Neuseeland-Links, Reisefueher/Literatur
          // backpacker und Bilder bleiben erstmal leer
	  sendXmlHttpCall("nz_collectLinks.php5", "?id=0", callbackCollectLinks, null, "nzlinks", "Allgemeine Links", "xml", null);
	  // sendXmlHttpCall("nz_collectLiteratur.php5", "?", callbackGeneralBooks, null, "nzliteratur", 1, "xml", null);

          sendXmlHttpCall("nz_collectLiteraturCategories.php5", "?", callbackCategoryInfo, null, "nzliteratur", 'init', "xml", null);

	  ccontrol=true;
       }
*/

       function callbackNZSummary( tagName, action, resultString, resultType ){
          // Pull-Down-Menue befuellen
	  var object= document.getElementById(tagName);
          var JSONObj = eval('(' + resultString + ')');
          if (JSONObj != null){
	     if (typeof JSONObj.error == "undefined") {
                addNewOptions(object, 'Alle', '0');
	           for(var i=0; i<JSONObj.records.length; i++){
		      var content= JSONObj.records[i].place + " (" + JSONObj.records[i].district_name + " District) Bilder: " + JSONObj.records[i].gallery + " Links: " + JSONObj.records[i].links + " Literatur: " + JSONObj.records[i].literatur + " Backpacker: " + JSONObj.records[i].backpacker;
	              addNewOptions(object, content, JSONObj.records[i].id);
                   }
             } else{
	        // TODO: Fehler-Test ausgeben
	     }
	  } else {
	     // Fehler in der Rueckgabe
	  }

       }

       function callbackGeneralBooks( tagName, action, resultString, resultType ){
          var object = document.getElementById(tagName);
	  object.innerHTML += resultString;
	  
	  // Kategorien werde angefordert zu der weitere Literatur existiert
	  if( ccontrol==true ){
	     ccontrol=false;
	     sendXmlHttpCall("nz_collectLiteraturCategories.php5", "?", callbackCategoryInfo, null, "nzliteratur", null, "xml", null);
	  }
       }

       function callbackCategoryInfo(tagName, action, resultString, resultType){
          //
	  var JSONObj = eval('(' + resultString + ')');
	  if (JSONObj != null){
	     if (typeof JSONObj.error == "undefined") {
	        var txt= "";
	        for(var i=0; i<JSONObj.records.length; i++){
		   txt += "<div class=\"box\"><div class=\"head\"><div class=\"ds\">" + JSONObj.records[i].category + "</div><div><img src=\"bilder/button_down_outset.gif\" border=\"0\" id=\"" + JSONObj.records[i].id  + "boxbild\" onclick=\"einblenden("+ JSONObj.records[i].id + ",'content','boxbild',1);\"></div></div><div id=\"" + JSONObj.records[i].id + "content\" class=\"content\" style=\"display:none;\"></div></div>";
		}
	        var object= document.getElementById(tagName);
		object.innerHTML += txt;

                // Blendet beim initialen Start direkt die Reisefuehrer ein
		if( action == "init"){
		   einblenden(1, 'content', 'boxbild',1 );
		}

	     } else {
	        // Fehler-Ausgabe
	     }
	  } else {
	     // Fehler in Rueckgabe
	  }
       }

	function locationInfo(id){
	   sendXmlHttpCall("nz_collectPlaceInfo.php5", "?id=" + id, callbackLocationInfo, null, "location", null, "xml", null);
	}

	function callbackLocationInfo( tagName, action, resultString, resultType){
	   var JSONObj = eval('(' + resultString + ')');
	   if (JSONObj != null){
	      if (typeof JSONObj.error == "undefined") {
	         var object= document.getElementById(tagName);
		 // TODO: Was passiert wenn zwei Orte gefunden werden
		 object.innerHTML= "<b>" + JSONObj.records[0].place + " (" + JSONObj.records[0].district_name + ")</b>";
		 // Kartenausschnitt mit Koordinaten des Ortes verschieben
		 //
		 var lonLat = new OpenLayers.LonLat(JSONObj.records[0].lon, JSONObj.records[0].lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
		 map.setCenter( lonLat, 10 );
                 // auskommentiert fuer Mercator-Projection
		 // map.setCenter(new OpenLayers.LonLat(JSONObj.records[0].lon, JSONObj.records[0].lat), 4);
	      } else {
	         // Fehler-Ausgabe
	      }
	   } else {
	      // Fehler in Rueckgabe
	   }
	}

       function collectPlaceInfo(response){
	  // Methode mit der alle Informationen eines Standorts zusammengetragen werden
          // Zusaetzlich wird das Pulldown-Menue auf den gefundenen Ort eingestellt

          // Resettet die Feldinhalte 
	  resetContentCollection();
          ccontrol=true;

	  // sendXmlHttpCall(url, parameters, callback, mimetype, tagname, action, resultString, requestHeader);
	  var JSONObj = eval('(' + response.responseText + ')');
	  //console.log("ds anzahl: %s", JSONObj.records.length);
	  if (JSONObj != null){
	   if(JSONObj.records.length>0){
	     for(var i=0; i<JSONObj.records.length; i++){
                // alert( JSONObj.records[0].vorname + " - " + JSONObj.records[i]);
	        // Bilder-Abfrage
                sendXmlHttpCall("nz_collectImages.php5", "?id=" + JSONObj.records[i].id +"&aid=" + JSONObj.records[i].autorenid , callbackCollectImages, null, "nzbilder", JSONObj.records.length, "xml", null);

		// Standort-Info wird gelesen
		if( JSONObj.records[i].id != 0) {
		   locationInfo( JSONObj.records[i].id );
		}

		// Auswahl-Selector wird angepasst
		selectOptionField(JSONObj.records[i].id, "overviewSelector");

	     }
	     // Link-Abfrage (Standort-Spezifische und District-Links
	     sendXmlHttpCall("nz_collectLinks.php5", "?id=" + JSONObj.records[0].id, callbackCollectLinks, null, "nzlinks", "Standort spezifische Links", "xml", null);
	     sendXmlHttpCall("nz_collectDistrictLinks.php5", "?id=" + JSONObj.records[0].id, callbackCollectLinks, null, "nzlinks", "District Links", "xml", null);
	     // Literatur-Abfrage
	     // TODO: weitere Rubriken hinzufuegen
	     sendXmlHttpCall("nz_collectLiteratur.php5", "?id=" + JSONObj.records[0].id, callbackGeneralBooks, null, "nzliteratur", null, "xml", null);

	     // 
	     // Backpacker-Abfrage - Bei leeren Ergebnissen Eingabe-Formular einblenden
	     sendXmlHttpCall("nz_collectBackpacker.php5", "?id=" + JSONObj.records[0].id, callbackCollectBackpacker, null, "nzbackpacker", null, "xml", null);
           }
	  } else {
	  	alert("Fehler bei der Bildzusammenstellung");
	  }
       }

       function resetContentCollection(){
          // TODO ueber Schleife laufen lassen
          document.getElementById("nzbilder").innerHTML="<i>Bilder</i>";
	  document.getElementById("nzlinks").innerHTML="<i>Links</i>";
	  document.getElementById("nzliteratur").innerHTML="<i>Literatur</i>";
	  document.getElementById("nzbackpacker").innerHTML="<i>Backpacker</i>";
       }

	function callbackCollectBackpacker(tagName, action, resultString, resultType){
           var object = document.getElementById(tagName);
           var JSONObj = eval('(' + resultString + ')');
	   if (JSONObj != null){
	      if (typeof JSONObj.error == "undefined") {
	         // var object = document.getElementById(tagName);
		 if( JSONObj.records.length>0 ) {
		   var contentBackpacker= '<ul class="bblist">';
		   for(var i=0; i<JSONObj.records.length; i++){
		      // Coordinate wird ausgewertet
		      var bblocation= "";
		      if( JSONObj.records[i].coordinate != "" ){
		         var coordinate= JSONObj.records[i].coordinate.split(',');
		         bblocation= "<img src='bilder/Grey_house.png' title='Unterkunft auf Karte zeugen' onClick='javascript:showLocation(" + coordinate[0] + "," + coordinate[1] + ");'>";
			 // var bblocation = document.createElement("img");
			 // bblocation.setAttribute("src", "bilder/Grey_house.png");
			 // bblocation.setAttribute("title", "Unterkunft auf Karte zeugen");
			 // bblocation.onclick= function(){ showLocation(coordinate[0], coordinate[1]); };
		      } 
		      contentBackpacker += "<li><b>" + JSONObj.records[i].bbname +  "</b><br/>" + JSONObj.records[i].strasse + "<br/>" + JSONObj.records[i].place + "<br/>Tel.: " + JSONObj.records[i].telefon + "<br/>" + JSONObj.records[i].url + "<br/>" + bblocation + "</li>";
                   }
		   contentBackpacker += "</ul>";
		   // object.innerHTML += contentBackpacker;
		   // contentBackpacker= "";
		 } else {
		    // keine Backpacker für den aktuellen Ort gespeichert
		    var contentBackpacker= backpackerForm();
		 }
		 // object.innerHTML += contentBackpacker;
	      }
	   } else {
	      var contentBackpacker= backpackerForm();
	   }
	   object.innerHTML += contentBackpacker;
	   contentBackpacker= "";
	}

	function backpackerForm(){
	    
	    // keine Backpacker für den aktuellen Ort gespeichert

	    var contentBackpacker= '<br/>F&uuml;r den aktuellen Standort wurden kein Backpacker gefunden! <br/> <br/>Kann eigentlich nicht sein. Backpacker gibt es (fast) &uuml;berall in Neuseeland und sind Ort der Begegnungen, des Erfahrungsaustausches, multinationale Treffpunkte, St&auml;tte neuer Freundschaften und Herbergen die den Reisenden zur &Uuml;bernachtung dienen. Und wie &uuml;berall gibt es gute und weniger gute Einrichtungen. Und ehemals gute k&ouml;nnen zu schlechten und schlechte zu guten werden. Helft mit und empfehlt Eure besten Backpacker. Danke!';
            
	    contentBackpacker += '<form action="/neuseeland.htm" method="POST">Ort: <select id="pdm_standorte" class="pdListings" style="width:140px"></select><br/>Backpacker-Name: <INPUT type="text" name="backpacker" size="15" style="width:110px;font:8px"> <br/>Adresse: <input type="text" name="adresse" size="15" style="width:110px;font:8px"> <br/>Telefon: <input type="text" name="telefon" size="15" style="width:110px;font:8px"> <br/></form>';
	    sendXmlHttpCall("nz_backpackerForm.php5", "?", callbackBackpackerForm, null, "pdm_standorte", null, "xml", null);

	    return( contentBackpacker );
	}

        function callbackBackpackerForm(tagName, action, resultString, resultType){
	   // Pull-Down-Menue wird erstellt
	   var object = document.getElementById(tagName);
	   settlementJSONObj = eval('(' + resultString + ')');
	   if (settlementJSONObj != null){
	      for(var i=0; i<settlementJSONObj.records.length; i++){
	         addNewOptions(object, settlementJSONObj.records[i].place, settlementJSONObj.records[i].id);
	      }
           }
	}

	function callbackCollectImages(tagName, action, resultString, resultType){
           // TODO: onMouseOver fuer Tooltip mit Bildinfo und groesseren Vorschau-Bildern
           var JSONObj = eval('(' + resultString + ')');
	   if (JSONObj != null){
	      if (typeof JSONObj.error == "undefined") {
	         var object = document.getElementById(tagName);
	         var contentImage = "<br/><b>" + JSONObj.records[0].vorname + " " + JSONObj.records[0].name +  "</b><br/>";
		 for(var i=0; i<JSONObj.records.length; i++){
		    var txt= JSONObj.records[i].place + " (" + JSONObj.records[i].bildjahr + ", (c) " + JSONObj.records[i].vorname + ", " + JSONObj.records[i].name +")<br/><i>" + JSONObj.records[i].bildname +"</i>";
		    contentImage += "<img src=" + JSONObj.records[i].bild + " border=\"0\" width=\"35\" onClick=\"javascript:showImages(" + JSONObj.records[i].gid + "," + JSONObj.records[i].autorenid +");\" onMouseOver=\"javascript:createImageTooltip('" + JSONObj.records[i].bild + "', 'tt" + JSONObj.records[i].gid + "', '" + txt +"');\" id=\"img" + JSONObj.records[i].gid  + "\" onMouseOut=\"javascript:hideTooltip('tt"+ JSONObj.records[i].gid +"'," + JSONObj.records.length +")\">";
		 }
	         object.innerHTML += contentImage;
		 contentImage="";
              }
	   }
	}

	function createImageTooltip(image,id, txt){
	   // http://webmatze.de/wirklich-einfache-javascript-tooltips/
	   imageTooltip = document.createElement('div');
	   imageTooltip.id = id;
	   imageTooltip.source= "image";
	   imageTooltip.setAttribute('class', 'tooltip');
	   // console.log("id: %s", imageTooltip.id);
	   imageTooltip.innerHTML = txt + '<br/>';
	   var img = document.createElement("img");
	   img.setAttribute("src", image);
	   img.setAttribute("width", 400);
	   img.setAttribute("height", 300);
	   imageTooltip.appendChild(img);
	   imageTooltip.style.display = "block";
	   imageTooltip.style.zIndex= 1001;
	   document.body.appendChild(imageTooltip);
	}

	function createLinkTooltip(id, url, txt){
	   imageTooltip = document.createElement('div');
	   imageTooltip.id = id;
	   imageTooltip.source= "link";
	   imageTooltip.setAttribute('class', 'tooltip');
	   imageTooltip.innerHTML = "<i>" + url + "</i><br/>" + txt;
	   imageTooltip.setAttribute("width", 200);
	   imageTooltip.style.display = "block";
	   imageTooltip.style.zIndex= 1001;
	   document.body.appendChild(imageTooltip);
	}

/*
	function getMouseCoordinates(e) {
	  if (imageTooltip != null) {
	      x = (document.all) ? window.event.x + imageTooltip.offsetParent.scrollLeft : e.pageX;
	      y = (document.all) ? window.event.y + imageTooltip.offsetParent.scrollTop  : e.pageY;
	      if( imageTooltip.source== "image"){
	        imageTooltip.style.left = (x + 40) + "px";
                imageTooltip.style.top   = (y - 220) + "px";
              } else {
	        imageTooltip.style.left = (x + 20) + "px";
		imageTooltip.style.top   = (y - 20) + "px";
	      }
          }
        }
*/
        
	function getMouseCoordinates(e) {
	  if (imageTooltip != null) {
	       if( document.all ){
	          // x= window.event.x + imageTooltip.offsetParent.scrollLeft;
		  x= window.event.x;
		} else {
		  x= e.pageX;
		}

		if( document.all ){
		   // y= window.event.y + imageTooltip.offsetParent.scrollLeft;
		   y= window.event.y;
                } else {
                   y= e.pageY;
                }
		if( imageTooltip.source== "image"){
	           imageTooltip.style.left = (x + 40) + "px";
	           imageTooltip.style.top   = (y - 220) + "px";
		} else {
		   imageTooltip.style.left = (x + 20) + "px";
		   imageTooltip.style.top   = (y - 20) + "px";
		}
	      }
	}


        function showLocation(lat, lon){
	   var icon = new OpenLayers.Icon('http://geoworld.de/bilder/Grey_house.png',null,null);
	   var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
	   markers.addMarker(new OpenLayers.Marker( lonLat, icon ));
	   map.setCenter( lonLat, 15);

	}


	function hideTooltip(tagID, cnt){
	   imageTooltip = document.getElementById(tagID);
	   // console.log("hide id: %s", imageTooltip.id )
	   document.getElementsByTagName("body")[0].removeChild(imageTooltip);
	}

	function checkElements(obj){
	   for (i=0; i<obj.childNodes.length; i++){
	      // console.log(" %s. %s", i, obj.childNodes[i].nodeName);
	   }
	}

        function addNewOptions(Pdm, otext, ovalue){
	   var newOption = document.createElement("option");
	   newOption.value = ovalue;
	   newOption.text = otext;
	   Pdm.options.add(newOption);
        }

	function changeLocation(id){
	   var response={};
	   response.responseText= '{"records": [{"id":' + id +',"autorenid":0,"vorname":"NaN","nachname":"NaN","anzahl": 1}]}';
	   collectPlaceInfo(response);
	}

	function callbackCollectLinks(tagName, action, resultString, resultType){
	   var JSONObj = eval('(' + resultString + ')');
	   if (JSONObj != null){
	      if (typeof JSONObj.error == "undefined") {
	         var object = document.getElementById(tagName);
		 var contentLink = "<br/><b>" + action + "</b><br/>";
		 contentLink += "<ol>";
	         for(var i=0; i<JSONObj.records.length; i++){
                    contentLink += "<li><a href=\"" + JSONObj.records[i].url + "\" target=\"_blank\" onMouseOver=\"javascript:createLinkTooltip('ltt" + JSONObj.records[i].id + "','" + JSONObj.records[i].url + "','" + JSONObj.records[i].bemerkung + "')\" onMouseOut=\"javascript:hideTooltip('ltt" + JSONObj.records[i].id +"', null)\">" + JSONObj.records[i].thema + "</a></li>";
	         }
		 contentLink += "</ol>";
	         object.innerHTML += contentLink;
              }
           }
	}

	function einblenden(id, tagName, boxName, pageID) {
	  // Methode zum Einblenden der Literatur bei erweiterten Kategorien
	  // Objekt fuer die Uebergabe der Paramter an die AJAX Funktion wird definiert
	  var parameter= { "id": id, "tagName": tagName, "boxName": boxName, "pageID": pageID };
	  // console.log('display: %s - pageID: %d - tagName: %s - boxName: %s', document.getElementById(id + tagName).style.display, pageID, tagName, boxName);
	  with(document.getElementById(id + tagName).style) {
	    if(display=="none"){
	      contentEinblenden(id, tagName, boxName, pageID);
	    } else{
	      contentAusblenden(id, tagName, boxName, pageID);
	    }
	    // Daten zu dieser Kategorie werden angefordert
            sendXmlHttpCall("nz_collectLiteraturPerCategory.php5", "?id=" + id + "&p=" + pageID, callbackEinblenden, null, id + tagName, parameter, "xml", null);
	  }
        }

	function callbackEinblenden(tagName, action, resultString, resultType){
	   var object = document.getElementById(tagName);
	   object.innerHTML= resultString;
	   contentEinblenden(action["id"], action["tagName"], action["boxName"], action["pageID"]);
	}

        function contentAusblenden(id, tagName, boxName, pageID){
	   // console.log("%d - %s", id, tagName);
	   var object= document.getElementById(id + tagName).style.display= "none";
	   var boxObject= document.getElementById(id + boxName);
	   boxObject.onclick= function(){ contentEinblenden(id,tagName,boxName, pageID); };
	   boxObject.src = 'bilder/button_down_outset.gif';
	}

	function contentEinblenden(id, tagName, boxName, pageID){
	   var object= document.getElementById(id + tagName).style.display= "inline";
	   var boxObject= document.getElementById(id + boxName);
           boxObject.onclick= function(){ contentAusblenden(id, tagName, boxName, pageID); };
	   boxObject.src = 'bilder/button_up_outset.gif';
	}

	function selectOptionField(id, tagName){
	   var object = document.getElementById( tagName );
	   for(var i=0; i<object.length; i++){ 
	      if(id == object.options[i].value){
	         object.options[i].selected = true;
	      }
	   }
	}

