if ( typeof JsHttpReq == 'undefined' ) document.write('<script src="/js/ajax/JsHttpRequest/JsHttpRequest.js"></script>');
/**
*	Дополнительный модуль для работы с 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.reset();
	this.backFunctions = {'true' : "alert( _oT.req.ok, 'ok' );", 'false':"alert( _oT.req.err );"};
	this.retParams = null;
	return this; 
}

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.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.retParams = that.reqJS.responseJS;
        	
    			if ( typeof that.backFunctions == 'object' ) {
		        	if ( that.reqJS.responseJS.result > 0 ) {
		        		that._doBack(that,'true');		        		
			    	} else {
			    		that._doBack(that,'false');
					}
    			} else {
    				setTimeout( that.backFunctions, 1 );
    			}
				return;
        	}
        }
    },

    _doBack : function( o, mode ) {
    	if ( typeof o.backFunctions[mode] != 'undefined' ){
			if ( typeof o.backFunctions[mode] == 'string' ) {
				eval( o.backFunctions[mode] );
			} else if (typeof o.backFunctions[mode] == 'function' ) {
				setTimeout(o.backFunctions[mode],5);
			}
    	}
    },
    
    setAction : function( sAction ) {
    	if ( !sAction ) sAction = '';
		this.action = '/end.php?Be=' + sAction ;
	},
	
	setBack : function( oBackFuncs ) {
		
		if ( typeof oBackFuncs == 'object'){
			if ( oBackFuncs['true']!='' ) {
				this.backFunctions['true'] = oBackFuncs['true'];
			}
			if ( oBackFuncs['false'] != '' ) {
				this.backFunctions['false'] = oBackFuncs['false'];
			}
		} else {
			this.backFunctions = oBackFuncs;
		}
		return this;
	},
	
	reset : function(){
		this.reqJS = new JsHttpRequest();
	}
}

