var yScroll;
var myWidth = 0, myHeight = 0;
var preferitiDiChi='';
var albumUtente='';


function spostaOmbra() {
	chiappaloscroll();
	document.getElementById('ombra').style.top=yScroll;

}

function chiappaloscroll(){

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth -15;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 

}


function showPreferiti(chi){

	preferitiDiChi=chi;
	chiappaloscroll();

	document.getElementById('mascherapreferiti').style.top="50%";
	document.getElementById('mascherapreferiti').style.marginTop=yScroll-260+"px";

	if (myHeight<550) document.getElementById('mascherapreferiti').style.top='264px';

	document.getElementById('titoloPreferiti').innerHTML="I Preferiti di <b>"+chi+"</b>";

	document.getElementById('mascherapreferiti').style.display="block";

	document.getElementById('ombra').style.top=yScroll;
	document.getElementById('ombra').style.left="0px";
	document.getElementById('ombra').style.width=myWidth;
	document.getElementById('ombra').style.height=myHeight;

	document.getElementById('ombra').style.display="block";

	document.getElementById('preferiti').innerHTML="loading...";

	if (document.getElementById('selectShop')) document.getElementById('selectShop').style.display="none";

	if (document.getElementById('selectCateFoto')) document.getElementById('selectCateFoto').style.display="none";

	if (document.getElementById('selectRubrica')) document.getElementById('selectRubrica').style.display="none";

	r=Math.random();

	_url="preferiti.php?fase=7&nick="+chi+"&ran="+r;


	httpRequest("GET", _url, true, handleResponsePreferiti);

}






function handleResponsePreferiti(){

	if (request.readyState==4){
		if (request.status==200){
			var mex=request.responseText;


	document.getElementById('preferiti').innerHTML=mex;

		} else {
			alert ("Problema di connessione");
		}
	} 
}







function showpic(cosa, foto){


chiappaloscroll();


	if (preferitiDiChi!='') {document.getElementById('mascherapreferiti').style.display="none";}


	document.getElementById('tastieraFoto').foto.value=foto;

	document.getElementById('mascherafoto').style.top="50%";
	document.getElementById('mascherafoto').style.marginTop=yScroll-290+"px";

	if (myHeight<550) document.getElementById('mascherafoto').style.top='294px';

	document.getElementById('mascherafoto').style.display="block";

	document.getElementById('ombra').style.top=yScroll;
	document.getElementById('ombra').style.left="0px";
	document.getElementById('ombra').style.width=myWidth;
	document.getElementById('ombra').style.height=myHeight;

	document.getElementById('ombra').style.display="block";


	if (document.getElementById('selectShop')) document.getElementById('selectShop').style.display="none";

	if (document.getElementById('selectCateFoto')) document.getElementById('selectCateFoto').style.display="none";

	if (document.getElementById('selectRubrica')) document.getElementById('selectRubrica').style.display="none";



	document.getElementById('dettagli').innerHTML="...";


	document.getElementById('pic').innerHTML="loading...";

	document.getElementById('tastieraFoto').voto.selectedIndex=0;

	_url="foto_ajax.php?foto="+foto+"&cosa="+cosa;


	httpRequest("GET", _url, true, handleResponseFoto);

}






function vota(voto, foto){


	_url="foto_ajax.php?foto="+foto+"&cosa="+7+"&voto="+voto;

	httpRequest("GET", _url, true, handleResponseFoto);

}







function preferiti(id, tipo, fase, descrizione, fanclub){

	if (fase=='6') {if (!confirm('Eliminare: '+descrizione+'?')) return;}


	descrizione=descrizione.replace(/\r\n/g,"<br>");
	descrizione=descrizione.replace(/\r/g,"<br>");
	descrizione=descrizione.replace(/\n/g,"<br>");

	descrizione=encodeURIComponent(descrizione);

	if (fase!='1' && descrizione=='') {
		alert('Inserire una descrizione!');
		return;
	}

	r=Math.random();

	_url="preferiti.php?id="+id+"&tipo="+tipo+"&fase="+fase+"&descrizione="+descrizione+"&fanclub="+fanclub+"&ran="+r;


	httpRequest("GET", _url, true, handleResponsePref);

}





function commenta(commento, foto){

	commento=commento.replace(/\r\n/g,"<br>");
	commento=commento.replace(/\r/g,"<br>");
	commento=commento.replace(/\n/g,"<br>");

	r=Math.random();

	_url="foto_ajax.php?foto="+foto+"&cosa="+8+"&commento="+encodeURIComponent(commento)+"&ran="+r;

	document.getElementById('pic').innerHTML="invio in corso";

	httpRequest("GET", _url, true, handleResponseFoto);

}



function cartolina(foto, mittente, emailmittente, ricevente, emailricevente, messaggio){

	messaggio=messaggio.replace(/\r\n/g,"<br>");
	messaggio=messaggio.replace(/\r/g,"<br>");
	messaggio=messaggio.replace(/\n/g,"<br>");

	messaggio=encodeURIComponent(messaggio);

	_url="foto_ajax.php?foto="+foto+"&cosa="+9+"&mittente="+mittente+"&emailmittente="+emailmittente+"&ricevente="+ricevente+"&emailricevente="+emailricevente+"&messaggio="+encodeURIComponent(messaggio);



	httpRequest("GET", _url, true, handleResponseFoto);

}

function chiudiFoto(){

	if (preferitiDiChi!='') {
		document.getElementById('mascherapreferiti').style.display="block";

	}

	else {
		document.getElementById('ombra').style.display="none";

	if (document.getElementById('selectShop')) document.getElementById('selectShop').style.display="block";

	if (document.getElementById('selectCateFoto')) document.getElementById('selectCateFoto').style.display="block";

	if (document.getElementById('selectRubrica')) document.getElementById('selectRubrica').style.display="block";

	}

	document.getElementById('mascherafoto').style.display="none";


}



function chiudiPreferiti(){
	preferitiDiChi='';


	if (document.getElementById('selectRubrica')) document.getElementById('selectRubrica').style.display="none";

	if (document.getElementById('selectShop')) document.getElementById('selectShop').style.display="block";

	if (document.getElementById('selectCateFoto')) document.getElementById('selectCateFoto').style.display="block";

	if (document.getElementById('selectRubrica')) document.getElementById('selectRubrica').style.display="block";

	document.getElementById('mascherapreferiti').style.display="none";
	document.getElementById('ombra').style.display="none";
}


function handleResponseFoto(){

	if (request.readyState==4){
		if (request.status==200){
			var mex=request.responseText;


	uscita=mex.split("[#]");


	document.getElementById('pic').innerHTML=uscita[1];

	if (uscita[0].match(/album/)) {
		albumUtente="&album=1";
		uscita[0].replace("album","");
	}
	else albumUtente="";


	document.tastieraFoto.foto.value=uscita[0];

	if (uscita[2]) document.getElementById('dettagli').innerHTML=uscita[2];


		} else {
			alert ("Problema di connessione");
		}
	} 
}




function handleResponsePref(){

	if (request.readyState==4){
		if (request.status==200){
			var mex=request.responseText;


	
	if (document.getElementById('mascherafoto').style.display=='block') document.getElementById('pic').innerHTML=mex;

else document.getElementById('preferiti').innerHTML=mex;


		} else {
			alert ("Problema di connessione");
		}
	} 
}



