
var Widget = new Class(
{
   initialize: function(id)
   {
      if (id == undefined) id = 'widget';
      this.wid = id;
   },

   update: function(page, sortby)
   {
      var values = $(this.wid).getFormValues();
      if (page != undefined) values['page'] = page;
      if (sortby != undefined) values['sortby'] = sortby;

      this.showMessage();
      if (arguments.length > 2 && typeof(arguments[2]) == 'object')
      {
         for (i in arguments[2]) values[i] = arguments[2][i];
      }

      if ( $('jobID')!= undefined )
      {
        values['jobID'] = $('jobID').value;
      }

      ajax.call('UIControl::display', values, 'redraw');
   },

   gotopage: function(gotoid)
   {
      this.update($(gotoid).value - 1);
   },

   reset: function()
   {
      $(this.wid + '_searchform').cleanFormValues();
      this.update();
   },

   showMessage: function(msg)
   {
     if (!$('statusmessage_' + this.wid)) return;
      if (!msg) msg = '<b>Updating the data</b>';
      $('statusmessage_' + this.wid).setHTML(msg);
      $('statusmessage_' + this.wid).display();
   },

   getData: function(func, msg)
   {
     if (func == undefined) func = 'redraw';
     this.showMessage(msg);
     var params = $(this.wid).getFormValues();
     if (arguments.length > 2 && typeof(arguments[2]) == 'object')
     {
        for (i in arguments[2]) params[i] = arguments[2][i];
     }
     ajax.call('UIControl::display', params, func);
   },

   getCheckValues: function()
   {
      var elements = $$($(this.wid).getElementsByTagName('input'));
      var vals = new Array();
      for (var i = 0; i < elements.length; i++)
      {
         if (elements[i].type == 'checkbox') if (elements[i].checked) vals[vals.length] = elements[i].value;
      }
      return vals;
   }

});
