/**
*	Дополнительный модуль для работы с JsHttpRequest( Д. Котеров )
*	@author Popko Vitaliy
*	@since 2008-12-10
*/

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] = 'Ошибка. Не установлено действие';
}

function HttpReq(){
	this.action  = null;
	this.reqJS = new JsHttpRequest;
	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 ) {
			alert(aTranslate_message_http_req[3]);
			return;
		}
		this.reqJS.open( null, this.action, true);
    	this.reqJS.send( {params:oSendParams} );
    	this.result();
	},
	
	result 	: function() {
		that = this;
		this.reqJS.onreadystatechange = function() {
        if ( that.reqJS.readyState == 4 && that.reqJS.responseJS ) {
        		that.retParams = that.reqJS.responseJS;
	        	if ( that.reqJS.responseJS.result > 0 ) {
	        		if ( typeof that.backFunctions['true'] != 'undefined' ){
	        			eval( that.backFunctions['true'] );
	        		}
		    	} else {
		    		if ( typeof that.backFunctions['false'] != 'undefined' ){
		    			eval( that.backFunctions['false'] );
		    		}
				}
        	}
        }
    },

    setAction : function( sAction ) {
    	this.action = '?md=ajax&ac=' + sAction;
	},
	
	setBack : function( oBackFuncs ) {
		if ( oBackFuncs['true'] ) {
			this.backFunctions['true'] = oBackFuncs['true'];
		}
		if ( oBackFuncs['false'] ) {
			this.backFunctions['false'] = oBackFuncs['false'];
		}
		
	}
}
