// JavaScript Document By Angel Adrian Retali.



/* -------------------- Start class -------------------- */

function PageManager(args)
{		
	// Vars
	this.url = args[1]; // url para la llamada del ajax
		
	this.params = '';
								        
	this.index = 0;
	
	this.tags = new Array(); // referencia a cada uno de los tags
		
		NAME = args[0];  // nombre del conjunto de tags
			
		foo = document.getElementsByTagName("div");
		
		n = foo.length;
		
		for (i = 0, j = 0; i < n; i++) 
		{	
			if(foo.item(i).getAttribute('name') == NAME) { this.tags[j] = foo.item(i); j++; } 
		}
			
	this.n = j; // numero total de paginas
	                       
	this.visited = new Array();
		
		for(i = 0; i < this.n; i++) this.visited[i] = false;
			
	// Methods
	this.makeRequest = function(index, params)
	{				
		this.onCreate();
					
		if(this.visited[index]) { this.onComplete(); return; }
		
		INDEX = index;
					
		TAGS = this.tags;
					
		REQUEST = this.url+'?'+params; 
		
		new Ajax.Request
		(   
			REQUEST,
						
			{
		    		method:'get', 
		           			
		            	onLoading: this.onLoading, 
	                	
		       		onLoaded: this.onLoaded,
		      		
                                onSuccess: function (transport)
				{						
					TAGS[INDEX].innerHTML = transport.responseText;					
				},
                                
                                onFailure: function (transport) {},
                                   
		        	onComplete: this.onComplete
		    	}
		);  
			
		this.visited[this.index] = true;
	}
	
	this.onCreate = function () {}
	
	this.onLoading = function () {}
	
	this.onLoaded = function () {}
		
	this.onComplete = function () {}
	
	this.showResponse = function () 
	{
		for(i = 0; i < this.n; i++) this.tags[i].style.display = 'none';
					
		this.tags[this.index].style.display = 'block';
	}
	
	this.goTo = function (index, params) 
	{	
		this.index = index; 
		
		if(this.index < 0) this.index = 0;
		
		if(this.index > this.n -1) this.index = this.n -1;
		
		this.params = params;		
				
		this.makeRequest(index, params); 
	}

    this.hideAll = function ()
    {
        for(i = 0; i < this.n; i++) this.tags[i].style.display = 'none';
    }
}


/* -------------------- End class -------------------- */




