//Funzioni comuni un po' dappertutto



function aggiungiContattoInListaAmici(id,nome){

	if(!zXmlHttp.isSupported()){//Non leggo il div, visualizzazione classica

		alert('Ajax non disponibile per aggiunta in lista amici; contattare il webmaster!');

		return;

	}

	else{

		var esito = confirm('Confermi l\'inserimento di ' + nome + ' nella lista dei tuoi Amici?');

		if(esito){

			var oXmlHttp = zXmlHttp.createRequest();

			oXmlHttp.open('get','/ajaxRequest/posta_utenti/amici.php?id='+id+'&nome_contatto='+escape(nome),true);

			oXmlHttp.onreadystatechange=function(){

				if(oXmlHttp.readyState == 4){

					if(oXmlHttp.status == 200){

						eval(oXmlHttp.responseText)

					}

					else{

						alert('Error Opening Message');

					}

				}		

			}

			oXmlHttp.send(null);

		}

	}

}



//Torniamoidietro col browser

function tornaIndietro(url_caming_from){

	if(!document.getElementById('LayerElencoMessaggi') || !zXmlHttp.isSupported()){//Non leggo il div, visualizzazione classica

		//Invio classico



		if(document.getElementById('FormInvioMessaggi') && document.getElementById('FormInvioMessaggi').url_caming_from && document.getElementById('FormInvioMessaggi').url_caming_from.value != ''){

			window.location.href = document.getElementById('FormInvioMessaggi').url_caming_from.value;

			return;

		}

		else if(url_caming_from){

			window.location.href = url_caming_from;

			return ;

		}

		else{

			history.go(-1);

			return;

		}

	}

	else{

		if(!document.getElementById('LayerElencoMessaggi') || !document.getElementById('LayerDinamicoSuperiore') || !document.getElementById('LayerDinamicoInferiore') ){

			history.go(-1);

			return;			

		}

		

		//i messaggi SEMPRE nascosti

		document.getElementById('LayerElencoMessaggi').style.display='none';

		//Riattiviamo il form di lettura

		document.getElementById('LayerDinamicoSuperiore').style.display='block';



		//Nascondiamo e ripuliamo il layer dell'utente

		document.getElementById('LayerDinamicoInferiore').innerHTML = '';

		document.getElementById('LayerDinamicoInferiore').style.display='none';

		return;

	}



}







function ajax_admin(){

	if(!zXmlHttp.isSupported()){//Non leggo il div, visualizzazione classica

		alert('Ajax non disponibile; contattare il webmaster');

		return;

	}

	else{

		var oXmlHttp = zXmlHttp.createRequest();

		oXmlHttp.open('get','/ajaxRequest/ajax_admin.php',true);

		oXmlHttp.onreadystatechange=function(){

			if(oXmlHttp.readyState == 4){

				if(oXmlHttp.status == 200){

					eval(oXmlHttp.responseText)

				}

				else{

					displayAjaxContent('LayerDinamicoSuperiore','Error Opening Message');

				}

			}		

		}

		oXmlHttp.send(null);

	}

}



function SwapCommento(hide,show){

	definisciStile(hide).display='none';

	definisciStile(show).display='block';	

}



function SwapCommento4(hide,show,hide_2,show_2){

	

	definisciStile(hide).display='none';

	definisciStile(show).display='block';	

	definisciStile(hide_2).display='none';

	

	definisciStile(show_2).display='block';	

}





function ShowCommentoFoto(id){

	var aLayer = document.getElementsByTagName('div');

	for(i in aLayer){

		if(aLayer[i].id && aLayer[i].id.indexOf('LayerCommentoFoto') != -1 ){

			aLayer[i].style.display='none';

		}

	}

	definisciStile('LayerCommentoFoto_'+id).display='block';

}



//Questa funzione restituisce lo stile di un particolare tag

function definisciStile(type){ 

	if (document.all) calqueStyle = document.all[type].style; 

	if (document.layers) calqueStyle = document.layers[type].style; 

	if (document.getElementById) calqueStyle = document.getElementById(type).style; 

	return calqueStyle; 

} 



function definisciTag(type){ 

	if (document.all) calqueStyle = document.all[type]; 

	if (document.layers) calqueStyle = document.layers[type]; 

	if (document.getElementById) calqueStyle = document.getElementById(type); 

	return calqueStyle; 

} 







function swapButton(type,h1,h2,h3){



	if ( definisciStile(h1).display == 'block')

		definisciStile(h1).display="none"; 

		

	if ( definisciStile(h2).display == 'block')

		definisciStile(h2).display="none"; 

		

	if ( definisciStile(h3).display == 'block')

		definisciStile(h3).display="none"; 

		

	if ( definisciStile(type).display == 'block')

		definisciStile(type).display="none"; 

		

	else

		definisciStile(type).display="block"; 

}







function gotoregister(id){

	window.opener.location = "/register/login/registrazione.php?idinserzionista="+id;

	this.close();

}

function gotologin(id){

	window.opener.location = "/register/login/?idinserzionista="+id;

	this.close();

}



function changeCalqueAndResize(type){ 

	if ( styleCalque(type).display == 'block'){

		styleCalque(type).display="none"; 

		self.resizeTo(570,300) ;

	}

	else{

		self.resizeTo(570,720) ;

		styleCalque(type).display="block"; 

	} 

}





function ControlloAnnuncioFotoscambio()

{

	var f = document.inserimento;

	var l = f.elements.length;

	var ok = 0, cerco = '', offro = '', genereofferta = '', genererichiesta = '';



	for(i = 0; i <= l-1 ; i++)

	{

		if(f.elements[i].name == "offro[]")

		{

			if(f.elements[i].checked == true )

			{

				cerco += f.elements[i].value + '  ';

				ok = 1;

			}

		}

	}

	

	if(ok == 0)

	{

		alert('Devi indicare qualcosa da offrire!');

		return false;

	}

		

	ok=0;

	for(i = 0; i <= l-1 ; i++)

	{

		if(f.elements[i].name == "cerco[]")

		{

			if(f.elements[i].checked == true )

			{

				cerco += f.elements[i].value + '  ';

				ok = 1;

			}

		}

	}

	

	if(ok == 0)

	{

		alert('Devi indicare cosa cerchi!');

		return false;

	}

	ok=0;

	for(i = 0; i <= l-1 ; i++)

	{

		if(f.elements[i].name == "genererichiesta[]")

		{

			if(f.elements[i].checked == true )

			{

				genererichiesta += f.elements[i].value + '  ';

				ok = 1;

			}

		}

	}

	if(ok == 0)

	{

		alert('Devi indicare il genere di quello che cerchi!');

		return false;

	}

	ok=0;

	

	for(i = 0; i <= l-1 ; i++)

	{

		if(f.elements[i].name == "genereofferta[]")

		{

			if(f.elements[i].checked == true )

			{

				genereofferta += f.elements[i].value + '  ';

				ok = 1;

			}

		}

	}

	

	if(ok == 0)

	{

		alert('Devi indicare il genere della tua offerta!!');

		return false;

	}





	msg ='\n\nConfermi l\'inserimento del tuo annuncio di fotoscambio?'

	

	return confirm(msg);

	

		

}







function ControlloInvioMessaggio()

{



	var f = document.postautenti;

	var msg;

	var op;

	if(f.oggetto.value == "")

		f.oggetto.value = "C'è un messaggio per te...";

		

	if(f.idcontatto && f.idcontatto.value == "")

	{

		alert('Attenzione!\n\nNon hai inserito il destinatario del messaggio!');

		f.idcontatto.focus();

		return false;

	}











var host = false;





/* playtimes.it*/

var regex = /[p][\s]*[l][\s]*[a][\s]*[y][\s]*[t][\s]*[i][\s]*[m][\s]*[e][\s]*[s][\s]*[\.]*[\s]*[i][\s]*[t]/i;

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}



/* hotsexduo.com*/

var regex = /[h][\s]*[o][\s]*[t][\s]*[s][\s]*[e][\s]*[x][\s]*[d][\s]*[u][\s]*[o][\s]*[\.]*[\s]*[c][\s]*[o][\s]*[m]/i;

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}



/* answers*/

var regex = /[a][\s]*[n][\s]*[z][\s]*[w][\s]*[e][\s]*[r][\s]*[s][\s]*[\.]*[\s]*[n][\s]*[e][\s]*[t]/i;

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}



/* happysexo */

var regex = /[h][\s]*[a][\s]*[p][\s]*[p][\s]*[y][\s]*[s][\s]*[e][\s]*[x][\s]*[o][\s]*[\.]*[\s]*[c][\s]*[o][\s]*[m]/i;

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}



/*Coppiasex.net*/

var regex = /[c][\s]*[o][\s]*[p][\s]*[p][\s]*[i][\s]*[a][\s]*[x][\s]*[\.]*[\s]*[n][\s]*[e][\s]*[t]/i;

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}





/* laurax.it */

var regex = /[l][\s]*[a][\s]*[u][\s]*[r][\s]*[a][\s]*[x][\.]*[\s]*[i][\s]*[t]/i;

if(regex.test(f.testo.value)){

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}



/* Morenasex.net */

var regex = /[m][\s]*[o][\s]*[r][\s]*[e][\s]*[n][\s]*[a][\s]*[s][\s]*[e][\s]*[x][\s]*[\.]*[\s]*[n][\s]*[e][\s]*[t]/i;

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}



/* erositaly */

var regex = /[e][\s]*[r][\s]*[o][\s]*[s][\s]*[i][\s]*[t][\s]*[a][\s]*[l][\s]*[y][\s]*[\.]*[\s]*[n][\s]*[e][\s]*[t]/i;

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}





/* annunci69 */

var regex = /[a][\s]*[n][\s]*[n][\s]*[u][\s]*[n][\s]*[c][\s]*[i][\s]*[6][\s]*[9][\s]*[\.]*[\s]*[i][\s]*[t]/i;

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}





/* annuncisessuali */

var regex = /[a][\s]*[n][\s]*[n][\s]*[u][\s]*[n][\s]*[c][\s]*[i][\s]*[s][\s]*[e][\s]*[s][\s]*[s][\s]*[u][\s]*[a][\s]*[l][\s]*[i][\s]*[\.]*[i][\s]*[t]/i;

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}





/*eroticissimo */

var regex = /[e][\s]*[r][\s]*[o][\s]*[t][\s]*[i][\s]*[c][\s]*[i][\s]*[s][\s]*[s][\s]*[i][\s]*[m][\s]*[o][\s]*[\.]*[i][\s]*[t]/i;

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}





/* incontri-on-line.net */

var regex = /[i][\s]*[n][\s]*[c][\s]*[o][\s]*[n][\s]*[t][\s]*[r][\s]*[i][\s]*[\-]*[o][\s]*[n][\s]*[\-]*[l][\s]*[i][\s]*[n][\s]*[e][\s]*[\.]*[n][\s]*[e][\s]*[t]/i;

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}



/* incontri-on-line.com */

var regex = /[i][\s]*[n][\s]*[c][\s]*[o][\s]*[n][\s]*[t][\s]*[r][\s]*[i][\s]*[\-]*[o][\s]*[n][\s]*[\-]*[l][\s]*[i][\s]*[n][\s]*[e][\s]*[\.]*[c][\s]*[o][\s]*[m]/i;	

if(regex.test(f.testo.value)){ 

	host = true;

	f.testo.value = f.testo.value.replace(regex,'   ***********   ');

}





	if(host == true){

		alert('Attenzione, è vietato inserire riferimenti a portali '+

			  'di annunci esterni nei vostri messaggi privati.\n'+

//			  'Vi preghiamo pertanto di modificare il testo del messaggio.\n\n'+

			  'Il testo del messaggio è stato pertanto modificato!\n\n'+

			  'Vi ricordiamo a tal proposito che Desiderya  permette la creazione di tutto ciò che  serve per farvi conoscere al meglio:\n\n'+

			  '- photogallery;\n'+

			  '- videogallery;\n'+

			  '- profili.\n\n'+

			  'Potete anche attivare immediatamente uno spazio personale del tipo:\n\n'+

			  'www.desiderya.it/vostronome\n\n'+

			  'Trovate tutte le informazioni nella vostra area utente.');

		f.testo.focus();

		return false;

	}



	







	if(f.testo.value == "")

	{

		alert('Attenzione!\n\nNon hai inserito il testo di risposta al messaggio!');

		f.testo.focus();

		return false;

	}

	msg = 'Ecco il messaggio che stai per spedire :\n\nOggetto: '+f.oggetto.value+'\n\n';

	msg +='Messaggio:\n\n'+f.testo.value+'';

	

	msg += '\n\n\n******  OPZIONI  ******';

	

	if(f.notifica && f.notifica[0].checked == true)

	{

		msg += '\n\nHai richiesto la notifica di lettura tramite email.';

		op = 1;

	}



	if(f.notifica && f.notifica[1].checked ==  true)

	{

		msg += '\n\nHai richiesto la notifica di lettura tramite messaggio su Desiderya';

		op = 1;

	}



	if(f.salvamessaggio && f.salvamessaggio.checked == true)

	{

		msg += '\n\nHai richiesto il salvataggio del messaggio nella posta inviata';

		op = 1;

	}

	if(!op) msg += '\n\nNessuna opzione selezionata';

	

	msg += '\n\n***********';

	

	msg += '\n\nPROCEDI CON L\'INVIO?';

	

	return confirm(msg);



				

}



function help()

{

	msg='COS\'E\' LA NOTIFICA DI LETTURA?\n\nTramite questa utile opzione, sarai avvisato quando l\'utente legge il messaggio che gli hai inviato.\n\nPuoi attivarla in due modi diversi:\n\n - con un messaggio di avviso direttamente nella tua casella email;\n - ricevendo un messaggio nella tua posta personale su Desiderya.\n\n';

	alert(msg)

}









function ConfermaModificaPassword()

{

	var form = document.FormModificaPassword;

	if (form.new_password.value== "") 

	{

		alert('Devi inserire la nuova password!')

		form.new_password.focus();

		return false;

	}

	if (form.verifica_new_password.value== "") 

	{

		alert('Devi inserire la conferma della nuova password!')

		form.verifica_new_password.focus();

		return false;

	}

	if (form.verifica_new_password.value != form.new_password.value) 

	{

		alert('La password e la sua verifica NON coincidono!')

		form.verifica_new_password.select();

		return false;

	}

	return confirm('confermi questa nuova password?\n\n'+form.new_password.value);

}



function ConfermaEliminaAccount()

{

	var form = document.FormEliminaAccount;



	if (form.remove_user.checked != true) 

	{

		alert('Devi spuntare la casella di conferma, se vuoi di proseguire nell\'eliminazione dell\'account!')

		form.remove_user.focus();

		return false;

	}



	return true;

}







function ConfermaModificaCategoria()

{

	var form = document.FormModificaCategoria;

	if (form.new_cat.value== "") 

	{

		alert('Devi inserire la nuova categoria!')

		form.new_cat.focus();

		return false;

	}

	return confirm('confermi questa nuova categoria?\n\n');

}



function ConfermaModificaEmail()

{

	var form = document.FormModificaEmail;

	if (form.new_email.value== "") 

	{

		alert('Devi inserire la nuova email!')

		form.new_email.focus();

		return false;

	}

	if (form.verifica_new_email.value== "") 

	{

		alert('Devi inserire la conferma della nuova email!')

		form.verifica_new_email.focus();

		return false;

	}

	if (form.verifica_new_email.value != form.new_email.value) 

	{

		alert('L\' email e la sua verifica NON coincidono!')

		form.verifica_new_email.focus();

		form.verifica_new_email.select();

		return false;

	}

	return confirm('confermi questa nuova email?\n\n'+form.new_email.value);

}





//Questa funzione controlla la corretta immissione del nickname

function ModuloModificaNick(f)

{



	if (f.new_nick.value == "") 

	{

		alert('Devi inserire il tuo nuovo username!')

		f.new_nick.focus();

		return false;

	}

	if (f.verifica_new_nick.value== "") 

	{

		alert('Devi inserire la conferma del tuo nuovo username!')

		f.verifica_new_nick.focus();

		return false;

	}

	if (f.verifica_new_nick.value != f.new_nick.value) 

	{

		alert('Lo username e la sua verifica NON coincidono!')

		f.verifica_new_nick.select();

		return false;

	}

	return confirm('Stai per modificare il tuo username di accesso.\n\nConfermi questo nuovo username?\n\n'+f.new_nick.value);



}







//Questa funzione restituisce lo stile di un particolare tag

function styleCalque(type){ 

	if (document.all) calqueStyle = document.all[type].style; 

	if (document.layers) calqueStyle = document.layers[type].style; 

	if (document.getElementById) calqueStyle = document.getElementById(type).style; 

	return calqueStyle; 

} 







//Questa funzione apre una photogallery

function openPhotogallery(idutente,id,width,height){

//	alert("Attenzione, le photogallery non saranno disponibili per qualche ora causa lavori di manutenzione del sito.");

//	return;

	var newWindow=	window.open('/script/php/display/photogallery.php?idfoto='+id+'&id='+idutente+'','blank','width='+width+',height='+height+'');

	newWindow.focus();

}



//Questa funzione apre una photogallery

function openPhotogalleryConcorsi(nome,idutente,concorso,mese,anno,id,width,height){	

	var newWindow=	window.open('/script/php/display/photogallery_concorsi.php?nome='+nome+'&concorso='+concorso+'&mese='+mese+'&anno='+anno+'&idfoto='+id+'&partecipante='+idutente+'','blank','width='+width+',height='+height+'');

	newWindow.focus();

}





//Questa funzione apre una videogallery

function openVideogallery(idutente,id,width,height){

	var newWindow=window.open('/script/php/display/videogallery.php?idvideo='+id+'&id='+idutente+'','blank','width='+width+',height='+height+'');

	newWindow.focus();

}



//Questa function chiama lo script Foto che apre un'immagine in una foto

function  apri(p,w,h){



	window.open('/script/php/display/foto.php?path='+p+'','_blank','width='+w+',height='+h+'');

//	return false;

}

function  apriFotoPresentazione(p,w,h){



	var newWindow=window.open('/script/php/display/foto.php?path='+p+'','blank','width='+w+',height='+h+'');

	newWindow.focus();

//	return false;

}

function  apriFotoBazar(p,idp,f,w,h){



	var newWindow=window.open('/script/php/display/fotobazar.php?idprodotto='+idp+'&path='+p+'&f='+f+'','blank','width='+w+',height='+h+'');

	newWindow.focus();

//	return false;

}





function mostravideo(p){

	var newWindow=window.open('/script/php/video.php?path='+p+'','blank','width=600,height=400,resizable=yes');

	newWindow.focus();

	return false;

}





function changeCalque(type) { 



	if ( styleCalque(type).display == 'block')

		styleCalque(type).display="none"; 

	else

		styleCalque(type).display="block"; 

} 

function changeHeader(type) { 



	styleCalque('sottoheader_inserimenti').display = 'none';

	styleCalque('sottoheader_chat').display = 'none';

	styleCalque('sottoheader_rubriche').display = 'none';

	styleCalque('sottoheader_sexyshop').display = 'none';

	styleCalque('sottoheader_annunci').display = 'none';

	styleCalque('sottoheader_locali').display = 'none';

	styleCalque('sottoheader_home').display = 'none';

	styleCalque('sottoheader_concorsi').display = 'none';

	if ( styleCalque(type).display == 'none'){

		styleCalque(type).display="block"; 

	}

	else{

		styleCalque(type).display="none"; 

	}

} 









/*

Questa function mette in evidenza il primo risultato

mentre il secondo viene nascosto, indipendentemente da display

*/	

function swap2(type,h1){

	if ( styleCalque(h1).display == 'block')

		styleCalque(h1).display="none"; 



	if ( styleCalque(type).display == 'none')

		styleCalque(type).display="block"; 

}







function changeCalque2(type,h1) { 



	if ( styleCalque(h1).display == 'block')

		styleCalque(h1).display="none"; 

	else

		styleCalque(h1).display="block"; 

	if ( styleCalque(type).display == 'block')

		styleCalque(type).display="none"; 

	else

		styleCalque(type).display="block"; 

} 







function changeCalque3(type,h1,h2) { 



	if ( styleCalque(h1).display == 'block')

		styleCalque(h1).display="none"; 

	if ( styleCalque(h2).display == 'block')

		styleCalque(h2).display="none"; 

	if ( styleCalque(type).display == 'block')

		styleCalque(type).display="none"; 

	else

		styleCalque(type).display="block"; 

} 





function assign(id){

	if(id && document.getElementById && document.getElementById(id))

		return document.getElementById(id);

	else

		return null;

}







var userSectionInPrifile = ['annuncioprofilo','annunciointervista','annunciolastminute','annunciovideo','annunciophotogallery','annuncioreferenze'];

function showUserSectionInProfile(section_to_show,id){

	var span = '';

	//Nascondiamo le sezioni

	for(i in userSectionInPrifile){

		if(userSectionInPrifile[i] == section_to_show)

			continue;

		

		span = userSectionInPrifile[i] + id;

		span = assign(span);

		if(span)

			span.style.display = 'none';

	}

	

	span = section_to_show + id;

	span = assign(span);

	

	span.style.display=='block'?span.style.display='none':span.style.display='block';	

}





function changeCalque4(type,h1,h2,h3) { 





	if ( styleCalque(h1).display == 'block')

		styleCalque(h1).display="none"; 

	if ( styleCalque(h2).display == 'block')

		styleCalque(h2).display="none"; 

	if ( styleCalque(h3).display == 'block')

		styleCalque(h3).display="none"; 

	if ( styleCalque(type).display == 'block')

		styleCalque(type).display="none"; 

	else

		styleCalque(type).display="block"; 

} 







function changeCalque5(type,h1,h2,h3,h4) { 





	if ( styleCalque(h1).display == 'block')

		styleCalque(h1).display="none"; 

	if ( styleCalque(h2).display == 'block')

		styleCalque(h2).display="none"; 

	if ( styleCalque(h3).display == 'block')

		styleCalque(h3).display="none"; 

	if ( styleCalque(h4).display == 'block')

		styleCalque(h4).display="none"; 

	if ( styleCalque(type).display == 'block')

		styleCalque(type).display="none"; 

	else

		styleCalque(type).display="block"; 







} 

