 /* EPICO */
function comancheAjax( httpAddress ) { function idle() { }
this.timeout = -1;
this.onAjaxNotInitialized = idle;
this.onAjaxRequestSetUp = idle;
this.onAjaxRequestSent = idle;
this.onAjaxRequestInProcess = idle;
this.onAjaxRequestComplete = idle;
this.onAjaxTimeout = idle;
this.time_left = this.timeout + 1;
this.continue_ticking = false;
this.request_number = 0;
this.httpAddress = httpAddress;
this.lastAjaxResponse = undefined;
this.ajaxObject = undefined;
this.stateChangedEventGenerator = function ( comancheAjaxObject, request_number ) { return function() { if ( comancheAjaxObject.ajaxObject.readyState == 0 ) { comancheAjaxObject.onAjaxNotInitialized();
}
else if ( comancheAjaxObject.ajaxObject.readyState == 1 ) { comancheAjaxObject.onAjaxRequestSetUp();
}
else if ( comancheAjaxObject.ajaxObject.readyState == 2 ) { comancheAjaxObject.onAjaxRequestSent();
}
else if ( comancheAjaxObject.ajaxObject.readyState == 3 ) { comancheAjaxObject.onAjaxRequestInProcess();
}
else if ( comancheAjaxObject.ajaxObject.readyState == 4 ) { if ( request_number == comancheAjaxObject.request_number ) { comancheAjaxObject.continue_ticking = false;
comancheAjaxObject.lastAjaxResponse = comancheAjaxObject.ajaxObject.responseText;
comancheAjaxObject.rebuildAjax();
comancheAjaxObject.onAjaxRequestComplete();
}
}
}
}
;
this.rebuildAjax = function() { this.request_number++;
this.continue_ticking = false;
this.time_left = this.timeout + 1;
try { this.ajaxObject = new XMLHttpRequest();
}
catch( XA0731313402 ) { try { this.ajaxObject = new ActiveXObject( "Msxml2.XMLHTTP" );
}
catch( XA0731313402 ) { try { this.ajaxObject = new ActiveXObject( "Microsoft.XMLHTTP" );
}
catch( XA0731313402 ) {}
}
}
if ( this.ajaxObject != undefined ) { this.ajaxObject.onreadystatechange = this.stateChangedEventGenerator( this, this.request_number );
}
}
;
this.checkTimeout = function() { if ( this.continue_ticking && ( this.time_left != -1 ) ) { this.time_left--;
if ( this.time_left == 0 ) { this.rebuildAjax();
this.onAjaxTimeout();
}
else { var XsAoA4d12a04405A9A4 = this;
setTimeout( function() { XsAoA4d12a04405A9A4.checkTimeout();
}
, 1000 );
}
}
}
;
this.getResponse = function() { return this.lastAjaxResponse;
}
;
this.sendRequest = function ( address, method, arguments ) { this.rebuildAjax();
if ( this.ajaxObject.readyState != 0 ) { return false;
}
if ( ( method != "GET" ) && ( method != "POST" ) ) { return false;
}
if ( method == "GET" ) { address += '?' + arguments;
}
this.ajaxObject.open( method, this.httpAddress + '/' + address, true );
if ( method == "GET" ) { this.ajaxObject.send( null );
}
else { this.ajaxObject.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
this.ajaxObject.setRequestHeader( "Content-length", arguments.length );
this.ajaxObject.setRequestHeader( "Connection", "close" );
this.ajaxObject.send( arguments );
}
this.continue_ticking = true;
this.checkTimeout();
return true;
}
;
}
