//---------------------------------------------------- setting the cookie

function pad(inTxt,length) {
    var str = inTxt;
    while (str.length < length)
        str = str + ' ';
    return str;
}

function setCookie(name, value) {   
    var argv = setCookie.arguments;
    var argc = setCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null; 
    var path = (argc > 3) ? argv[3] : null; 
    var domain = (argc > 4) ? argv[4] : null; 
    var secure = (argc > 5) ? argv[5] : false;

    document.cookie = name + "=" + escape(value) + 
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
        ((path == null) ? "" : ("; path=" + path)) + 
        ((domain == null) ? "" : ("; domain=" + domain)) + 
       ((secure == true) ? "; secure" : "");
}

function register(userName, value) {

    var this_day_total = userName.substring(25,32)

    if (userName.substring(0,24) == "                        " ) {
        // The name is missing, so register this user as "Anonymous."
        userName = "Anonymous";
		// combine the name and the date again
		userName = pad(userName,25) + this_day_total 
    }

     // Set the expiration date to today.
     var expdate = new Date();
     var expUserName;

     if(userName.substring(0,24) == "myCookie") {                                            
		   // expire after 1 day for normal users - so they don't keep getting the intro
		   expdate.setTime(expdate.getTime() + (1000 * 60 * 60 * 24 * 1));  
		 }
		else {
           // Otherwise fo me set the expiration date (which JavaScript stores as milliseconds
           // to a date exactly one year in the future.
           expdate.setTime(expdate.getTime() + (1000 * 60 * 60 * 24 * 365)); 
		}   
		
     setCookie('myCookie', userName, expdate);  
 
}

//------------------------------------------------- get the cookie
// test for the cookie
function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }

    return unescape(document.cookie.substring(offset, endstr));
}

function getCookie (name)  {
    // Pick apart the cookie text.  We do this by
    // finding the
    var arg = name + "=";  

    var argLength = arg.length;
    var cookieLength = document.cookie.length;

    var i = 0;
    while (i < cookieLength)  {
        var j = i + argLength;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j)
            i = document.cookie.indexOf(" ", i) + 1;
        }
        if (i == 0) {
            break
        }
     } 
     return null;
}


