/**** Scripts für www.wag-berlin.de ****/


function showImage(strUrl, width, height) {
  width +=20; height +=20;
  var availWidth  = screen.availWidth - 10;
  var availHeight = screen.availHeight - 32;
  var width  = Math.min(width, availWidth);
  var height = Math.min(height, availHeight);
  var left   = (availWidth - width) / 2;
  var top    = (availHeight - height) / 2;

  var strBig = (width == availWidth || height == availHeight) ? "yes" : "no";

  var strWndParams = "left=" + left + ",top=" + top + ",width=" + width + ",height=" + height +
                     ",resizable=" + strBig + ",scrollbars=" + strBig +
                     ",menubar=no,status=no,toolbar=no,directories=no";

  if (isOpera()) strUrl = strUrl.replace(/\//g, "%2F");

  checkCloseImage(); // neue Größe erzwingen
  wndImage = self.open(strUrl, "_Image_Viewer_", strWndParams);
  if (wndImage != null) wndImage.focus();
}


function showPano(strParams) {
  if (navigator.javaEnabled()) {
    var availWidth  = screen.availWidth - 10;
    var availHeight = screen.availHeight - 32;
    var width  = Math.min(720, availWidth);
    var height = Math.min(560, availHeight);
    var left   = (availWidth - width) / 2;
    var top    = (availHeight - height) / 2;

    var strBig = (width == availWidth || height == availHeight) ? "yes" : "no";
    var strResizable = isMSIE() ? "yes" : "no";
    var strWndParams = "left=" + left + ",top=" + top + ",width=" + width + ",height=" + height +
                       ",resizable=" + strResizable +
                       ",scrollbars=no,menubar=no,status=no,toolbar=no,directories=no,dependent=no";

    if (isOpera()) strParams = strParams.replace(/\//g, "%2F");

    wndImage = self.open("../PanoramaViewer.htm?" + strParams, "_Image_Viewer_", strWndParams);
    if (wndImage != null) wndImage.focus();
  }
  else {
    alert("Bitte aktivieren Sie in Ihrem Browser die Ausführung von Java-Applets!");
  }
}


function showVideo(strTarget) {
  var strWndParams = "scrollbars=no,menubar=no,status=no,toolbar=no,directories=no,dependent=no";

  if (isOpera()) strTarget = strTarget.replace(/\//g, "%2F");

  wndImage = self.open(strTarget, "_Image_Viewer_", strWndParams);
  if (wndImage != null) wndImage.focus();
}


function checkCloseImage() {
  if (!this.wndImage);
  else if (!(this.wndImage.closed))
    this.wndImage.close();
}


function onLoadIndex() {
  var strPage, wndTopic, posSlash;

  if (top != self || top.location.hostname != self.location.hostname)
    top.location.replace(self.location.href);

  top.status=document.title;

  if (!(wndTopic = top.frames["Topic"])) return;

  if ((strPage = unescape(self.location.search)) != "") {
    if (strPage.lastIndexOf("_") != -1) {
      posSlash = strPage.indexOf("/");
      strPage = strPage.substr(1, posSlash) + strPage.substr(1, posSlash - 1) + ".htm?" + strPage.substr(posSlash + 1);
    }

    wndTopic.location.href = strPage;
  }
  else if (isOldBrowser())
    alert("Achtung!\nSie verwenden einen älteren Webbrowser, der möglicherweise nicht alle Style-Eigenschaften korrekt darstellen kann!");
}


function onLoadHome() {
  var i, img, str, pos;

  if (typeof(self.imgLoaded) == "undefined") self.imgLoaded = 0;

  if (self.imgLoaded >= document.images.length) return;
  str = "img" + self.imgLoaded;

  img = document.images[str];

  if (typeof(img) != "undefined") {
    str = img.src;

    if ((pos = str.lastIndexOf("_bw")) >= 0) {
      str = str.substr(0, pos) + ".jpg";
      img.src = str;
    }
  }

  self.imgLoaded++;
  setTimeout("onLoadHome()", 2000);
}


function onLoadTopic() {
  var strPage, wndContent;

  strPage = unescape(self.location.search);
  if (strPage == "") return;
  strPage = strPage.substr(1);

  if (wndContent = self.frames["Content"]) {
    wndContent.location.replace(strPage);
  }
}


function updateContent()  {
  var strPage = self.location.href;
  
  if (parent.name != "Topic" || window.name != "Content") {
    var posPage = strPage.lastIndexOf("/");
    if (posPage == -1) return;
    posPage = strPage.lastIndexOf("/", posPage - 1);
    if (posPage == -1) return;
    strPage = strPage.substring(posPage + 1);
    top.location.replace("../index.htm?" + strPage);
  }

  else if (getFolder(this) != getFolder(parent)) {
    var posPage = strPage.lastIndexOf("_");
    strPage = strPage.substring(0, posPage) + ".htm";
    parent.location.replace(strPage);
  }

  var wndNav, Links, Link, length, i, bActive, strLink;
  strPage = self.location.href;
  var strTopic = getFolder(this);
  var strContent = strPage.substring(strPage.lastIndexOf("_") + 1, strPage.lastIndexOf("."));

  // Akt. Topic hervorheben:
  if (wndNav = top.frames["Nav"]) {
    if (Links = wndNav.document.links) {
      for (i = 0; i < Links.length; i++) {
        Link = Links[i];
        strLink = Link.href;
        strLink = strLink.substring(strLink.lastIndexOf("/") + 1, strLink.lastIndexOf("."));
        bActive = (strTopic == strLink);
        Link.className = bActive ? "active" : "";
      }
    }
  }

  // Akt. Content hervorheben:
  if (wndNav = parent.frames["Top"]) {
    if (Links = wndNav.document.links) {
      for (i = 0; i < Links.length; i++) {
        Link = Links[i];
        strLink = Link.href;
        strLink = strLink.substring(strLink.lastIndexOf("_") + 1, strLink.lastIndexOf("."));
        bActive = (strContent == strLink);
        Link.className = bActive ? "active" : "";
      }
    }
  }
}


function popup(strDoc, width, height, bScrollbars) {
  if (!width) width = 600;
  if (!height) height = 500;
  var scrollbars = bScrollbars ? "yes" : "no";

  var strWndParams = "width=" + width + ",height=" + height +
                     ",resizable=yes,scrollbars=" + scrollbars + ",menubar=no,status=no,toolbar=no,directories=no";
  var wnd = self.open(strDoc, "_Post_", strWndParams);
  if (wnd != null) wnd.focus();
}


function onPosted() {
  opener.location.reload();
  opener.focus();
  window.close();
}


function onNewsPosted() {
  opener.location.reload();
}


function checkMessage(Form) {  // f. Schw. Bretter/Gästebuch
  if (typeof(Form.name) == "undefined");
  else if (Form.name.value == "") {
    alert("Bitte tragen Sie Ihren Namen ein!");
    Form.name.focus();
    return false;
  }

  if (typeof(Form.msg) == "undefined");
  else if (Form.msg.value == "") {
    alert("Bitte geben Sie den Nachrichtentext ein!");
    Form.msg.focus();
    return false;
  }

  if (typeof(Form.email) == "undefined");
  else if (Form.email.value == "");
  else if (!checkMailAddress(Form.email.value)) {
    alert("Bitte prüfen Sie die E-Mail-Adresse!");
    Form.email.focus();
    return false;
  }

  return true;
}


function checkNews(Form) {  // f. Neues
  if (typeof(Form.headline) == "undefined");
  else if (Form.name.value == "") {
    alert("Bitte tragen Sie die &uuml;berschrift ein!");
    Form.headline.focus();
    return false;
  }

  if (typeof(Form.msg) == "undefined");
  else if (Form.msg.value == "") {
    alert("Bitte geben Sie den Nachrichtentext ein!");
    Form.msg.focus();
    return false;
  }

  return true;
}


function checkMail(Form) {  // Kontakt
  if (typeof(Form.name) == "undefined");
  else if (Form.name.value == "") {
    alert("Bitte tragen Sie Ihren Namen ein!");
    Form.name.focus();
    return false;
  }

  if (typeof(Form.email) == "undefined");
  else if (!checkMailAddress(Form.email.value)) {
    alert("Bitte tragen Sie Ihre E-Mail-Adresse ein!");
    Form.email.focus();
    return false;
  }

  return true;
}


function checkWFG(Form) {  // WFG
  if (Form.event.value == "") {
    alert("Bitte tragen Sie den Namen des Ereignisses ein!");
    Form.event.focus();
    return false;
  }

  if (Form.contact.value == "") {
    alert("Bitte tragen Sie Ihren Namen ein!");
    Form.contact.focus();
    return false;
  }

  if (Form.email.value == "");
  else if (!checkMailAddress(Form.email.value)) {
    alert("Bitte prüfen Sie die E-Mail-Adresse!");
    Form.email.focus();
    return false;
  }

  return true;
}


function checkMailAddress(strAddress)
{
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

  return filter.test(strAddress) ? true : false;
}


function isMSIE () {
   return (navigator.appName == "Microsoft Internet Explorer") ? true : false;
}


function isNetscape () {
   return (navigator.appName == "Netscape") ? true : false;
}


function isOpera () {  // Opera fälscht aber gerne!
   return (navigator.appName == "Opera") ? true : false;
}


function isOldBrowser() {
  if (isMSIE() || isOpera()) // Opera's Default: simuliert MSIE
    return (navigator.appVersion.substring(0,1) < "4");
  else if (isNetscape())     // kann auch Firefox sein
    return (navigator.appVersion.substring(0,1) < "5");
  else                       // unbekannt
    return false;
}


function getFolder(wnd) {
  var strPage = wnd.location.href;

  var posPage2 = strPage.lastIndexOf("/");
  if (posPage2 == -1) return "";
  var posPage1 = strPage.lastIndexOf("/", posPage2 - 1);
  if (posPage1 == -1) return "";

  return strPage.substring(posPage1 + 1, posPage2);
}


function getParam(strParams, strName) {
   strVal = null;

   if (((posName = strParams.indexOf("?" + strName + "=")) >= 0) ||
   ((posName = strParams.indexOf("&" + strName + "=")) >= 0)) {
      strVal = strParams.substr(posName + strName.length + 2);

      if ((posEnd = strVal.indexOf("&")) >= 0)
         strVal = strVal.substr(0, posEnd);
   }

   return strVal;
}


function writeParam(strParams, strName) {
  strVal = getParam(strParams, strName);

  if (strVal != null)
    document.writeln('<param name=' + strName + ' value="' + strVal + '">');
}




function mvShowMember(element, strBoxNo) {
   var strDisp, coords, bkcolor;
   var disp, img;
   
   disp = document.getElementById("disp");
   select = document.getElementById("select");
   img = document.getElementById("img");

   if (strBoxNo.charAt(0) == "#") {
      if (strDisp = mvGetDispText(strBoxNo, "members1"))
         bkcolor = "#000";
      else if (strDisp = mvGetDispText(strBoxNo, "members2"))
         bkcolor = "#000";
      else { 
         strDisp = strBoxNo.substr(1) + ":<br>frei";
         bkcolor = "#f00";
      }
   }
   else {   // kein Liegeplatz
      bkcolor = "#028";
      strDisp = strBoxNo;
   }

   disp.innerHTML = strDisp;
   coords = element.getAttribute("coords").split(",");

   with (disp.style) {
      left = (Number(img.offsetLeft) + Number(coords[2]) + 2).toString() + "px";
      top = (Number(img.offsetTop) + Number(coords[1])).toString() + "px";
      display = "block";
      padding = "2";
      backgroundColor = bkcolor;
   }
}


function mvGetDispText(strBoxNo, tableId) {
   var node1, node2, data1, data2, strDisp, iTd;
   var members;

   members = document.getElementById(tableId); if (!members) return false;
   strDisp = false;

   // MSIE und Mozilla liefern unterschiedliche Child Nodes -> Iterieren!
   for (node1 = members.firstChild; node1 != null; node1 = node1.nextSibling) {
      if (node1.nodeName == "TBODY") break;
   }

   for (node1 = node1.firstChild, data1 = data2 = null; node1 != null; node1 = node1.nextSibling) {
      if (node1.nodeName == "TR") {
         iTd= 0;
         
         for (node2 = node1.firstChild; node2 != null; node2 = node2.nextSibling) {
            if (node2.nodeName == "TD") {  // 1. Spalte
               if (node2.firstChild) {
                  data1 = node2.firstChild.data;

                  if (!data1 && node2.firstChild.firstChild)  // <A> 
                     data1 = node2.firstChild.firstChild.data;
               }

               iTd++;
               break;
            }
         }
   
         for (node2 = node2.nextSibling, data2 = null; node2 != null; node2 = node2.nextSibling) {
            if (node2.nodeName == "TD") {        // 3. Spalte
               if (node2.firstChild && iTd == 2) {
                  data2 = node2.firstChild.data;  
                  break;
               }
               
               iTd++;
            }
         }

         if (!data2);
         else if (data2 == strBoxNo.substr(1, 4)) {
            strDisp = strBoxNo.substr(1) + ":<br>" + data1;
            break;
         }
      }
   }
   
   return strDisp;
}


function mvHideMember() {
   var disp = document.getElementById("disp");
   if (!disp) return;
   disp.style.display = "none";
}



