//  Set user_id cookie
//  Expires in one year
//  Called by OnLoad in Classlist and Classlist2

<!--

// Function: Check to see if cookie already exists
function get_cookie(name_to_get) {

    var cookie_pair
    var cookie_name
    var cookie_value
    
    // Split all the cookies into an array
    var cookie_array = document.cookie.split("; ")
    
    // Run through the cookies
    for (counter = 0; counter < cookie_array.length; counter++) {
    
        // Split the cookie into a name/value pair
        cookie_pair = cookie_array[counter].split("=")
        cookie_name = cookie_pair[0]
        cookie_value = cookie_pair[1]
        
        // Compare the name with the name we want
        if (cookie_name == name_to_get) {
        
            // If this is the one, return the value
            return unescape(cookie_value)
        }
    }
    
    // If the cookie doesn't exist, return null
    return null
}

// MAIN FUNCTION: called by OnLoad 
function set_user_id () {

// Call get_cookie
// Get the user_name cookie
var user_id = get_cookie("user_id")

// If the cookie does not exist?
if (!user_id) {

    // Set a new cookie
	var date_obj = new Date()

	// user_id = today's date/time in millisecs followed by a two-digit random number
    	user_id = date_obj.getTime() + "." + Math.round (Math.random() * 100)

	var ms_to_expire = 365 * 24 * 60 * 60 * 1000
	date_obj.setTime(date_obj.getTime() + ms_to_expire)
	var expire_string = date_obj.toGMTString()

    	document.cookie = "user_id=" + escape(user_id) + "; expires=" + expire_string
  }
}

window.onload = set_user_id(); //create event listener
//-->

