﻿///
/// <reference path="../Edentity.Global.js" />
/// <reference path="/External/jquery-1.4.1-vsdoc.js" />

Edentity.RegisterNamespace("Shoppers.Cookie");

(function(SC, $) {

    SC.Set = function(c_name, value, expireminutes) {
        var exdate = new Date();

        if (expireminutes == undefined) {
            expireminutes = -1;
        }

        if (expireminutes == -1) {
            exdate.setMinutes(exdate.getYear() + 10);
        }
        else {
            exdate.setMinutes(exdate.getMinutes() + expireminutes);
        }

        var domain = null;
        //if (CookieDomain != undefined && CookieDomain != null) {
        //    domain = CookieDomain;
        //}

        document.cookie = c_name + "=" + escape(value) +
            ((expireminutes == null) ? "expires=Thu, 01-Jan-1970 00:00:01 GMT" : ";expires=" + exdate.toGMTString()) +
            "; path=" + escape("/") + ((domain) ? ";domain=" + domain : "");
    };

    SC.Get = function(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;
                }
                return unescape(document.cookie.substring(c_start, c_end));
            }
        }
        return "";
    };

    SC.Clear = function(cookieName) {
        Shoppers.Cookie.Set(cookieName, '', null);
    };

    SC.SetPreferredStore = function(StoreID) {
        Shoppers.Cookie.Set("ShoppersMyStore", StoreID);
    };

    SC.GetPreferredStore = function() {
        return Shoppers.Cookie.Get("ShoppersMyStore");
    };
	
	/************************
	 * Amigo
	 ***********************/
	 
	SC.SetAmigoEntriesCookie = function(urls) {
		Shoppers.Cookie.Set("ShoppersAmigoEntries", urls, 60 * 24 * 365);
	};
	
	SC.GetAmigoEntriesCookie = function() {
		return Shoppers.Cookie.Get("ShoppersAmigoEntries");
	};
	
	/************************
	 * Birthday
	 ***********************/
	 
	SC.SetOptimumAuthCookie = function(urls) {
		Shoppers.Cookie.Set("ShoppersOptimumAuth", urls);
	};
	
	SC.GetOptimumAuthCookie = function() {
		return Shoppers.Cookie.Get("ShoppersOptimumAuth");
	};
	 
	SC.SetFTECookie = function(urls) {
		Shoppers.Cookie.Set("ShoppersFTE", urls);
	};
	
	SC.GetFTECookie = function() {
		return Shoppers.Cookie.Get("ShoppersFTE");
	};
	
	/************************
	 * Promo
	 ***********************/
	 
	SC.SetPromoCookie = function(urls) {
		Shoppers.Cookie.Set("ShoppersPromo", urls);
	};
	
	SC.GetPromoCookie = function() {
		return Shoppers.Cookie.Get("ShoppersPromo");
	};
	
	/************************
	 * Videos
	 ***********************/
	 
	SC.SetUGCRatingCookie = function(recordType, ids) {
		Shoppers.Cookie.Set("Shoppers" + recordType, ids, 60 * 24);
	};

	SC.GetUGCRatingCookie = function(recordType) {
		return Shoppers.Cookie.Get("Shoppers" + recordType);
	};
	 

})(Shoppers.Cookie, jQuery);

