var authRequest = new Class({

  Extends: Request,

  onClose: false,



  initialize: function(url, div, options)
  {
    if (!options)
    {
	    var options = {

	    };
	  }
    this.parent(options);

    this.onClose = options['onClose'] || false;

    this.busy = null;
    this.url = url;
    this.div = div;
  },

  request: function(data)
  {


    this.data = data;
    return this.send(this.url, data);
  },

  send: function(url, data)
  {

  if (this.div)
  {
    this.busy = getBusyOverlay($(this.div));
  }



    if (!this.check(url, data)) return this;
    return this.parent({url: url, data: data});

  },

  success: function(text, xml)
  {
   if (this.div)
   {
    text = this.processScripts(text);

    $(this.div).innerHTML = text;
    }
    if(this.isSuccess()) this.parent(text, xml);
  },

  failure: function()
  {
    if(this.status == 403 || this.status == 0 || this.status == 12031)
    {
    
       this.delayed = this.url;

       var href = "/accounts/login/";

       href = href.setQueryValues({'ajax': 'yes'});//.setQueryValues({'next': next})

       this.modal(href);
    } else {
        this.parent();
    }
    if (this.busy) this.busy.remove();
  },

  modal: function(href)
  {
    if (this.busy)
    {
      this.busy.remove();
    }
    MOOdalBox.open (href, '', 'class', this.onClose);
  },

  repeat: function()
  {
    MOOdalBox.close();

    this.send(this.delayed || this.url, this.data);
  }
});


