/* copyright (c) 2007, 2008 - Patrick Kracht < patrick.kracht@gmail.com > : request functions */

function request( id )
{
 var _this = this;
 
 this.id   = id;
 this.xobj = null;
 this.data = null;
 this.url  = null;
 
 this.construct = function ()
 {
  loading( true );
  if ( window.XMLHttpRequest )
  {
   this.xobj = new XMLHttpRequest();
   if ( this.xobj.overrideMimeType ) this.xobj.overrideMimeType( 'text/html' );
  }
  else if ( window.ActiveXObject )
  {
   try { this.xobj = new ActiveXObject( 'Msxml2.XMLHTTP' ); }
   catch (e)
   {
    try { this.xobj = new ActiveXObject( 'Microsoft.XMLHTTP' ); }
    catch (e) {}
   }
  }
  if ( ! this.xobj ) alert( 'Error: No XMLHttpRequest possible!' );
 };
 
 this.get = function( url )
 {
  this.url = url;
  this.xobj.onreadystatechange = this.response;
  this.xobj.open( 'GET', url, true );
  this.xobj.setRequestHeader( 'Referer', document.location.href );
  this.xobj.send( null );
 };
 
 this.post = function( url, data )
 {
  this.url  = url;
  this.data = data;
  this.xobj.onreadystatechange = this.response;
  this.xobj.open( 'POST', url, true );
  this.xobj.setRequestHeader( 'Referer', document.location.href );
  this.xobj.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8' );
  this.xobj.send( data );
 };
 
 this.response = function()
 {
  if ( _this.xobj.readyState == 4 )
  {
   var content = _this.xobj.responseText;
   var correct = content.indexOf( "<" );
   $( _this.id ).innerHTML = _this.xobj.responseText.substring( correct );
   loading( false );
  }
 };
 
 this.construct();
 return this;
};

