﻿var Landor = Landor || {};

Landor.Canvas = function (container, backgroundContainer, tileSize, margin)
{
    this._container = $(container);
    this._backgroundContainer = $(backgroundContainer);
    this._tileSize = tileSize;
    this._margin = margin;
    this._layoutSize = this._tileSize + this._margin;
    this._backgroundWidth = 0;
    this._backgroundHeight = 0;
    this._windowWidth = $(window).width();
    this._windowHeight = $(window).height();
    this._templateHeight = 0;

    this._clickedTile = null;
    this._showContent = null;
    this._contentArea = null;
    this._contentBody = null;
    this._contentLeft = null;

    this._leftNav = null;
    this._filterIds = new Array();
    this._values = new Array();

    this._locationHref = null;
    this._cookieName = "Landor.Location";

    $("div.contentBox:not(.popUpContainer)", this._container).live({ "click" : this._ClickHandler, "mouseover" : $.proxy(this._HoverHandler, this) });
    this._backgroundContainer.live({ "click" : this._ClickHandler });
    $("div.contentBox", this._backgroundContainer).live("mouseover", $.proxy(this._HoverHandler, this));
}

Landor.Canvas.PageCanvasTiles = function(index, size)
{
    var data = { "url": window.location.hash, "pageIndex": index, "pageSize": size };

    if (0 != canvas._leftNav._filterIds.length)
    {
        data["filters"] = canvas._leftNav._filterIds;
        data["values"] = canvas._leftNav._values;
    }

    $.ajax({
        'url': '/data-services/clientservice.svc/getdocumentcontent',
        'context': this,
        'type': 'POST',
        'contentType': 'application/json',
        'dataType': 'json',
        'data': JSON.stringify(data),
        'success': function (content)
        {
            if (null == content || null == content.d)
            {
                return;
            }

            canvas.ClearTemplateContent();

            if(null != content.d.HtmlContent && 0 != content.d.HtmlContent.length)
            {
                canvas.DisplayContent(content.d.HtmlContent);
            }
            else if(null != content.d.ContentViews && 0 != content.d.ContentViews.length)
            {
                canvas.LayoutTiles(content.d.ContentViews);
            }
        },
        'error': function (jqXHR, textStatus, errorThrown)
        {
            alert(textStatus);
            alert(errorThrown);
        }
    });
}

Landor.Canvas.prototype =
{
    LayoutTiles: function (tileContent)
    {
        var width = this._GetWidth();
        var height = this._windowHeight;

        if(null == tileContent || 0 == tileContent.length)
        {
            this._GetTileContent(width, height, 0, true, $.proxy(function (content)
                {
                    this._BuildCanvas(content);
                }, this));
        }
        else
        {
            this._BuildCanvas(tileContent, true);
        }
    },

    Resize: function (overloadHeight, overloadWidth)
    {
        this._windowWidth = $(window).width();
        this._windowHeight = $(window).height();

        var newWidth = null == overloadWidth ? this._windowWidth : overloadWidth;
        var newHeight = null == overloadHeight ? this._windowHeight : overloadHeight;

        if (0 == this._backgroundWidth && 0 == this._backgroundHeight)
        {
            return;
        }

        var top = 0;
        var left = this._backgroundWidth;
        var originalWidth = this._backgroundWidth;

        var newTiles = new Array();

        while (left < newWidth)
        {
            while (top < newHeight)
            {
                newTiles.push({ "Top" : top, "Left" : left });
                top += this._layoutSize;
            }

            top = 0;
            left += this._layoutSize;

            this._backgroundWidth = left;
        }

        top = this._backgroundHeight;
		left = 0;

        while (top < newHeight)
        {
            while (left < originalWidth)
            {
                newTiles.push({ "Top" : top, "Left" : left });
                left += this._layoutSize;
            }

            top += this._layoutSize;
            left = 0;

            this._backgroundHeight = top;
        }

        if (0 != newTiles.length)
        {
            var tiles = "";
            var tileCount = Math.ceil(this._windowWidth / this._layoutSize);

            this._GetTileContent(0, 0, newTiles.length, false, $.proxy(function (content, clearTiles)
            {
                for (var i = 0; i < newTiles.length; ++i)
                {
                    var tileInfo = newTiles[i];

                    tiles += this._CreateNewTile({ "Top" : tileInfo.Top, "Left" : tileInfo.Left, "Height" : this._tileSize, "Width" : this._tileSize, "ZIndex" : 0, "Html" : content[i].Html }, false, false);
                }

                var childCount = this._backgroundContainer.children().length;
                $(this._backgroundContainer.children()[childCount - 1]).append(tiles);

                var newBackgroundTiles = $(this._backgroundContainer.children()[childCount]).children();
                var animatedTiles = new Array();

                for(tileCount; tileCount < newBackgroundTiles.length; ++tileCount)
                {
                    var tile = $(newBackgroundTiles[tileCount]);
                    var isVisible = this._IsTileVisible(tile.offset().top, tile.height());

                    if(true == isVisible)
                    {
                        animatedTiles.push(tile);
                    }

                    this._AnimateTiles(animatedTiles);
                }

                this._InitCaptions(newBackgroundTiles);

                var stool = $("#stool", this._backgroundContainer.children()[0]);

                if(0 != stool.length)
                {
                    var offset = stool.offset();

                    offset.top = this._GetHeight() + 50;
                    stool.offset(offset);
                }
            }, this));
        }        
        
        this._CenterTiles();
    },

    HashChangedCallback: function (e)
    {
        var hash_str = e.fragment;

        if (null != this._contentArea)
        {
            this._contentArea.remove();
            this._contentArea = null;
        }

        $('div', this._container).not('.popUpContainer').remove();

        this._GetTileContent(this._GetWidth(), this._windowHeight, 0, true, $.proxy(function (content)
        {
            $('div', this._container).not('.popUpContainer').remove();

            this._BuildCanvas(content);

            if (null != this._clickedTile && '#' != window.location.hash)
            {                
                if(true == this._clickedTile.hasClass('hasContent'))
                {
                    this.DisplayContent();
                }
            }
        }, this));
    },

    DisplayContent: function (contentBody)
    {
        if (null != contentBody)
        {
            this._contentBody = contentBody;
        }

        if (null != this._clickedTile)
        {
            this._contentArea = $(this._clickedTile).clone();
            this._container.append(this._contentArea);
        }

        if (null == this._contentArea)
        {
            this._contentArea = $('<div class="contentBox" style="top: 154px; left: ' + this._contentLeft + 154 + 'px;"></div>');
            this._container.append(this._contentArea);
        }

        if (null != this._contentBody)
        {
            this._contentArea.empty();
            this._contentArea.append(this._contentBody);
        }

        this._contentArea.addClass('popUpContainer');
        this._contentArea.css('z-index', '');
        this._contentArea.css("height", "auto");

        var oldHeight = this._contentArea.height();
        var newHeight = this._layoutSize * Math.ceil(oldHeight / this._layoutSize);

        if(newHeight > this._templateHeight)
        {
            this._templateHeight = newHeight;
        }

        this._contentArea.css("height", newHeight);

        this._contentArea.animate({
            top: 154,
            left: this._contentLeft + 147,
            height: this._contentArea.height(),
            width: 728
        }, { duration: 400 });

        //if(newHeight > this._backgroundHeight)
        {
            this.Resize(newHeight + this._layoutSize + this._margin);
        }

        this._clickedTile = null;
        this._contentBody = null;
        this._showContent = null;

        var newURL = 'https://twitter.com/share?url=' + encodeURIComponent(window.location) + '&text=' + encodeURIComponent('Check out Landor!');
        $('#sharePopupTwitter').attr('href', newURL);
        newURL = 'https://www.facebook.com/sharer.php?u=' + encodeURIComponent(window.location) + '&t=' + encodeURIComponent('Check out Landor!');
        $('#sharePopupFacebook').attr('href', newURL);
        newURL = 'mailto:?subject=Landor.com Content&body=Check out this content I found on Landor: ' + encodeURIComponent(window.location);
        $('#sharePopupEmail').attr('href', newURL);
        newURL = 'https://plusone.google.com/_/+1/confirm?hl=en&url=' + encodeURIComponent(window.location) + '&title=' + encodeURIComponent('Check out Landor!');
		$('#sharePopupGoogle').attr('href', newURL);
    },

    ClearTemplateContent: function ()
    {
        var templateContent = $("div.contentBox:not([id=t0])", this._container).not(".popUpContainer");

        templateContent.each(function (i, tile)
        {
            $(tile).remove();
        });
    },

    SetFilters: function (filterKeys, filterValues)
    {
        this._filterKeys = filterKeys;
        this._filterValues = filterValues;
    },

    SetLocation: function (locationName, locationHref)
    {
        this._locationHref = locationHref;

        CreateCookie(this._cookieName, locationName + ':' + locationHref);
    },

    ClearLocation: function ()
    {
        this._locationHref = null;

        EraseCookie(this._cookieName);
    },

    _GetTileContent: function (width, height, count, loadTemplateContent, callback)
    {
        var data = { 'url': window.location.hash, 'width': width, 'height': height, 'count': count };

        if (null != loadTemplateContent && true == loadTemplateContent)
        {
            data['loadTemplateContent'] = loadTemplateContent;
        }

        if (null != this._filterKeys && 0 != this._filterKeys.length && null != this._filterValues && 0 != this._filterValues.length)
        {
            data['filters'] = this._filterKeys;
            data['values'] = this._filterValues;
        }

        if (null != this._locationHref && 0 != this._locationHref.length)
        {
            data['location'] = this._locationHref;
        }

        $.ajax({
            'url': '/data-services/clientservice.svc/gettilecontent',
            'context': this,
            'type': 'POST',
            'contentType': 'application/json',
            'dataType': 'json',
            'data': JSON.stringify(data),
            'success': function (content)
            {
                if (null == content || null == content.d)
                {
                    return;
                }

                this._filterKeys = null;
                this._filterValues = null;

                if(null != content.d.Title)
                {
                    $("title").html(content.d.Title);
                }

                callback(content.d.ContentViews);
            },
            'error': function (jqXHR, textStatus, errorThrown)
            {
                alert(textStatus);
                alert(errorThrown);
            }
        });
    },

    _BuildCanvas: function (tiles, templateOnly)
    {
        var templateTemp = "";
        var backgroundTemp = "";

        this._templateHeight = this._margin;

        if(true != templateOnly)
        {
            this._backgroundWidth = this._margin;
            this._backgroundHeight = this._margin;
        }

        for (var i = 0; i < tiles.length; ++i)
        {
            var tileInfo = tiles[i];

            if (null != tileInfo.IsContent && true == tileInfo.IsContent)
            {
                if (null == this._clickedTile)
                {
                    this._contentArea = $(this._CreateNewTile(tileInfo));
                    this._container.append(this._contentArea);
                }
                else
                {
                    this._contentBody = tileInfo.Html;
                }
            }
            else if (null != tileInfo.Id)
            {
                templateTemp += this._CreateNewTile(tileInfo, false, true);
            }
            else if(true != templateOnly)
            {
                backgroundTemp += this._CreateNewTile(tileInfo, true, false);
            }
        }

        this._container.append("<div>" + templateTemp + "</div>");

        var leftNav = $(".leftNav", this._container);

        if (0 != leftNav.length && true != templateOnly)
        {
            this._leftNav = new Landor.LeftNav(leftNav, this);
        }

        if(true != templateOnly)
        {
            this._CenterTiles();
        }
        else
        {
            this._ShiftTiles($("div.contentBox[id!=t0]", this._container));
        }

        if (null != this._contentArea || (null != this._clickedTile && true == this._clickedTile.hasClass("hasContent")))
        {
            this.DisplayContent();
        }

        if(true != templateOnly)
        {
            this._backgroundContainer.append("<div>" + backgroundTemp + "</div>");
            
            var index = this._backgroundContainer.children().length;
            var backgroundTiles = $(this._backgroundContainer.children()[index > 1 ? index - 1 : 0]).children();

            var animatedTiles = new Array();
        
            for(var i = 0; i < backgroundTiles.length - 1; ++i)
            {
                var backgroundTile = $(backgroundTiles[i]);
                
                animatedTiles.push(backgroundTile);
            }

            this._AnimateTiles(animatedTiles);

            if(index > 1)
            {
                setTimeout($.proxy(function()
                    {
                        var children = this._backgroundContainer.children();

                        for(var i = 0; i < children.length - 1; ++i)
                        {
                            $(children[i]).remove();
                        }
                    }, this), 2000);
            }
        }

        var stool = $("#stool", this._backgroundContainer.children()[index > 1 ? index - 1 : 0]);
        var height = this._GetHeight();

        if(0 == stool.length)
        {
            $(this._backgroundContainer.children()[index > 1 ? index - 1 : 0]).append('<div id="stool" style="position: absolute; height: 59px; width: 100%; top: ' + height + 'px;"></div>');
        }

        if(height > this._backgroundHeight && true != templateOnly)
        {
            this.Resize(height);
        }

        this._InitCaptions($('div.graphicModuleTextDiv'));

        $('#top').click(function ()
        {
            $("body,html,document").scrollTop();
        });

        $("#englishLink").click(function ()
        {
            $("#english").show();
            $("#french").hide();
            return false;
        });

        $("#frenchLink").click(function ()
        {
            $("#french").show();
            $("#english").hide();
            return false;
        });

        this._ResizeLeftNav();
    },

    _InitCaptions: function(tiles)
    {
        var captions = $('div.graphicModuleTextDiv');

        for(var i = 0; i < captions.length; ++i)
        {
            var caption = $(captions[i]);
            var tile = $(caption.parents("div.contentBox"));

            var offset = caption.offset();
            offset.top = tile.height();
            caption.offset(offset);
        }
    },

    _CreateNewTile: function (tileInfo, hide, isTemplate)
    {
        if(null == isTemplate)
        {
            isTemplate = false;
        }

        var newTile = '<div class="contentBox';

        if(true == tileInfo.HasContent)
        {
            newTile += ' hasContent';
        }
        
        newTile += '"';

        if(null != tileInfo.Id)
        {
            newTile += ' id=t' + tileInfo.Id;
        }

        var xOffset = tileInfo.Left + this._margin;
        var yOffset = tileInfo.Top + this._margin;

        if(false == isTemplate)
        {
            if(yOffset + tileInfo.Height > this._backgroundHeight)
            {
                this._backgroundHeight = yOffset + tileInfo.Height;
            }

            if(xOffset + tileInfo.Width > this._backgroundWidth)
            {
                this._backgroundWidth = xOffset + tileInfo.Width;
            }
        }
        else
        {
            if(yOffset + tileInfo.Height > this._templateHeight)
            {
                this._templateHeight = yOffset + tileInfo.Height;
            }
        }
         
        newTile += ' style="top: ' + yOffset + 'px; left: ' + xOffset + 'px; width: ' + tileInfo.Width + 'px; height: ' + (0 != tileInfo.Height ? tileInfo.Height + 'px' : 'auto') + '; z-index: ' + tileInfo.ZIndex + ';';
        
        if(true == hide)
        {
            newTile += ' visibility: hidden;';
        }

        newTile += '">';
        
        if(null != tileInfo.Html)
        {
            newTile += tileInfo.Html;
        }
        
        newTile += '</div>';

        return newTile;
    },

    _AnimateTiles: function(tiles)
    {
        for(var i = 0; i < tiles.length; ++i)
        {
            var random = Math.floor(Math.random() * (1600 - 500 + 1) + 500);
            this._tileAnimateCallback(tiles[i], random);
        }
    },  

    _tileAnimateCallback: function (tile, random)
    {
        var a = $($("a", tile));
        a.delay(random).animate({ "opacity" : "0" }, { "duration" : 100, "complete" : function()
            {
                tile.css('visibility', 'visible');
                a.animate({ "opacity" : "1" }, { "duration" : 400 });
            } });
    },

    _ClickHandler: function(e)
    {
        $("body,html,document").scrollTop(0);
        
        var tile = $(e.target).parents("div.contentBox");

        if(0 == tile.length)
        {
            return;
        }

        var link = $(tile.children("a")[0]);

        if (1 == link.length && null != link.attr('href') && "#" == link.attr('href')[0] && 1 != link.attr('href').length)
        {
            canvas._clickedTile = $(link.parent());
        }
    },

    _HoverHandler: function(e)
    {
        var target = $(e.target);

        if (!target.data('init'))
        {
            target.data('init', true);

            var tile = target.parents("div.contentBox");

            tile.hoverIntent(this._HoverStartHandler, this._HoverEndHandler);
            tile.trigger('mouseover');
        }
    },

    _HoverStartHandler: function()
    {
        var caption = $(this).find('div.graphicModuleTextDiv');

        if (0 != caption.length)
        {
            var captionTop = $(this).height() - 70;

            caption.css('display', '');
            caption.css('z-index', 100);
            caption.stop().animate({ 'top': captionTop + 'px' }, { 'queue': false, 'duration': 100 });
        }

        var hidden = $(this).find('.hidden');

        if (0 != hidden.length)
        {
            hidden.stop().fadeTo(250, 1);
        }
    },

    _HoverEndHandler: function()
    {
        var caption = $(this).find('div.graphicModuleTextDiv');

        if (0 != caption.length)
        {
            var top = $(this).height();

            caption.css('z-index', -1);
            caption.stop().animate({ 'top': top + 'px' }, { 'queue': false, 'duration': 250 });
        }

        var hidden = $(this).find('.hidden');

        if (0 != hidden.length)
        {
            hidden.stop().fadeTo(800, 0);
        }
    },

    _IsTileVisible: function(top, height)
    {
        var docViewTop = $(window).scrollTop(); 
        var docViewBottom = docViewTop + this._windowHeight;
 
        return ((top + height) >= docViewTop && top <= docViewBottom); 
    },

    _CenterTiles: function ()
    {
        var contentLeft = null;
                
        var contentTiles = $("div.contentBox[id]", this._container);

        for (var i = 0; i < contentTiles.length; ++i)
        {
            var contentTile = $(contentTiles[i]);
            var offset = contentTile.offset();

            if (null == contentLeft || offset.left < contentLeft)
            {
                contentLeft = offset.left;
            }
        }

        var contentRight = contentLeft + (this._layoutSize * 7);

        var contentColumns = 7;
        var columns = Math.round(this._windowWidth / this._layoutSize);
        var padding = columns - contentColumns;

        var currentShift = (contentLeft - this._margin) / this._layoutSize;
        var shiftColumns = Math.floor(Math.floor(padding) / 2);

        if (shiftColumns >= 0)
        {
            var contentDelta = (shiftColumns * this._layoutSize) > 0 ? (shiftColumns * this._layoutSize) : 0;
            this._contentLeft = contentDelta + this._margin;

            for(var i = 0; i < contentTiles.length; ++i)
            {
                var tile = $(contentTiles[i]);
                var offset = tile.offset();

                var tileDelta = Math.abs(contentLeft - offset.left);
                offset.left = this._contentLeft + tileDelta;

                tile.offset(offset);
            }

            if (null != this._contentArea)
            {
                var offset = this._contentArea.offset();

                offset.left = this._contentLeft + this._layoutSize;

                this._contentArea.offset(offset);
            }

            $.event.trigger('canvasResize', { 'left': this._contentLeft });
        }
        else if (0 == shiftColumns && 0 == currentShift)
        {
            this._contentLeft = this._margin;
        }
    },

    _ShiftTiles: function(contentTiles)
    {
        for(var i = 0; i < contentTiles.length; ++i)
        {
            var tile = $(contentTiles[i]);
            var offset = tile.offset();

            offset.left += this._contentLeft - this._margin;

            tile.offset(offset);
        }
    },

    _ResizeLeftNav: function ()
    {
        var leftNav = $('.leftNav');

        if (0 == leftNav.length)
        {
            return;
        }

        var roundTo = 147;
        var oldHeight = leftNav.height();

        if (oldHeight % 140 !== 0)
        {
            leftNav.css("height", roundTo * Math.ceil(oldHeight / roundTo));
        }
    },

    _GetHeight: function ()
    {
        var height = this._backgroundHeight;
        var delta = this._templateHeight - this._backgroundHeight;

        if(delta >= 0)
        {
            height = this._templateHeight + this._layoutSize;
        }

        return height;
    },

    _GetWidth: function ()
    {
        var columns = Math.round(this._windowWidth / this._layoutSize);
        return columns * this._layoutSize;
    },    

    _GetSearchResults: function (term, callback)
    {
        var data = { 'searchTerm': term };

        $.ajax({
            'url': '/data-services/clientservice.svc/GetSearchResults',
            'context': this,
            'type': 'POST',
            'contentType': 'application/json',
            'dataType': 'json',
            'data': JSON.stringify(data),
            'success': function (content)
            {
                if (null == content || null == content.d)
                {
                    return;
                }
            },
            'error': function (jqXHR, textStatus, errorThrown)
            {
                alert(textStatus);
                alert(errorThrown);
            }
        });
    },

    SubmitContact: function (topic, comments, fName, lName, email, phone, city, country, jobTitle, company) 
    {
        var dataError = false;
        $('#contactTopic, #contactComments, #contactFirstName, #contactLastName, #contactEmail').css('borderWidth', '1px');
        $('#contactTopic, #contactComments, #contactFirstName, #contactLastName, #contactEmail').css('borderColor', '#F0F0F0');

        if (topic == '-1') {
            $('#contactTopic').css('borderWidth', '3px');
            $('#contactTopic').css('borderColor', '#FF0000');
            dataError = true;
        }
        if (comments == '') {
            $('#contactComments').css('borderWidth', '3px');
            $('#contactComments').css('borderColor', '#FF0000');
            dataError = true;
        }
        if (fName == '') {
            $('#contactFirstName').css('borderWidth', '3px');
            $('#contactFirstName').css('borderColor', '#FF0000');
            dataError = true;
        }
        if (lName == '') {
            $('#contactLastName').css('borderWidth', '3px');
            $('#contactLastName').css('borderColor', '#FF0000');
            dataError = true;
        }
        var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        if (!emailPattern.test(email)) {
            $('#contactEmail').css('borderWidth', '3px');
            $('#contactEmail').css('borderColor', '#FF0000');
            dataError = true;
        }

        if (dataError == true) {
            alert('Please fill out all required data');
            return;
        }

        var e = document.getElementById('contactTopic');
        var topicText = e.options[e.selectedIndex].text;

        var data = { "topic": topicText, "comments": comments, "fName": fName, "lName": lName, "email": email, "phone": phone, "city": city, "country": country, "jobTitle": jobTitle, "company": company };

        $.ajax({
            'url': '/data-services/clientservice.svc/SubmitContact',
            'context': this,
            'type': 'POST',
            'contentType': 'application/json',
            'dataType': 'json',
            'data': JSON.stringify(data),
            'success': function (content)
            {
                if (content.d == false) 
                {
                    alert('Contact Form Failed');
                    return;
                }
                else
                {
                    alert('Contact Form Successful');
                    $('#contactTopic').val('');
                    $('#contactComments').val('');
                    $('#contactFirstName').val('');
                    $('#contactLastName').val('');
                    $('#contactEmail').val('');
                    $('#contactPhone').val('');
                    $('#contactCity').val('');
                    $('#contactCountry').val('');
                    $('#contactJobTitle').val('');
                    $('#contactCompany').val('');
                }
            },
            'error': function (jqXHR, textStatus, errorThrown)
            {
                alert(textStatus);
                alert(errorThrown);
            }
        });
    },

    SubmitNewsletter: function (fName, lName, email, dropdown, callback) 
    {
        var dataError = false;
        $('#newsletterFirstName, #newsletterLastName, #newsletterEmail').css('borderWidth', '1px');
        $('#newsletterFirstName, #newsletterLastName, #newsletterEmail').css('borderColor', '#F0F0F0');

        if (fName == '') {
            $('#newsletterFirstName').css('borderWidth', '3px');
            $('#newsletterFirstName').css('borderColor', '#FF0000');
            dataError = true;
        }
        if (lName == '') {
            $('#newsletterLastName').css('borderWidth', '3px');
            $('#newsletterLastName').css('borderColor', '#FF0000');
            dataError = true;
        }
        var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        if (!emailPattern.test(email)) {
            $('#newsletterEmail').css('borderWidth', '3px');
            $('#newsletterEmail').css('borderColor', '#FF0000');
            dataError = true;
        }

        if (dataError == true) {
            alert('Please fill out all required data');
            return;
        }

        var data = { "fName": fName, "lName": lName, "email": email, "dropdown": dropdown };

        $.ajax({
            'url': '/data-services/clientservice.svc/SubmitNewsletter',
            'context': this,
            'type': 'POST',
            'contentType': 'application/json',
            'dataType': 'json',
            'data': JSON.stringify(data),
            'success': function (content)
            {
                if (content.d == false) 
                {
                    alert('Newsletter Form Failed');
                    return;
                }
                else
                {
                    alert('Newsletter Form Successful');
                    $('#newsletterFirstName').val('');
                    $('#newsletterLastName').val('');
                    $('#newsletterEmail').val('');
                    $('#newsletterDropdown').val('');
                }
            },
            'error': function (jqXHR, textStatus, errorThrown)
            {
                alert(textStatus);
                alert(errorThrown);
            }
        });
    }
}


