// "Internal" function to return the decoded value of a cookie 
// WARNING Filemode must be 0664 (-rw-r--r--) sonst mag es der ie nicht
// File.: clpbrd.js

//var dt = new Date(2002,12);
// create an instance of the Date object
var expires = new Date();
// fix the bug in Navigator 2.0, Macintosh
//fixDate(expires);
// cookie expires in one year (actually, 365 days)
// 365 days in a year
// 24 hours in a day
// 60 minutes in an hour
// 60 seconds in a minute
// 1000 milliseconds in a second
expires.setTime(expires.getTime() + 365 * 24 * 60 * 60 * 1000);

function lpraOne() { 
 // ' OR Nr\= '
 var gg = new Array();  
 var aa = new Array();
 var or = "\' OR Nr\= \'";
 var aaa = '/cgi-bin/Klm.pl?adverttype=Lesen&send=Abschicken&command=4000&ok=true&nr=';
 
 var fuc = notepad_load() || 'EMTY25400';
 gg = fuc.split(/,/);
 
 var lpara = location.href=aaa + '0' + '&kkk=' + gg + '&nachricht=CLIP_BOARD' + '&adm=OK';
	return lpara;
	}

//
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) 
	{
	if(is.ie) {var arg = name}
	else {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 to create or update a cookie.
function SetCookie (name,value,expires,path,domain,secure) 
	{
	document.cookie = name + "=" + escape (value) +
	 ((expires) ? "; expires=" + expires.toUTCString() : "") +
	 ((path) ? "; path=" + path : "") +
	 ((secure) ? "; secure" : "");
	 //alert(document.cookie);
	}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
function DeleteCookie (name,path,domain) 
	{
	if (GetCookie(name))
		{
    	document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}
	}

// Notizbuch Funktionen Version (2001-05-04: TG)	
//
//  Notizbuch lesen
function notepad_load()
	{
	
	var lstNOTEPAD = GetCookie('NOTEPAD') || "IS_NULL";
	if(is.ie && lstNOTEPAD != "IS_NULL"){lstNOTEPAD = lstNOTEPAD.substr(1,lstNOTEPAD.length-1);}
	if (lstNOTEPAD != "IS_NULL")
		{
			//alert(lstNOTEPAD); 
		return lstNOTEPAD;
		} else {
		
		//alert('ClipBoard ist leer!!'); return null;
		}
	
		//return lstNOTEPAD;
	}
	
// Angebot in Notizbuch legen
// TT 16.11.2001	No origin needed
function notepad_add(adno)
	{
	var s_cookie, n_check, n_l, n_r, key = adno;	
	if (is.ns)
		{if (isCookie() == false)
			{alert("Bitte aktivieren Sie 'Cookies akzeptieren' in Ihrem Browser.");
			 return;
			}
		}
	s_cookie = GetCookie('NOTEPAD');	
	if (s_cookie == null) s_cookie='';
	if(is.ie)
		{s_cookie = s_cookie.substr(1,s_cookie.length-1);}
	n_check = s_cookie + key;
	
	if (n_check.length > 2048){alert('Notizbuch ist voll. Eintrag kann nicht gespeichert werden.');return;}
	if (s_cookie != '') s_cookie += ",";
	s_cookie += key;
	if (notepad_find(adno) != true)
		{SetCookie('NOTEPAD',s_cookie,expires,'/',null);
		//alert(expires);
		 //alert("Angebot hinzugefügt.");
		}
	else
		{alert("Das Angebot befindet sich bereits im Notizbuch.");}
	}

// Angebot aus Notiuzbuch entfernen
// TT 16.11.2001	No origin needed
function notepad_remove(adno)
	{
	var s_cookie, n_l, n_r, key = adno;
	s_cookie = GetCookie('NOTEPAD');
	if(is.ie){s_cookie = s_cookie.substr(1,s_cookie.length-1);}
   if (s_cookie.indexOf(key) != -1)
	   {
	   n_l = s_cookie.indexOf(key);
	   n_r = n_l + key.length;
		s_cookie = s_cookie.substring(0,n_l) +  s_cookie.substring(n_r,s_cookie.length);
		if(s_cookie.charAt(0) == ',') s_cookie = s_cookie.substring(1,s_cookie.length+1);
		if(s_cookie.charAt(s_cookie.length-1) == ',') s_cookie = s_cookie.substring(0,s_cookie.length-1);
		s_cookie = s_cookie.replace(/,,/,",","ALL");
      SetCookie('NOTEPAD',s_cookie,expires,'/',null);

	//alert(s_cookie + '; ' + s_cookie.charAt(s_cookie.length-1) + '; ' + s_cookie.charAt(0) +  '; ' + 'substr' + '; ' + s_cookie.substring(0,s_cookie.length));
	//if(lpraOne() == "EMTY25400") location.reload();
  	  }
	}
		
// Angebot schon in Notizbuch?
// TT 16.11.2001	No origin needed
function notepad_find(adno)
	{
	var s_cookie, key = adno;	
	s_cookie = GetCookie('NOTEPAD');
	if(s_cookie == null)	return false;
	if(is.ie){s_cookie = s_cookie.substr(1,s_cookie.length-1);}
	if (s_cookie.indexOf(key) != -1)return true;
	else return false;
	}

	
// -------------------------------- Fehlerhafte funktion Wurde in den Klm ausgelagert

// Notizbuch hinzufügen / löschen
// TT 22.08.2001
// TT 16.11.2001	No origin needed
function notepad_modify(adno,b_CONFIRMandRELOAD,b,d)
	{if (b_CONFIRMandRELOAD == null)
		{b_CONFIRMandRELOAD = false;}
	 if (notepad_find(adno))
	 	{if (b_CONFIRMandRELOAD)
			{if (confirm("M\xF6chten Sie das Inserat mit der Nr. " + adno + " aus dem ClipBoard Entfernen?"))
			 	{notepad_remove(adno);
			 	 location.reload();
				}
			 else
			 	{
				eval("document.formNOTEPAD_" + adno + ".MODIFY" + adno + ".checked=true");
				}
			}
		 else	
		 	{
			notepad_remove(adno);
			 alert("Angebot mit der Nr. " + adno + " wurde aus dem ClipBoard entfernt.");
			}
		}
	 else
		{	
		// if(GetCookie('NOTEPAD') == null) location.reload();
		//notepad_add(adno);
		//alert("Inserat mit der Nr. "+adno+" wurde zum ClipBoard hinzugefügt."+"Wagenr " + d + ": " + b);
		if (confirm("Der Artikel Nr : (" + adno + ") Wurde zu Ihrer Beobachtungsliste hinzugef\xFCgt"))
		{notepad_add(adno);
		location.reload();
		   }
		   else
			 	{
				eval("document.formNOTEPAD_" + adno + ".MODIFY" + adno + ".checked=false");
				}
		   if(GetCookie('NOTEPAD') == null) location.reload();	
		}
	return true;
	}

// -------------------------------------------- WARNUNG IE MAG KEINE UMLAUTE

// Notizbuch entfernen	
function notepad_del()
	{DeleteCookie('NOTEPAD','/',null);}

// Cookiedaten anzeigen
function ShowCookie()
	{
	alert('Cookie:\n'+document.cookie);
	return true;
	}
