
	/**
	 * class Cookies
	 *
	 * depends on:
	 * prototype >= 1.6.0
	 * scriptaculous >= 1.8.1
	 *
	 * @since 11.08.2008 15:55
	 * @version 1.0.0
	 * @author Markus Huber
	 *
	 *
	 *
	 */

	var Xover_Cookies = Class.create();

	Xover_Cookies.prototype = {
	
		/**
		 * method initialize
		 *
		 *
		 *
		 */
		initialize: function()
		{
			var defaults = {
				domain: false,
				expires: false,
				days: 1
			}

			var options = Object.extend(defaults, {});

			if(!options.domain) {
				options.domain = window.location.hostname;
			}

			if(!options.expires) {
				var expires = new Date();
				var expiresDiff = expires.getTime() + (options.days * 24 * 60 * 60 * 1000);
				expires.setTime(expiresDiff);
				options.expires = expires.toGMTString();
			}

			if(!this.domain) this.domain = options.domain;
			if(!this.expires) this.expires = options.expires;
		},
		
		/**
		 * method setCookie
		 *
		 *
		 *
		 */
    	setCookie: function(name, wert, domain, expire, path, secure)
		{
			var cook = name + "=" + unescape(wert);
			cook += (domain) ? "; domain=" + domain : "; domain=" + this.domain;
			cook += (expire) ? "; expires="+expire : "; expires=" + this.expires;
			cook += (path) ? "; path="+path : "; path=/";
			cook += (secure) ? "; secure" : "";
			document.cookie = cook;
		},
		
		/**
		 * method getCookie
		 *
		 *
		 *
		 */
		getCookie: function(cookieName)
		{
			if(document.cookie) { 
				var i = 0;
				var suche = cookieName + "=";

				while(i < document.cookie.length) {
					if(document.cookie.substring(i, i + suche.length) == suche) {
						var ende = document.cookie.indexOf(";", i + suche.length);
						ende = (ende > -1) ? ende : document.cookie.length;
						var cook = document.cookie.substring(i+suche.length, ende);
						return unescape(cook);
					}

					i++;
				}

				return false;
			} else {
				return false;
			}
		},
		
		/**
		 * method checkCookie
		 *
		 *
		 *
		 */
		checkCookie: function()
		{
			this.setCookie("XoverTemp", "ok");

			if (!this.getCookie("XoverTemp")) {
				return false;
			} else {
				this.eraseCookie("XoverTemp");
				return true;
			}
		},
		
		/**
		 * method eraseCookie
		 *
		 *
		 *
		 */
		eraseCookie: function(name, domain, path)
		{
			var cook = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
			cook += (domain) ? "; domain=" + domain : "; domain=" + this.domain;
			cook += (path) ? "; path=" + path : "; path=/";
			document.cookie = cook;
		}
	}