function refreshProdotti() {
	try {
		var req = new JSRequest();
		var xml = req.openXMLURL('vetrinaProdottiAjax.php?');
		
		var prodotti = xml.getElementsByTagName('prodotto');
		
		var id;
		var prodotto;
		var foto;
		var idCategoria;
		var categoria;
		var nome;
		var prezzo;
		
		var div;
		var html;
	
		for (var i = 0;i < prodotti.length;i++) {
			try {
				prodotto = prodotti[i];
				id = prodotto.getElementsByTagName('id')[0].firstChild.nodeValue;
				try { foto = prodotto.getElementsByTagName('foto')[0].firstChild.nodeValue; } catch(ex) {foto = ''};
				try { idCategoria = prodotto.getElementsByTagName('idCategoria')[0].firstChild.nodeValue; } catch(ex) {idCategoria = ''};
				try { categoria = prodotto.getElementsByTagName('categoria')[0].firstChild.nodeValue;} catch(ex) {categoria = ''};
				try { nome = prodotto.getElementsByTagName('nome')[0].firstChild.nodeValue;} catch(ex) {nome = ''};
				try { prezzo = prodotto.getElementsByTagName('prezzo')[0].firstChild.nodeValue;} catch(ex) {prezzo = ''};
				
				div = document.getElementById('vetrinaprodotti' + (i + 1));
				
				html  = '<br>';
				html += '<img src="foto/' + foto + '" class="minilink1" alt="' + nome + '" onclick="location.href = \'shopd.php?id=' + id +'\';"><br>';
				html += '<a href="categoriad.php?id=' + idCategoria +'">' + categoria +'</a>';
				html += '<h3><a href="shopd.php?id=' + id + '">' + nome +'<br>' + prezzo + '</a></h3>';
				
				div.innerHTML = html;
			} catch(ex) {};
		}
	} catch(ex) {};
}

function refreshInterviste() {
	try {
		var req = new JSRequest();
		var xml = req.openXMLURL('vetrinaIntervisteAjax.php?');
		
		var interviste = xml.getElementsByTagName('intervista');
		
		var id;
		var foto;
		var titolo;
		var data;
		var autore;
		var descrizione;
		
		var div;
		var html;
		
		var fotoImg;
		var height;
		var width;
	
		for (var i = 0;i < interviste.length;i++) {
			try {
				intervista = interviste[i];
				id = intervista.getElementsByTagName('id')[0].firstChild.nodeValue;
				try { foto = intervista.getElementsByTagName('foto')[0].firstChild.nodeValue; } catch(ex) {foto = ''};
				try { titolo = intervista.getElementsByTagName('titolo')[0].firstChild.nodeValue; } catch(ex) {titolo = ''};
				try { data = intervista.getElementsByTagName('data')[0].firstChild.nodeValue; } catch(ex) {data = ''};
				try { autore = intervista.getElementsByTagName('autore')[0].firstChild.nodeValue; } catch(ex) {autore = ''};
				try { descrizione = intervista.getElementsByTagName('descrizione')[0].firstChild.nodeValue; } catch(ex) {descrizione = ''};
				
				div = document.getElementById('vetrinainterviste' + (i + 1));
				
				if (i == 0) {
					fotoImg = new Image();
					fotoImg.src = 'foto/' + foto;
					altezza = fotoImg.height;
					larghezza = fotoImg.width;
					
					if (larghezza > 400) {
						altezza = (altezza * 400) / larghezza;
						larghezza = 400;
					}
					
					if (altezza > 400) {
						larghezza = (larghezza * 400) / altezza;
						altezza = 400;
					}
					
					html  = '<img src="foto/' + foto + '" width="' + larghezza + '" height="' + altezza + '" alt="">';
					html += '<h2><a href="intervistad.php?id=' + id + '">' + titolo + '</a></h2>';
					html += '<h6>(' + data + ') di ' + autore + '</h6>';
					html += '<p> ' + descrizione + '</p>';
				} else {
					html  = '<h3><a href="intervistad.php?id=' + id + '">' + titolo + '</a></h3>';
					html += '<h6>(' + data + ') di ' + autore + '</h6>';
					html += '<p> ' + descrizione + '</p>';
				}
				
				div.innerHTML = html;
			} catch(ex) {};
		}
	} catch(ex) {};
}

function refresh() {
	refreshInterviste();
	refreshProdotti();
	setTimeout("refresh()",10000);
}
