/*
 * Author: Joel Stevick
 * Copyright (c) 2007, CorData, Inc
 * Program Name: C.H.I.P. - CorData Hierarchical Inference Program
 */
/*
 * Read a cookie value 
 */
function ReadCookie(name) {
	/* 
	 * Get the complete set of cookies
	 */
    var cookies = document.cookie;
	
	/*
	 * Does this cookie exist?
	 */
    var pos = cookies.indexOf(name + '=');
	var value = '';
	
	if (pos != -1) {
		/* 
		 * Yes, extract the value
		 */
		var start = pos + name.length + 1;
		var end = cookies.indexOf(';', start);
		
		if (end == -1)
			end = cookies.length;
			
		value = cookies.substring(start, end);
		
		/*
		 * Unescape the value
		 */
		value = unescape(value);
    }
	
	return value;
}
/*
 * Store a cookie 
 */
function StoreCookie(name, value) {
    /* 
	 * Get the date for today
	 */
	var nextyear = new Date();
	nextyear.setFullYear(nextyear.getFullYear() + 1);
	
	var expires = "; expires=" + nextyear.toGMTString();
	
	/*
	 * Append the new cookie value
	 */
	var path = window.location.pathname;
	var indexOfTemplate = path.indexOf('template.php');
	path = path.substr(0, indexOfTemplate);
	document.cookie = name + "=" + value + expires + "; path=" + path;
}

