﻿
/*This file deals with coookies management*/
//setCookie('username',username,365)
/* check whetehr cookie is enabled by client or not*/
function isCookiesEnabled()
{
    if( window.clientInformation.cookieEnabled ==false)
    {
        alert("Cookies not enabled on this system, You may feel inconveniency, surfing this site,\nplease enable cookies for better user experience.");
        return false;
    }
    else
        return true;
}

/*The parameters of the function above hold the name of the cookie, the value of the cookie, and the number of 
days until the cookie expires.*/
function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
    document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+";path=/");
    //alert(path);
    var domain;
    var secure;
	document.cookie = escape(c_name) + '=' + escape(value)
			+ (expiredays ? '; expires=' + expiredays.toGMTString() : '')
			+ ( '; path=/')
			+ (domain ? '; domain=' + domain : '')
			+ (secure ? '; secure' : '');
			+ (path ? '; path=' + path : '')
}

/*
The function above first checks if a cookie is stored at all in the document.cookie object. If the document.cookie 
object holds some cookies, then check to see if our specific cookie is stored. If our cookie is found, then return 
the value, if not - return an empty string.
*/
function getCookie(c_name)
{
    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
                //alert( unescape(document.cookie.substring(c_start,c_end)) );
            return unescape(document.cookie.substring(c_start,c_end))
        } 
        return "";
    }
    return "";
}
