function showAdressDetail(link,id)//Öffnet einen Popupdialog zum anzeigen der Adressdetails
{
   link.href = "javascript:void(0);";
   
   document.getElementById("PopupDialogContent").innerHTML = "<strong style='text-align:center;'>Bitte warten...</strong>";
   
   AjaxGetAdressDetail(id);
      
   //document.getElementById("PopupDialog").style.left = "50%";
   //document.getElementById("PopupDialog").style.marginLeft ="-325px";
   PopupDialogOpen();
}

function AjaxGetAdressDetail(id)//läd ein Element mit der ID vom Server
{
   //alert(anzahl);
   //AjaxStartWait()
   var req = null;
   try{req = new XMLHttpRequest();}
   catch(ms)
      {try{req = new ActiveXObject("Msxml2.XMLHTTP");}   
      catch (nonms)
         {try{req = new ActiveXObject("Microsoft.XMLHTTP");} 
         catch (failed){req = null;}
      }  
   }
   if (req == null)alert("Fehler beim Laden!");
   
   req.open("GET", '/ajax.php?action=getAdressDetail&id='+id, true);
   req.onreadystatechange = function()
   {            
      switch(req.readyState) 
      {
         case 4:
         if(req.status!=200)
            alert("Fehler:"+req.status); 
         else
         {   
            try{req.responseXML.normalize();}catch(e){}
            var xml = req.responseXML;
            var temp = "<div id='KartePop' style='width:300px;height:300px;float:right;padding-left:20px;'></div>";
            //temp += "<div style='float:right;padding-left:20px;'>"+xml.getElementsByTagName("karte")[0].firstChild.nodeValue
            temp += "</div>"
            temp += "<h3>"+xml.getElementsByTagName("name")[0].firstChild.nodeValue+"</h3>"
            temp += "<p>"+xml.getElementsByTagName("adresse")[0].firstChild.nodeValue+"</p>"  
            if(xml.getElementsByTagName("tel")[0])temp += "<p>"+xml.getElementsByTagName("tel")[0].firstChild.nodeValue+"</p>" 
            if(xml.getElementsByTagName("mobil")[0])temp += "<p>"+xml.getElementsByTagName("mobil")[0].firstChild.nodeValue+"</p>" 
            if(xml.getElementsByTagName("fax")[0])temp += "<p>"+xml.getElementsByTagName("fax")[0].firstChild.nodeValue+"</p>"     
            if(xml.getElementsByTagName("mail")[0])temp += "<p>"+xml.getElementsByTagName("mail")[0].firstChild.nodeValue+"</p>" 
            if(xml.getElementsByTagName("web")[0])temp += "<p>"+xml.getElementsByTagName("web")[0].firstChild.nodeValue+"</p>" 
                                                              //+"<p>"+xml.getElementsByTagName("cat")[0].firstChild.nodeValue+"</p>" 
            temp += "<p>"+xml.getElementsByTagName("export")[0].firstChild.nodeValue+"</p>"
             
            document.getElementById("PopupDialogContent").innerHTML = temp;   

            //KARTE////////////////////////////////////////////////////////////////////////////////////////////////
            $(document).ready(function() 
            {
               ShowKarte('KartePop',
                        xml.getElementsByTagName("name")[0].firstChild.nodeValue,
                        xml.getElementsByTagName("strasse")[0].firstChild.nodeValue,
                        xml.getElementsByTagName("plz")[0].firstChild.nodeValue,
                        xml.getElementsByTagName("ort")[0].firstChild.nodeValue,
                        xml.getElementsByTagName("lat")[0].firstChild.nodeValue,
                        xml.getElementsByTagName("lng")[0].firstChild.nodeValue);
            });
            //KARTE////////////////////////////////////////////////////////////////////////////////////////////////
         }
         break;
         default:
            return false;
         break;     
      }
   };
   req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
   req.send(null);
   try{req.overrideMimeType('text/xml');}catch(e){}
}

function ShowKarte(divID,name,strasse,plz,ort,lat,lng)
{
   var m = $("#"+divID)[0];
   var myOptions = {zoom: 15, mapTypeId: google.maps.MapTypeId.ROADMAP}
   var map = new google.maps.Map(m, myOptions);
               
   if(lat && lng && lat!=0 && lng!=0)
   {
      var myLatlng = new google.maps.LatLng(lat, lng);
      map.setCenter(myLatlng);  
      var marker = new google.maps.Marker(
      {
         position: myLatlng,
         map: map,
         title: name
      });                                  
   }
   else
   {
      var adresse = strasse+", "+plz+" "+ort;
      geocoder = new google.maps.Geocoder();
      geocoder.geocode( { 'address': adresse}, function(results, status) 
      {
         if (status == google.maps.GeocoderStatus.OK) 
         {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker(
            {
               map: map, 
               position: results[0].geometry.location,
               title: name
            });
         } 
         else 
         {
            document.getElementById('KartePop').innerHTML = 'Karte konnte nicht geladen werden!<br />('+adresse+')'; 
         }
      });
   }
}
