/********************************************************
CreateCookie:
--------------------------------------------------------
To add or modify a cookie
*********************************************************/

function createCookie(name,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 = name+"="+value+expires+"; path=/";
}

/********************************************************
ReadCookie:
--------------------------------------------------------
To read a cookie value
*********************************************************/

function readCookie(name) 
{
	var nameEQ = name + "=";
	
	//Separate all the cookie entries
	var ca = document.cookie.split(';');
	
	//Read all the cookies
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		
		//Remove preceding white spaces
		while (c.charAt(0)==' ') 
			c = c.substring(1,c.length);
		
		//Check if the cookie name is the specified name
		//If yes, return the value of cookie
		if (c.indexOf(nameEQ) == 0) 
			return c.substring(nameEQ.length,c.length);
	}
	
	//If no details found, return NULL
	return null;
}

/********************************************************
EraseCookie:
--------------------------------------------------------
To delete a cookie value
*********************************************************/

function eraseCookie(name) 
{
	//Set the cookie expiry to earlier time
	createCookie(name,"",-1);
}

