
function Cookies ( habitat ) {
	habitat.session = this.get( "session" );
	if( habitat.session ) {
		habitat.set_vis( "no_cookies", "hidden" );
	}
	return this;
}

Cookies.prototype.get = function( name ) {
	var cookie_str = "" + document.cookie;
	var result_1 = cookie_str.indexOf( name );
	if( result_1 == -1 || name == "" ) {
		return false;
	}
	var result_2 = cookie_str.indexOf( ";", result_1 );
	if( result_2 == -1 ) {
		result_2 = cookie_str.length;
	}
	var cookie = cookie_str.substring( result_1 + name.length + 1, result_2 );
	return unescape( cookie );
};

Cookies.prototype.set = function( name, value, expires, path, domain, secure ) {
	var curCookie = name + "=" + escape( value ) +
	( (expires) ? "; expires=" + this._get_expires( expires ) : "" ) +
	( (path) ? "; path=" + path : "; path=/" ) +
	( (domain) ? "; domain=" + domain : "" ) +
	( (secure) ? "; secure" : "" );
	document.cookie = curCookie;
	if( !this.get( name ) ) {
		return false;
	} else {
		return true;
	}
};

Cookies.prototype._get_expires = function( num_days ) {
	if( num_days == "" ) {
		return num_days;
	}
	var UTC_str;
	var second = new Date();
	num_milli = Date.parse( second );
	second.setTime( num_milli + ( num_days * 24 * 60 * 60 * 1000 ) );
	UTC_str = second.toUTCString();
	return UTC_str;
};

