/* JavaScript-Funktionen

  * @version       3.00
  * @revision      $Revision: 001 $
  * @lastmodified  $Date: 2008-02-01 11:26:42 +0200 (Sa, 18 Aug 2007) $
  * @author        M. Overkamp
  * @copyright     Copyright 2004 - 2008 GISWORKS
  *
  * @package       Businessportraits metropoleruhr
  * @subpackage    public lokal

*/
  var isNav = (navigator.appName.indexOf("Netscape") >= 0);

  function openNormalHTML() {
    open("http://217.78.131.130/kvr/htmlclient/viewer.htm?startX=<?php echo $geo_rechts;?>&amp;startY=<?php echo $geo_hoch;?>&amp;stadt=<?php echo htmlentities($ort);?>", "AppletWindow", "width=820,height=610,locationbar=no,menubar=no,toolbar=no,resizable=yes,status=yes");
  }

  function openNormalHtmlPoint(geo_rechts, geo_hoch, ort) {
    open("http://217.78.131.130/kvr/htmlclient/viewer.htm?startX=" + geo_rechts + "&amp;startY=" + geo_hoch + "&amp;stadt=" + ort + "", "AppletWindow", "width=820,height=610,locationbar=no,menubar=no,toolbar=no,resizable=yes,status=yes");
  }

  function openHTMLApplet() {
    AppletWindow = open("http://217.78.131.130/kvr/htmlclient/run.htm", "AppletWindow", "width=840,height=590,locationbar=no,menubar=no,toolbar=no,resizable=yes,status=yes");
    AppletWindow.focus();
  }

  function openLukasBox(rechts_min, hoch_min, rechts_max, hoch_max) {
    AppletWindow = open("http://217.78.131.130/lukas/index.jsp?viewextent=" + rechts_min + "," + hoch_min + "," + rechts_max + "," + hoch_max + ""  , "AppletWindow", "locationbar=no,menubar=no,toolbar=no,resizable=yes,status=yes");
    AppletWindow.focus();
  }

  // ToDo
  function openLukasPoint(geo_rechts, geo_hoch) {
    AppletWindow = open("http://217.78.131.130/lukas/index.jsp?X=" + geo_rechts + "&amp;Y=" + geo_hoch + ""  , "AppletWindow", "locationbar=no,menubar=no,toolbar=no,resizable=yes,status=yes");
    AppletWindow.focus();
  }

  function openLukas() {
    AppletWindow = open("http://217.78.131.130/lukas/index.jsp", "AppletWindow", "locationbar=no,menubar=no,toolbar=no,resizable=yes,status=yes");
    AppletWindow.focus();
  }

  function pop(url, weite, hoehe) {
    var hoehepop = hoehe + 40;
    var weitepop = weite + 20;

    var win = window.open(url,"second","resizable=1,scrollbars=1,width="+weitepop+",height="+hoehepop+",screenX=10,screenY=10,left=10,top=10");
    if (win != null)
    if (win.closed);
    win.focus();
  }

  function PopupPic(pfad, sPicURL) {
    window.open( "./pop_up.php?pfad="+pfad+"&name="+sPicURL, "","resizable=1,HEIGHT=200,WIDTH=200");
  }


  function pop1(url, weite, hoehe){
    var win = window.open(url,"second","resizable=0,scrollbars=0,width="+weite+",height="+hoehe+",screenX=10,screenY=10,left=10,top=10");
    if (win != null)
    if (win.closed);
    win.focus();
  }

  function pop2(url){
    var win = window.open(url,"second","resizable=0,scrollbars=0,width=730,height=600,screenX=10,screenY=10,left=10,top=10");
    if (win != null)
    if (win.closed);
    win.focus();
  }

  function real_clean() {
    var text = 'Datei unwiderruflich löschen?\n';
    if (!confirm(text)){
      return false;
    }
    return true;
  }

  function bookmark()	{
  	if (navigator.appName == 'Microsoft Internet Explorer') {
  		window.external.AddFavorite(eval(self.location),document.title);
  	} else {
  		alert('Leider wird diese Funktion nur vom Internet Explorer unterstützt. \n \n \nIn allen anderen Browsern können Sie ein Bookmark auf diese Seite setzen, indem Sie: \n1. einen Rechtsklick auf der Seite machen und \"Lesezeichen hinzufügen\" wählen oder \n2. die Tasten STRG-D drücken.');
  	}
  }
  function div_show () {
    document.getElementById ('control').style.visibility = 'visible';
    document.getElementById ('control').style.width = '100%';
    document.getElementById ('control').style.height = '70px';
    document.getElementById ('control').style.left = '1em';
  }

  // Folgende Funktion nutzt JavaScript, um das DIV auszublenden
  function div_hide () {
    document.getElementById ('control').style.visibility = 'hidden';
    document.getElementById ('control').style.width = '0px';
    document.getElementById ('control').style.height = '0px';
    document.getElementById ('control').style.left = '-10000px';
  }

  function set_DIV_position (x_position, y_position) {
    // Abstand vom linken Seitenrand
    document.getElementById ('control').style.left = x_position;
    // Amstand vom oberen Seitenrand
    document.getElementById ('control').style.top = y_position;
  }

  function set_dimensions (width, height) {
    // Breite des DIV-Elements setzen
    document.getElementById ('control').style.width = width;
    // Höhe des DIV-Elements ändern
    document.getElementById ('control').style.height = height;
  }


  // Werte Select-Schlagwort aktualisieren, wenn select 'branche' onchange
  // Nur wenn kein Flash verfügbar
  function up_schlagwort(schlagwort_id) {
     // Selectliste Schlagwort leeren
     var x = document.form_branche_schlagwort.schlagwort.length;
     for(var n = 0; n < x ; n++) {
        document.form_branche_schlagwort.schlagwort.options[0] = null;
     }

     // Eintrag 'Alle Schlagworte' fuer Branchen in Schlagwortliste einfuegen
     if(document.form_branche_schlagwort.branche.value != 0){
      var NeuerEintrag = new Option(liste_schlag[1][1], liste_schlag[1][0]);
      document.form_branche_schlagwort.schlagwort.options[document.form_branche_schlagwort.schlagwort.length] = NeuerEintrag;
     }

     for (element in liste_schlag) {
        if(liste_schlag[element][2] == document.form_branche_schlagwort.branche.value) {
          if(liste_schlag[element][0] == schlagwort_id) {
            var NeuerEintrag = new Option(liste_schlag[element][1], liste_schlag[element][0], false, true);
          } else {
            var NeuerEintrag = new Option(liste_schlag[element][1], liste_schlag[element][0], false, false);
          }
         document.form_branche_schlagwort.schlagwort.options[document.form_branche_schlagwort.schlagwort.length] = NeuerEintrag;
       }
     }

     var branche_id = document.form_branche_schlagwort.branche.value;
     var branche_text = document.form_branche_schlagwort.branche[document.form_branche_schlagwort.branche.selectedIndex].text;

     var schlag_id = document.form_branche_schlagwort.schlagwort.value;
     var schlag_wort = document.form_branche_schlagwort.schlagwort[document.form_branche_schlagwort.schlagwort.selectedIndex].text;
  }

  //
  function up_schlagwort_suche() {
    var x = document.form_suche.suche_schlagwort.length;
    for(var n = 0; n < x ; n++) {
      document.form_suche.suche_schlagwort.options[0] = null;
    }
    // Eintrag 'Alle Schlagworte' füfr Branchen in Schlagwortliste einfuegen
    if(document.form_suche.suche_branche.value != 0){
      var NeuerEintrag = new Option(liste_schlagwort[0][1], liste_schlagwort[0][0]);
      document.form_suche.suche_schlagwort.options[document.form_suche.suche_schlagwort.length] = NeuerEintrag;
    }

    for(n = 0 ; n < liste_schlagwort.length ; n++) {
      if(liste_schlagwort[n][2] == document.form_suche.suche_branche.value) {
        var NeuerEintrag = new Option(liste_schlagwort[n][1], liste_schlagwort[n][0]);
        document.form_suche.suche_schlagwort.options[document.form_suche.suche_schlagwort.length] = NeuerEintrag;
      }
    }
  }

  // Ermitteln und Anzeigen der noch verbleibenden Anzahl an Zeichen in einem Feld
  function Rest_Zeichen(form, max_laenge, anzeige) {
  	var ErlaubteAnzahl = max_laenge;
    var Laenge;
    var RestlicheZeichen;

  	Laenge = form.value.length;
  	if(Laenge > ErlaubteAnzahl) {
  	  form.value = form.value.substring(0,ErlaubteAnzahl);
  	  RestlicheZeichen = 0;
  	} else {
  		RestlicheZeichen = ErlaubteAnzahl - Laenge;
  	}
  	anzeige.value = RestlicheZeichen;
  }

  // Ermitteln und Anzeigen der Anzahl der bereits angegebenen Zeichen in einem Feld
  function Anzahl_Zeichen(form, anzeige) {
    var Laenge;
    Laenge = form.value.length;
    anzeige.value = Laenge;
  }


  // E-Mail-Adresse auf gewisse Regeln &uuml;berpr&uuml;fen wird von function ok() aufgerufen
  function check_email(str) {
    var at = "@";
		var dot = ".";
		var lat = str.indexOf(at);
		var lstr = str.length;
		var ldot = str.indexOf(dot);
		if (str.indexOf(at) == -1) { return false;}
		if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) { return false;}
		if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) { return false;}
		if (str.indexOf(at, (lat + 1)) != -1) {	return false;}
		if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1,lat + 2) == dot) { return false;}
		if (str.indexOf(dot, (lat + 2)) == -1) { return false;}
		if (str.indexOf(" ") != -1) { return false;}
		if (str.indexOf(",") != -1) { return false;}
		if (str.indexOf("'") != -1) { return false;}
		if (str.indexOf('"') != -1) { return false;}


 		return true;
	}

	// Website-Adresse auf gewisse Regeln &uuml;berpr&uuml;fen wird von function ok() aufgerufen
  function check_website(str) {
    if (str.indexOf("'") != -1) { return false;}
		if (str.indexOf('"') != -1) { return false;}

		return true;
  }

	// Koordinaten darauf prüfen, dass nur Ziffern 0 - 9 eingetragen sind
	function check_koordinate(koordinate) {
    var length = koordinate.length;
    var aChar;
    for(var i = 0; i != length; i++) {
      aChar = koordinate.substring(i, i + 1)
      if(aChar < "0" || aChar > "9") {
        return false;
      }
    }
    return true;
  }

  // Rechtswert auf innerhalb Boundingbox prüfen
  // metropoleruhr Hochwert zwischen 5675000 und 5744000
  function check_rechtswert(koordinate) {
    if(koordinate < 2520000 || koordinate > 2639000) {
      return false;
    }
    return true;
  }

  // Hochwert auf innerhalb Boundingbox prüfen
  // metropoleruhr Hochwert zwischen 5675000 und 5744000
  function check_hochwert(koordinate) {
    if(koordinate < 5675000 || koordinate > 5744000) {
      return false;
    }
    return true;
  }

  // Eingabe darauf prüfen, dass nur Ziffern 0 - 9 eingetragen sind
	function check_zahl(zahl) {
    var length = zahl.length;
    var aChar;
    for(var i = 0; i != length; i++) {
      aChar = zahl.substring(i, i + 1)
      if(aChar < "0" || aChar > "9") {
        return false;
      }
    }
    return true;
  }