﻿function getCookie(name) 
{   
    var cookieValues = new RegExp(name + "=([^;]+)").exec(document.cookie);
    if (cookieValues)
    {
        // unescape our values
        var value = cookieValues[1].replace(/%0a|%0d|%25|%3b/ig, function(str, offset, s) { return unescape(str);});
        if (value != unescape(cookieValues[1]))
            {
                return cookieValues[1]; //wasn't us that escaped it
            }
        return value;
    }
    return null;
} 

function setCookie(name,value,expires,path,domain,secure) 
{
    value = value.replace(/[\n\r%;]+/g, function (str, offset, s) { return escape(str);}); //escape only special characters
    document.cookie = name + "=" + value
       + ((expires) ? ";expires=" + expires.toGMTString() : "")
       + ((path) ? ";path=" + path : "")
       + ((domain) ? ";domain=" + domain : "")
       + ((secure) ? ";secure" : "");
} 

function deleteCookie(name,path,domain) 
{
    if (getCookie(name)) 
        setCookie(name, '', new Date(0,0,0), path, domain);
} 

