var CURRENT_CATEGORY = "";
var CURRENT_OPEN_STATE = 0;
var PREV_CATEGORY = "";

function ShowMoreFacets(categoryName,sid,tid,qry,txt,fc,pg)
{
	var ctgName = categoryName.toString();
	PREV_CATEGORY = CURRENT_CATEGORY;
	//alert("prev div = "+PREV_CATEGORY);
	CURRENT_CATEGORY = ctgName;
	if(CURRENT_OPEN_STATE == 1 && PREV_CATEGORY == ctgName) // open
	{
		//alert("close div for = "+CURRENT_CATEGORY);
		closeMoreSearch();
		CURRENT_OPEN_STATE = 0;
		$('MoreButton_'+ctgName).firstChild.nodeValue = "more...";
		return;
	}
	else
	{
		//alert("open div for = "+CURRENT_CATEGORY);
		CURRENT_OPEN_STATE = 1;
		$('MoreButton_'+ctgName).firstChild.nodeValue = "less...";
	}
	
	var urlPart = "sid=" + sid + "&tid=" + tid + "&query=" + qry + "&facet=" + fc + "&page=" + pg;
	if(txt != "" && txt != null)
	{
		urlPart = urlPart + "&txt=" + txt;
	}
	//alert("/bzJApp/MoreStoreSearch.action?"+urlPart+"&expandcategory="+ctgName);
	
	showFacetLoaderUI(ctgName);
	var ajaxReq = new Ajax.Request("/bzJApp/MoreStoreSearch.action?"+urlPart+"&expandcategory="+ctgName, 
	{ 	method: 'get', 
		onSuccess: this.processMoreSearch, 
		onFailure : this.processFailure, 
		onComplete : this.processComplete, 
		onException : this.processException 
	});	
}

function showFacetLoaderUI(ctName)
{
	$('ajaxLoader_'+ctName).innerHTML = '<img style="position: absolute;" src="/bzJApp/views/store/images/ajax_loader.gif" alt="" />';
}

function processMoreSearch (transport) {
	$('moreDiv_tab_'+CURRENT_CATEGORY).innerHTML = transport.responseText;
	$('moreDiv_tab_'+CURRENT_CATEGORY).parentNode.style.visibility = 'visible';
	$('ajaxLoader_'+CURRENT_CATEGORY).innerHTML = '';
	if(PREV_CATEGORY != CURRENT_CATEGORY)
	{
		//alert("close div for pec ctg = "+PREV_CATEGORY);
		$('moreDiv_tab_'+PREV_CATEGORY).innerHTML = '';
		$('moreDiv_tab_'+PREV_CATEGORY).parentNode.style.visibility = 'hidden';
		$('MoreButton_'+PREV_CATEGORY).firstChild.nodeValue="more...";
	}
}

function closeMoreSearch () {
	$('moreDiv_tab_'+CURRENT_CATEGORY).innerHTML = '';
	$('moreDiv_tab_'+CURRENT_CATEGORY).parentNode.style.visibility = 'hidden';
}

function processFailure(transport) {
	logToWindow("NAV.INC.1 processFailure - failed. " + transport.status);
}//END: processFailure

function processComplete(transport) {
	logToWindow("NAV.INC.2 processComplete - complete.");
}//END: processComplete

function processException(Req, Ex1) {
	logToWindow("NAV.INC.3 processException - execption " + Ex1);
}//END: processException
