﻿var addEmailtUrl = "../Services/MailingListService.asmx/AddEmail";

$(document).ready(function () {
    // put all your jQuery goodness in here.
    $("#divmailinglistcontainer").dialog({
        autoOpen: false,
        modal: true,
        width: 350
    });

});

function showMailingList() {
    $("#divmailinglistcontainer").dialog('open');
    $(".jqrydivmailinglistsucess").hide();
    $(".jqrydivmailinglistentry").show();
}

function closeMailingList() {
    HideValidators();
    $(".jqrymailinglistemail").val('');
    $("#divmailinglistcontainer").dialog('close');
}

function addEmailAddress(validationGroup) {
    if (typeof (Page_ClientValidate) == "function") {
        Page_ClientValidate(validationGroup);
    }
    if (typeof (Page_IsValid) != "undefined") {
        if (Page_IsValid) {

            var email = $(".jqrymailinglistemail").val();

            var jsonObjectArray = new Array();
            jsonObjectArray.push(new dataRequestObject(name = "email", value = email, dataType = "string"));
            jsonObjectArray.push(new dataRequestObject(name = "mailingGroupCode", value = "WS", dataType = "string"));
           
            try {
                $.ajax({
                    type: "POST",
                    contentType: 'application/json; charset=utf-8',
                    url: addEmailtUrl,
                    data: buildJSONDataRequest(jsonObjectArray),
                    dataType: 'json',
                    success: function (result, status) {
                        try {
                            $(".jqrydivmailinglistentry").hide();
                            $(".jqrydivmailinglistsucess").show();
                        } catch (e) {
                            showAlert("ERROR " + e.message);
                        }
                    },
                    error: function (xhr, textStatus, errorThrown) {
                        // typically only one of textStatus or errorThrown 
                        // will have info
                        showAlert(xhr.responseText);
                    }

                });
            } catch (e) {
                showAlert(e.message);
            }
        }
    }
}


