﻿      

function createCookie(name, value, days)
{
    var expires = "";
    
    if (days) 
    {
        var date    = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        expires     = "; expires="+date.toGMTString();
    }
    
    document.cookie = name+"="+value+expires+"; path=/";
}

function deleteCookie(name)
{
    createCookie(name,"",-1);
}

function getCookie(name)
{
    if (document.cookie.length>0)
    {
        var start = document.cookie.indexOf(name + "=");
        
        if (start != -1)
        {
            start   = start + name.length+1;
            end     = document.cookie.indexOf(";", start);
            
            if (end == -1) 
            { 
                end=document.cookie.length; 
            }
            
            return unescape(document.cookie.substring(start,end));
        }
    }
    return "";
}
        
function setStylesheet(title)
{
    var stylesheets = document.getElementsByTagName("link");
    
    if (stylesheets != null && stylesheets.length > 0)
    {
        for (var i = 0; i < stylesheets.length; i++)
        {
            if (stylesheets[i].getAttribute("rel") == "alternate stylesheet")
            {
                stylesheets[i].disabled = true;              
            }

         if (stylesheets[i].getAttribute("title") != null) 
         {
                if (stylesheets[i].getAttribute("title").toLowerCase() == title) 
                {
                    stylesheets[i].disabled = false;
                }
            }
            
            createCookie("SiteTheme", title, 365);
        }
    }
}

