var __LANG__ = typeof __LANG__ != 'undefined' ? __LANG__ : 'ru';
if( typeof aTranslate_message_http_req == 'undefined' ) {var aTranslate_message_http_req = new Array();aTranslate_message_http_req[1] = 'Запрос успешно обработан';aTranslate_message_http_req[2] = 'Произошла неизвестная ошибка';aTranslate_message_http_req[3] = 'Ошибка. Не установлено действие';}

/**
*	Дополнительный модуль для работы с JsHttpRequest( Д. Котеров )
*	@author Popko Vitaliy
*	@since 2008-12-10
*	@copyright so-good.ru	
*/
function HttpReq( action ){
	this.a=action;
	this.action = null;
	this.reqJS = null;
	this.busy = false;
	this.reset();
	this.backFunctions = {'true' : "alert( aTranslate_message_http_req[1] );", 'false':"alert( aTranslate_message_http_req[2] );"};
	this.retParams = null;
}

HttpReq.prototype = {

	send 	: function( oSendParams ) {
		if ( !this.action )this.setAction( this.a )
		//this.reset();
		if ( !this.action ) {
			alert( _oT.req.dont_set_action );
			return;
		}
		this.busy = true;
		this.reqJS.open( null, this.action, true);
    	this.reqJS.send( {params:oSendParams} );
    	this.result();
	},
	
	result 	: function() {
		var that = this;
		this.reqJS.onreadystatechange = function() {
        if ( that.reqJS.readyState == 4 && that.reqJS.responseJS ) {
        		that.busy = false;
        		that.retParams = that.reqJS.responseJS;
    			if ( typeof that.backFunctions == 'object' ) {
		        	if ( that.reqJS.responseJS.result > 0 ) {
		        		if ( typeof that.backFunctions.t != 'function' ) {eval( that.backFunctions.t );}else {setTimeout(that.backFunctions.t,10)};
			    	} else {
			    		if ( typeof that.backFunctions.f != 'function' )eval( that.backFunctions.f );else setTimeout(that.backFunctions.f,10);
					}
    			} else {
    				setTimeout( that.backFunctions, 1 );
    			}
				return;
        	}
        }
    },

    setAction : function( sAction ) {
		this.action = '/end.php?action=' + sAction;
		return this;
	},
	
	setBack : function( oBackFuncs ) {		
		if ( typeof oBackFuncs == 'object'){
			if (oBackFuncs['true'])oBackFuncs.t=oBackFuncs['true'];
			if (oBackFuncs['false'])oBackFuncs.f=oBackFuncs['false'];
			this.backFunctions = oBackFuncs;
		}
		return this;
	},
	
	reset : function(){
		this.reqJS = new JsHttpRequest();
	},

	abort : function() {
		if ( typeof this.reqJS.abort != 'undefined' ) {
			this.busy = false;
			this.reqJS.abort();
		}
	}
}
