/**
 * function for handling ajax 
 */ 

function PagedProductListManager() 
	{

	}

PagedProductListManager.prototype.changePage = function(page) {
	var options = ( '&args[page]=' + page );
	
	this.updateResultsDefinition(options);
}

PagedProductListManager.prototype.changeOrderBy = function(orderBy) {
	//parse orderBy clausule from URL
	var pos = orderBy.indexOf('orderBy=');
	if(pos == -1) 
		{ return; }
		
	orderBy = orderBy.substring(pos + 8);
	
	var options = ( '&args[orderBy]=' + orderBy );
	
	this.updateResultsDefinition(options);
}

PagedProductListManager.prototype.updateResultsDefinition = function(options) {
	var url = 'index.php?section=ajax';
	 url += '&controller=SearchEngine';
	 url += '&method=actionUpdateResultsDefinition';
	 url += '&widget=PagedProductList';
	 
	 // ADD ENCODED URL
	 url += options;
	
	  AjaxRequest.get(
	    {
	      'url':url
	      ,'onSuccess':function(req) 
	      		{ 
	      		place = document.getElementById('PagedProductList');
	      		place.innerHTML = req.responseText;
	      		}
	      ,'onErrror':function(req)
	      		{
	      		alert('Error: Ajax communication error.');
	      		}
	    }
	  );
}

PagedProductListManager.prototype.updateSearchCriteriaOptions = function(options) 
	{
	 var url = 'index.php?section=ajax';
	 url += '&controller=SearchEngine';
	 url += '&method=actionUpdateSearchCriteriaOptions';
	 url += '&widget=PagedProductList';
	 
	 // ADD ENCODED URL
	 url += options;
	
	  AjaxRequest.get(
	    {
	      'url':url
	      ,'onSuccess':function(req) 
	      		{ 
	      		place = document.getElementById('PagedProductList');
	      		place.innerHTML = req.responseText;
	      		}
	      ,'onErrror':function(req)
	      		{
	      		alert('Error: Ajax communication error.');
	      		}
	    }
	  );
	}

// CREATE PRODUCT DETAILS MANAGER
var pagedProductListManager = new PagedProductListManager();