﻿var pbModal;
var GenericHandlerURL = '/Site/handlers/GenericHandler.ashx';

function saveMail(email, type) {
   $.ajax({
      url: GenericHandlerURL,
      type: "POST",
      dataType: 'json',
      data: ({ event: 'saveMail', txtMail: email, type: type }),
      success: function (data, status) {
         if ((typeof (data.save) != 'undefined') & (data.save == 'true')) {
            openModal('Bilgi', 'Kaydınız Alındı.<br/>Teşekkürler.');
         }
         else {
            openModal('Hata', 'Kaydınız Alınamadı.');
         }
      },
      error: function (data, status, e) { openModal('Hata', 'Kaydınız Alınamadı.'); return -1; }
   });
}


$(window).load(function () {
   pbModal = $('#pbModal').dialog({ position: 'center', minWidth: 100, minHeight: 100, resizable: false, autoOpen: false, buttons: { "Kapat": function () { closeModal(); } } });
   $('#btnEMailList').bind('click', function () { saveMail($('#txtEMailList').val(), 1) });
});

function openModal(title, text) {
   pbModal.dialog("option", "title", title);
   $('#pbModal').html(text);
   pbModal.dialog('open');
}

function closeModal() {
   pbModal.dialog('close');
}
