// Objekt erstellung 2004
// Klasse Object
// Erstellt von Robert Engelhardt
// Frima Internetagentur More Style Berlin
// http://www.more-style.de

var $_COOKIE = {

	set_cookie : function(cName,cValue,cDays) {

		var cookieQuery = new String();
		var temporArray = new Array();

		var alowedTypes = ["string","array","object","number"];
		var inComingTyp = String(cValue.constructor);

		inComingTyp = inComingTyp.split(" ")[1];
		inComingTyp = inComingTyp.split("()").join("").toLowerCase();

		if(alowedTypes.join(",").indexOf(inComingTyp) < 0) return false;

		if(inComingTyp == "array") {

			cValue = "a##"+cValue.join(",");

		} else if(inComingTyp == "object") {

			for(x in cValue) temporArray[temporArray.length] = x +":"+ cValue[x];

			cValue = "o##"+temporArray.join(",");

		} else {

			cValue = "s##"+cValue;
		}

		cookieQuery += cName+"=";
		cookieQuery += escape(cValue)+"; expires=";
		cookieQuery += new Date(new Date().getTime()+(86400*(cDays*1000))).toLocaleString();

		window.document.cookie = cookieQuery;
	},

	read_cookie : function(cName) {

		var cookies = document.cookie.split(";");

		for(x=0; x<cookies.length; x++) {

			var cookie = cookies[x].split("=");

			if(cookie[0] == cName) {

				var locaType = String(unescape(cookie[1])).split("##");

				if(locaType[0] == "a") {

					return locaType[1].split(",");

				} else if(locaType[0] == "o") {

					var tmpArr = locaType[1].split(",");

					for(tmpObj={},x=0;x<tmpArr.length;x++) {

						values = tmpArr[x].split(":");

						tmpObj[values[0]] = values[1];
					}

					return tmpObj;

				} else {

					return locaType[1];
				}
			}
		}

		return false;
	},

	delete_cookie : function(cName) {

		this.set_cookie(cName,"",-99999999);
	}
};
