//  1.  The expires parameter is now optional - that is, you can omit
//      it instead of passing it null to expire the cookie at the end
//      of the current session.
//
//  2.  An optional path parameter has been added.
//
//  3.  An optional domain parameter has been added.
//
//  4.  An optional secure parameter has been added.
//
//  For information on the significance of these parameters, and
//  and on cookies in general, please refer to the official cookie
//  spec, at:
//
//      http://www.netscape.com/newsref/std/cookie_spec.html
//
//
// "Internal" function to return the decoded value of a cookie
//
    function getCookieVal (offset)
    {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
    }

//
//  Function to return the value of the cookie specified by "name".
//  name - String object containing the cookie name.
//  returns - String object containing the cookie value, or null if
//  the cookie does not exist.
//

    function GetCookie (name)
    {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
    }

    return getCookieVal ("kein Cookie vorhanden");
    }

//  Function to create or update a cookie.
//  name - String object object containing the cookie name.
//  value - String object containing the cookie value.  May contain
//  any valid string characters.
//  [expires] - Date object containing the expiration data of the cookie.  If
//  omitted or null, expires the cookie at the end of the current session.
//  [path] - String object indicating the path for which the cookie is valid.
//  If omitted or null, uses the path of the calling document.
//  [domain] - String object indicating the domain for which the cookie is
//  valid.  If omitted or null, uses the domain of the calling document.
//  [secure] - Boolean (true/false) value indicating whether cookie transmission
//  requires a secure channel (HTTPS).
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//

   function SetCookie (name, value)
   {
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path = (argc > 3) ? argv[3] : null;
   var domain = (argc > 4) ? argv[4] : null;
   var secure = (argc > 5) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) +
   ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
   ((path == null) ? "" : ("; path=" + path)) +
   ((domain == null) ? "" : ("; domain=" + domain)) +
   ((secure == true) ? "; secure" : "");
   }

//  Function to delete a cookie. (Sets expiration date to current date/time)
//    name - String object containing the cookie name
//

  function DeleteCookie (name)
  {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);  // This cookie is history
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  }


// Wird bei onsubmit aufgerufen

 function SaveCookie() {

// Prüft ob das Feld Firmenbezeichnung gefüllt wurde.
// Wenn nein, wird eine Alert-Meldung ausgegeben, da das Feld Pflicht ist.
       var _123 = document.save_cookie.firmenbezeichnung.value;
       if (_123 == ""){
       alert("Bitte geben Sie noch Ihre Firmenbezeichnung an!");
       document.save_cookie.firmenbezeichnung.focus();
       return false;}

// Prüft ob das Feld Anrede gefüllt wurde.
// Wenn nein, wird eine Alert-Meldung ausgegeben, da das Feld Pflicht ist.
       var _123 = document.save_cookie.anrede.value;
       if (_123 == ""){
       alert("Sie haben Ihre Anrede (Frau, Herr, Firma) nicht eingetragen!");
       document.save_cookie.anrede.focus();
       return false;}

// Prüft ob das Feld Ansprechpartner gefüllt wurde.
// Wenn nein, wird eine Alert-Meldung ausgegeben, da das Feld Pflicht ist.
       var _123 = document.save_cookie.ansprechpartner.value;
       if (_123 == ""){
       alert("Bitte geben Sie noch einen Ansprechpartner an!");
       document.save_cookie.ansprechpartner.focus();
       return false;}

// Prüft ob das Feld Strasse gefüllt wurde.
// Wenn nein, wird eine Alert-Meldung ausgegeben, da das Feld Pflicht ist.
       var _123 = document.save_cookie.strasse.value;
       if (_123 == ""){
       alert("Bitte geben Sie noch die Strasse und ggf. die Hausnummer an!");
       document.save_cookie.strasse.focus();
       return false;}

// Prüft ob das Feld PLZ gefüllt wurde.
// Wenn nein, wird eine Alert-Meldung ausgegeben, da das Feld Pflicht ist.
       var _123 = document.save_cookie.plz.value;
       if (_123 == ""){
       alert("Bitte geben Sie noch die Postleitzahl an!");
       document.save_cookie.plz.focus();
       return false;}

// Prüft ob das Feld Ort gefüllt wurde.
// Wenn nein, wird eine Alert-Meldung ausgegeben, da das Feld Pflicht ist.
       var _123 = document.save_cookie.ort.value;
       if (_123 == ""){
       alert("Bitte geben Sie noch den Ort an!");
       document.save_cookie.ort.focus();
       return false;}


// Prüft ob das Feld E-Mail gefüllt wurde.
// Wenn nein, wird eine Alert-Meldung ausgegeben, da das Feld Pflicht ist.
       var _123 = document.save_cookie.email.value;
       if (_123 == ""){
       alert("Bitte geben Sie noch Ihre E-Mail-Adresse an!");
       document.save_cookie.email.focus();
       return false;}

// Überprüft die Eingaben des Feld "E-Mail".

      var _123 = document.save_cookie.email.value;
      if(_123 != '')
      {
      if(document.save_cookie.email.value.indexOf(' ') != -1)
      { alert('Achten Sie bitte darauf, keine Leerzeichen einzugeben!');
      document.save_cookie.email.focus();
      return false; }

      if(document.save_cookie.email.value.indexOf('@') == -1)
      { alert('Ihre E-Mail-Adresse ist nicht korrekt eingetragen.\nBitte tragen Sie noch das @-Zeichen ein!');
      document.save_cookie.email.focus();
      return false; }

      if(document.save_cookie.email.value.indexOf('.') == -1)
      { alert('Bitte denken Sie auch an den Punkt in Ihrer E-Mail-Adresse!\nZum Beispiel ".com" oder ".de".');
      document.save_cookie.email.focus();
      return false; }
      }

// Prüft ob das Feld Telefon gefüllt wurde.
// Wenn nein, wird eine Alert-Meldung ausgegeben, da das Feld Pflicht ist.
       var _123 = document.save_cookie.telefon.value;
       if (_123 == ""){
       alert("Bitte geben Sie noch Ihre Telefonnummer an!");
       document.save_cookie.telefon.focus();
       return false;}

var expdate = new Date ();
expdate.setTime(expdate.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));
SetCookie('firmenbezeichnung', document.save_cookie.firmenbezeichnung.value, expdate,'/');

var expdate = new Date ();
expdate.setTime(expdate.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));
SetCookie('anrede', document.save_cookie.anrede.value, expdate,'/');

var expdate = new Date ();
expdate.setTime(expdate.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));
SetCookie('ansprechpartner', document.save_cookie.ansprechpartner.value, expdate,'/');

var expdate = new Date ();
expdate.setTime(expdate.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));
SetCookie('strasse', document.save_cookie.strasse.value, expdate,'/');

var expdate = new Date ();
expdate.setTime(expdate.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));
SetCookie('plz', document.save_cookie.plz.value, expdate,'/');

var expdate = new Date ();
expdate.setTime(expdate.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));
SetCookie('ort', document.save_cookie.ort.value, expdate,'/');

var expdate = new Date ();
expdate.setTime(expdate.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));
SetCookie('land', document.save_cookie.land.value, expdate,'/');

var expdate = new Date ();
expdate.setTime(expdate.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));
SetCookie('email', document.save_cookie.email.value, expdate,'/');

var expdate = new Date ();
expdate.setTime(expdate.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));
SetCookie('telefon', document.save_cookie.telefon.value, expdate,'/');

var expdate = new Date ();
expdate.setTime(expdate.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));
SetCookie('fax', document.save_cookie.fax.value, expdate,'/');

var expdate = new Date ();
expdate.setTime(expdate.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));
SetCookie('website', document.save_cookie.website.value, expdate,'/');

alert('Das Cookie wurde gesetzt!');
window.location.href = "cookie_auslesen.php";
return false;

}
