// $Id: DynTable.js,v 0.1 beta 2003/04/06 04:44:44 Tobse Exp $ $Name:  $
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com
// ----------------------------------------------------------------------
// LICENSE
//
// This program is not free software; you can't redistribute it and/or
// modify it.
//
// This program is distributed in the context of the diploma
// "www.ES-hilft.de - Mediation im Internet als Portal für soziale
// Institutionen - ein Prototyp für die Region Esslingen a.N.".
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// This sourcecode is only published because of the rules according to
// the university this diploma is made. Any use of this source or parts
// of it requires the direct and confirmable permission of the author.
// ----------------------------------------------------------------------
// Original author of file: Tobias Jerg (tobse@hotmail.com)
// Purpose of file: Social assistance
// ----------------------------------------------------------------------
// This file makes the dynamic Table which opens on click into the table
// of results.

var isFirst = true;
var textReihe = null;
var textSpalte = null;
var count = 0;

function mkTable(reihe, spalte, editStr) {
   count++;
   textReihe = reihe-1; 
   textSpalte = spalte;
   var div = document.getElementById('myerg');
   if (!isFirst) {      
      removeElements(div);
   } else {
      isFirst = false;
   }
   createElements(div, editStr);
}     

function createElements(div, editStr) {	
   table = document.createElement('table');
   tBody = document.createElement('tbody');
   div.appendChild(table);
   table.appendChild(tBody);
   for (var i=0; i<ausBez.length; i++) {

      //Spalte 1
      text = ausBez[i];
      newRow = document.createElement('tr');
      tBody.appendChild(newRow);
      newCell = document.createElement('td');
      newCell.setAttribute('valign','top'); 
      newB = document.createElement('b');
      textNode = document.createTextNode(text);
      newB.appendChild(textNode);
      newCell.appendChild(newB);
      newRow.appendChild(newCell);
      
      //Spalte 2
      text = getText(i);
      if (i == 11) {text = getText(27);} // Kostenfeld abfangen
      if (i == 12) {text = getText(28);} // Beschreibungsfeld abfangen
      if (i == 13) { // hier wird map24-link generiert
       text = 'http://link2.map24.com/?lid=21ab9d96&maptype=JAVA&width0=1500&street0=';
       text += escape(getText(3));
       text += '&zip0=' + getText(4) + '&city0=' + escape(getText(5));
       text += '&country0=de&description0=' + escape(getText(1));
      }
      newCell = document.createElement('td');
      newCell.setAttribute('valign','top'); 
      if ( (text.indexOf("http://") > -1) || (text.search(/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/) > -1 ) ) {
         newA = document.createElement('a');
         linkLocation = null;
         if (text.indexOf("http://") > -1) {
            linkLocation = text;
            text = text.split("http://")[1];            
         } else if (text.search(/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/) > -1) {
            linkLocation = 'mailto:' + text;
         }
         newA.setAttribute('href', linkLocation);
         if (i == 13) {newA.setAttribute('target', 'map24');}
          else {newA.setAttribute('target', '_blank');}
         if (i == 13) {text = ausBez[i];}  // "In Stadtplan anzeigen" abfangen
         linkText = document.createTextNode(text);
         newA.appendChild(linkText);         
         newA.style.textDecoration = "none";
         newCell.appendChild(newA);
      } else {
      	 newCell = document.createElement('td');
         newCell.setAttribute('valign','top'); 
      	 textNode = document.createTextNode(text);
         newCell.appendChild(textNode);         
      }
      newCell.style.paddingLeft = "10px";
      newCell.valign = "top";
      newRow.appendChild(newCell);
   }

   if (editStr != '0') {
      newRow = document.createElement('tr');
      tBody.appendChild(newRow);
      newCell = document.createElement('td');
      newCell.setAttribute('valign','top'); 
      newRow.appendChild(newCell);
      newA = document.createElement('a');
      newA.setAttribute('href', 'modules.php?op=modload&name=1st-aid&file=update&update=1&editieren=1&datasetid='+getText(0));
      newA.style.textDecoration = "none";
      linkText = document.createTextNode(editStr);
      newA.appendChild(linkText);
      newBR = document.createElement('br');
      newCell.appendChild(newBR);
      newCell.appendChild(newA);
      newRow.appendChild(newCell);
   }

}


function removeElements(div) {
   while (firstChild = div.childNodes[0]) {
      div.removeChild(firstChild);
   }
}

function getText(i) {
   var returnString = "";
   if (textSpalte == 0) {
      returnString = ausHard[textReihe][i];
   } else if (textSpalte == 1) {
      returnString = ausScore[textReihe][i];
   } else if (textSpalte == 2) {
      returnString = ausStich[textReihe][i];
   }
   return returnString;
}
