// name - name of the desired cookie
// * return string containing value of specified cookie or -1 if cookie does not exist
function getCookieValue (name) {
	var desiredCookie = name + "=";
	var cookieStartIndex = document.cookie.indexOf(desiredCookie);
	if (cookieStartIndex == -1) {
		return -1;  //cookie not found
	}
	return readCookie(name);  //cookie found
}

/* 
 * More Cookie functions
 */
/* ORIGINAL VERSION (without path option)
function createCookie(name, value, days) {
    var expires = '';
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        var expires = '; expires=' + date.toGMTString();
    }
    document.cookie = name + '=' + value + expires + '; path=/';
}
*/
/* MY version with optional path argument  */
function createCookie(name, value, days, path) {
    var expires = '';
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        var expires = '; expires=' + date.toGMTString();
    }
    if (!path) { var path='/'; }  //default path is full domain
    document.cookie = name + '=' + value + expires + '; path=' + path;
}

function readCookie(name) {
    var cookieCrumbs = document.cookie.split(';');
    var nameToFind = name + '=';
    for (var i = 0; i < cookieCrumbs.length; i++) {
        var crumb = cookieCrumbs[i];
        while (crumb.charAt(0) == ' ') {
            crumb = crumb.substring(1, crumb.length); /* delete spaces */
        }
        if (crumb.indexOf(nameToFind) == 0) {
            return crumb.substring(nameToFind.length, crumb.length);
        }
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, '', -1, '/');
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}