/* simple cookie functions adapted from: 

	http://techpatterns.com/downloads/javascript_cookies.php
	http://msdn.microsoft.com/en-us/library/ms533693(VS.85).aspx

	Requires global variables:

		gs_blast_lib
*/

var gb_lib_cookies = function(){

	var o_funcs = {

		set_cookie: function(s_name, s_value, n_days, s_path, s_domain, b_secure) {

			var d_expire_date = null
				, n_expire_ms = 0
				;

			if (n_days) {
				d_expire_date = new Date(); // today
				n_expire_ms = d_expire_date.getTime() + (n_days * 24 * 60 * 60 * 1000)
				d_expire_date.setTime(n_expire_ms);
			}

			document.cookie = s_name + '=' + escape(s_value) 
				+ (n_days ? ';expires=' + d_expire_date.toUTCString() : '') 
				+ (s_path ? ';path=' + s_path : '')
				+ (s_domain ? ';domain=' + s_domain : '') 
				+ (b_secure ? ';secure' : '' )
				;
		},
		//-----

		set_blast_cookie: function(s_name, s_value, n_days) {
			
			o_funcs.set_cookie(s_name, s_value, n_days, '/blast');

		},
		//-----

		get_cookie: function(s_name) {

			var b_found = false
				, a_cookies = document.cookie.split(';')
				, n_cookies_len = a_cookies.length
				, a_crumb = []
				, i = 0
				;

			for (i = 0; i < n_cookies_len; i++) {

				a_crumb = a_cookies[i].split('=');

				// does any browser really pad cookie names/values with spaces?!

				if (a_crumb[0].replace(/^\s+|\s+$/g, '') == s_name) {
					return unescape(a_crumb[1].replace(/^\s+|\s+$/g, ''));
				}
			}

			return null;
		},
		//-----

		clear_cookie: function(s_name) {

			o_funcs.set_cookie(s_name, '', -1);

		},
		//-----

		dummy_field: null // so all other can end with ","

	};

}();

// end of scripts
