  // *************** GOLI.AT ******************
  //
  //  Script (c) by DI Philipp Michael Metzler
  //
  //             http://www.goli.at
  //
  //       http://www.philippmetzler.com
  //
  // *************** GOLI.AT ******************


  myFilepath = 'fileadmin/images/';

  function ChangeOver(object)
  {
    tmp = document.getElementById(object);
    tmp.src = myFilepath + object + '_on.gif';
//    document[object].src = 'images/'+object+'_on.gif';
  }

  function ChangeOut(object)
  {
    tmp = document.getElementById(object);
    tmp.src = myFilepath + object + '_off.gif';
//    document[object].src = 'images/'+object+'_off.gif';
  }

  function ChangeObject(object, picture)
  {
    tmp = document.getElementById(object);
    tmp.src = myFilepath + picture;
//    document[object].src = 'images/'+picture;
  }

  function myRecommend(myArtikel)
  {
/*
    myBody = '';
    myBody = myBody + 'Ich bin gerade auf einen interessanten Artikel im alTiGER Shop gestoßen:' + '\n';
    myBody = myBody + '\'' + myArtikel + '\', ' + unescape(document.URL) + '\n';
    myBody = myBody + 'Ich denke, das könnte auch für Dich interessant sein!' + '\n';
    myBody = myBody + '\n';
    myBody = myBody + 'Sportliche Grüße' + '\n';
*/
    myBody = '';
    myBody = myBody + 'Ich bin gerade auf einen interessanten Artikel im MUSTER Shop gestossen:' + '\n';
    myBody = myBody + '\'' + myArtikel + '\', ' + unescape(document.URL) + '\n';
    myBody = myBody + 'Ich denke, das koennte auch fuer Dich interessant sein!' + '\n';
    myBody = myBody + '\n';
    myBody = myBody + 'Sportliche Gruesse' + '\n';
//    alert(myBody);
//    alert(escape(document.URL));
//    alert(unescape(document.URL));
//    alert(utf8Encode(myBody));
//    alert(utf8Decode(myBody));
//    alert('Artikel: ' + escape(myArtikel));

    myMailString = 'mailto:somebody@internet.com?subject=' + escape('Empfehlung aus dem MUSTER Shop') + '&body=' + escape(myBody);
    location.href = myMailString;
  }

  function chkFormular()
  {
   if(document.shop_form.bestaetigung.checked == "")
   {
     alert("Sie müssen die AGBs akzeptieren!");
     document.shop_form.bestaetigung.focus();
     return false;
    }
  }

  function openWindow(theURL, winName, features)
  { //v2.0
    oldWin = window.open(theURL, winName, features);
    oldWin.focus();
  }

  function openDirection(toAddress)
  {
    openWindow('/fileadmin/scripts/routenplaner.php?toAddress=' + URLEncode(toAddress), 'GoogleDirections', 'width=800, height=600, toolbar=yes, location=no, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes');
//    openWindow('/fileadmin/scripts/routenplaner.php?toAddress=' + toAddress, 'GoogleDirections', 'width=800, height=600, toolbar=yes, location=no, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes');
  }

  function URLDecode (encodedString) {
    var output = encodedString;
    var binVal, thisString;
    var myregexp = /(%[^%]{2})/;
    while ((match = myregexp.exec(output)) != null
               && match.length > 1
               && match[1] != '') {
      binVal = parseInt(match[1].substr(1),16);
      thisString = String.fromCharCode(binVal);
      output = output.replace(match[1], thisString);
    }
    return output;
  }

  function URLEncode (clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
      var match = regex.exec(clearString.substr(x));
      if (match != null && match.length > 1 && match[1] != '') {
        output += match[1];
        x += match[1].length;
      } else {
        if (clearString[x] == ' ')
          output += '+';
        else {
          var charCode = clearString.charCodeAt(x);
          var hexVal = charCode.toString(16);
          output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
        }
        x++;
      }
    }
    return output;
  }


  // Focus auf das erste aktive Formular-Element
  function FocusFirst()
  {
//      alert('hi');

    // Based on http://www.codeproject.com/KB/scripting/FocusFirstInput.aspx
    var bFound = false;
    //for each form
    for (f=0; f < document.forms.length; f++)
    {
      //for each form element
      for (i=0; i < document.forms[f].length; i++)
      {
        el = document.forms[f][i]
        if (el.disabled != true)
        {
          if (el.type != undefined)
          {
            switch (el.type.toLowerCase())
            {
              case "text" : el.focus(); bFound = true; break;
              case "textarea" : el.focus(); bFound = true; break;
              case "checkbox" : el.focus(); bFound = true; break;
              case "radio" : el.focus(); bFound = true; break;
              case "file" : el.focus(); bFound = true; break;
              case "password" : el.focus(); bFound = true; break;
              case "select-one" : el.focus(); bFound = true; break;
              case "select-multiple" : el.focus(); bFound = true; break;
            } // switch el.type
          } //if (el.type != undefined)
        } //if (el.disabled != true)
        if (bFound == true) break;
      } //for each form element
      if (bFound == true) break;
    } //for each form
  }
  

  function showMessage(myMessage)
  {
      document.getElementById("statusMsg").innerHTML = myMessage;
  }

  /*
   Um einen eigenen Zustand für die aktiven Menüpunkte zu machen müsste dieses zweite GMENU verwendet werden: lib.graphicalMenuItemsActive 
  */

  function menuOn(menuID, menuItem, menuGraphicsOn, menuGraphicsOff)
  {
      if (menuItem.className == 'active')
      {
      }
      else
      {
          menuItem.src = menuGraphicsOn;
      }      
  }

  function menuOff(menuID, menuItem, menuGraphicsOn, menuGraphicsOff)
  {
      // Bei onMouseOut das normale Bild nur dann anzeigen, wenn das Menue nicht aktiv d.h. nicht aufgeklappt ist.
      
      if (menuItem.className == 'active')
      {
      }
      else
      {
          menuItem.src = menuGraphicsOff;
      }  
  }
  
  function switchMenuState(menuID, menuItem, menuGraphicsOn, menuGraphicsOff)
  {
      if (menuItem.className == 'active')
      {
          menuItem.className = 'normal';
          menuItem.src = menuGraphicsOff;
      }
      else
      {
          menuItem.className = 'active';
          menuItem.src = menuGraphicsOn;
      }  
  }

  function renderMenus()
  {
      /*
        http://bugs.typo3.org/view.php?id=5053
        http://www.syger.it/Tutorials/JavaScriptIntrospector.html
      */
      
      /*
        LABORATORY:
        ===========
        eval is evil!
        
        Wenn man die graphischen Menuepunkte vornezu laden will muss man ein assoziatives Array aufbauen.
        
        alert(document.images[3].name);
      
        myMenu = document.getElementById('71');
        alert(myMenu.firstChild.nodeValue); // = 'hello world';
        myMenu.firstChild.nodeValue = 'hello world';
      
        myMenu.innerHTML = '<img src="typo3temp/menu/52f43d3f18.gif" border="0">';
            
 
        var x = document.images; 
        for (var i=0;i<x.length;i++)
        { 
//            var theName = x[i].name;
//            alert(theName);
//            theStatus[theName] = 'normal';                  
        } 
//      alert(window['img117_0_n'].src);            
      */      
                 
      var img = document.getElementsByTagName('img');      
  
      for (var i = 0; i < img.length; i++)
      {
          var name = img[i].name;
          var n_name = name + '_n';
          var h_name = name + '_h';
  
          if (n_name.substr(0, 7) == 'menuimg' )       
          {
              var myPosTmp = name.indexOf('_');
              
              var myID = name.substr(7, myPosTmp);
              var myID = myID.substr(0, myID.indexOf('_'));
              
              myMenu = document.getElementById('Menulink_' + myID);
              myMenu.innerHTML = '<img src="' + window[n_name].src + '" border="0" onClick="switchMenuState(' + myID + ', this, \'' + window[h_name].src + '\', \'' + window[n_name].src + '\');"  onMouseOver="menuOn(' + myID + ', this, \'' + window[h_name].src + '\', \'' + window[n_name].src + '\');" onMouseOut="menuOff(' + myID + ', this, \'' + window[h_name].src + '\', \'' + window[n_name].src + '\');">';
                            
              // (document.getElementsByName(name))[0].src = eval(n_name + ".src");              
          }
      }
      
      document.getElementById("progressBar").style.display = 'none';                  
  }  
  