
function RequestManager()
{
	this.requestQue=new Array();// request que
	this.activeRequests = 0;
	
	this.onAllRequestsEnd = null;
	
	/**
	*@param object  The creator of the new request
	*@param string  The url of the request
    *@desc create a new Request with the necessary 
    */
    this.createRequest = function (callObj, url)
	{	   
	   var nrq=new Request(callObj,url);	   
	   var ind=this.requestQue.length;
	   for(var i=0;i<this.requestQue.length;i++)
	   {
            if(!this.requestQue[i])
            {
                ind=i; 
                break;       
            }
       }	   
	   nrq.setManagerIndex(ind);
	   this.requestQue[ind]=nrq;
       return ind;  
	}
	
	/**	
	*@param number     The index of the object
    *@desc Creates a new Request with the necessary 
    *@return object  Request object
    */
	this.getRequestObj = function (index)
	{
	   return this.requestQue[index];
	}
	
	/**	
	*@param number     The index of the object
    *@desc Remove the request from the manager que
    */
	this.removeRequest = function (index)
	{
	   if(this.getRequestObj(index))
	   {
           this.getRequestObj(index).abort();           
           this.requestQue[index]=null; 
       }       
	}	
	
	/**	
	*@param number     The index of the object
    *@desc start the request
    */
	this.startRequest = function (index)
	{
	   if(this.getRequestObj(index)) 
       {
            this.getRequestObj(index).start();
            return true;
       } 
       return false; 
	}
    
    /**	
	*@param number     The index of the object
    *@desc abort a request
    */
    this.abortRequest = function (index)
	{
	   if(this.getRequestObj(index)) 
       {
            this.getRequestObj(index).abort();
            return true;
       } 
       return false; 
	}	
	
}

RequestManager.__instance__=null;

/**
*@desc since it is a Singleton class , this is the unique constructor of this object
*@return object 
*/
RequestManager.getInstance=function ()
{
    if(RequestManager.__instance__==null)
    {
        this.__instance__=new RequestManager();
    }
    return this.__instance__;
}
