var lista = "";
var arrayResponse = new Array();

function vistaProdotti(categoria,tipo){
	var req = Math.floor(Math.random()*1000);	
		var myConn = new XHConn();
		if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
		var fnWhenDone = function (oXML) {
		var response = oXML.responseText;			    
			mostraProdotti(response);				          
		  };
	 if(!categoria==""){
	  switch(categoria)
    {
     case 'Sci':
         myConn.connect("/design/shop/php/VisualizzaProdottiSci.php", "GET","&req="+req, fnWhenDone);
     break    
     case 'Abbigliamento':
         if(!tipo==""){
			myConn.connect("/design/shop/php/VisualizzaProdottiAbbigliamento.php", "GET","tipo="+tipo+"&req="+req, fnWhenDone);
		}
		else{
			myConn.connect("/design/shop/php/VisualizzaProdottiAbbigliamento.php", "GET","tipo=0&req="+req, fnWhenDone);
		}
     break
     case 'Accessori':
         if(!tipo==""){
			myConn.connect("/design/shop/php/VisualizzaProdottiAccessori.php", "GET","modello="+tipo+"&req="+req, fnWhenDone);
		}
		else{
			myConn.connect("/design/shop/php/VisualizzaProdottiAccessori.php", "GET","modello=0&req="+req, fnWhenDone);
		}
     break
    }
    }	
}

function visualizzaProdotto(){
    if(!document.prodotti.categoria.selectedIndex==""){
        var categoria = document.prodotti.categoria.options[document.prodotti.categoria.selectedIndex].value;
		if(!document.prodotti.tipo.selectedIndex==""){
			var tipo = document.prodotti.tipo.options[document.prodotti.tipo.selectedIndex].value;
			}
		}
	vistaProdotti(categoria,tipo);
	}

function mostraProdotti(response) {
    var bloccoevento=document.getElementById("mostraProdotti");
    bloccoevento.innerHTML=response;
    }
/*funzione che mi genera gli elementi "option" dopo la selezione della categoria di abbigliamento */
function setTipiProdotti(chooser) {
    var newElem;
    var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    var cityChooser = chooser.form.elements["tipo"];
    while (cityChooser.options.length) {
        cityChooser.remove(0);
    }
    var categoria = chooser.options[chooser.selectedIndex].value;
    var tipi = generaListaTipi(categoria);
    newElem = document.createElement("option");
    newElem.text = "Tutti";
    newElem.value = "";
    cityChooser.add(newElem, where);
    if (categoria != "") {
        for (var i = 0; i < tipi.length; i++) {
            newElem = document.createElement("option");
            newElem.text = tipi[i];
            newElem.value = tipi[i];
            cityChooser.add(newElem, where);
        }
    }
}

/*Funzione che interroga il database (attraverso il file php specifico per quella categoria) e mi ritorna un array di stringhe*/
function generaListaTipi(categoria){

 var listaProdotto = new Array();

	switch(categoria)
    {
	 case 'Sci':
         lista="";
     break 
     case 'Abbigliamento':
         lista=arrayResponse['308'];
     break
     case 'Accessori':
        lista=arrayResponse['314'];
     break
    }
 listaProdotto = lista.split('--');
 return (listaProdotto);
}

function raccogliTipi(){
	leggiLista("308");
	leggiLista("314");
}

function leggiLista(tipo){
	var req = Math.floor(Math.random()*1000);	
		var myConn = new XHConn();
		if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
		var fnWhenDone = function (oXML) {
		var response = oXML.responseText;
        arrayResponse[tipo]=response;				          
		  };
	    myConn.connect("/design/shop/php/LeggiAttributo.php", "GET","attributo="+tipo+"&req="+req, fnWhenDone);
}

