function RefreshCombo(idObjSel, strValori) 
{
	var obj = MM_findObj(idObjSel)
	var posEnd = strValori.indexOf("[EOL]");
	if (posEnd >= 0)
		strValori = strValori.substring(0, posEnd);
	
	if (strValori != "")
	{
		var valori = strValori.split('|');

		var pos = 0;
		for (x = 0; x < valori.length; x++) 
		{
			var valore = valori[x];
			if (valore != "")
			{
				obj.options[pos + 1] = new Option(valori[x], valori[x]);
				pos++;
			}
		}
	}
	else
		obj.options[1] = new Option("", "");
}

function UnloadValues(idObj) 
{
	var obj = MM_findObj(idObj);
	//se c'è l'hidden vuol dire che è arrivato alla pagina come parametro "imposto"... quindi lo lascio stare
	//obj.value = "";
	if (obj.type != "hidden")
	{
		//evito di cancellare l'indice 0 per non togliere la scritta "seleziona..."
		for (var i = obj.options.length - 1; i > 0; i--)
			obj.options[i] = null;
	}
}

function GetValue(idObj) 
{
	var obj = MM_findObj(idObj);
	if (obj.type == "hidden")
		return obj.value;
	else
		return obj.options[obj.selectedIndex].value;
}

function CaricaSelect(idObjChanged, idObj) 
{
	var objChanged = MM_findObj(idObjChanged);
	
	UnloadValues(idObj);
	
	if (idObj == "con")
		UnloadValues("naz");

	if (idObj == "con" || idObj == "naz")
		UnloadValues("reg");
	
	if (idObj == "con" || idObj == "naz" || idObj == "reg")
		UnloadValues("pro");
	
	if (idObj == "con" || idObj == "naz" || idObj == "reg" || idObj == "pro")
		UnloadValues("com");

	var cat = GetValue("cat");
	var con = GetValue("con");
	var naz = GetValue("naz");
	var reg = GetValue("reg");
	var pro = GetValue("pro");
	var com = GetValue("com");

	new Ajax.Request("/index.aspx?m=ReteVendita&f=3" +
		"&field=" + encodeURIComponent(idObj) + 
		"&cat=" + encodeURIComponent(cat) + 
		"&con=" + encodeURIComponent(con) + 
		"&naz=" + encodeURIComponent(naz) + 
		"&reg=" + encodeURIComponent(reg) + 
		"&pro=" + encodeURIComponent(pro) + 
		"&com=" + encodeURIComponent(com),
		{    
			method:'get',     
			onSuccess: function(transport){
				RefreshCombo(idObj, transport.responseText);
			},     
			onFailure: function(){ 
				alert('ERRORE: impossibile recuperare i gruppi. Si prega di riprovare più tardi.') 
			}   
		});
}