var expdate = new Date ();
expdate.setTime (expdate.getTime() + (365 * 24 * 60 * 60 * 1000)); // 24 hrs from now 

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

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 getCookieVariable(cookieName,cookieVariable)
{
	cookieValue = GetCookie(cookieName);
	if (cookieValue != null)
		{
		valueStart =  cookieValue.indexOf(cookieVariable + "=");
		
		if (valueStart != -1)
			{
			valueStart += + cookieVariable.length + 1;
			valueEnd = cookieValue.indexOf("&",valueStart);
			value =  cookieValue.substring(valueStart,valueEnd);
			}
		else
			{
			value = false;
			}
		
		return value;
		}
}

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";
  }
}

function saveAddress(cookieName){
var cookieValue = "name=" + document.order.Name.value + "&vorname=" + document.order.Vorname.value + "&strasse=" + document.order.Strasse.value + "&plz=" + document.order.PLZ.value + "&ort=" +document.order.Ort.value + "&land=" +document.order.Land.value + "&tel=" + document.order.Tel.value + "&natel=" + document.order.Natel.value + "&email=" + document.order.EMail.value + "&";
SetCookie (cookieName, cookieValue, expdate);
if (cookieName=='user'){
alert("Ihre Adresse wurde gespeichert!");}
}

function loadAddress(cookieName){
cookieValue = GetCookie('userTmp');
if (cookieValue != null){
	cookieName = 'userTmp';
	}
else{
	cookieValue = GetCookie('user');
	if (cookieValue != null){
		cookieName = 'user';
		}
	}
//cookieValue = GetCookie(cookieName);
if (cookieName != null){
	document.order.Name.value = getCookieVariable(cookieName,"name");
	document.order.Vorname.value = getCookieVariable(cookieName,"vorname");
	document.order.Strasse.value = getCookieVariable(cookieName,"strasse");
	document.order.PLZ.value = getCookieVariable(cookieName,"plz");
	document.order.Ort.value = getCookieVariable(cookieName,"ort");
	document.order.Land.value = getCookieVariable(cookieName,"land");
	document.order.Tel.value = getCookieVariable(cookieName,"tel");
	document.order.Natel.value = getCookieVariable(cookieName,"natel");
	document.order.EMail.value = getCookieVariable(cookieName,"email");
	}
DeleteCookie ('userTmp');
}

function deleteAddress(cookieName){
DeleteCookie (cookieName);
alert("Ihre Adresse wurde gelöscht!");
}
