function Set_Cookie( name, value, expires, path, domain, secure ) 
{ 
// set time, it's in milliseconds 
var today = new Date(); 
today.setTime( today.getTime() ); 
/* 
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24 
*/ 
if ( expires ) 
{ 
expires = expires * 1000 * 60 * 60 * 24; 
} 
var expires_date = new Date( today.getTime() + (expires) ); 
document.cookie = name + "=" +escape( value ) + 
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) + 
( ( secure ) ? ";secure" : "" ); 
} 
function Get_Cookie( check_name ) { 
// first we'll split this cookie up into name/value pairs 
// note: document.cookie only returns name=value, not the other components 
var a_all_cookies = document.cookie.split( ';' ); 
var a_temp_cookie = ''; 
var cookie_name = ''; 
var cookie_value = ''; 
var b_cookie_found = false; // set boolean t/f default f 
for ( i = 0; i < a_all_cookies.length; i++ ) 
{ 
// now we'll split apart each name=value pair 
a_temp_cookie = a_all_cookies[i].split( '=' ); 
// and trim left/right whitespace while we're at it 
cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, ''); 
// if the extracted name matches passed check_name 
if ( cookie_name == check_name ) 
{ 
b_cookie_found = true; 
// we need to handle case where cookie has no value but exists (no = sign, that is): 
if ( a_temp_cookie.length > 1 ) 
{ 
cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') ); 
} 
// note that in cases where cookie is initialized but no value, null is returned 
return cookie_value; 
break; 
} 
a_temp_cookie = null; 
cookie_name = ''; 
} 
if ( !b_cookie_found ) 
{ 
return null; 
} 
} 
function unserialize(data){ 
var error = function (type, msg, filename, line){throw new this.window[type](msg, filename, line);}; 
var read_until = function (data, offset, stopchr){ 
var buf = []; 
var chr = data.slice(offset, offset + 1); 
var i = 2; 
while (chr != stopchr) { 
if ((i+offset) > data.length) { 
error('Error', 'Invalid'); 
} 
buf.push(chr); 
chr = data.slice(offset + (i - 1),offset + i); 
i += 1; 
} 
return [buf.length, buf.join('')]; 
}; 
var read_chrs = function (data, offset, length){ 
var buf; 
buf = []; 
for(var i = 0;i < length;i++){ 
var chr = data.slice(offset + (i - 1),offset + i); 
buf.push(chr); 
} 
return [buf.length, buf.join('')]; 
}; 
var _unserialize = function (data, offset){ 
var readdata; 
var readData; 
var chrs = 0; 
var ccount; 
var stringlength; 
var keyandchrs; 
var keys; 
if(!offset) {offset = 0;} 
var dtype = (data.slice(offset, offset + 1)).toLowerCase(); 
var dataoffset = offset + 2; 
var typeconvert = new Function('x', 'return x'); 
switch(dtype){ 
case 'i': 
typeconvert = function (x) {return parseInt(x, 10);}; 
readData = read_until(data, dataoffset, ';'); 
chrs = readData[0]; 
readdata = readData[1]; 
dataoffset += chrs + 1; 
break; 
case 'b': 
typeconvert = function (x) {return parseInt(x, 10) == 1;}; 
readData = read_until(data, dataoffset, ';'); 
chrs = readData[0]; 
readdata = readData[1]; 
dataoffset += chrs + 1; 
break; 
case 'd': 
typeconvert = function (x) {return parseFloat(x);}; 
readData = read_until(data, dataoffset, ';'); 
chrs = readData[0]; 
readdata = readData[1]; 
dataoffset += chrs + 1; 
break; 
case 'n': 
readdata = null; 
break; 
case 's': 
ccount = read_until(data, dataoffset, ':'); 
chrs = ccount[0]; 
stringlength = ccount[1]; 
dataoffset += chrs + 2; 
readData = read_chrs(data, dataoffset+1, parseInt(stringlength, 10)); 
chrs = readData[0]; 
readdata = readData[1]; 
dataoffset += chrs + 2; 
if(chrs != parseInt(stringlength, 10) && chrs != readdata.length){ 
error('SyntaxError', 'String length mismatch'); 
} 
break; 
case 'a': 
readdata = {}; 
keyandchrs = read_until(data, dataoffset, ':'); 
chrs = keyandchrs[0]; 
keys = keyandchrs[1]; 
dataoffset += chrs + 2; 
for(var i = 0;i < parseInt(keys, 10);i++){ 
var kprops = _unserialize(data, dataoffset); 
var kchrs = kprops[1]; 
var key = kprops[2]; 
dataoffset += kchrs; 
var vprops = _unserialize(data, dataoffset); 
var vchrs = vprops[1]; 
var value = vprops[2]; 
dataoffset += vchrs; 
readdata[key] = value; 
} 
dataoffset += 1; 
break; 
default: 
error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype); 
break; 
} 
return [dtype, dataoffset - offset, typeconvert(readdata)]; 
}; 
return _unserialize(data, 0)[2]; 
} 
function serialize( mixed_value ) { 
var _getType = function( inp ) { 
var type = typeof inp, match; 
var key; 
if (type == 'object' && !inp) { 
return 'null'; 
} 
if (type == "object") { 
if (!inp.constructor) { 
return 'object'; 
} 
var cons = inp.constructor.toString(); 
match = cons.match(/(\w+)\(/); 
if (match) { 
cons = match[1].toLowerCase(); 
} 
var types = ["boolean", "number", "string", "array"]; 
for (key in types) { 
if (cons == types[key]) { 
type = types[key]; 
break; 
} 
} 
} 
return type; 
}; 
var type = _getType(mixed_value); 
var val, ktype = ''; 
switch (type) { 
case "function": 
val = ""; 
break; 
case "undefined": 
val = "N"; 
break; 
case "boolean": 
val = "b:" + (mixed_value ? "1" : "0"); 
break; 
case "number": 
val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value; 
break; 
case "string": 
val = "s:" + mixed_value.length + ":\"" + mixed_value + "\""; 
break; 
case "array": 
case "object": 
val = "a"; 
/* 
if (type == "object") { 
var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/); 
if (objname == undefined) { 
return; 
} 
objname[1] = serialize(objname[1]); 
val = "O" + objname[1].substring(1, objname[1].length - 1); 
} 
*/ 
var count = 0; 
var vals = ""; 
var okey; 
var key; 
for (key in mixed_value) { 
ktype = _getType(mixed_value[key]); 
if (ktype == "function") { 
continue; 
} 
okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key); 
vals += serialize(okey) + 
serialize(mixed_value[key]); 
count++; 
} 
val += ":" + count + ":{" + vals + "}"; 
break; 
} 
if (type != "object" && type != "array") { 
val += ";"; 
} 
return val; 
} 
