

function aggiungi_sottocategoria() {
	var hiddenValue = document.getElementById("elencoSottocategorie");
	var hiddenValueSubsub = document.getElementById("elencoSottosottocategorie");
	
	var cboCat = document.getElementById("categoria");
	var cboSubcat = document.getElementById("sottocategoria");
	var cbosubSubcat = document.getElementById("sottosottocategoria");
	
	var nuova_sottocat = cboSubcat.value;
	var nuova_sottosottocat = cbosubSubcat.value;
	
	if (nuova_sottocat=="") {
		return;
	}
	
	var presentiSottocat = hiddenValue.value.split(";");
	if (nuova_sottosottocat != -1) {
		var presentiSottosottocat = hiddenValueSubsub.value.split(";");
	}
	
	var i;
	var z;
	
	for(i=0;i<presentiSottocat.length;i++) {
		if(presentiSottosottocat != null)
		{
			for(z=0;z<presentiSottosottocat.length;z++) {
				if (presentiSottosottocat[z]==nuova_sottosottocat) {
					alert("Sottosottocategoria gia\' presente");
					return;
				}
			}
		}
		else {
			if(presentiSottocat[i]==nuova_sottocat) {
				alert("Sottocategoria gia\' presente");
				return;
			}
		}
	}
	
	var tabella_hr = document.getElementById("TabellaSottocategorie_HiddenRow");
	var tabella = document.getElementById("TabellaSottocategorie");
	var nome_cat = (cboCat.options[cboCat.selectedIndex].firstChild.nodeValue);
	var nome_sottocat = (cboSubcat.options[cboSubcat.selectedIndex].firstChild.nodeValue);
	
	if (nuova_sottosottocat != -1) {
		var nome_sottosottocat = (cbosubSubcat.options[cbosubSubcat.selectedIndex].firstChild.nodeValue);
	}
	else {
		var nome_sottosottocat = '';
	}
	
	hiddenValue.value = hiddenValue.value+nuova_sottocat+";";
	if (hiddenValueSubsub != null) hiddenValueSubsub.value = hiddenValueSubsub.value+nuova_sottosottocat+";";
	
	var r = tabella.insertRow(tabella.rows.length);
	r.setAttribute("subcat", nuova_sottocat);
	var nc=r.insertCell(0);
	nc.innerHTML=nome_cat;
	nc=r.insertCell(1);
	nc.innerHTML=nome_sottocat;
	nc=r.insertCell(2);
	nc.innerHTML=nome_sottosottocat;
	nc=r.insertCell(3);
	nc.innerHTML="<a href=\"#TabellaSottocategorie\" onclick=\"elimina_sottocategoria(this);\"><img src=\"risorse/elimina.png\" alt=\"elimina\" title=\"elimina\" border=\"0\" /></a>";
	
}

function elimina_sottocategoria(riga) {
	while (riga.nodeName !="TR") riga = riga.parentNode;
	var subcat = riga.getAttribute("subcat");
	var subSubcat = riga.getAttribute("subsubcat");
	
	var tabella = riga.parentNode;
	tabella.removeChild(riga);
	
	var hiddenValue = document.getElementById("elencoSottocategorie");
	var hiddenValueSubsub = document.getElementById("elencoSottosottocategorie");
	
	var newValue = "";
	var newValueSubsub = "";
	
	var presenti = hiddenValue.value.split(";");
	var presentiSubsub = hiddenValueSubsub.value.split(";");
	
	var i;
	for(i=0;i<presenti.length;i++) {
		if ((presenti[i]!=subcat & (presenti[i] != "")) ) {
			newValue = newValue+presenti[i]+";";
		}
	}
	hiddenValue.value = newValue;
	
	var z;
	for(z=0;z<presentiSubsub.length;z++) {
		if ((presentiSubsub[z]!=subSubcat & (presentiSubsub[z] != "")) ) {
			newValueSubsub = newValueSubsub+presentiSubsub[z]+";";
		}
	}
	hiddenValueSubsub.value = newValueSubsub;
}

function filtraCatSottocat() {
	filtraCat();
	filtraSottocat();
}

/* VECCHIA funzionante
function filtraCat() 
{
	var cboCat = document.getElementById("categoria");
	var cboSubcatHidden = document.getElementById("sottocategoria_hidden");
	var cboSubcat = document.getElementById("sottocategoria");
	var opts = cboSubcatHidden.getElementsByTagName("OPTION");
	//ripulisco tutto
	while (cboSubcat.options.length>0) {
		cboSubcat.remove(0);
	}
	var i;
	for(i=0;i<opts.length;i++) {
		if ((opts[i].attributes['cat'].value == cboCat.value) || (opts[i].attributes['cat'].value == -2)) {
			var elOptNew = document.createElement('option');
			elOptNew.text = opts[i].text;
			elOptNew.value = opts[i].value;
			try {
			  cboSubcat.add(elOptNew, null); // standards compliant; doesn't work in IE
			} catch(ex) {
			  cboSubcat.add(elOptNew); // IE only
			}			//mostra
		}*/ /*else {
			//nascondi
			opts[i].className = "invisibile";
		}*/
	/*}
	cboSubcat.selectedIndex = 0;
	//cboSubcat.setAttribute("size","9");
}*/

function filtraCat() 
{
	var cboCat = document.getElementById("categoria");
	var cboSubcatHidden = document.getElementById("sottocategoria_hidden");
	var cboSubcat = document.getElementById("sottocategoria");
	var cboSubsubcatHidden = document.getElementById("sottosottocategoria_hidden");
	var cboSubsubcat = document.getElementById("sottosottocategoria");
	var opts = cboSubcatHidden.getElementsByTagName("OPTION");
	var subOpts = cboSubsubcatHidden.getElementsByTagName("OPTION");
	
	//ripulisco tutto
	while (cboSubcat.options.length>0) {
		cboSubcat.remove(0);
	}
	var i;
	//creo un'opzione vuota
	var elOptNew = document.createElement('option');
	elOptNew.text = '';
	elOptNew.value = '-1';
	try {
		cboSubcat.add(elOptNew, null); // standards compliant; doesn't work in IE
	} catch(ex) {
		cboSubcat.add(elOptNew); // IE only
	}
	for(i=0;i<opts.length;i++) {
		if ((opts[i].attributes['cat'].value == cboCat.value) || (opts[i].attributes['cat'].value == -2)) {
			var elOptNew = document.createElement('option');
			elOptNew.text = opts[i].text;
			elOptNew.value = opts[i].value;
			try {
			  cboSubcat.add(elOptNew, null); // standards compliant; doesn't work in IE
			} catch(ex) {
			  cboSubcat.add(elOptNew); // IE only
			}//mostra
		}
	}
	cboSubcat.selectedIndex = 0;
	
	//ripulisco tutto
	while (cboSubsubcat.options.length>0) {
		cboSubsubcat.remove(0);
	}
	var z;
	//creo un'opzione vuota
	var elSubOptNew = document.createElement('option');
	elSubOptNew.text = '';
	elSubOptNew.value = '-1';
	try {
		cboSubsubcat.add(elSubOptNew, null); // standards compliant; doesn't work in IE
	} catch(ex) {
		cboSubsubcat.add(elSubOptNew); // IE only
	}
	//creo tutte le altre opzioni
	for(z=0;z<subOpts.length;z++) {
		if ((subOpts[z].attributes['subcat'].value == cboSubcat.value) || (subOpts[z].attributes['subcat'].value == -2)) {
			var elSubOptNew = document.createElement('option');
			elSubOptNew.text = subOpts[z].text;
			elSubOptNew.value = subOpts[z].value;
			try {
			  cboSubsubcat.add(elSubOptNew, null); // standards compliant; doesn't work in IE
			} catch(ex) {
			  cboSubsubcat.add(elSubOptNew); // IE only
			}			//mostra
		} /*else {
			//nascondi
			opts[i].className = "invisibile";
		}*/
	}
	cboSubsubcat.selectedIndex = 0;
}

function filtraSottocat() 
{
	var cboSottoCat = document.getElementById("sottocategoria");
	var cboSubsubcatHidden = document.getElementById("sottosottocategoria_hidden");
	var cboSubsubcat = document.getElementById("sottosottocategoria");
	var subOpts = cboSubsubcatHidden.getElementsByTagName("OPTION");
	//ripulisco tutto
	while (cboSubsubcat.options.length>0) {
		cboSubsubcat.remove(0);
	}
	var z;
	//creo un'opzione vuota
	var elSubOptNew = document.createElement('option');
	elSubOptNew.text = '';
	elSubOptNew.value = '-1';
	try {
	  cboSubsubcat.add(elSubOptNew, null); // standards compliant; doesn't work in IE
	} catch(ex) {
	  cboSubsubcat.add(elSubOptNew); // IE only
	}
	//creo tutte le altre opzioni
	for(z=0;z<subOpts.length;z++) {
		if ((subOpts[z].attributes['subcat'].value == cboSottoCat.value) || (subOpts[z].attributes['subcat'].value == -2)) {
			var elSubOptNew = document.createElement('option');
			elSubOptNew.text = subOpts[z].text;
			elSubOptNew.value = subOpts[z].value;
			try {
			  cboSubsubcat.add(elSubOptNew, null); // standards compliant; doesn't work in IE
			} catch(ex) {
			  cboSubsubcat.add(elSubOptNew); // IE only
			}			//mostra
		} /*else {
			//nascondi
			opts[i].className = "invisibile";
		}*/
	}
	cboSubsubcat.selectedIndex = 0;
	//cboSubcat.setAttribute("size","9");
}





