function checkInvio(lng){

	if(lng== 'it'){
		var strErrore = 'Campo richiesto';
		var strEmail = 'E-mail non valida';	
	}else if(lng=='en'){
		var strErrore = 'Request Field';
		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("privacy").checked==false){
		ok = false;
		document.getElementById('output_privacy').style.display ='block';
	}

	with (document.form_contatti){
		for (var i=0; i < elements.length; i++) {	
			if (elements[i].type == 'checkbox' && elements[i].name == 'cosa[]' && elements[i].checked==true){
				controlloRadio = true;
			}
		}
	}

	if(controlloRadio == false) {
		ok= false;
		document.getElementById('output_radio').style.display ='block';
	}	
	
	if(ok){
		document.getElementById("form_contatti").submit();
	}
}
//////////////////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;
}


function SelProd() {

	document.getElementById("output_radio").style.display = 'none';

	with (document.form_contatti){
		for (var i=0; i < elements.length; i++) {	
			dove = "A"+elements[i].value;
			if (elements[i].type == 'checkbox' && elements[i].name == 'cosa[]' && elements[i].checked==true){
				document.getElementById(dove).style.fontWeight = 'bold';
			}else if(elements[i].type == 'checkbox' && elements[i].name == 'cosa[]' && elements[i].checked==false){
				document.getElementById(dove).style.fontWeight = 'normal';
			}
		}
	}
	

}

var n_aperti=0;

function ApriChiudi(dove){
	if(document.getElementById(dove).style.display == 'none'){
		//document.getElementById(dove).style.display = 'block';
		new Effect.Appear(document.getElementById(dove));
		n_aperti++;
	}else if(document.getElementById(dove).style.display == ''){
		//new Effect.Fade(document.getElementById(dove))		
		document.getElementById(dove).style.display = 'none';
		n_aperti--;
	}
	if(n_aperti>0){
		document.getElementById("toplink").style.display = "block";
	}else{
		document.getElementById("toplink").style.display = "none";
	}
}

function ApriChiudiContatti(dove,numero){
	if(document.getElementById(dove).style.display == 'none'){
		new Effect.Appear(document.getElementById(dove))
		document.getElementById('chiudi_'+numero).style.display ='block';
		document.getElementById('apri_'+numero).style.display ='none';
	}else if(document.getElementById(dove).style.display == ''){
		document.getElementById('apri_'+numero).style.display ='block';
		document.getElementById('chiudi_'+numero).style.display ='none';
		new Effect.Fade(document.getElementById(dove))
	}
}

function ExptOpenClose(id){
	if(document.getElementById('prodotti_'+id).style.display == 'none'){
		new Effect.Appear(document.getElementById('prodotti_'+id))
		document.getElementById('close_'+id).style.display ='block';
		document.getElementById('open_'+id).style.display ='none';
	}else if(document.getElementById('prodotti_'+id).style.display == ''){
		document.getElementById('open_'+id).style.display ='block';
		document.getElementById('close_'+id).style.display ='none';
		new Effect.Fade(document.getElementById('prodotti_'+id))
	}
}
function ApriChiudiINv(id){
	if(document.getElementById('prova_'+id).style.display == 'none'){
		new Effect.Appear(document.getElementById('prova_'+id))
		document.getElementById('titolo_inv_'+id).style.display ='none';
		document.getElementById('link_inv_'+id).style.display ='none';
	}else if(document.getElementById('prova_'+id).style.display == ''){
		new Effect.Fade(document.getElementById('prova_'+id))
		document.getElementById('titolo_inv_'+id).style.display ='block';
		document.getElementById('link_inv_'+id).style.display ='block';
	}
}
function Ricerca(){
	self.location.href = "search_result.php?q=" + (document.getElementById('cerca').value);
}
