/**
 * @copyright  Copyright(c) 2005-2007, IC Zones
 * @author     Michael Jolin
 * @since      2007,04,13
 * @package		JS
**/

/**
 * Object constructor
 *
 * @author		Michael Jolin
 * @since		2007,04,13
**/
iczones.object.cookie = {
	/**
	 * Get value of a cookie
	 *
	 * @author		Michael Jolin
	 * @since		2007,04,13
	**/
	get: function( _name ) {
		var start	= document.cookie.indexOf( _name + '=' );
		var len		= start + _name.length + 1;

		if( ( !start ) && ( _name != document.cookie.substring( 0, _name.length ) ) ) {
			return null;
		}
		if( start == -1 ) {
			return null;
		}

		var end	= document.cookie.indexOf( ';', len );
		if( end == -1 ) {
			end = document.cookie.length;
		}

		return unescape( document.cookie.substring( len, end ) );
	},

	/**
	 * Set a new cookie
	 *
	 * @author		Michael Jolin
	 * @since		2007,04,13
	**/
	set: function( _name, _value, _expires, _path, _domain, _secure ) {
		var today = new Date();
		var expires = ( _expires ? _expires * 1000 * 60 * 60 * 24 : 24 * 3600000 );

		today.setTime( today.getTime() );

		var expires_date = new Date( today.getTime() + ( expires ) );

		document.cookie = _name + '=' + escape( _value ) +
			( ( _expires ) ? ';expires=' + expires_date.toGMTString() : '' ) +
			( ( _path ) ? ';path=' + _path : '' ) +
			( ( _domain ) ? ';domain=' + _domain : '' ) +
			( ( _secure ) ? ';secure' : '' );
	},

	/**
	 * Delete a cookie
	 *
	 * @author		Michael Jolin
	 * @since		2007,04,13
	**/
	remove: function( _name, _path, _domain ) {
		if( this.get( _name ) ) {
			document.cookie = _name + '=' +
				( ( _path ) ? ';path=' + _path : '') +
				( ( _domain ) ? ';domain=' + _domain : '' ) +
				';expires=Thu, 01-Jan-1970 00:00:01 GMT';
		}
	}
};


