//////////////////////////////////////////////////////
//Get the value of the cookie id
//////////////////////////////////////////////////////
function getCookieVal (offset) 
{  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}
//////////////////////////////////////////////////////////////////////////////////////
//Read the cookie and make sure it matches the name of the cookie
//It accepts the "name" parameter which is basically the name of the cookieid("northern")
//////////////////////////////////////////////////////////////////////////////////////
function GetCookie (name) 
{  
	var arg = name + "=";  
	var alen = arg.length;  //This is the length of name of the cookieid
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen)
	{    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
		return getCookieVal (j);     
		i =	document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
		return null;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Set the new cookie
//the first parameter is the name of the cookieid to capture the id value
//the second parameter is the actual random cookieid that gets generated when users visits the page for the first time
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function SetCookie (name, value) 
{  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	//var expires = new Date();
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	//the path is set as same on all the pages so that every page can share the same cookie
	("; path=" + "/") +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}