
function readCookie(name) {

	// declare variable to set the <name>= value
	var start = document.cookie.indexOf(name + "=");

	// Det the index if the cookie name is found
	if (start == -1){
		return "";
	}  

	// Get the first character of the cookie
	start = document.cookie.indexOf("=", start) + 1;

	// Read to the end of the cookie
	var end = document.cookie.indexOf(";", start);
	if (end == -1){
		end = document.cookie.length;
	}
	// Get the cookie value, reversing the escaped format by
	// using the unescape method
	var value = unescape(document.cookie.substring(start, end));
	if(value == null){
		return "";
	}
	else{
		return value;
	}
}

function setCookie (name, value, hours, path, domain, secure) {

	if(hours) {
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.

} 