function retrieveCookie( cookieName ) {
    /* retrieved in the format
    cookieName4=value; cookieName3=value; cookieName2=value; cookieName1=value
    only cookies for this domain and path will be retrieved */
    var rtnVal = null
    var cookieJar = document.cookie.split( "; " );
    for( var x = 0; x < cookieJar.length; x++ ) {
        var oneCookie = cookieJar[x].split( "=" );
        if( oneCookie[0] == escape( cookieName ) ) {
            rtnVal = unescape(oneCookie[1]);
        }
    }
    //alert(rtnVal)
    return rtnVal;
}

function setCookie( cookieName, cookieValue, lifeTime, path, domain, isSecure ) {
    //alert(cookieValue)
    path = "/"
    if( !cookieName ) { return false; }
    if( lifeTime == "delete" ) { lifeTime = -10; } //this is in the past. Expires immediately.
    /* This next line sets the cookie but does not overwrite other cookies.
    syntax: cookieName=cookieValue[;expires=dataAsString[;path=pathAsString[;domain=domainAsString[;secure]]]]
    Because of the way that document.cookie behaves, writing this here is equivalent to writing
    document.cookie = whatIAmWritingNow + "; " + document.cookie; */
    document.cookie = escape( cookieName ) + "=" + escape( cookieValue ) +
        ( lifeTime ? ";expires=" + ( new Date( ( new Date() ).getTime() + ( 10000 * lifeTime ) ) ).toGMTString() : "" ) +
        ( path ? ";path=" + path : "") + ( domain ? ";domain=" + domain : "") +
        ( isSecure ? ";secure" : "");
    //check if the cookie has been set/deleted as required
    if( lifeTime < 0 ) { if( typeof( retrieveCookie( cookieName ) ) == "string" ) { return false; } return true; }
    if( typeof( retrieveCookie( cookieName ) ) == "string" ) { return true; } return false;
}