var popwindowbacheca;
var popwindowchat;



function changetour(sala){
	var thecontent = document.getElementById('videotour');
	thecontent.innerHTML ="<applet id=\"legambiente\" codebase=\"./\"  archive=\"ptviewer.jar\" code=\"ptviewer.class\"  width=\"450\" height=\"300\" align=\"center\" onmouseover=\"this.style.cursor='move'\"> <param name=\"file\" value=\"asset/tourvirtualeimg/" + sala + "\"> <param name=\"auto\" value=\"0.40\"> <param name=tiltmin value=\"-30.80\"> <param name=tiltmax value=\"30.80\">/applet>";
}

function uploadimgbacheca(){
	if(popwindowbacheca == null || popwindowbacheca.closed)
		popwindowbacheca = window.open('uploadimgxbacheca.php','','left=200,top=330 width=650, height=400,menubar=0,toolbar=0,location=0');
	else
		popwindowbacheca.focus();
}

function showchat(){
	if(popwindowchat == null || popwindowchat.closed)
		popwindowchat = window.open('popwindowchat.php', 'foto','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=200,top=200,copyhistory=no,width=650,height=420');
	else
		popwindowchat.focus();
}

function sendlogin(){
	var msgs = "";
	var email = document.getElementById('email').value;
	var pw = document.getElementById('pw').value;

	if((email=='') || (leftTrim(email)=='')){
		msgs +='- Inserire l\'email! \n';
	} else {
		var espressione = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+[\.]([a-z0-9-]+)*([a-z]{2,3})$");
		if(!espressione.test(email)){
			msgs +='- Email non valida! Assicurarsi che sia corretta.\n';
		} 
	}
	if((pw=='') || (leftTrim(pw)==''))
		msgs +='- Inserire la password! \n';
		
		
	if(msgs==""){
		var url='loginutente.php' 
			+ '?email=' + encodeURIComponent(email)
			+ '&pw=' + encodeURIComponent(pw) ;
		Richiesta(url);
	}else
		alert(msgs);
	
}

function forgetemail(){
	var msgs = "";
	var email = document.getElementById('forgetemail').value;

	if((email=='') || (leftTrim(email)=='')){
		msgs +='- Inserire l\'email! \n';
	} else {
		var espressione = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+[\.]([a-z0-9-]+)*([a-z]{2,3})$");
		if(!espressione.test(email)){
			msgs +='- Email non valida! Assicurarsi che sia corretta.\n';
		} 
	}
	
	if(msgs==""){
		var url='forgetmail.php' 
			+ '?em=' + encodeURIComponent(email)
		Richiesta(url);
	}else
		alert(msgs);
	
}

function sendackchat1(idchat){
	chatPost('gestchat1.php', 'rifid=' + idchat);
}


function sendackchat2(idchat, newmsgs, toidchat){
	chatPost2('gestchat2.php', 'rifid=' + idchat +'&msgg=' + newmsgs  + '&toidchat=' + toidchat);
}



function sendregistrazione(){
	var msgs = "";
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var cnfremail = document.getElementById('cnfremail').value;
	var pw = document.getElementById('pw').value;
	var cnfrpw = document.getElementById('cnfrpw').value;
	
	
	var eta = document.getElementById('eta').value;
	var sesso = document.getElementById('sesso').value;
	var indirizzo = document.getElementById('indirizzo').value;
	var citta = document.getElementById('citta').value;

	var contractAccept = document.getElementById('contractAccept').checked;
	
	if((name=='') || (leftTrim(name)==''))
		msgs +='- Inserire il nome e cognome! \n';
	if((email=='') || (leftTrim(email)=='')){
		msgs +='- Inserire l\'email! \n';
	} else {
		var espressione = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+[\.]([a-z0-9-]+)*([a-z]{2,3})$");

		if(!espressione.test(email)){
			msgs +='- Email non valida! Assicurarsi che sia corretta.\n';
		} else {	
			if( (leftTrim(email)!='') && (cnfremail != leftTrim(email)) )
			msgs +='- I valori email e conferma email non sono corrispondenti! \n';
		}
	}
	
	
	if((pw=='') || (leftTrim(pw)==''))
		msgs +='- Inserire la password! \n';
	if( (leftTrim(pw)!='') && (cnfrpw != leftTrim(pw)) )
		msgs +='- I valori Password e conferma Password non sono corrispondenti! \n';
	if( contractAccept ==false)
		msgs +='- Necessario accettare il trattamento dei Dati! \n';
		
	if(msgs==""){
		var url='nome=' 
			+ name 
			+ '&email=' + email
			+ '&pw=' + pw 
			+ '&sesso=' + sesso;
		if(leftTrim(eta)!='')
			url += '&eta=' + eta;
		if(leftTrim(indirizzo)!='')
			url += '&indirizzo=' + indirizzo;
		if(leftTrim(citta)!='')
			url += '&citta=' + citta;
		RichiestaPost('registrazione.php', url);
	}else
	alert(msgs);
}


function pubblicainbacheca(){
	var msgs = "";
	var tipologia = document.getElementById('tipologia').value;
	var ambito = document.getElementById('ambito').value;
	var oggetto = document.getElementById('oggetto').value;
	var desnote = document.getElementById('desnote').value;
	var note = document.getElementById('note').value;
	
	var imgbacheca = document.getElementById('imgbacheca').value;

	var acceptresp = document.getElementById('acceptresp').checked;
	
	if((oggetto=='') || (leftTrim(oggetto)==''))
		msgs +='- Inserire l\'oggetto della pubblicazione! \n';
		
	if((desnote=='') || (leftTrim(desnote)=='')){
		msgs +='- Inserire la descrizione! \n';
	} 
	
	
	
	if( acceptresp ==false)
		msgs +='- E\' necessario assumersi la responsabilità per le dichiarazioni mendaci! \n';
	
	if(msgs==""){
		var url='tipologia=' + tipologia 
			+ '&ambito=' + ambito
			+ '&ogg=' + oggetto 
			+ '&des=' + desnote;
		if(leftTrim(imgbacheca)!='')
			url += '&img=' + imgbacheca;
		if(leftTrim(note)!='')
			url += '&note=' + note;
		RichiestaPost('salvaannuncio.php',url);
	}else
	alert(msgs);
}


function sendcontatti(){
	var msgs = "";
	var nome = document.getElementById('nome').value;
	var contenuto = document.getElementById('contenuto').value;
	
	if((nome=='') || (leftTrim(nome)==''))
		msgs +='- Inserire il nome e cognome! \n';
	if((contenuto=='') || (leftTrim(contenuto)==''))
		msgs +='- Inserire un Contenuto valido! \n';
		
	var oggetto = document.getElementById('object').value;
	var email = document.getElementById('email').value;
		
	if(msgs==""){
		var url='contattiresult.php?nome='+ encodeURIComponent(nome) + '&des=' + encodeURIComponent(contenuto);
		if(leftTrim(email)!='')
			url += '&email=' + encodeURIComponent(email);
		if(leftTrim(oggetto)!='')
			url += '&ogg=' + encodeURIComponent(oggetto);
		Richiesta(url);
	}else
	alert(msgs);
}

function leftTrim(stringa){
	while (stringa.substring(0,1) == ' '){
		stringa = stringa.substring(1, stringa.length);
	}
	return stringa;
}

function window_open(type)
{
//windowops = "'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=200,top=200,copyhistory=no,width=400,height=300'";
windowops = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=200,top=200,copyhistory=no,width=400,height=300';
if(type==1)
	window.open('descrdownloadfoto.php', 'foto', windowops);
if(type==2)
	window.open('descrcorpoliberochat.php', 'popwindow', windowops);
if(type==3)
	window.open('descrbacheca.php', 'Chat', windowops);
if(type==4)
	window.open('descrprendialvolo.php', 'prendilealvolo', windowops);
return;
}

