//CookieSaveFormular,CookieLoadFormular

function GetCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}

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 null;
}

function GetCookieStr (name) {
  var arg = GetCookie(name);
  if (arg == null) {
    return ""
  } else {
    return arg;
  }
}

//expires: Verfallzeit in s
function SetCookie (name,value,expires,path,domain,secure) {
  var dt = new Date();
  dt.getTime()
  if (expires) {
    dt.setTime(dt.getTime() + 1000 * expires);
  }
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + dt.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

//Formulardaten als Cookie Speichern, Formular muss formular heissen
//InputNameList z.B. 'Name,eMail,Telefon'

function CookieSaveFormular(CookieName,InputNameList,ValidDays)
{
  var spElem = InputNameList.split(',');
  var SpeicherWert = '';

  for (var i=0; i < spElem.length; i++)
    SpeicherWert += document.formular[spElem[i]].value + ';';

  SpeicherWert = SpeicherWert.substring(0, SpeicherWert.length-1);

  //var expdate = new Date();
  //FixCookieDate (expdate);
  //expdate.setTime (expdate.getTime() + (ValidDays * 24 * 60 * 60 * 1000));

  SetCookie (CookieName, SpeicherWert, 60*60*24*ValidDays);
}

function CookieLoadFormular(CookieName,InputNameList)
{
  if (GetCookie(CookieName)) {

    var laElem = GetCookie(CookieName).split(';');
    var spElem = InputNameList.split(',');

    for (var i=0; i < laElem.length; i++)
      if (laElem[i])
        document.formular[spElem[i]].value = laElem[i];

  }
}