﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"/>
/// <reference path="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"/>
/// <reference path="~/services/global.asmx" />
/// <reference path="~/src/json2.js" />

$(function () {

    //Client info request
    var clientInfoForm = $("#enquiryForm");
    clientInfoForm.find('.submit').css({cursor:"pointer"}).click(function () {
        $.ajax({
            contentType: 'application/json; charset=UTF-8',
            url: $page.appPath + 'Services/Global.asmx/ClientInfoRequest',
            type: "POST",
            dataType: "json",
            data: JSON.stringify({ name: clientInfoForm.find('.name').val(), email: clientInfoForm.find('.email').val(), clientName: clientInfoForm.find('.clientName').val() }),
            success: function (resutls) {
                if (resutls.d)
                    alert(resutls.d);
                else {
                    alert("Thank you");
                    clientInfoForm.find('.name').val('');
                    clientInfoForm.find('.email').val('');
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert("Error");
            }
        });
    });

    //News Letter Signup
    $('#stayinformed,.newsSignup,.signup').click(function () {
        $.ajax({
            url: $page.appPath + '_includes/htmlSnipits/NewsLetterPopup.htm',
            success: function (data) {
                var signupForm = $(data);
                $('body').prepend(signupForm);

                signupForm.find('.shroud').css({ opacity: 0.65, height: $(document).height() });
                signupForm.find('.shroud, a.close').click(function () { signupForm.remove(); });
                signupForm.find('.signup').click(function () {
                    $.ajax({
                        contentType: 'application/json; charset=UTF-8',
                        url: $page.appPath + 'Services/Global.asmx/NewsLetter',
                        type: "POST",
                        dataType: "json",
                        data: JSON.stringify({ name: signupForm.find('#txtSignupName').val(), email: signupForm.find('#txtSignupEmail').val() }),
                        success: function (resutls) {
                            if (resutls.d)
                                alert(resutls.d);
                            else {
                                signupForm.remove();
                                alert("Thank you");
                            }
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            alert("Error");
                        }
                    });
                });
            }
        });
    });
});
