function toggle_visibility(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'block')
	e.style.display = 'none';
	else
	e.style.display = 'block';
}
function ControlloNews(lng, page){
	if (document.getElementById('giorno').value != 'A' && document.getElementById('mese').value != 'A') {
		self.location.href = page + '?p=4&giorno=' + document.getElementById('giorno').value + '&mese=' + document.getElementById('mese').value;
	}else if(document.getElementById('giorno').value == 'A' && document.getElementById('mese').value != 'A'){
		self.location.href = page + '?p=4&mese=' + document.getElementById('mese').value;
	}else{
		if(lng == 'ita'){
			alert("Selezionare sia mese che giorno");
		}else{
			alert("Select month and day");
		}
	}
}

function checkInvio(lng,dove){
	if(lng== 'ita'){
		var strErrore = '*';
		var strEmail = 'E-mail non valida';	
	}else if(lng=='eng'){
		var strErrore = '*';
		var strEmail = 'Invalid email address';	
	}
	var ok = true;
	var controlloRadio = false;
	
	for(var i=0;i<arrayCampi.length;i++){
		var myCampo = arrayCampi[i];
		if(document.getElementById(myCampo).value != strErrore){
			if(!checkField(document.getElementById(myCampo).value)){
				document.getElementById(myCampo).style.color ='#FF0000';
				document.getElementById(myCampo).value = strErrore;
				document.getElementById(myCampo).onclick = function(){
					this.style.color = '#333333';
					this.value ='';
					this.onclick = '';
				};
				ok = false;
			}
		}else{
			ok = false;
		}
	}
	
	for(var n=0;n<arrayEmail.length;n++){
		var myCampo = arrayEmail[n];
		if(!checkEmail(document.getElementById(myCampo).value)){
			document.getElementById(myCampo).style.color ='#FF0000';
			document.getElementById(myCampo).value = strEmail;
			document.getElementById(myCampo).onclick = function(){
				this.style.color = '#333333';
				this.value ='';
				this.onclick = '';
			};
			ok = false;
		}
	}
	
	if(document.getElementById("acconsento").checked==false){
		ok = false;
		document.getElementById('output_privacy').style.display ='block';
	}else{
		ok = true;
		document.getElementById('output_privacy').style.display ='none';
	}
	if(ok){
		return true;
		//document.getElementById(dove).submit();
	}else{
		return false;
	}
}
function checkInvio2(lng,dove){
	if(lng== 'ita'){
		var strErrore = '*';
		var strEmail = 'E-mail non valida';	
	}else if(lng=='eng'){
		var strErrore = '*';
		var strEmail = 'Invalid email address';	
	}
	var ok = true;
	for(var i=0;i<arrayCampi.length;i++){
		var myCampo = arrayCampi[i];
		if(document.getElementById(myCampo).value != strErrore){
			if(!checkField(document.getElementById(myCampo).value)){
				document.getElementById(myCampo).style.color ='#FF0000';
				document.getElementById(myCampo).value = strErrore;
				document.getElementById(myCampo).onclick = function(){
					this.style.color = '#333333';
					this.value ='';
					this.onclick = '';
				};
				ok = false;
			}
		}else{
			ok = false;
		}
	}
	for(var n=0;n<arrayEmail.length;n++){
		var myCampo = arrayEmail[n];
		if(!checkEmail(document.getElementById(myCampo).value)){
			document.getElementById(myCampo).style.color ='#FF0000';
			document.getElementById(myCampo).value = strEmail;
			document.getElementById(myCampo).onclick = function(){
				this.style.color = '#333333';
				this.value ='';
				this.onclick = '';
			};
			ok = false;
		}
	}
	if(ok){
		return true;
		//document.getElementById(dove).submit();
	}else{
		return false;
	}
}
//////////////////CHECK FIELD (se vuoto return false)
function checkField (myText)
{
	var lunghezza = myText.length;
	if (lunghezza > 0)
	{
		for (var i = 0; i < lunghezza; i++)
		{
			if (myText.charAt (i) != " ")
			{
				return true;
			}
		}
	}
	else
	{
		return false;
	}
}

//////////////////CHECK email (se non valida return false)
var arrInvalid = new Array (" ", "|", "\\", "!", "\"", "£", "$", "%", "&", "/", "(", ")", "=", "?", "'", "^", "ì", "è", "é", "[", "]", "*", "ç", "ò", "@", "°", "à", "#", "§", "ù", ",", ";", ":", "{", "}");
var myInvalid = "";
function checkEmail (myText)
{
		////////////////////////////
		//accountName
		////////////////////////////
		if (myText.indexOf ("@") != -1)
		{
			var accountName = myText.substr (0, myText.indexOf ("@"));
			//controlla se non è vuoto
			if (checkField (accountName))
			{
				//controlla se inizia o finisce col .
				var pointPos = accountName.indexOf (".");
				if (pointPos != 0 && pointPos != accountName.length - 1)
				{
					//controlla se ci sono caratteri non validi da qualche parte
					for (var i = 0; i < arrInvalid.length; i++)
					{
						myInvalid = arrInvalid[i];
						if (accountName.indexOf (myInvalid) != -1)
						{
							//trovato carattere non valido
							return false;
						}
					}
				}
				else
				{
					//cè il punto come primo o ultimo
					return false;
				}
			}
			else
			{
				//tutto vuoto
				return false;
			}
		}
		else
		{
			//@ non presente
			return false;
		}
		/////////////////////////////////
		//domainName
		/////////////////////////////////
		var domainName = myText.substr (myText.indexOf ("@") + 1, myText.length);
		//controlla se non è vuoto
		if (checkField (domainName))
		{
			//controlla che ci sia almeno 1 punto
			if (domainName.indexOf (".") != -1)
			{
				//controlla se inizia o finisce col
				var pointPos = domainName.indexOf (".");
				if (pointPos != 0 && pointPos != domainName.length - 1)
				{
					//controlla se ci sono caratteri non validi da qualche parte
					for (var i = 0; i < arrInvalid.length; i++)
					{
						myInvalid = arrInvalid[i];
						if (domainName.indexOf (myInvalid) != -1)
						{
							//trovato carattere non valido
							return false;
						}
					}
					//controlla se ci sono 2 punti attaccati
					for (var i = 0; i < domainName.length; i++)
					{
						if (domainName.charAt (i) == ".")
						{
							if (i > 0 && i < domainName.length)
							{
								if (domainName.charAt (i - 1) == "." || domainName.charAt (i + 1) == ".")
								{
									//ci sono 2 punti attaccati
									return false;
								}
							}
						}
					}
				}
				else
				{
					//inizia o finisce col punto
					return false;
				}
			}
			else
			{
				//non c'è neanche 1 punto
				return false;
			}
		}
		else
		{
			//tutto vuoto
			return false;
		}

	return true;
}