﻿/*
*   GetCookie
*   @param cookieName - name of the cookie you are looking for
*   @return string - returns cookie value if it exists, null otherwise;
*/
function GetCookie (cookieName)
{
    var cookieValue = null
    if (document.cookie.indexOf(cookieName) == -1)
    {
        // there is no cookie by this name for this user
        return null;
    }
    else
    {
        // get the beginning index of the cookie by looking for the cookie name
        var cookieStart = document.cookie.indexOf(cookieName);
        // get the beginning index of the cookie value by looking for the equal sign after the name
        var cookieValStart = (document.cookie.indexOf("=", cookieStart) + 1);
        // get the end index of the cookie value by looking for the semi-colon after the value
        var cookieValEnd = document.cookie.indexOf(";", cookieStart);
        // if no semi-colon, then use the whole length
        if (cookieValEnd == -1)
        {
            cookieValEnd = document.cookie.length
        }
        // use substring to get the text between the two indices and that is the value of the cookie
        cookieValue = document.cookie.substring(cookieValStart,cookieValEnd);
        return cookieValue;
    }
}

/*
*   SetSessionCookie - Sets a session cookie w/ no expiration date so it just lasts while browser is open
*   @param _cookieName - name of the cookie
*   @param _cookieValue - value for the cookie
*/
function SetSessionCookie(_cookieName, _cookieValue)
{
    var expires = ""; /* this expires the cookie at the end of the session */
    document.cookie = _cookieName+"=" + _cookieValue+";expires="+expires;
}

/*
*   GetUrlVariableValue
*   @param variableName - name of query string variable to get value for
*   @return string - the value of the variableName , null if it can't find it
*/
function GetUrlVariableValue(variableName)
{
    var queryString = document.location.search.substring(1);
    var variableDictionary = queryString.split("&");
    for(i= 0; i<variableDictionary.length; i++)
    {
        var pair = variableDictionary[i].split("=");
        var name = pair[0];
        var value = pair[1];
        if(name == variableName)
        {
            //SetSessionCookie('isFromCorporate',value);
            return value;
        }
    }
    return null;
}


function GetMenuPlusCookie()
{
    var value = GetCookie('MenuPlus');
    if(value == "MenuPlus=MenuPlus") return true;
}


/* see if url variable 'isFromCorporate' evals to true , if so , set the proper style sheet */
var isFromCorporate = GetUrlVariableValue("isFromCorporate");
/* if url var is not set, check for cookie */
if(  isFromCorporate == null || isFromCorporate == false  )   isFromCorporate =  GetMenuPlusCookie();


/* get the style sheet LINK elements */
var defaultStyle  = document.getElementById('_defaultStyle');
var corporateStyle = document.getElementById('_corporateStyle');

if(isFromCorporate)
{
    /* set the active stylesheet */
    defaultStyle.disabled = true;
    corporateStyle.disabled = false;
}
else
{
   /* set the active stylesheet */
    defaultStyle.disabled = false;
    corporateStyle.disabled = true;
}


