﻿var plcCookieName = "PLC",
    plAuthCookieName = "PLAUTH",
    plAuthValue = "OK",
    plcEmail = "email",
    plcItems = "basketItems",
    plcPrice = "basketPrice",
    plcUnregistered = "anonymous",
    plcZero = "0",
    pls_appName = "/",
    plcLoginLink = pls_appName + "User/Login.aspx",
    plcAccountLink = pls_appName + "Profiles/Default.aspx",
    plcBasketLink = pls_appName + "Cart.aspx",
    plcCookie;

//returns a singleton jQuery object from the
//json string stored in the cookie's value
function loadPlc() {
    if (plcCookie !== undefined)
        return plcCookie;
    var plc = $.cookie(plcCookieName);
    try {
        return plcCookie = plc === null ? null : jQuery(JSON.parse(plc));
    }
    catch (e) {
        return null;
    }
}

//gets the email value of the plcCookie object
function getPlcEmail() {
    var plc = loadPlc();
    return plc === null ? plcUnregistered : plc.attr(plcEmail);
}

//gets the basketItems value of the plcCookie object
function getPlcBasketItems() {
    var plc = loadPlc();
    return plc === null ? plcZero : plc.attr(plcItems);
}

//gets the basketPrice value of the plcCookie object
function getPlcBasketPrice() {
    var plc = loadPlc();
    return plc === null ? plcZero : plc.attr(plcPrice);
}

