//send request to the command.
function geteSpotDetailsArray(eSpotArray,storedId,catalogId,langId)
{    	
	var nvps = new Array();
	nvps = formatAjaxEspotNVParrays(eSpotArray,storedId,catalogId,langId);
	ajaxEngine.sendRequest('SYESpotDisplayAjax', {method:'post', parameters:nvps});			
		
}

var EspotHeaderUpdater = {};
EspotHeaderUpdater.ajaxUpdate = function(ajaxResponse) {
	showEspotHeader();
}
	
ajaxEngine.registerAjaxObject("EspotHeaderUpdater", EspotHeaderUpdater);	

function showEspotHeader()
{
	if ($$('div.specialOffersRightRail'))
	{
		var count=0;
		$$("div.specialOffersRightRail div").each(function(element){
			var classname = element.readAttribute('class');
			if (classname == "module promo" || classname == "rightRailSpot" || classname== "accessoryFinderSection")
			{
				count++;
			}
		});
		
		if (count == 0)
		{
			$$(".specialOffersRightRail").invoke('hide');
		} else
		{
			$$(".specialOffersRightRail").invoke('show');
		}
	}
	
	if ($('productListingsPromos'))
	{
		var count=0;
		$$("#productListingsPromos div").each(function(element){
			var classname = element.readAttribute('class');
			if (classname == "module promo" || classname == "rightRailSpot" || classname== "accessoryFinderSection")
			{
				count++;
			} 
		});
		
		if (count == 0)
		{
			$$("#productListingsPromos").invoke('hide');
		} else
		{
			$$("#productListingsPromos").invoke('show');
		}
	}	
}

//construct the NVP for the post request.
function formatAjaxEspotNVParrays(eSpotArray,storedId,catalogId,langId)
{
	
	var data = new Array();
	var counter = 0; 
	var sParam = "";	

	for ( var i=0, len=eSpotArray.length; i<len; ++i ){
  		sParam = encodeURIComponent("eSpotName_"+i);
  		sParam += "=";
  		sParam += encodeURIComponent(eSpotArray[i]);
   	    data.push(sParam);
  		//alert("eSpotName_"+i+"="+eSpotArray[i]);	
	}
  	sParam = encodeURIComponent("storeId");
  	sParam += "=";
  	sParam += encodeURIComponent(storedId);
  	data.push(sParam);		
  	sParam = encodeURIComponent("catalogId");
  	sParam += "=";
  	sParam += encodeURIComponent(catalogId);
  	data.push(sParam);   	
  	sParam = encodeURIComponent("langId");
  	sParam += "=";
  	sParam += encodeURIComponent(langId);
  	data.push(sParam);    
  		   	
   	return data.join("&");			
}
//construct espot string with unique espot url attributes.
function getEspotURL(eSpotName,elementType,pageType,htmlTag,divClass)
{    
	var concatOper=':';
	return eSpotName+concatOper+elementType+concatOper+pageType+concatOper+htmlTag+concatOper+divClass;
	
}
