﻿/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />

/// <reference path="jquery.intellisense.js"/>

if (window["console"] === undefined)
{
    window["console"] = function() {};
    console.log = function() {};
}

// FIX: a function the MS AJAX client-side library has a bug, the function 
// is redefined here to prevent the exception (a.disabled failes because a is undefined)
//var $$_onFormElementActive = Sys.WebForms.PageRequestManager.prototype._onFormElementActive;
//Sys.WebForms.PageRequestManager.prototype._onFormElementActive = function(a,c,d)
//{
//    this._onFormElementActiveFIXED = $$_onFormElementActive;
//    if (a !== undefined)
//    {
//        this._onFormElementActiveFIXED(a,c,d);
//    }
//};

// set up for cross-domain scripting (Same Origin Policy)
//if (window.location.hostname == 'www.kleenex.com')
//{
//    document.domain = 'www.kleenex.com';
//}

Type.registerNamespace('Kleenex');

// Kleenex Variables
Kleenex.Variables = {};
Kleenex.Variables.RootUrl = '/';
Kleenex.Variables.BlankUrl = '/Blank.aspx';
Kleenex.Variables.CloseModalUrl = '/CloseModal.aspx';
Kleenex.Variables.SecureCloseModalUrl = '/SecureCloseModal.aspx';
Kleenex.Variables.LIOHomeUrl = '/Let-It-Out/Default.aspx';
Kleenex.Variables.LIOCardCreationUrl = '/Let-It-Out/CardCreation.aspx';

Kleenex.Extend = function(destination, source)
{
    /// <summary>Extends one object with the properties from a source object</summary>
    /// <param name="destination">destination</param>
    /// <param name="source">source</param>
    /// <returns type="object">object</returns>
    for (var property in source.prototype) 
    {
        if (destination.prototype[property] === undefined)
        {
            destination.prototype[property] = source.prototype[property];
        }
    }
    return destination;
};

Kleenex.Core = function() {};
Kleenex.Core.prototype =
{
    Name : 'Kleenex.Core',
    __typeName : 'Kleenex.Core',
    __class : true,
    Display : function() 
    {
    /// <summary>Stub for Display</summary>
    },
    ShowError : $Kleenex_ShowError,
    ErrorHandler : $Kleenex_ErrorHandler,
    InitializeServices : function()
    {
        this.MemberService = Kleenex.Services.MemberService;
        this.MemberService.set_defaultUserContext(this);
        this.MemberService.set_defaultFailedCallback(this.ErrorHandler);
    
        this.CardService = Kleenex.Services.CardService;
        this.CardService.set_defaultUserContext(this);
        this.CardService.set_defaultFailedCallback(this.ErrorHandler);
        
        this.QuickReleaseService = Kleenex.Services.QuickReleaseService;
        this.QuickReleaseService.set_defaultUserContext(this);
        this.QuickReleaseService.set_defaultFailedCallback(this.ErrorHandler);
        
        this.MailingListService = Kleenex.Services.MailingListService;
        this.MailingListService.set_defaultUserContext(this);
        this.MailingListService.set_defaultFailedCallback(this.ErrorHandler);
        
        this.EPrizeService = Kleenex.Services.EPrizeService;
        this.EPrizeService.set_defaultUserContext(this);
        this.EPrizeService.set_defaultFailedCallback(this.ErrorHandler);
    },
    AttachEvents : function()
    {
    },
    Display : function()
    {
    },
    Initialize : function()
    {
        this.PreInitialize();
        this.InitializeServices();
        this.AttachEvents();
        this.Display();
        this.PostInitialize();
    },
    PreInitialize : function()
    {
    },
    PostInitialize : function()
    {
    },
    ShowMask: function() 
    {
        // create the mask if it is not on the page yet
        if ($('div#Mask').length === 0)
        {
            var maskContent = '<div id="Mask" style="display: none;"></div>';
            $('form:first').prepend(maskContent);
        }
        var mask = $('#Mask');
        mask.css("position", "absolute").
            css("width", "100%").
            css("height", $(document).height()).
            css("top", 0).
            css("left", 0).
            css("z-index", "2000").
            css("overflow", "hidden").
            show().
            fadeTo(100, 0.65);
    },
    HideMask: function() 
    {
        $('#Mask').hide();
    },
    ShowOverlayFrame : function(url)
    {
        var __app = this;
        
        if ($('div#Frame').length === 0)
        {
            var frameContent = '<div id="Frame" style="display: none;">' +
                '<iframe src="" frameborder="0" ALLOWTRANSPARENCY="true"></iframe>' +
                '</div>';
            $('form:first').prepend(frameContent);
        }
        this.ShowMask();
        
        var width = ($(window).width() - 45) + 'px';
        var height = ($(window).height() - 45) + 'px';
        var scrollTop = $(window).scrollTop();
        
        $('#Frame iframe').css('width', width).css('height', height).attr('src', url);
        
        $('#Frame').css('position', 'absolute').
            css('top', (scrollTop + 30) + 'px').
            css('left', '30px').
            css('z-index', '2005').
            show();
    },
    HideOverlayFrame : function()
    {
        $('#Frame').fadeOut();
        $('#Frame iframe').attr('src', Kleenex.Variables.BlankUrl);
        this.HideMask();
    }
};

Kleenex.UserControl = function() {};
Kleenex.UserControl.prototype =
{
    Name : 'Kleenex.UserControl',
    __typeName : 'Kleenex.UserControl',
    __class : true,
    ClientID : 'undefined',
    Initialize : function()
    {
        this.InitializeServices();
        var k = Kleenex.GetApplication();
        k.RegisterUserControl(this);
        this.AttachEvents();
        this.Display();
    },
    ChangeLoginStatus : function(isAuthenticated)
    {
    }
};

// inherit from the core
Kleenex.Extend(Kleenex.UserControl, Kleenex.Core);
