/**
 * @author Ryan Johnson <ryan@livepipe.net>
 * @copyright 2007 LivePipe LLC
 * @package Prototype.Tidbits
 * @license MIT
 * @url http://livepipe.net/projects/prototype_tidbits/
 * @version 1.7.0
 * 
 * Note that each tidbit is independent, and is meant to be copied and pasted as you see fit into your application rather than used as a whole.
 */

/**
 * Tidbit : Cookie
 */

var Cookie = {
	set: function(name,value,intDays)
	    {
		    if(intDays)
		    {
			    d = new Date();
			    d.setTime(d.getTime() + (intDays * 24 * 60 * 60 * 1000));
			    expiry = '; expires=' + d.toGMTString();
		    }
		    else 
		    {
			    expiry = '';
		    }
		    //alert('SET: ' + new Date() + ' - ' + name + '=' + value + expiry + '; path=/');
		    document.cookie = name + "=" + value + expiry + "; path=/";
	    },
	get: function(name)
	    {
		    nameEQ = name + "=";
		    ca = document.cookie.split(';');
		    for(i = 0; i < ca.length; i++)
		    {
			    c = ca[i];
			    //alert('got: ' + c);
			    while(c.charAt(0) == ' ') 
			    {
				    c = c.substring(1,c.length);
				}
			    if(c.indexOf(nameEQ) == 0) 
			    {
			        //alert('GET: ' + new Date() + ' - ' + c.substring(nameEQ.length,c.length));
				    return c.substring(nameEQ.length,c.length);
				}
		    }
		    return null
	    },
	unset: function(name)
	    {
		    Cookie.set(name,'',-1);
	    }
}

 