|
// Generic function to create cookies with a variable name, the value, and time for the cookie to expire. |
|
setCookie: function(c_name, value, exdays){ |
|
var exdate = new Date(); |
|
exdate.setDate(exdate.getDate() + exdays); |
|
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()) + "; path=/"; |
|
document.cookie = c_name + "=" + c_value; |
|
}, |
|
|
|
// Generic function to get a cookie by it's name and load the value from it. |
|
getCookie: function(c_name){ |
|
var i, x, y, ARRcookies = document.cookie.split(";"); |
|
var returnval = ""; |
|
for (i = 0; i < ARRcookies.length; i++){ |
|
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("=")); |
|
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1); |
|
x = x.replace(/^\s+|\s+$/g, ""); |
|
if (x == c_name){ |
|
returnval = unescape(y); |
|
} |
|
} |
|
return returnval; |
|
}, |
|
|
|
// checks if cookies are enabled, returns boolean value |
|
cookiesEnabled: function() { |
|
// first we'll split this cookie up into name/value pairs |
|
// note: document.cookie only returns name=value, not the other components |
|
var all_cookies = document.cookie.split(';'); |
|
var temp_cookie = ''; |
|
var cookie_name = ''; |
|
var cookie_value = ''; |
|
var cookie_found = false; // set boolean t/f default f |
|
|
|
for (i = 0; i < all_cookies.length; i++){ |
|
// now we'll split apart each name=value pair |
|
temp_cookie = all_cookies[i].split('='); |
|
// and trim left/right whitespace while we're at it |
|
cookie_name = temp_cookie[0].replace(/^\s+|\s+$/g, ''); |
|
// if the extracted name matches the session cookie name |
|
if (cookie_name == 'sid'){ |
|
// we need to handle case where cookie has no value but exists (no = sign, that is): |
|
if (temp_cookie.length > 1){ |
|
cookie_value = unescape(temp_cookie[1].replace(/^\s+|\s+$/g, '')); |
|
} |
|
if (cookie_value.length > 0){ |
|
cookie_found = true; |
|
break; |
|
} |
|
} |
|
temp_cookie = null; |
|
cookie_name = ''; |
|
} |
|
return cookie_found; |
|
}, |