

var xmlHttp;
var numFoto = 1;
var lock = 0;


function createXmlHttpRequest(){
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}else{
		alert('altro');
	}
}

function avanza(){
	if(numFoto <= 10){
		createXmlHttpRequest();
		numFoto++;
		var url = "aiax.php?op=avanza&num=" + numFoto;
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = callback;
		xmlHttp.send(null);
	}	
}

function avanzaSingolo(){
	if(numFoto <= 10){
		createXmlHttpRequest();
		numFoto++;
		var url = "aiax.php?op=avanza&num=" + numFoto;
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = singleCallback;
		xmlHttp.send(null);
	}
}

function indietreggia(){
	if(numFoto >=2){
		createXmlHttpRequest();
		numFoto--;
		var url = "aiax.php?op=avanza&num=" + numFoto;
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = singleCallback;
		xmlHttp.send(null);
	}
}

function callback(){
	if(lock == 0){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			document.getElementById('stato').style.visibility = 'hidden';
			aggiorna();			
				inizia();						
		}
	}else if ((xmlHttp.readyState == 2) || (xmlHttp.readyState == 3)){
		document.getElementById('stato').style.visibility = 'visible';
	}
	}
}

function singleCallback(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			document.getElementById('stato').style.visibility = 'hidden';
			aggiorna();
		}
	}else if((xmlHttp.readyState == 2) || (xmlHttp.readyState == 3)){
		document.getElementById('stato').style.visibility = 'visible';
	}
}

function aggiorna(){
	var nuovaFoto = xmlHttp.responseXML.getElementsByTagName('foto')[0].firstChild.nodeValue;	
	var divFoto = document.getElementById('immagine_fumetto').getElementsByTagName('img')[0].src = nuovaFoto;	
}

function inizia(){
	if(document.getElementById('immagine_fumetto')){
		lock = 0;
		setTimeout("avanza()",4000);
	}	
}

function stop(){
	lock = 1;
}

function riavvolgi(){
	numFoto = 0;
	lock = 0;
	avanzaSingolo();	
}

function apriBlog(){
	window.open("http://unavitadacazzetti.blogspot.com","","height=600,width=800,resizable=yes,menubar=yes,scrollbars=yes,location=yes,toolbar=yes,status=yes");
}

function mostraFoto(id,testo){
	if((document.getElementById(id).style.display == '') || (document.getElementById(id).style.display == 'none')){
		document.getElementById(id).style.display = 'block';
		document.getElementById('testo_'+id).innerHTML = testo + ' (chiudi)';
	}else{
		document.getElementById(id).style.display = 'none';
		document.getElementById('testo_'+id).innerHTML = testo+'...';
	}
	
}

function mostraPrivacy(testo){
	if((document.getElementById('privacy').style.display == '') || (document.getElementById('privacy').style.display == 'none')){
		document.getElementById('privacy').style.display = 'block';
		document.getElementById('testo_privacy').innerHTML = testo + ' (chiudi)';
	}else{
		document.getElementById('privacy').style.display = 'none';
		document.getElementById('testo_privacy').innerHTML = testo;
	}
	
}

function controlla(){
	var email = document.getElementById('email').value;
	var Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if(! Filtro.test(email)){
		alert('Indirizzo e-mail non valido!');
	}else{
		document.forms[0].submit();
	}

}


function apriPopup(foto){	
	immagine.setAttribute('src','images/shop/big/'+foto); 
	var altezza = immagine.height;

	var larghezza = immagine.width;
	window.open("popup.html","Dettaglio","width=450,height=360");
	
}

function apriPopupFans(foto){	
	immagine.setAttribute('src','images/baby_cazzetti/big/'+foto); 
	var altezza = immagine.height;

	var larghezza = immagine.width;
	window.open("popup.html","Dettaglio","width=450,height=360");
	
}

function aggiungiCarrello(articolo){
	window.open("carrello.php?item="+articolo,"Aggiungi","width=600,height=200");
}
var immagine = document.createElement('img');

function controllaTest(){
	document.getElementById('invia').disabled = false;
}

function riempi_mio_nome(){
	var mio_nome = document.getElementById('io').value;
	document.getElementById('mio_nome').innerHTML = mio_nome;
}

function riempi_nome_amico(){
	var nome_amico = document.getElementById('nome_amico').value;
	document.getElementById('amico').innerHTML = nome_amico;
}

function mostraModulo(livello){
	if(document.getElementById(livello).style.display == 'none'){
		document.getElementById(livello).style.display = 'block';
	}else if(document.getElementById(livello).style.display == 'block'){
		document.getElementById(livello).style.display = 'none';
	}
}
