var aro = new AjaxRenderObject();
var limitResults = 6;

function getSearchTips(value,lang) {
	//if (aro.isActive) { alert(); return};
	aro.getContainer("searchTips")
	aro.onShowContainer = showContainerEffect
	aro.onHideContainer = hideContainerEffect

	var txb = document.getElementById("txbSearchTips");
	if (txb && !value) {
		value = txb.value;
	}
	if ((value.replace(" ","") == "") || (!showSearchTips())) {
		aro.hideContainer();
		return;
	}

	aro.wait = true;
	aro.url = "/ajax/json.aspx"
	aro.parameters = { 'op':'GetProdottiXML', 'name':value, 'top':limitResults, 'lang':lang }
	aro.loadingMessage = "<img src='/images/indicator_wheel2.gif' align='absmiddle'> Loading data, please wait..."
	aro.completeMessage = "<img src='/images/indicator_wheel2.gif' align='absmiddle'> Data loaded..."
	aro.timeout = 10000
	aro.timeoutMessage = "Error: request timed out."
	aro.onSuccess = processElements;
	aro.onError = requestError;
	aro.headerTemplateHTML = "<ol>"
//	aro.itemTemplateHTML = "<li><a href='/product.aspx?ID=#IDprodotto#'>#nome#</a></li>"
//	aro.itemTemplateHTML = "<li><a href='/" + lang + "/products/product_#IDprodotto#.aspx'>#nome#</a></li>"
	aro.itemTemplateHTML = "<li><a href='/" + lang + "/categories/category_#IDcategoria#.aspx'>#nome#</a></li>"
	aro.footerTemplateHTML = "</ol>"
	aro.showContainer();
	aro.getData();
}

function processElements(req, aro) {
	if (aro.processedObject) {
		var o = aro.processedObject;

		var elements = new Array();

		if (o.prodotto.length) {
			var limit = limitResults;
			if (o.prodotto.length > limit) {
				/*aro.footerTemplateHTML = "<li><a href=\"#\">[more]...</a></li></ol>"*/
			} else {
				limit = o.prodotto.length;
			}
			if (o.prodotto.length > 1) {
				for (var i=0;i<limit ;i++ ) {
					elements[i] = o.prodotto[i].prodotto;
				}
				aro.container.innerHTML = aro.renderAll(elements);
			}
		} else if (o.prodotto.prodotto) {
			aro.container.innerHTML = aro.renderAll(o.prodotto.prodotto);
		}
		aro.showContainer();
		//alert(aro.renderItem(o.prodotto[0].prodotto));
	} else {
		aro.hideContainer();
	}

}

function requestError(req, aro) {
	aro.hideContainer();
}


function showSearchTips() {
	var chk = document.getElementById("displaySearchTips");
	if (chk) return chk.checked;
	return false;
}

function showContainerEffect(obj) {
	obj.showMe = function () {
		var	div = this;
		var	container = this.parentNode;
		var realheight = 0;
		realheight = bytefx.$size(div).height;
		realwidth = bytefx.$size(div).width;

		var newsize = {width:realwidth, height:realheight, $width:2, width$:2};
		bytefx.size(container, newsize, 60);
	}
	obj.style.display = "";
	obj.showMe();
}

function hideContainerEffect(obj) {
	obj.hideMe = function () {
		var	div = this;
		var	container = this.parentNode;
		realwidth = bytefx.$size(div).width;
		var newsize = {width:realwidth, height:0, $width:2, width$:2};
		bytefx.size(container, newsize, 60);
	}
	obj.hideMe();
	obj.style.display = "none";
}