/**
 * Methoden zum Setzen, Auslesen und Löschen von Cookies
 *
 * @authors		Martin Widemann
 * @copyright	Copyright 2008-2011 - Netigo GmbH
 * @version		1.3
 * @modified	2011-09-21
 */
var Cookie = {

	/**
	 * Cookie auslesen
	 *
	 * @param String name Name des Cookies
	 */
	get: function(name)
	{
		if(name == void(0)){ throw 'Missing Parameter \'name\' in Method \'get\'.'; } // if

		if(document.cookie.length > 0){ 
			begin = document.cookie.indexOf(name + '='); 
	
			if (begin != -1){ 
				begin += name.length + 1; 
				end = document.cookie.indexOf(';', begin);
	
				if (end == -1){
					end = document.cookie.length;
				} // if
	
				return unescape(document.cookie.substring(begin, end));
			} // if
		} // if

		return null;
	}, // function

	/**
	 * Cookie setzen
	 *
	 * @param String name Name des Cookies
	 * @param String value Inhalt des Cookies
	 * @param Number expire_days Haltbarkeit des Cookies (Anzahl Tage)
	 * @param String path Cookie-Path (default = '/')
	 */
	set: function(name, value, expire_days, path)
	{
		if(name == void(0)){ throw 'Missing Parameter \'name\' in Method \'set\'.'; } // if
		if(value == void(0)){ throw 'Missing Parameter \'value\' in Method \'set\'.'; } // if

		if(path == null){
			if(Cookie.isIE()){
				path = '';
			}else{
				path = '/';
			} // if
		} // if

		var expire_date = new Date();
		expire_date.setTime(expire_date.getTime() + (expire_days * 24 * 3600 * 1000));
		document.cookie = name + '=' + escape(value) + ((expire_days == void(0)) ? '' : '; expires=' + expire_date.toGMTString()) + '; path=' + path;
	}, // function

	/**
	 * Cookie löschen
	 *
	 * @param String name Name des Cookies
	 */
	del: function(name, path)
	{
		if(name == void(0)){ throw 'Missing Parameter \'name\' in Method \'del\'.'; } // if

		if(path == null){
			if(Cookie.isIE()){
				path = '';
			}else{
				path = '/';
			} // if
		} // if

		if(Cookie.get(name)){
			document.cookie = name + '=' + '; expires=Thu, 01-Jan-70 00:00:01 GMT; path=' + path;
		} // if
	}, // function

	isIE: function()
	{
		var ie = (function(){
			var undef,
				v = 3,
				div = document.createElement('div'),
				all = div.getElementsByTagName('i');
		 
			while (
				div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
				all[0]
			);
		 
			return v > 4 ? v : undef;
		}());

		return ie;
	}
} // class

