/**
 * @package jalib
 * @author Adam van Dongen
 * @copyright (c) 2008 - Joomla-addons.org
 * @version $Id:$
 * 
 * --------------------------------------------------------------------------------
 * Joomla-addons programming library which will act as a 
 * compatibility layer with Joomla and other CMS applications
 * 
 * This library is distributed and released under the terms and conditions
 * of the GNU/Lesser General Public License version 2.1.
 * See LICENSE.php for an more information
 * --------------------------------------------------------------------------------
 */
;(function($) {
  $.jalib = {
    option: '',
    controller: '',
    jabutton: function(button){
      $.jalib.jasubmit(button);
    },
    button: function(button){
      $.jalib.submit(button);
    },
    jasubmit: function(button){
      $.jalib.submit(button);
    },
    submit: function(button){
      var form = document.jaForm;
      
      // append option, controller and task to form action
      form.action += '?option=' + ja.jalib.option + '&controller=' + ja.jalib.controller + '&task=' + button;
      if(button == 'edit'){
        form.action += '&id=' + $('input[rel=ja_box]:checked').val();
      }
      
      try {
        document.jaForm.onsubmit();
      }
      catch(e){}
    
      form.submit();
    },
    update: function(file, application, id){
      $.get('index3.php?option=' + ja.jalib.option + '&controller=' + ja.jalib.controller + '&task=updatefile&no_html=1&application=' + application + '&file=' + file, function(data, status){
        if(data.length != 0){
          alert(data);
        } else {
          $('#' + id).fadeTo("slow", 0.33);
          $('#' + id + ' td:last').html("");
        }
      });
    },
    ajaxError: function(xmlrequest, textStatus, error){
      alert('Error processing xml ajax request:' + "\n" + xmlrequest.responseText);
    }
  }
  jQuery(function(){ $.ajaxSetup({error: $.jalib.ajaxError}); });
})(jQuery);
