//PER SELECT DINAMICHE


//Definisco categoria e marca selezionate
var path = window.location.search;

if(path.indexOf('=')<0){
	var cat = 'Cucine';
	var sel = 'Maistri';
}else{
	var cat = path.split("=")[2];
	var sel = path.split("=")[1].split("&")[0];
	}
//alert(sel+' || '+cat);  //OK
/*
selectSx = window.document.getElementById('category');
selectSx.selectedIndex = 2;
*/



var arrayData = new Array(); 

arrayData[0]	= 'Cucine|Selezionare|'
arrayData[1]	= 'Cucine|Maistri|prodotti_cucine_maistri.php|'
arrayData[2]	= 'Cucine|Grattarola|prodotti_cucine_grattarola.php|'
arrayData[3]	= 'Salotti|Selezionare|'

arrayData[4]	= 'Salotti|Giulio Marelli|prodotti_soggiorni_giulio_marelli.php|'

arrayData[5]	= 'Camere|Selezionare|'
arrayData[6]	= 'Camere|Mobilform|prodotti_camere_mobilform.php|'
arrayData[7]	= 'Camere|Jesse|prodotti_camere_jesse.php|'
//arrayData[8]	= 'Camere|Tessilform|prodotti_camere_tessilform.php|'
arrayData[8]	= 'Complementi|Selezionare|'
arrayData[9]	= 'Complementi|Longhi|prodotti_complementi_longhi.php|'

arrayData[10] 	= 'Soggiorni|Selezionare|';
arrayData[11]	= 'Soggiorni|Grattarola|prodotti_soggiorni_pedretti.php|'
arrayData[12]	= 'Soggiorni|Jesse|prodotti_soggiorni_jesse.php|'
arrayData[13]	= 'Camerette|Selezionare'
arrayData[14]	= 'Camerette|Varie|prodotti_camerette.php'


function populateData( name ) { 
 	select	= window.document.getElementById('SubCategory');
	string	= ""; 
	count	= 0;
	select.options.length = count; 
	
	// Inserisce nelle opzioni della lista tutte le categorie corrispondenti 
	for( i = 0; i < arrayData.length; i++ ) { 
		string = arrayData[i].split( "|" ); 
		if( string[0] == name ) {
			idx = count++;
			select.options[idx] = new Option( string[1]);
			select.options[idx].text = string[1];
			//imposto opzione selezionata
			if(select.options[idx].text == sel){
				select.options.selectedIndex = 0;
				/*select.options.selectedIndex = idx;*/
				}

			select.options[idx].value = string[2];
		} 

	} 
 	// Imposta quali opzioni della sottocategoria devono essere selezionate
	// select.options.selectedIndex = 0; 

	// Da il focus alle sottocategorie
	select.focus(); 
}

function vai(selezione){
	categoria = window.document.getElementById('category').options[window.document.getElementById('category').selectedIndex].text;
	location.href = selezione.value+'?sel='+selezione.text+'&cat='+categoria;
	//location.href = selezione.value+'?sel='+selezione.text;
}

