//Retrieves cookie data

function getCookieData(name) {
    
    //Check if the cookie string length is longer than 0
    
    if(document.cookie.length > 0) {
        
        //Check for the '=' delimeter
        
        cookieStart     =   document.cookie.indexOf(name + "=");
        
        //If cookies exist, handle them
        
        if(cookieStart != -1) {
            
            //Find the start and the end of the specified cookie
            
            cookieStart     =   cookieStart + name.length + 1;
            cookieEnd       =   document.cookie.indexOf(";", cookieStart);
            
            //Create the cookie's string end
            
            if(cookieEnd == -1) cookieEnd   =   document.cookie.length;
            
            //Return the cookie data string
            
            return unescape(document.cookie.substring(cookieStart, cookieEnd));
            
        }
        else return false;
        
    }
    else return false;
    
}



//Set the data of a cookie

function setCookieData(name, value, expires, path, domain, secure) {
    
    //Set the current time
    
    var today       =   new Date();
    today.setTime(today.getTime());

    //Set the expiration time
    
    if(expires) expires     =   expires * 1000 * 60 * 60 * 24;
    var expirationDate      =   new Date(today.getTime() + (expires));
    
    //Create the cookie
    
    document.cookie         =   name + "=" + escape(value) + ((expires) ? ";expires=" + expirationDate.toGMTString() : "") + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ((secure) ? ";secure" : "");
    
}

