/*  
	Stefan Schwerdtner (stefan.schwerdtner@gmx.de)
	last change 2007-03-16

	I M P O R T A N T !
	-------------------
	to avoid data loss, initialise the object "gValues" before using the
	function "setValue", by calling the function "getValue". (e.g. getValue("");)
	if you work with a function to initialise all values, be sure to include 
	this script before initialising.
*/

// object for storing multiple values in a single cookie
getValue("");
gValues = new Object();

function setValue(variable, value){
	//Wert schreiben
	gValues[variable] = value;
	//Object serialisieren
	var strValues = "";
	for(var strProp in gValues){
		if(strProp!="" && gValues[strProp]!=undefined){
			strValues = strValues.concat("|", escape(strProp) , ";", escape(gValues[strProp]));
		}
	}
	//serialisiertes Objekt im Cookie speichern
	//var expDate = new Date(2099, 11, 31);
	//document.cookie = "gValues=" + escape(strValues.slice(1)) + "; expires=" + expDate.toUTCString();
	document.cookie = "gValues=" + escape(strValues.slice(1));
}

function getValue(variable){
	if (variable!=undefined && variable!="") {
		var strValues = unescape(document.cookie);
		strValues = strValues.slice(strValues.indexOf('=') + 1);
		
		var values = strValues.split("|");
		for(i=0;i<values.length;i++){
			var valuepair = values[i].split(";");
			gValues[unescape(valuepair[0])] = unescape(valuepair[1]);
		}
		return gValues[variable];
	} else {
		return "";	
	}
}

function killCookie(){
	var killDate = new Date(1970, 0, 1);
	//document.cookie = "gValues=0; expires=" + killDate.toUTCString();
	document.cookie = "gValues=0;";
}

function killValue(variable){
	var strValues = "";
	gValues[variable] = undefined;
	for(var strProp in gValues){
		if((strProp!=variable) && (gValues[strProp]!=undefined)){
			strValues = strValues.concat("|", escape(strProp) , ";", escape(gValues[strProp]));
		}
	}
	var expDate = new Date(2099, 11, 31);
	document.cookie = "gValues=" + escape(strValues.slice(1)) + "; expires=" + expDate.toUTCString();
}

function killValues(){
	oValues = gValues;
	gValues = new Object;
	var strValues = "";
	for(var strProp in oValues){
		if((strProp=="UserID" || strProp=="LoginToken") && (oValues[strProp]!=undefined && oValues[strProp]!="")){
			strValues = strValues.concat("|", escape(strProp) , ";", escape(oValues[strProp]));
			gValues[strProp] = oValues[strProp];
		}
	}
	//var expDate = new Date(2099, 11, 31);
	//document.cookie = "gValues=" + escape(strValues.slice(1)) + "; expires=" + expDate.toUTCString();
	document.cookie = "gValues=" + escape(strValues.slice(1));	
}
