var ROOT;
var IDI;
var cestaTimeoutActualizar = null;
var cestaTimeoutAdd = null;
var CESTA_TIMEOUT = 1000 * 30; // 30 segundos

//*****************************************************************************
function cestaActualizarTexto(data)
{
	for(var i in data)
	{
		var obj = document.getElementById(i);
		if(!obj) continue;
		obj.innerHTML = data[i];
	}
}

//*****************************************************************************
function cestaActualizarDatos()
{
	if(cestaTimeoutActualizar) clearTimeout(cestaTimeoutActualizar);

	(new AjaxRequest).send({
		url				: ROOT+"/"+IDI+"/cesta.php",
		method			: "get",
		data			: {
			ajax			: 1
		},
		onSuccess		: function(data, info)
		{
			cestaActualizarTexto(data.resp);
			cestaTimeoutActualizar = setTimeout("cestaActualizarDatos()", CESTA_TIMEOUT);
		}
	});
}
cestaTimeoutActualizar = setTimeout("cestaActualizarDatos()", CESTA_TIMEOUT);

//*****************************************************************************
function cestaAgregarProducto(prdId)
{
	if(cestaTimeoutActualizar) clearTimeout(cestaTimeoutActualizar);

	(new AjaxRequest).send({
		url				: ROOT+"/"+IDI+"/cesta-add.php",
		method			: "get",
		data			: {
			id				: prdId,
			num				: parseInt(document.getElementById("cstNum").value),
			ajax			: 1
		},
		onSuccess		: function(data, info)
		{
			cestaActualizarTexto(data.resp);
			cestaTimeoutActualizar = setTimeout("cestaActualizarDatos()", CESTA_TIMEOUT);

			var cestaAdd = document.getElementById("cesta_add");
			if(cestaAdd) {
				cestaAdd.style.display = "inline";
				if(false) cestaTimeoutAdd = setTimeout(function() {
					clearTimeout(cestaTimeoutAdd);
					cestaAdd.style.display = "none";
				}, 1000*3);
			}
		}
	});
	return false;
}

//*****************************************************************************
function nietoAmpliarFoto(prd_id, img_id, img_w, img_h)
{
	var pad = 30;
	var W = window.open(ROOT+"/"+IDI+"/producto-foto.php?id="+prd_id+"&img="+img_id, "_blank",
		"width="+(img_w+pad)+", height="+(img_h+pad)+", toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1");
	return false;
}

//*****************************************************************************
function nietoCambioComoConocio(slct)
{
	var t = document.getElementById("cli_conocio1");
	if(slct.selectedIndex == slct.length - 1)
	{
		t.style.visibility = "visible";
	} else {
		t.style.visibility = "hidden";
		t.value = "";
	}
}

//*****************************************************************************
var nacTO;
function nietoActualizarComent()
{
	if(nacTO) clearInterval(nacTO);

	var cmn = document.getElementById("txt_coment");
	if(cmn) cmn.value = cmn.value.substr(0, 70);

	nacTO = setInterval("nietoActualizarComent()", 200);
}
window.onload = function(){ nietoActualizarComent(); }

//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
