﻿/// <reference path="jquery.intellisense.js"/>
/// <reference path="jquery.easing.1.3.js"/>
/// <reference path="jquery.dimensions.js"/>
/// <reference path="Kleenex.Core.js"/>

Kleenex.LetItOutPromo = function(clientId, promoUrl, registrationUrl)
{
    this.ClientID = clientId;
    this.Selector = "#" + clientId;
    this.PromoUrl = promoUrl;
    this.RegistrationUrl = registrationUrl;
    this.Initialize();
};

Kleenex.LetItOutPromo.prototype =
{
    Name : 'Kleenex.LetItOutPromo',
    __typeName : 'Kleenex.LetItOutPromo',
    __class : true,
    Display : function()
    {
        var isAuthenticated = Kleenex.GetApplication().IsUserAuthenticated();
        if(isAuthenticated)
        {
            $('#promoViewNotLoggedIn').hide();
            $('#promoViewLoggedIn').show();
        }
        else
        {
            $('#promoViewNotLoggedIn').show();
            $('#promoViewLoggedIn').hide();
        }
    },
    AttachEvents : function()
    {
        var __app = this;
        
        $('.lioPromoSigninButton').click(function()
        {
            //Kleenex.ShowModal(__app.PromoUrl, true, 'letitoutpromo');
            Kleenex.ShowModal('/NA/Promotions-Special-Offers/letitoutpromo.aspx', true, 'letitoutpromo');
        });
        
        $('.lioPromoRegisterButton').click(function()
        {
            Kleenex.ShowModal(__app.RegistrationUrl, false, 'letitoutpromo');
        });

        $('.lioPromoEnterButton').click(function()
        {
            __app.EPrizeService.DisplayInline(function(result)
            {
                if(result)
                {
                    // ePrize Hack:  uncomment this line to enter the promotion via a page redirect (same window)
                    __app.EPrizeService.Register(function(e){
                        if(e){
                            window.parent.location = __app.PromoUrl;
                        }
                    });
                }
                else
                {
                    // ePrize Hack:  uncomment this line to enter the promotion via a pop up window
                    // the value in the web.config, Kleenex.Url.EPrizePromoDestination should be configured
                    // with a url that points to the LetItOutPromo.aspx page.  When displaying inline,
                    // the url will be set to the eprize server location.
                    Kleenex.ShowModal(__app.PromoUrl, true, 'letitoutpromo');
                }
            });
        });
    },
    ChangeLoginStatus : function(isAuthenticated)
    {
        if (isAuthenticated)
        {
            $('#promoViewNotLoggedIn').hide();
            $('#promoViewLoggedIn').show();
        }
    }
};

Kleenex.Extend(Kleenex.LetItOutPromo, Kleenex.UserControl);