// funzioni gestione DB per pagina Enciclopedia

// visualizza elenco federati per categoria
function showEnciclopediaByCategory(cat) {

	// salva categoria scelta per utilizzo in getComboBoxCategorie
	top.selectedCategory = cat;

	if (cat != "none") {
		if (cat == "newEntries")
		{
			top.body.location = "enciclopedia.html?t=SelectNewEntries";
		}
		else if (cat == "allEntries")
		{
			top.body.location = "enciclopedia.html?t=SelectAllEntries";
		}
		else if (cat == "italian")
		{
			top.body.location = "enciclopedia.html?t=SelectIsInSorted&f1="+DB_LINGUA+"&v1=I";
		}
		else if (cat == "stranger")
		{
			top.body.location = "enciclopedia.html?t=SelectNotEqualSorted&f1="+DB_LINGUA+"&v1=I";
		}
		else {
			top.body.location = "enciclopedia.html?t=SelectIsInSorted&f1="+DB_CHIAVE+"&v1="+cat;
		}
	}
	
}

function getComboBoxCategorie() {

	//db_cat.sort(); // Sort tabella categorie

	// Crea combobox
	document.write('<select name="categorie" size="1"');
	document.write(' onchange="showEnciclopediaByCategory(document.enciclopedia.categorie.value);">');

	// Imposta titolo e ricerche fisse
	document.write('<option value="none">--- Seleziona una categoria ---</option>');

	document.write('<option value="allEntries"');
	if (top.selectedCategory == "allEntries") {document.write(' selected');}
	document.write('>=> TUTTI I SITI ISCRITTI</option>');

	document.write('<option value="newEntries"');
	if (top.selectedCategory == "newEntries") {document.write(' selected');}
	document.write('>=> ULTIMI 10 SITI ISCRITTI</option>');

	document.write('<option value="italian"');
	if (top.selectedCategory == "italian") {document.write(' selected');}
	document.write('>=> TUTTI I SITI ITALIANI</option>');

	document.write('<option value="stranger"');
	if (top.selectedCategory == "stranger") {document.write(' selected');}
	document.write('>=> TUTTI I SITI STRANIERI</option>');

	for (i_cat=0; i_cat<db_cat.length; i_cat++) {
		cat_codice = db_cat[i_cat][CAT_CODICE];
		cat_testo  = db_cat[i_cat][CAT_TESTO];
		//document.write('<option value="'+cat_codice+'">'+cat_testo+'</option>');	

		document.write('<option value="'+cat_codice+'"');
		if (top.selectedCategory == cat_codice) {document.write(' selected');}
		document.write('>'+cat_testo+'</option>');
	}

	document.write('</select>');

}
