function ServerCommunication(action, asynchronous, noSC)
{
    this._responseObj = null;
    this._asynchronous = asynchronous;
    this._params = new Object();
    if(arguments.length < 3 || !arguments[2])
        this.AddParam('SC', '1');
    if(action !== null)
        this.AddParam('action', action);
}
ServerCommunication.prototype.RESULT_OK = 1;
ServerCommunication.prototype.RESULT_FAILED = 0;

ServerCommunication.prototype.Send = function(url, caller_id, fhinstance)
{
    caller_id = typeof(caller_id) != 'undefined' ? caller_id : 0;
	if ( caller_id > 0 ) this._asynchronous = true;
    this.fhinstance = typeof(fhinstance) != 'undefined' ? fhinstance : null;
	
	this._responseObj = null;
    var url =  (arguments.length==1 ? url : window.location.href);
    //var pars = this._BuildURLParams() + DEBUG_SESSION_ID;
    this.AddParam('encoded', 1);
    this._EncodeParams();
	
	if ( typeof(AJAXPATH) != "undefined" && typeof(this._params['SC']) != "undefined" && this._params['SC']=='1' ) url = AJAXPATH;
    
    var tthis = this;
    var myAjax = new Ajax.Request( url, { 
            encoding: 'ISO-8859-2',
            asynchronous: this._asynchronous,
            method: 'post', 
            parameters: this._params, 
            onComplete: function(transport){ tthis._OnCompleted(transport, caller_id); },
            onFailure: function(){ tthis._OnFailure(); }
        });
    
    return this._responseObj;
}

ServerCommunication.prototype.GetResponse = function()
{
    return this._responseObj;
}

ServerCommunication.prototype._EncodeParams = function()
{
    for(var prop in this._params)
    {
        this._params[prop] = URL.encode(this._params[prop]);
    }
}

ServerCommunication.prototype._OnCompleted = function(transport, caller_id)
{
    this._responseObj = transport.responseText.evalJSON();
	
	if ( caller_id == 1 )
		this.fhinstance._UpdateVEStatusAsyncronAnswer(this._responseObj, this);
}

ServerCommunication.prototype._OnFailure = function()
{
    this._responseObj = null;
}

ServerCommunication.prototype.AddParam = function(name, value)
{
    this._params[ name ] = value;
}

ServerCommunication.prototype.ClearParams = function()
{
    this._params = new Object();
}
