function readCookie(pattern) {
	var allCookies = document.cookie;
	var pos1 = allCookies.indexOf(pattern + "=");
	var val1 = null;
	if (pos1 != -1) {
		var start1 = pos1 + pattern.length + 1;
		var end1   = allCookies.indexOf(";", start1);
		if (end1 == -1) end1 = allCookies.length;
		val1 = allCookies.substring(start1, end1);	
	}
	
	return unescape(val1);
}

// store cookie value with optional details as needed
function writeCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

// utility function to retrieve an expiration date in proper
// format; pass three integer parameters for the number of days, hours,
// and minutes from now you want the cookie to expire (or negative
// values for a past date); all three parameters are required,
// so use zeros where appropriate
function getExpDate(days, hours, minutes) {
    var expDate = new Date( );
    if (typeof days == "number" && typeof hours == "number" && 
        typeof minutes == "number") {
        expDate.setDate(expDate.getDate( ) + parseInt(days));
        expDate.setHours(expDate.getHours( ) + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));
        return expDate.toGMTString( );
    }
}

function deleteCookie(name, path, domain) {  
	if (readCookie(name)) {  
		document.cookie = name + "=" +  
           ((path) ? "; path=" + path : "") +  
           ((domain) ? "; domain=" + domain : "") +  
           "; expires=Thu, 01-Jan-70 00:00:01 GMT" 
        }  
     }  

