$(document).ready(function(){
	$('.scdates').datetimepicker({
        format: 'YYYY-MM-DD'
    });
	$('select').select2();
	$('#createSmsShortCodeBtn').click(function(evt){
      evt.preventDefault();
      $('#shortCodeType').val('sms');
      $('#newShortCodeFormModal').modal('show');
    });
    $('#createUssdShortCodeBtn').click(function(evt){
      evt.preventDefault();
      $('#shortCodeType').val('ussd');
      $('#newShortCodeFormModal').modal('show');
    });
    $('#createVoiceShortCodeBtn').click(function(evt){
      evt.preventDefault();
      $('#shortCodeType').val('voice');
      $('#newShortCodeFormModal').modal('show');
    });



    $('#shortCodeForm').submit(function(evt){
      evt.preventDefault();
      var formData = new FormData($(this)[0]);
      $.ajax({
          type: "POST",
          url: base_url + '/clients/shortcode_store',
          data : formData,
          processData: false,
          contentType: false,
          async: false,
          success: function (data){
            if (data.code === 1) {
              $.alert({
                  title: 'Alert!',
                  content: 'Short code details successfully saved',
              });
              setTimeout(function(){
                location.reload();
              }, 5000);
            }
            else if (data.code > 1) {
              $.alert({
                  title: 'Alert!',
                  content: data.msg,
              });
            }
            else {
              $.alert({
                  title: 'Alert!',
                  content: 'Your request could not be handled. Try again !',
              });

            }
          },
          error: function (data) {
              var output = $.parseJSON(data.responseText);
              // console.log(output.errors);
              $('#notifyArea').removeClass('hidden');
              $.each(output.errors, function (key, value) {
                // console.log(value[0]);
                $('#notifyArea').text(value[0]);
              });
          },
          fail : function(errordata){
            // console.log(errordata);
          }
      });
    });
});