var Content
  = new Object();

Content.LOADER_READYSTATE_UNITIALIZED = 0;
Content.LOADER_READYSTATE_LOADING = 1;
Content.LOADER_READYSTATE_LOADER = 2;
Content.LOADER_READYSTATE_INTERACTIVE = 3;
Content.LOADER_READYSTATE_COMPLETE = 4;

// Content.Loader - Asynch data loader
//####################################
//####################################
Content.Loader
= function( httpUrl,
            httpMethod,
            httpParams,
            httpHeaders,
            onLoad,
            onError,
            extraArguments ) {
  this.req
    = null;
  this.httpUrl
    = httpUrl;
  this.httpMethod
    = (httpMethod)
        ? httpMethod
        : 'GET';
  this.httpParams
    = httpParams;
  this.httpHeaders
    = httpHeaders;
  this.onLoad
    = onLoad;
  this.onError
    = (onError)
        ? onError
        : this.defaultError;
  this.extraArguments
    = extraArguments;
  this.loadXMLDoc(
    this.httpUrl,
    this.httpMethod,
    this.httpParams,
    this.httpHeaders ); }

// Content.Loader.loadXMLDoc( httpUrl,
//                            httpMethod,
//                            httpParams,
//                            httpHeaders )
//----------------------------------------
// asynch load this request
//////////////////////////////////////////
Content.Loader.prototype.loadXMLDoc
= function( httpUrl,
            httpMethod,
            httpParams,
            httpHeaders ) {

  // get request object
  //-------------------
  if( window.XMLHttpRequest )
    this.req
      = new XMLHttpRequest();
  else
  if( window.ActiveXObject )
    this.req
      = new ActiveXObject(
          "Microsoft.XMLHTTP" );

  // make request
  //-------------
  if( this.req ) {

    try {
      var loader
        = this;
      this.req.onreadystatechange
        = function() {
            loader.onReadyState.call(
              loader ); }
      this.req.open(
        httpMethod,
        httpUrl,
        true );
      if( httpHeaders != null )
        for( httpHeaderName in httpHeaders )
          this.req.setRequestHeader(
            httpHeaderName,
            httpHeaders[httpHeaderName] );
      this.req.send(
        httpParams );
    } catch( err ) {
      this.onError.call(
        this ); } } }

// Content.Loader.onReadyState()
//------------------------------
// callback when request ready state changes
////////////////////////////////
Content.Loader.prototype.onReadyState
= function() {

  var req
    = this.req;
  var readyState
    = req.readyState;

  // content loaded state
  //---------------------
  if( readyState == Content.LOADER_READYSTATE_COMPLETE ) {
    var httpStatus
      = req.status;
    if( (httpStatus == 200)
        || (httpStatus == 0) )
      this.onLoad.call(
        this );
    else
      this.onError.call(
        this ); } }

// Content.Loader.defaultError()
//------------------------------
// default error routine, used when not supplied
////////////////////////////////
Content.Loader.prototype.defaultError
= function() {

  alert( "error loading data!\n\n"
        +" readyState: "+this.req.readyState+"\n"
        +" status: "+this.req.status+"\n"
        +" headers: "+this.req.getAllResponseHeaders() ); }

