/* ------------------------------------------------------------------

   Programm: CallMaps.js
             Aufruf der Kartenschnittstelle in einem Popup

   Autor:    Klaus Tucher
             Im Münzen 30
             73230 Kirchheim unter Teck

   Datum:    06.02.2008
   -------------------------------------------------------------------- */


function CallMaps (latitude,longitude,ZoomFaktor,Controls,Adresse,Infotext,Navtext) {
   /* Defaults: Ggf. anpassen---> */

   var DefaultOrt  = '73230 Kirchheim unter Teck';
   var DefaultLand = 'Deutschland';
   var Mandant     = '';
   var Verzeichnis = 'tmpGoogleMaps';

   /* <--- Defaults */

   if (Controls == null) {Controls = '';}
   if (Adresse  == null) {Adresse = '';}
   if (Infotext == null) {Infotext = '';}
   if (Navtext == null)  {Navtext = '';}

   Adresse = Adresse.replace(/str\./i,'strasse ');

   /* Individuelle Ersetzungen - ggf. anpassen --> */
   Adresse = Adresse.replace(/Kirchheim\/Teck/g,'Kirchheim unter Teck');
   Adresse = Adresse.replace(/Kirchheim\-Teck/g,'Kirchheim unter Teck');
   Adresse = Adresse.replace(/  /g,' ');
   /* <--- */

//   Adresse = encode_utf8(Adresse);

   if (Adresse != '' && Adresse.match(/^[0-9]*.[0-9]*, *[0-9]*.[0-9]* *$/) == null) {
      // Defaultort + Land einbauen
      if (Adresse.match(/,/) == null) {
         Adresse = Adresse + ', ' + DefaultOrt + ', ' + DefaultLand;
         }
      var Ausdruck = eval('/, *' + DefaultLand + '/');
      if (Adresse.match(Ausdruck) == null) {
         Adresse = Adresse + ', ' + DefaultLand;
         }
      }
//   Infotext = encode_utf8(Infotext);
   Navtext=encodeURIComponent(Navtext);

   var url = '/webios/cms/cms_ausgabe.pl?Mandant=' + Mandant + '&Verzeichnis=' + Verzeichnis 
           + '&latitude=' + latitude 
           + '&longitude=' + longitude 
           + '&ZoomFaktor=' + ZoomFaktor
           + '&Controls=' + Controls
           + '&Adresse=' + Adresse
           + '&Infotext=' + Infotext
           + '&Navtext=' + Navtext;
   url=encodeURI(url);
   window.open(url, 'MapWin','width=640,height=480,top=50,left=50,resizable=no,scrollbars=no');
   }


function encode_utf8(text) {

   var utftext = "";
   for(var n=0; n<text.length; n++) {
      var c=text.charCodeAt(n);
      if (c<128) {
         utftext += String.fromCharCode(c);
         }
      else {
         if ((c>127) && (c<2048)) {
            utftext += String.fromCharCode((c>>6)|192);
            utftext += String.fromCharCode((c&63)|128);
            }
         else {
            utftext += String.fromCharCode((c>>12)|224);
            utftext += String.fromCharCode(((c>>6)&63)|128);
            utftext += String.fromCharCode((c&63)|128);
            }
         }
       }
   return utftext;
   }
                                 
