function checkBestand(pID)
      {
        var intoCart = $F('valueIntoCart_' + pID);
        //if ( intoCart.length > 0 && (intoCart * 1) > 0 )
        if ( $('valueIntoCart_' + pID).present() && ($('valueIntoCart_' + pID).getValue() > 0) )
        {
          new Ajax.Request('/shop/ajax/checkBestand.php',
            {
              method        : 'get',
              parameters    : 'add2cart=' + intoCart + '&pID=' + pID,
              onComplete     : function(resp)
                              {
                                var bestand = resp.responseText * 1;
                                var eingabe = intoCart * 1;
                                if ( bestand < eingabe )
                                {
                                  $('cartMessage' + '_' + pID).update('<p class="error">Für dieses Produkt sind nur noch ' + resp.responseText + ' Einheiten lieferbar.</p>');
                                  $('valueIntoCart' + '_' + pID).value = resp.responseText;
                                  $('cartMessage' + '_' + pID).show();
                                }
                              },
              onFailure     : function(resp)
                              {
                                //alert('Fehler: ' + resp.statusText);
                              },
              onException   : function(resp, exception)
                              {
                                //alert('Ausnahme ' + exception);
                              }
            }
          );
        }
      }

      var theElements = new Array('Name', 'Anschrift', 'PLZ', 'Ort', 'Telefon');

      function stammKunde(janein)
      {
        if ( janein == 'ja' )
        {
          $('kundennummer').show();
          $('skw').hide();
          for ( i = 0; i < theElements.length; i++ )
          {
            $(theElements[i]).setStyle({'backgroundColor':'rgb(220,220,220)'});
          }
          disableAll();

        } else
        {
          $('kundennummer').hide();
          $('skw').show();

          for ( i = 0; i < theElements.length; i++ )
          {
            $(theElements[i]).setStyle({'backgroundColor':'rgb(255,249,176)'});
          }
          enableAll();
        }
      }

      function enableAll()
      {
        for ( i = 0; i < theElements.length; i++ )
        {
          $(theElements[i]).enable();
        }
      }

      function disableAll()
      {
        for ( i = 0; i < theElements.length; i++ )
        {
          $(theElements[i]).disable();
        }
      }

      function getKunde()
      {
      	
        if ( $('EMail').present() && $('KdNr').present() )
        {
          new Ajax.Request('/shop/ajax/getKunde.php',
            {
              method        : 'get',
              parameters    : 'EMail=' + $F('EMail') + '&KdNr=' + $F('KdNr'),
              onSuccess     : function(resp)
                              {
                              	
                                eval(resp.responseText);
                                if ( kunde.KdNr != "0" )
                                {
                                  //enableAll();
                                  $('Name').value = kunde.Name;
                                  $('Anschrift').value = kunde.Anschrift;
                                  $('PLZ').value = kunde.PLZ;
                                  $('Ort').value = kunde.Ort;
                                  $('Telefon').value = kunde.Telefon;
                                  $('Datenschutz').checked = true;
                                  if ( kunde.Werbung == '1' )
                                  {
                                    $('Werbung').checked = true;
                                  }
                                  $('Stammkunde').checked = true;
                                  //disableAll();
                                } else
                                {
                                  alert("Es wurde kein Kunden-Datensatz mit Ihren Angaben gefunden.");
                                }
                                
                              },
              onFailure     : function(resp)
                              {
                                //alert('Fehler: ' + resp.statusText);
                              },
              onException   : function(resp, exception)
                              {
                                //alert('Ausnahme ' + exception + ' | ' + resp.responseText);
                              }
            }
          );

        }

      }

      function initForm()
      {
        // nur etwas tun, wenn wir ein Formular haben
        
        if ( $('bestellform') != null )
        {
        
          if ( $('istKundeNein').checked )
          {
            stammKunde('nein');
          } else
          {
            stammKunde('ja');
          }
        }
        return true;
      }

      function showMessage(nachricht)
      {
        if ( nachricht != '' )
        {
          alert(nachricht);
        }
      }

      function Detail(seite, titel) {
          var bildfenster = window.open("/standard/detail_popup.php?seite=" + seite + "&titel="+titel,titel,"width=460,height=400,scrollbars=yes,location=no,status=no,resizable=yes");
      }
