/* gen_scripts.js
 * by patrick schmider v1.0 000101
 * Copyright (c) 2000 Patrick Schmider. All Rights Reserved.
 * License to use is granted if and only if this entire
 * copyright notice is included.
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
*/
//-------------------------------------------------------------------
//-------------------------GRAPHICS-SCRIPTS--------------------------
//-------------------------------------------------------------------

var swp_imgs = new Array();
var finished_loading = false;


function load_graphics()
{	
  //global variables: 'swp_imgs[]' and 'finished_loading'
  finished_loading = false;
  
  //load the images
  nav_bot   = new Image (); nav_bot.src   = "../../images/nav_bot_hover.png";
  nav_top   = new Image (); nav_top.src   = "../../images/nav_top_hover.png";
  nav_prev  = new Image (); nav_prev.src  = "../../images/nav_prev_hover.png";
  nav_next  = new Image (); nav_next.src  = "../../images/nav_next_hover.png";
  menu_up   = new Image (); menu_up.src   = "../../images/nav_top.png";
  menu_down = new Image (); menu_down.src = "../../images/nav_bot.png";
  
  //make images available in global array
  swp_imgs ["nav_bot"]   = nav_bot;
  swp_imgs ["nav_top"]   = nav_top;
  swp_imgs ["nav_prev"]  = nav_prev;
  swp_imgs ["nav_next"]  = nav_next;
  swp_imgs ["menu_up"]   = menu_up;
  swp_imgs ["menu_down"] = menu_down;
  
  //signal: ready
  finished_loading = true;
}


//---------------------------------------------------------
function swp_img (img_name)
{
  /*
  1) the image should have set 'name' tag to 'img_name': 
       <img name="img_name" src=...>
  2) if an image appears multiply, the name should be numbered: 
       <img name="img_name1" src=...>
     this function can test if 'img_name1' exists, if not it tests for 'img_name'
     -> therefore only 10 identical images  (with the same file-source !)
        ('<img name="img_name0" src=...> to '<img name="img_name9" src=...>') 
        can be handled automatically for achievin rollover effects!
  - The Function has to test if 
    a) document[img_name] exists -> if not: error -> do nothing
    b) swp_imgs[img_name] exists -> if not: clip last character, assuming it is a number
  - When finally/actually swapping images the old document[img] is stored swp_imgs[img]
    thus the funcion wil (should) work for both MouseOver AND MouseOut events !!!
    example of use:
       <a href="blah.htm" target="blub"
          onMouseOver="swp_img('img1')"
          onMouseOut="swp_img('img1')">
          <img name="img1" src="an_image.png" border=0>
       </a>
  */
  
  var test = new Image(); //for testing only
  var temp = new Image(); //for swapping only
  var img_name_swp = img_name; 
  //img_name is used to access 'document[]': document[img_name] 
  //img_name_swp is used to access 'swp_imgs[]': swp_imgs[img_name_swp]
  
  //test if provided img_name exists in the document
  if (document.images && document[img_name] && finished_loading) {
  	
    //test if image exists in the swp_imgs[] array
    test = swp_imgs[img_name_swp];
    if (!test) {
      //img_name doesn't exist -> assumption last character of image name is a number
      img_name_swp = img_name_swp.substring(0,(img_name_swp.length-1)); //clip last character
      test = swp_imgs[img_name_swp];
      //alert(img_name_swp + "; " + test);
    }
    
    //still not absol. sure that previous operation was successful
    if (test) { 
      //exchange images -> will work for OnMouseOver AND OnMouseOut events !
      temp.src = document[img_name].src;
      document[img_name].src = swp_imgs[img_name_swp].src;
      swp_imgs[img_name_swp].src = temp.src;
    }
    
  }
  
}



//---------------------------------------------------------
//---------------------------------------------------------
//---------------------------------------------------------
function getLanguage ()
{
  var language = "";
  if ( (getBrowser() == "IE3") || 
       (getBrowser() == "IE4") ||
       (getBrowser() == "IE5") ) {
    if(navigator.userLanguage.indexOf("de")>-1) {
      //alert("Sehr geehrter Besucher, willkommen auf unseren Seiten");
      language = "de";}
    if(navigator.userLanguage.indexOf("en")>-1) {
      //alert("dear vistor, welcome on our pages");
      language = "en";}
    if(navigator.userLanguage.indexOf("fr")>-1) {
      //alert("cher amis, welcome sur notre website");
      language = "fr";}
  } else {
    if(navigator.language.indexOf("en")>-1) {
      //alert("dear vistor, welcome on our pages");
      language = "en";}
    if(navigator.language.indexOf("de")>-1) {
      //alert("Sehr geehrter Besucher, willkommen auf unseren Seiten");
      language = "de";}
    if(navigator.language.indexOf("fr")>-1) {
      //alert("cher amis, welcome sur notre website");
      language = "fr";}
  }
  return language;
}


//-------------------------------------------------------------------
//------------------------SITE-ENTRY-SCRIPTS-------------------------
//-------------------------------------------------------------------

function enter(the_lang)
{
  var theBrowser = getBrowser();
  	//possible values are IE3, IE4, IE5, OP5, OP6, NS3, NS4, NS6
  var theLanguage = getLanguage();
  	//possible values are 'de', 'en' and 'fr'
  
  //Test the given parameter, if it is valid 
  //it gets a higher priority than the javascript language
  if (the_lang) { //the_lang != null
    if ( (the_lang == "de") ||
         (the_lang == "en") ||
         (the_lang == "fr") ) {
      theLanguage = the_lang;
    }
  }
  
  var ns3_msg_en = "You're using an old version of Netscape Navigator !\n";
    ns3_msg_en += "Unfortunately this browser is not fully supported by our website.\n\n";
    ns3_msg_en += "You can still view and access all our information,\n"; 
    ns3_msg_en += "but You'll probably experience some strange effects in the layout.\n\n";
    ns3_msg_en += "We are working on this issue, but we strongly recommend \n";
    ns3_msg_en += "updating Your browser to a newer version.\n\n";
    ns3_msg_en += "Sorry for this inconvience and thank You for Your visit.";  
  var ns3_msg_de = "Sie benutzen eine alte Version des Netscape Navigators !\n";
    ns3_msg_de += "Leider wird dieser Browser von unserer Webseite nicht vollständig unterstützt.\n\n";
    ns3_msg_de += "Sie können dennoch auf alle unsere Inhalte zugreifen, werden aber\n";
    ns3_msg_de += "unter Umständen einige kleinere Darstellungsprobleme bemerken.\n\n";
    ns3_msg_de += "Wir arbeiten an einer Abhilfe dieser Probleme, würden Ihnen aber generell\n";
    ns3_msg_de += "zum Update ihres Browsers auf eine neuere Versionsnummer raten.\n\n";
    ns3_msg_de += "Wir bitten diese Unannehmlichkeit zu Entschuldigen und danken für Ihren Besuch.";
    
  		
  //IE and OP are ok
  if ( (theBrowser == "IE5") || 
       (theBrowser == "OP6") ) {
    if (theLanguage == "de") {
      window.location.href ="iej/de/index.htm";
    } else if (theLanguage == "en") {
      window.location.href ="iej/en/index.htm";
    } else if (theLanguage == "fr") {
      window.location.href ="iej/en/index.htm";
    } else {
      window.location.href ="iej/en/index.htm";
    }
  } else if ( (theBrowser == "NS6") ||
  	      (theBrowser == "IE3") ||
              (theBrowser == "IE4") || 
              (theBrowser == "NS4") ||
              (theBrowser == "OP5") ) {
    if (theLanguage == "de") {
      window.location.href ="ien/de/home.htm";
    } else if (theLanguage == "en") {
      window.location.href ="ien/en/home.htm";
    } else if (theLanguage == "fr") {
      window.location.href ="ien/en/home.htm";
    } else {
      window.location.href ="ien/en/home.htm";
    }
  } else { //NS3 -> very old
    if (theLanguage == "de") {
      alert(ns3_msg_de);
      window.location.href ="ien/de/home.htm";
    } else if (theLanguage == "en") {
      alert(ns3_msg_en);
      window.location.href ="ien/en/home.htm";
    } else if (theLanguage == "fr") {
      alert(ns3_msg_en);
      window.location.href ="ien/en/home.htm";
    } else {
      alert(ns3_msg_en);
      window.location.href ="ien/en/home.htm";
    }
  }
  
}


//---------------------------------------------------------
function getBrowser() {

  var theBrowser = "";
  var OP = 0;
  var DHTML = 0; //nearly all browsers (ns4,ie4,op5)
  var DOM = 0;	 //only modern browsers (ie5,ns6,op6) 
 
  if(document.getElementById) {
    DHTML = 1;
    DOM = 1;
  }
 
  if (window.opera) {
    OP = 1;
    if (DOM && DHTML) {
      theBrowser = "OP6";
    } else {
      theBrowser = "OP5";
    }
  }

  if(document.all && !OP) {
    DHTML = 1;
    if (DOM) {
      theBrowser = "IE5"; //MSIE 5 or higher !
    } else {
      //navigator.appVersion returns e.g. :
      // - MS Internet Explorer 4.0  -> "4.0 (compatible; MSIE 4.0; Windows 95)"
      // - MS Internet Explorer 4.01 -> "4.0 (compatible; MSIE 4.01; Windows 98)"
      // - MS Internet Explorer 5.01 -> "4.0 (compatible; MSIE 5.01; Windows 98)" (Win98 SE)
      if(navigator.appVersion.substring(0,1) == "3") {
        theBrowser = "IE3";
      } else if (navigator.appVersion.indexOf("MSIE 4") != -1) {
      	theBrowser = "IE4";
      } else { //don't know which version but must be very old
      	theBrowser = "IE3";
      }
    }
  }
 
  if(document.layers && !OP) {
    DHTML = 1;
    if (DOM) {
      theBrowser = "NS6";
    } else {
      theBrowser = "NS4";
    }
  }

  //my linux mozilla doesn't seem to support 
  //the 'document.layers'-option thus ...
  if (navigator.appName.toLowerCase() == "netscape") {
    if (DHTML && DOM) {
      theBrowser = "NS6";
    } else {
      if(navigator.appVersion.substring(0,1) == "3") {
        theBrowser = "NS3";
      } else {
      	theBrowser = "NS4";
      }
    }
  }

  return theBrowser;
  
}




//---------------------------------------------------------------
//---------------------------------------------------------------
//-----OLD image-swapping procedures not used anymore (hopefully)
//---------------------------------------------------------------
function switch_hover (src_id, image)
{
  //image:
  //0+4 = 4 = previous	1+4 = 5 = next
  //2+4 = 6 = top	3+4 = 7 = bottom
  image = image + 4; // due to nav_array structure
  var newImage = new Image();
  newImage.src = nav_array[image].src;
  document.getElementById(src_id).src = newImage.src;
  /* EXAMPLE:
  onMouseOver="switch_hover('nav_prev1', 0)"
  */
}

//---------------------------------------------------------
function switch_out (src_id, image)
{
  //image:
  //0 = previous	1 = next
  //2 = top		3 = bottom  
  var newImage = new Image();
  newImage.src = nav_array[image].src;
  document.getElementById(src_id).src = newImage.src;
  /* EXAMPLE:
  onMouseOut="switch_out('nav_prev1', 0)">
  */ 
}

//---------------------------------------------------------
function swap_img (src_id, newImageUrl)
{
  // src_id 	 = id of the img to swap (string)
  // newImageUrl = url of the new image (string)
  var newImage = new Image();
  newImage.src = newImageUrl;
  alert("this is an old function !");
  if (document.getElementById) {
    document.getElementById(src_id).src = newImage.src;
  }
  
  /* EXAMPLE:
  onMouseOver="swap_img('nav_prev1', '../../images/nav_prev_hover.png')"
  onMouseOut="swap_img('nav_prev1', '../../images/nav_prev.png')"
  ...
  <img id="nav_prev1" src="../../images/old_image.png">
  */
}

//---------------------------------------------------------
function openWindow (new_window_url, window_name, x_left, y_top, w_width, w_height)
{
  /*
  required parameters:
  - new_window_url = page to open in new window 
  optional parameters:
  - window_name = internal name for popup
  - x_left/y_top: where to move popup to - position of upper-left corner 
  - w_width/w_height: window size
  */
  
  (window_name) ? null : window_name = "test";
  (x_left) ? null : x_left = 0;
  (y_top) ? null : y_top = 0;
  (w_width) ? null : w_width = 700;
  (w_height) ? null : w_height = 480;
  
  var window_params = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,";
  window_params += "width="+w_width+",height="+w_height;
  
  var temp_window = window.open(new_window_url, window_name, window_params);
  temp_window.moveTo(0,0);
  temp_window.focus();
}

