/**
 * AJAX loader for 'recently viewed products'
 */
 
 dojo.provide("atg.store.recViewedProducts");
 
  /**
   * Provides methods relating to the 'Recently Viewed Products' list
   */
 atg.store.recViewedProducts={
 
	/**
	 * Load the recently viewed products using an AJAX get and populate the
	 * recently viewed products container with the resulting product list 
	 * @param numToDisplay the number of products to display from the recently viewed
	 *        products list
	 */
	loadViewedProducts: function(contextPath, productId, isMerchantProduct, numToDisplay) {		
		var path = contextPath + "/global/gadgets/recViewedProductsLookup.jsp";
		
		//add the productId parameter, if one is given.
		if(productId != null){
			if(isMerchantProduct == 'true'){
				path = path + "?mproductId=" + productId;
			} else {
				path = path + "?productId=" + productId;
			}
		}
		
		if(numToDisplay != null){
			path = path + "&numToDisplay=" + numToDisplay;
		}		
		
		dojo.xhrGet( {
			// The following URL must match that used to test the server.
			url: path,

			timeout: 5000, // Time in milliseconds

			// The LOAD function will be called on a successful response.
			load: function(response, ioArgs) {
				var container = dojo.byId("atg_store_recViewedProducts_container");
				container.innerHTML = response;
				return response;
			},

			// The ERROR function will be called in an error case.
			error: function(response, ioArgs) {
				console.error("HTTP status code: ", ioArgs.xhr.status);
			return response;
			}
        });		
	}
 };
 
 /**
 * initialization  function for recViewedProducts.js
 */
dojo.addOnLoad(function(){
	var recViewedProducts = atg.store.recViewedProducts;	
});