

//for required assets in the resource library
function ResourceLibrary_AssetToAccess(locationOfAssetToAccess, typeOfAssetToAccess, assetTitle) {
    $("#LocationOfAssetToAccess").val(locationOfAssetToAccess);
    $("#TypeOfAssetToAccess").val(typeOfAssetToAccess);
    $("#AssetTitle").val(assetTitle);
}

$(document).ready(function () {




    //Submit contact form
    $('#submitContactForm').click(function (event) {

        event.preventDefault();

        var ContactSubmissionModel = {
            FirstName: $('#commentForm').find('#FirstName').val(),
            LastName: $('#commentForm').find('#LastName').val(),
            Email: $('#commentForm').find('#Email').val(),
            PhoneNumber: $('#commentForm').find('#PhoneNumber').val(),
            Comment: $('#commentForm').find('#Comment').val()
        };

        if ($('#commentForm').valid()) {
            //Set updating animation
            $('#contactFormContainer').block({
                message: '<img style="position: relative; top: 50%;" src="/Content/Images/Layout/ajax-loader.gif">',
                css: {
                    border: 'none',
                    backgroundColor: '#ebebeb',
                    width: '100%',
                    height: '100%',
                    opacity: .5
                }
            });

            //POST
            $.ajax({
                url: "/Home/ContactSubmission",
                type: "POST",
                data: JSON.stringify(ContactSubmissionModel),
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (response) {
                    if (response.success == "false") {
                        jQuery.each(response.message, function () {
                            jQuery.each(this.Errors, function () {
                                $('#contact-form-validation-summary').html(this.ErrorMessage);
                            });
                        });

                        $('#contact-form-validation-summary').fadeIn()
                        $('#contactFormContainer').unblock();
                    }
                    else if (response.success == "true") {
						_gaq.push(['_trackEvent', 'Form', 'Form Submitted', 'Contact Us']);
                        $('#contactFormContainer').html('Your message has been sent').fadeIn();
                        $('#contactFormContainer').unblock();
						
                    }

                }
            });
        }
        else {
            $('#contactFormContainer').unblock();
        }
    });






    //Submit Newsletter form
    $('#submitNewsletterForm').click(function (event) {

        event.preventDefault();

        var NewsletterSubmissionModel = {
            FirstName: $('#newsletterForm').find('#FirstName').val(),
            LastName: $('#newsletterForm').find('#LastName').val(),
            Email: $('#newsletterForm').find('#Email').val()
        };

        if ($("#newsletterForm").valid()) {

            //Set updating animation
            $('#newsletterForm').block({
                message: '<img style="position: relative; top: 50%;" src="/Content/Images/Layout/ajax-loader.gif">',
                css: {
                    border: 'none',
                    backgroundColor: '#ebebeb',
                    width: '70%',
                    height: '100%',
                    opacity: .5
                }
            });

            //POST
            $.ajax({
                url: "/Home/NewsletterSubmission",
                type: "POST",
                data: JSON.stringify(NewsletterSubmissionModel),
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (response) {
                    if (response.success == "false") {
                        jQuery.each(response.message, function () {
                            jQuery.each(this.Errors, function () {
                                $('#newsletter-form-validation-summary').html(this.ErrorMessage);
                            });
                        });

                        $('#newsletter-form-validation-summary').fadeIn()
                        $('#newsletterForm').unblock();
                    }
                    else if (response.success == "true") {
                        _gaq.push(['_trackEvent', 'Form', 'Form Submitted', 'Newsletter']);
                        $('#newsletterForm').html('<br />Thank you for signing up to our newsletter').fadeIn();
                        $('#newsletterForm').unblock();
                    }
                }
            });
        }
        else {
            $('#newsletterForm').unblock();
        }
    });




    //Submit Resource Library form
    $('#submitResourceLibraryForm').click(function (event) {

        event.preventDefault();

        var ResourceLibrarySubmissionModel = {
            FirstName: $('#formResourceLibrary').find('#FirstName').val(),
            LastName: $('#formResourceLibrary').find('#LastName').val(),
            Email: $('#formResourceLibrary').find('#Email').val(),
            Company: $('#formResourceLibrary').find('#Company').val(),
            LocationOfAssetToAccess: $('#formResourceLibrary').find('#LocationOfAssetToAccess').val(),
            TypeOfAssetToAccess: $('#formResourceLibrary').find('#TypeOfAssetToAccess').val(),
            AssetTitle: $('#formResourceLibrary').find('#AssetTitle').val()
        };

        if ($("#formResourceLibrary").valid()) {
            //Set updating animation
            $('#dialog').block({
                message: '<img style="position: relative; top: 50%;" src="/Content/Images/Layout/ajax-loader.gif">',
                css: {
                    border: 'none',
                    backgroundColor: '#ebebeb',
                    width: '80%',
                    height: '80%',
                    opacity: .5
                }
            });
            //POST
            $.ajax({
                url: "/ResourceLibrary/SubmitAssetDownloadForm",
                type: "POST",
                data: JSON.stringify(ResourceLibrarySubmissionModel),
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (response) {
                    $('#dialog').unblock();
                    if (response.success != "false") {
                        var returnUrl = response.jsonReturnUrl;
                        if (returnUrl) {
                            $('.jqmWindow').jqmHide();
                            _gaq.push(['_trackEvent', 'Form', 'Form Submitted', 'Asset Download']);
                            window.location.href = returnUrl;
                        }
                    }
                }
            });
        }
        else {
            $('#dialog').unblock();
        }
    });
});
