



function pubEleB(){
  if (document.sendamessage.sezEleB.value=="") {
      alert('scegliere la sezione dove si trova l\'elemento da pubblicare.');
  }
  else if (document.sendamessage.idEleB.value=="") {
      alert('inserire il numero ID delll\'elemento da pubblicare.');
  }
  else {
    codEleB=' [PUB '+document.sendamessage.sezEleB.value+']'+document.sendamessage.idEleB.value+'[END '+document.sendamessage.sezEleB.value+']';
   document.sendamessage.messaggio.value=document.sendamessage.messaggio.value+codEleB;
  nascondiFormEleB();
  }
  
  
 }

function mostraFormEleB(){
  document.getElementById('divLinkEleB').style.visibility="hidden";
  document.getElementById('divFormEleB').style.display="block";
    
 }

function nascondiFormEleB(){
  document.getElementById('divLinkEleB').style.visibility="visible";
  document.getElementById('divFormEleB').style.display="none";
    
 }






function showform(achi, riferimento){

chiappaloscroll();


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

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


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

	if (myHeight<550) {
		document.getElementById('maschera').style.top='224px';
		document.getElementById('loadingBacheca').style.top='224px';
	}

	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('contenuto').innerHTML="loading...";

	_url="bacheca_ajax.php?cosa=form&achi="+achi+"&riferimento="+riferimento;

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

}




///////////////////////
//////// RICERCA RAPIDA

var nomitrovati=new Array;
var ultimoselezionato=0;
var v=-1;

function captureKey(e) {
	e=e||window.event;
	v=e.keyCode;
	if (v==38 || v==40) spostaSel(v);
	else if (v==13) document.getElementById('CNB').style.display='none';

}

document.onkeydown = captureKey;


function spostaSel(v){
	if (v==40) ultimoselezionato++;
	else if (v==38) ultimoselezionato--;

	if (ultimoselezionato>=nomitrovati.length && ultimoselezionato>0) ultimoselezionato=1;
	if (ultimoselezionato<1) ultimoselezionato=nomitrovati.length-1;

	if (ultimoselezionato>0) {
		d="CN"+ultimoselezionato;
		
for (a=1; a<nomitrovati.length; a++)
{
    ddd="CN"+a;
    document.getElementById(ddd).style.backgroundColor="";

}

		document.getElementById(d).style.backgroundColor="#aaaaff";
    document.sendamessage.utenti.value=nomitrovati[ultimoselezionato-1];
	}
}


function cercanomi(){
	
n=document.sendamessage.utenti.value;


if (n.length>1 && v!=38 && v!=40 && v!=13) {
	_url="bacheca_cercanomi.php?n="+n;

	httpRequest("GET", _url, true, handleResponseCNB);
		
	}

}



function handleResponseCNB(){

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

			if (mex){

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

		nomitrovati=("");
		ultimoselezionato=0;

		nomitrovati=uscita[1].split("###");

		document.getElementById('CNB').style.left="50%";
		document.getElementById('CNB').style.marginLeft="-84px";

		document.getElementById('CNB').style.top="50%";
		document.getElementById('CNB').style.marginTop=yScroll+70+"px";

		if (myHeight<550) document.getElementById('CNB').style.top='-400px';

				document.getElementById('CNB').style.display='block';
				document.getElementById('CNB').innerHTML=uscita[0];
			}
		} else {
			alert ("Problema di connessione");
		}
	} 
}





function scriviNomeProposto(ni) {
	document.sendamessage.utenti.value=ni;
	document.getElementById('CNB').style.display='none';
	ultimoselezionato=0;
}


/////////////////////////////////////////////
/////////////////////////////////////////////









function handleResponseIcons(){

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


	document.getElementById('mascheraicone').innerHTML=mex;
	document.getElementById('icone').innerHTML='';

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



function handleResponseRub(){

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


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

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







function eliminaBac(iden, ric){

	if (confirm('Eliminare il messaggio?')) {
		urlo='bacheca_elimina.php?id='+iden+'&ric='+ric;
		httpRequest("GET", urlo, true, handleResponseEliminaBac);
	}
}






function showrub(){
	
	chiappaloscroll();

	document.getElementById('mascherarub').style.top="50%";
	document.getElementById('mascherarub').style.left="190";
	document.getElementById('mascherarub').style.marginTop=yScroll-150+"px";

	document.getElementById('ombrarub').style.top="50%";
	document.getElementById('ombrarub').style.left="210";
	document.getElementById('ombrarub').style.marginTop=yScroll-130+"px";

	document.getElementById('mascherarub').style.display="block";
	document.getElementById('ombrarub').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('rubrica').innerHTML="loading...";

	var ran=Math.random(100);

	_url="rubrica_ajax.php?ran="+ran;


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

}











function showSms(){

chiappaloscroll();


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

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

	if (myHeight<550) document.getElementById('maschera').style.top='224px';


	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('contenuto').innerHTML="loading...";

	_url="sms_ajax.php?p=form";

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

}




function conta(){	
sch=document.getElementById('formSms');
x=sch.message.value.length+1;	
sch.txt.value=160-x;	

if (x==161){
  alert('Il numero di caratteri massimi è stato superato');
  }

} 









function showicons(pagina){


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

	_url="icone_ajax.php?pagina="+pagina;

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

}






function addrub(cosa, nome){


	if (nome=="") {
			alert ('Selezionare il nome');
		return;
	}


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


	_url="rubrica_ajax.php?cosa="+cosa+"&aggiungi="+nome;


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


}








function inviaform(achi, messaggio, rubrica, riferimento){

	if (achi=='') {
		alert('Inserire un destinatario'); 
		return;
	}



	document.getElementById('maschera').style.display='none';
	document.getElementById('loadingBacheca').style.display='block';
	

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

	messaggio=encodeURIComponent(messaggio);
	achi=encodeURIComponent(achi) ;

	_url="bacheca_ajax.php";
	_data="cosa=invia&utenti="+achi+"&messaggio="+messaggio+"&rubrica="+rubrica+"&riferimento="+riferimento;


	httpRequest("POST", _url, true, handleResponseBac, _data);
}








function inviaSms(){	
sch=document.getElementById('formSms');
to=sch.to.value;


message=sch.message.value;

	if (to=='' || to=='39') {
		alert('Selezionare un destinatario'); 
		return;
	}
	else if (message=='') {
		alert('Messaggio vuoto'); 
		return;
	}




message=encodeURIComponent(message) ;

  stringa="?to="+to+"&message="+message;

  _url="sms_ajax.php"+stringa;

        document.getElementById('resultSms').innerHTML="Invio in corso";
       
sch.to.value='39';
sch.message.value='';
sch.txt.value='160';


 	httpRequest("GET", _url, true, handleResponseSms);
}












function rubricaSms(fase, destinatario, telefono, opz){	


destinatario=encodeURIComponent(destinatario);


if (fase==1){
_url='sms_ajax.php?rubrica=lista';

}
else if (fase==2){

_url='sms_ajax.php?rubrica=modifica&id='+opz;

}
else if (fase==3){

_url='sms_ajax.php?rubrica=aggiungi';

}
else if (fase==4){
	if (telefono=='') {
			alert('Inserire un numero');
			return;
	}
	if (destinatario=='') {
			alert('Inserire un nome');
			return;
	}


_url='sms_ajax.php?rubrica=eseguiAggiunta&destinatario='+destinatario+'&telefono='+telefono;

}

else if (fase==5){
	if (telefono=='') {
			alert('Inserire un numero');
			return;
	}
	if (destinatario=='') {
			alert('Inserire un nome');
			return;
	}

_url='sms_ajax.php?rubrica=eseguiModifica&id='+opz+'&destinatario='+destinatario+'&telefono='+telefono;

}

else if (fase==6){
	if (confirm('Eliminare '+telefono+' ?')) {
		_url='sms_ajax.php?rubrica=elimina&id='+opz;
	}
}


      document.getElementById('contenuto').innerHTML="Loading...";
       
  	httpRequest("GET", _url, true, handleResponseBac);
}













function chiudi(){

	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('maschera').style.display="none";
	document.getElementById('ombra').style.display="none";
}





function chiudiIcons(){

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

}







function chiudiRub(){

	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('mascherarub').style.display="none";
	document.getElementById('ombrarub').style.display="none";

}






function quota(chi, cosa){
					document.getElementById('sendamessage').messaggio.value+='\n\n--------------------------------------------- \n\n'+chi+' ha scritto: \n\n';
					document.getElementById('sendamessage').messaggio.value+=cosa;

}





function espandi(n){
		if (n==1) {
			document.getElementById('riferimento').style.display='block';
						document.getElementById('bottone').style.display='none';
		}	
		else {
			document.getElementById('riferimento').style.display='none';
						document.getElementById('bottone').style.display='block';
		}	
	}






 function icona(key){
var po=document.getElementById('sendamessage');

	po.messaggio.value=po.messaggio.value+ ' '+key+' ';
	po.messaggio.focus();
}








function seleziona(q,t){

document.sendamessage.utenti.value='TuttiGliAmici';

	if (t==3){

		for (a=0; a<q; a++){
			ami='amico'+a;
			document.getElementById(ami).checked=false;
		}
	}


	else if (t==2){

		for (a=0; a<q; a++){
			ami='amico'+a;
			document.getElementById(ami).checked=true;
			document.sendamessage.utenti.value+="-6#Q#2-"+document.getElementById(ami).value;
		}
	}



	else {
		for (a=0; a<q; a++){
			ami='amico'+a;
			if (document.getElementById(ami).checked==true) {
				document.sendamessage.utenti.value+="-6#Q#2-"+document.getElementById(ami).value;
			}
		}
	}



}








function handleResponseBac(){

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



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

	document.getElementById('loadingBacheca').style.display='none';
	document.getElementById('maschera').style.display='block';

	document.getElementById('contenuto').innerHTML=uscita[0];

	if (uscita[1]=="1") document.location.href="bacheca.php";
	else if (uscita[1]=="2") setTimeout("chiudi()",2000);

		} else {

			document.getElementById('loadingBacheca').style.display='none';
			document.getElementById('maschera').style.display='block';
			alert ("Problema di connessione");
		}
	} 
}




function handleResponseIcons(){

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


	document.getElementById('mascheraicone').innerHTML=mex;
	document.getElementById('icone').innerHTML='';

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



function handleResponseRub(){

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


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

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







function eliminaBac(iden, ric){

	if (confirm('Eliminare il messaggio?')) {
		urlo='bacheca_elimina.php?id='+iden+'&ric='+ric;
		httpRequest("GET", urlo, true, handleResponseEliminaBac);
	}
}



function handleResponseEliminaBac(){

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

	document.getElementById(mex).style.display='none';
	
		} else {
			alert ("Problema di connessione");
		}
	} 
}










function handleResponseSms(){



	if (request.readyState==4){
		if (request.status==200){
			var mex=request.responseText;
			
		        document.getElementById('resultSms').innerHTML=mex;


		} 
	}


}

