/*
 * DON'T REMOVE THE FOLLOWING LICENSE
 *           INFORMATION!
 * ----------------------------------
 * Copyright by
 * Dennis Ritz
 * Author: Dennis Ritz
 * dennis.ritz@gmx.net
 * 2007-2008
 * ----------------------------------
 */

function Cookie() {
	this.create = function create(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	
	this.read = function read(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) {
				if(c.substring(nameEQ.length,c.length).split(",").length > 1) {
					return c.substring(nameEQ.length,c.length).split(",");
				}else{
					return c.substring(nameEQ.length,c.length);
				}
			}
		}
		return null;
	}
	
	this.erase = function erase(name) {
		Cookie.create(name,"",-1);
	}
	
	this.eraseAll = function eraseAll() {
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			c = c.split("=");
			Cookie.erase(c[0]);
		}
		return null;
	}
}

var Cookie = new Cookie();
Cookie.create("test", 1);
if(Cookie.read("test")!=1) alert("You need to allow cookies for this webpage!");