	function apriWindowAll(id)
	{
		if((document.getElementById(id).style.visibility=='visible') || (document.getElementById(id).style.visibility==''))
		{
			document.getElementById(id).style.visibility = 'hidden';
			document.getElementById(id).style.position = 'absolute';
			document.getElementById(id).style.display = 'none';
		}
		else
		{
			document.getElementById(id).style.visibility = 'visible';
			document.getElementById(id).style.position = 'relative';
			document.getElementById(id).style.display = 'block';
		}
	}
	
	function apriWindow(id)
	{
		document.getElementById(id).style.visibility = 'visible';
		document.getElementById(id).style.position = 'relative';
		document.getElementById(id).style.display = 'block';
	}

	function chiudiWindow(id)
	{
		document.getElementById(id).style.visibility = 'hidden';
		document.getElementById(id).style.position = 'absolute';
		document.getElementById(id).style.display = 'none';
	}

	function trim(stringa)
	{
	    while (stringa.substring(0,1) == ' '){
	        stringa = stringa.substring(1, stringa.length);
	    }
	    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
	        stringa = stringa.substring(0,stringa.length-1);
	    }
	    return stringa;
	}

	function IsEmail(string)
	{
		if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
			return (true);
		else
			return (false);
	}
	
	function IsNumber(Expression)
	{
	    Expression = Expression.toLowerCase();
	    RefString = "0123456789";
	    
	    if (Expression.length < 1) 
	        return (false);
	    
	    for (var i = 0; i < Expression.length; i++) 
	    {
	        var ch = Expression.substr(i, 1);
	        var a = RefString.indexOf(ch, 0);
	        if (a == -1)
	            return (false);
	    }
	    return(true);
	}

	function evidenza(id)
	{
		if(document.getElementById(id).style.border!='1px solid red')
			document.getElementById(id).style.border = '1px solid red';
		else
			document.getElementById(id).style.border = '';
	}
	
	function evidenza_reset()
	{
		document.getElementById('nome').style.border='';
		document.getElementById('cognome').style.border='';
		document.getElementById('tel').style.border='';
		document.getElementById('email').style.border='';
		document.getElementById('cellulare').style.border='';
		document.getElementById('privacy_testo').style.border='';
		document.getElementById('loc1').style.border='';
		document.getElementById('loc2').style.border='';
		document.getElementById('via1').style.border='';
		document.getElementById('via2').style.border='';
		document.getElementById('prov1').style.border='';
		document.getElementById('prov2').style.border='';
	}
	
	function controllo()
	{
		evidenza_reset();
	
		var flag = 0;
	
		if(trim(document.getElementById('nome').value)=='')
		{
			flag = 1;
			evidenza('nome');
		}
		
		if(trim(document.getElementById('cognome').value)=='')
		{
			flag = 1;
			evidenza('cognome');
		}
		
		if(IsNumber(document.getElementById('tel').value)==false)
		{
			flag = 1;
			evidenza('tel');
		}
				
		if(IsEmail(document.getElementById('email').value)==false)
		{
			flag = 1;
			evidenza('email');
		}
		
		if(trim(document.getElementById('cellulare').value)!='')
			if(IsNumber(document.getElementById('cellulare').value)==false)
			{
				flag = 1;
				evidenza('cellulare');
			}
			
		if(trim(document.getElementById('loc1').value)=='')
		{
			flag = 1;
			evidenza('loc1');
		}

		if(trim(document.getElementById('loc2').value)=='')
		{
			flag = 1;
			evidenza('loc2');
		}

		if(trim(document.getElementById('via1').value)=='')
		{
			flag = 1;
			evidenza('via1');
		}
		
		if(trim(document.getElementById('via2').value)=='')
		{
			flag = 1;
			evidenza('via2');
		}

		if(trim(document.getElementById('prov1').value)=='')
		{
			flag = 1;
			evidenza('prov1');
		}

		if(trim(document.getElementById('prov2').value)=='')
		{
			flag = 1;
			evidenza('prov2');
		}

			
		if(document.getElementById('privacy').checked==false)
		{
			flag = 1;
			evidenza('privacy_testo');
		}
			
		if(flag==1)
			alert('Controlla i campi contrassegnati in rosso.');
		else
			document.getElementById('salvadati').submit();
	}