﻿

//Function to set the cookie with the specified name, value and expirydays
function SetCookie(name, value, expiredays)
{
    try
    {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + expiredays);
        document.cookie = name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
    }
    catch(e)
    {
    }
}

//function to get cookie. The value passed is the required attribute name in the cookie
function getCookie(c_name)
{
    try
    {
        if (document.cookie.length > 0)
        {
            c_start = document.cookie.indexOf(c_name + "=");
            if (c_start != -1)
            { 
                c_start = c_start + c_name.length + 1; 
                c_end = document.cookie.indexOf(";",c_start);
                if (c_end == -1)
                {
                    c_end = document.cookie.length;
                }
                //Returns the cookie value
                return unescape(document.cookie.substring(c_start,c_end));
            } 
        }
    }
    catch(e)
    {
    }
    //If no cookie exists return empty string
    return "";
}


