function toggleVisible(tagId){
	visibilityStatus = document.getElementById(tagId).style.display;
	if (visibilityStatus=='none')
		document.getElementById(tagId).style.display='inline';
	else
		document.getElementById(tagId).style.display='none';
}


function validate_email_address(email, idForm){
	
	opt = {
		method: 'get',
	  	onSuccess: function(transport) {
	    	var result = transport.responseText;
	    
		    if(result == 0)
		    	errori+='Email non valida\n';
		    
		    if(errori==""){
		    	if(idForm != "")
		    		$(idForm).submit();
		    }
	  		else
	  			alert(errori);
  		}
	};
	
	
	new Ajax.Request("/_validate_mail.php?email=" + email, opt);
	
}


/**
* Controllo se i campi della form sono corretti
*/

function controlla_campo_univoco(nome_tabella, nome_colonna, nome_col_id, label_campo_univoco, valore, id, idForm){
	var errori = "";
	$$('.obbligatorio').each(function(c){
		if(c.value=="")
			errori += 'campo obbligatorio: ' + c.title + '\n';
  	});
	
  	if(errori==""){
		new Ajax.Request("/_controlla_campo_ajax.php?nome_tabella=" + nome_tabella + "&nome_colonna=" + nome_colonna + "&valore=" + valore + "&id=" + id + "&nome_col_id=" + nome_col_id , {
			method: 'get',
		  	onSuccess: function(transport) {
		    	var result = transport.responseText;
		    
			    if(result == 1)
			    	errori+='valore gia usato nel campo ' + label_campo_univoco + ', scegline un altro\n';
			    
			    if(errori=="")
		  			$(idForm).submit();
		  		else
		  			alert(errori);
	  		}
		});
  	}else
  		alert(errori);
}

/**
*Controlla validità dei dati
*/

function controlla_form(obiettivo, sorgente){
	
	var	frm=$(sorgente);
	
	if( obiettivo == "contattaci" )
		frm.action='/_send_contatti.php';
	
	var errori = "";
	$$('.obbligatorio').each(function(c){
		if(c.value=="")
			errori += 'campo obbligatorio: ' + c.title + '\n';
  	});
	
  	if(errori==""){
  		
  		if($('email').value != ""){
	  		opt = {
				method: 'get',
			  	onSuccess: function(transport) {
			    	var result = transport.responseText;
			    
				    if(result == 0)
				    	errori+='Email non valida\n';
				    
				    if(errori==""){
				    	frm.submit();
				    }
			  		else
			  			alert(errori);
		  		}
			};
		
			new Ajax.Request("/_validate_mail.php?email=" + $('email').value, opt);
  		}else
  			frm.submit();	 
  		
  			
  	}
  	else
  		alert(errori);
}


/* CONTROLLA VALIDITà E UNICITà DELLA MAIL NEL DATABASE DELLA NEWSLETTER */
function check_newsletter(){
	
	var email = $('email_newsletter').value;
	
	if(email == "")
		alert('Email Obbligatoria');
	else{
		
		opt = {
			method: 'get',
		  	onSuccess: function(transport) {
		    	var result = transport.responseText;
		    
			    if(result !="")
			    	alert(result);
			    else
			    	$('form_newsletter').submit();
			    
	  		}
		};
	
		new Ajax.Request("/_validate_mail_newsletter.php?email=" + email, opt);
		
	}
	
}


function addToFavorites(url, title) {

	var sURL = window.location;
	var sText = title;

	try

	{	if (window.sidebar)

			window.sidebar.addPanel(sText, sURL, "");

		else if (window.external)

			window.external.AddFavorite(sURL, sText);

		else if (window.opera && window.print)

		{	var oA = document.createElement('a');

			oA.setAttribute('rel','sidebar');

			oA.setAttribute('href', sURL);

			oA.setAttribute('title', sText);

			oA.click();

		}

	}

	catch (e)

	{	

	}

}