var deleteItem = function (module, id) {
  var cf = confirm('Weet u zeker dat u dit item wilt verwijderen ?');
  if (cf) {
    var url = '/admin.php/' + module + '/delete';
    $.ajax({
      type:   "GET",
      url:    url,
      data:   {
        id: id
      },
      success:  function(msg)
      {
        msg = msg.split('|');
        if (msg[0] == 'success')
        {
          window.location='/' + module + '/list';
          //alert('Item verwijderd');
        }
      }
    });
  }
};

var stringToSlug = function (title) {
  return $.ajax({
    type:     "POST",
    url:      "/admin.php/slug",
    data:     "string=" + escape(title),
    async:    false
  }).responseText;
};

saveForm = function(url, data, redirect) {
  $.ajax({
    type: "POST",
    url:  url,
    data: data,
    success:  function(msg) {
      switch (msg) {
        case 'login':
          window.location = '/';
          return true;
          break;
        default:
          var msg = msg.split('|');
          if (msg[0] == 'success') {
            if (redirect)
            {
              if (id = parseInt(msg[1]))
              {
                redirect += id;
              }
              window.location = redirect;
            }
          } else {
            var errors = msg[1].split(',');
            var errorHtml = '';
            for (var i in errors) {
              errorHtml += '<li>'+errors[i]+'</li>';
            }
  
            $('div#errors ul').html(errorHtml);
            $('div#errors').hide().fadeIn(150);
          }
      }
    }
  });
};
