  // *************** GOLI.AT ******************
  //
  //  Script (c) by DI Philipp Michael Metzler
  //
  //             http://www.goli.at
  //
  //       http://www.philippmetzler.com
  //
  // *************** GOLI.AT ******************


  function swapOut(myElement)
  {
//      alert(rollImage[myElement.id]['over'].src);
      myElement.src = rollImage[myElement.id]['over'].src;
      return true;
  }

  function swapBack(myElement)
  {
      myElement.src = rollImage[myElement.id]['normal'].src;
      return true;
  }

/*
  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 MUSTER 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 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;
  }

// alert(URLEncode('test&test'));

  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;
  }

    var myFormErrors = new Array();
    var myCountFormErrors = 0;
    var mySpecialCountFormErrors = 0;

    function chkFormular()
    {
        myCountFormErrors = 0 + mySpecialCountFormErrors;

        elementFormSent = document.getElementById("FormSent");
        elementFormSent.style.display = 'none';

        elementFormError = document.getElementById("FormError");

        for ( myKey in myFields )
        {
            myTmp = eval('document.' + myFormName + '.' + myKey + '.value');

            if (myTmp == '')
            {
                myFormErrors[myKey] = 'Bitte f&uuml;lle auch dieses Feld aus: "' + myFields[myKey] + '"';
                myCountFormErrors += 1;
            }
            else
            {
                myFormErrors[myKey] = null;
            }
        }

        if (myCountFormErrors > 0)
        {
//            elementFormErrorText = document.getElementById("FormErrorText");
//            elementFormErrorText.firstChild.nodeValue = myFormError;
//            elementFormErrorText.innerHTML = myFormError;
/*
                document.userData.street.focus();
                scrollBy(0, -20);
*/

            elementFormError.innerHTML = '';

            elementFormError.style.display = '';

            var myDisplayFormErrors = '<table cellpadding="0" cellspacing="0" border="0">';
            for ( myKey in myFormErrors )
            {
                if (myFormErrors[myKey] != null)
                {
                    myDisplayFormErrors += '<tr>' + "\n";
                    myDisplayFormErrors += '  <td valign="top"><img src="/fileadmin/images/missing-fields.png" height="16" width="16"></td>' + "\n";
                    myDisplayFormErrors += '  <td width="5"></td>' + "\n";
                    myDisplayFormErrors += '  <td valign="bottom" height="20">' + "\n";
                    myDisplayFormErrors += '    <span class="FormError">' + myFormErrors[myKey] + '</span>';
                    myDisplayFormErrors += '  </td>' + "\n";
                    myDisplayFormErrors += '</tr>' + "\n";
                }
            }
            myDisplayFormErrors += '</table>' + "\n";

            elementFormError.innerHTML = myDisplayFormErrors;

            return false;
        }
        else
        {
            elementFormError.style.display = 'none';
            return true;
        }
    }
	
  // 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 validateEMail(s)
  {
      var a = false;
      var res = false;
      if (typeof(RegExp) == 'function')
      {
          var b = new RegExp('abc');
          if (b.test('abc') == true)
          {
              a = true;
          }
      }
  
      if (a == true)
      {
          reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                          '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                          '(\\.)([a-zA-Z]{2,4})$');
                          
          /* Das Versenden an IDN E-Mail Adressen ist leider nicht auf allen Servern möglich */                                       
/*
          reg = new RegExp('^([a-zA-ZäöüßÄÖÜ0-9\\-\\.\\_]+)'+
                          '(\\@)([a-zA-ZäöüßÄÖÜ0-9\\-\\.]+)'+
                          '(\\.)([a-zA-ZäöüßÄÖÜ]{2,4})$');
*/
          res = (reg.test(s));
      }
      else
      {
          res = (s.search('@') >= 1 &&
               s.lastIndexOf('.') > s.search('@') &&
               s.lastIndexOf('.') >= s.length-5)
      }
      return(res);
  }
    
  function replaceAll(text, strA, strB)
  {
      while ( text.indexOf(strA) != -1)
      {
          text = text.replace(strA,strB);
      }
      return text;
  } 
  
  function strpos( haystack, needle, offset)
  {
      var i = (haystack+'').indexOf( needle, offset );
      return i===-1 ? false : i;
  }
  
  function showComment(myContentElement)
  {
      myContent = '';
  
      if (document.getElementById(myContentElement))
      {
          myContent = document.getElementById(myContentElement).innerHTML;

//          alert(myResidenzName.substr(11,1).charCodeAt(0));

          myContent = replaceAll(myContent, String.fromCharCode(8220), '"'); // “
          myContent = replaceAll(myContent, String.fromCharCode(8221), '"'); // ”
      }
      
      openWindow('/fileadmin/scripts/comment.php?comment=' + URLEncode(myContent), 'Kommentar', 'width=500, height=300, toolbar=no, location=no, directories=no, status=yes, menubar=no scrollbars=no, resizable=no, copyhistory=no');
  }
  
  function showTipAFriend(myContent)
  {
      window.open(myContent, 'tip', 'width=500,height=400,left=0,top=0,scrollbars=no,menubar=no, resizable=1');
  }
  