/**
* JS object for handling cookies...
*/
function Cookie (name) {
	
	this.name = name;
}
/**
* Save the cookie
*/
Cookie.prototype.save = function (value, days) {
	
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires="+date.toGMTString();
	} else { 
		var expires = "";
	}
	
	document.cookie = this.name + "=" + value + expires + "; path=/";
}
//IE Version
function  saveCookie(cookie_name, value, days) 
{
	//alert("saveCookie");
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires="+date.toGMTString();
	} else { 
		var expires = "";
	}
	
	document.cookie = cookie_name + "=" + value + expires + "; path=/";
}
/**
* Read the cookie's value
*/
Cookie.prototype.read = function () {
	var nameEQ = this.name + "=";
	var ca = document.cookie.split(';');
	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;
}
//IE Version
function readCookie(cookie_name) 
{
	//alert("readCookie");
	var nameEQ = cookie_name + "=";
	var ca = document.cookie.split(';');
	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) {
			//alert("readCookie value="+c.substring(nameEQ.length, c.length));
			return c.substring(nameEQ.length, c.length);
		}
			
	}
	//alert("readCookie value=null");
	return null;
}
/**
* Erase the cookie
*/
Cookie.prototype.destroy = function () {
	this.save(this.name, "", -1);
}
/**
* Stringify the cookie as it's value
*/
Cookie.prototype.toString = function () {
	return this.read();
}

