/* $Id: js_functions.js,v 1.1 2004/06/01 11:48:03 www-data Exp $ */

var strPlugIn = "none"
var numPlugins = 0;

/*
 * Fenster zur Anzeige oeffnen
 * @param   string   url     Adresse der Seite die geoeffnet werden soll
 */
 
function openWindow(url, width, height){
  if(!width) width = 400;
  if(!height) height = 320;
  var newWindow = window.open(url, "", "scrollbars=yes,status=no,resizable,dependent,width="+width+",height="+height+",left=150,top=150")
  newWindow.focus();
}

/*
 * Fenster zur Bild-Anzeige oeffnen
 * @param   string   url     Bildurl die geoeffnet werden soll
 */
 
function showImage(url, width, height){
  if(!width) width = 400;
  if(!height) height = 320;
  var imgWindow = window.open("img.php?img=" + url, "", "scrollbars=no,status=no,resizable=no,dependent,width="+width+",height="+height+",left=150,top=150");
  imgWindow.focus();
}


/**
 * Displays an confirmation box before to execute a link.
 * This function is called while clicking links
 *
 * @param   string   confirmMsg     The message to display
 *
 * @return  boolean  whether to execute the link or not
 */

function confirmLink(confirmMsg){
  if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
      return true;
  }
  var is_confirmed = confirm(confirmMsg);
  return is_confirmed;
}

function showTip(nr) {
  document.getElementById('tips').innerHTML = tips[nr];
}

function agentSum(){
  var str = navigator.userAgent;
  var sum = 0;
  
  for(i=0; i < str.length; i++){
    sum += str.charCodeAt(i);
  }
  return sum;
}

function setPlugin(pluginString, pc){ 
  document.images['plpic'].src = "setPlugIn.php?pic="+pc+"&pi=" + screen.width + agentSum() + pluginString;
}

/*
 * Zeichen zählen
 * @param   string   text     Text in dem die Wörter gezählt werden sollen
 * @param   string   text     Text in dem die Wörter gezählt werden sollen
 */
 
function remainingChars(text, maxChars, outputTag, outputText){
  var remaining = maxChars - text.length;
  if(remaining < 0) remaining = 0;
  
  var output = outputText.replace(/%s/, remaining);
  
  document.getElementById(outputTag).innerHTML = output;
}

/*
 * Wörter zählen
 * @param   string   text     Text in dem die Wörter gezählt werden sollen
 * @param   string   text     Text in dem die Wörter gezählt werden sollen
 */
 
function countWords(text, outputField, outputText){
  text = text.replace(/^\s+/,'');
  text = text.replace(/\s+$/,'');
  text = text.replace(/\n+/g,' ');
  text = text.replace(/\s+/g,' ');
  var words = text.split(" ");
  
  var wordCount = (words.length);
  if(wordCount == 1 && words[0] == '') wordCount = 0;

  document.getElementById(outputField).innerHTML = "(" + wordCount + " " + outputText + ")";
}