/* *********************************************************** */
/* Helper functions for manipulating cookies.
/* 
/* Author: Joel Perras, Kiwi-Interactif Inc.	
/* Copyright: GPL (http://www.gnu.org/licenses/gpl.txt)
/* Date: December 6th, 2007												 
/* *********************************************************** */

/* Will create a cookie */
function makeCookie(name,value,expiry_days) {
	var expires;
	if (expiry_days) {
		var date = new Date();
		date.setTime(date.getTime()+(expiry_days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	else expires = ""; //If no expiry date set
	
	document.cookie = name+"="+value+expires+"; path=/"; //Write the cookie
}// End createCookie()

/* Gives the key-value pair of a cookie if it exists, otherwise returns null */
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');  //Pattern matching of cookie string
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}// End readCookie()

/* Removes a named cookie by setting expiry time to negative value */
function eraseCookie(name) {
	makeCookie(name,"",-1);
}// End eraseCookie()