<!--
function Trim(stringa)
{
   reTrim=/\s+$|^\s+/g;
   return stringa.replace(reTrim,"");
}

function ControllaMail(strEmail)
{
Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
if (Filtro.test(strEmail))
{
  return true;
}
else
{
	return false;
}
}

function CheckForm()
{
	var ok = false;
	var errors = false;
	
	var oLang = document.getElementById("lang");
	var message1 = "";
	var message2 = "";
	switch (oLang.value)
	{ 
		case "italiano": 
			message1 = "Non tutti i campi obbligatori sono compilati!";
			message2 = "Alcuni valori non sono corretti! (Se vengono inseriti valori decimali inserirli utilizzando il \".\" e non la virgola!)";
		break;
		
		case "inglese": 
			message1 = "Not all required fields are filled!";
			message2 = "Some values are not correct! (If decimal digits are entered, enter them using the character \".\" Don't use the comma!)";
		break;
		
		case "francese": 
			message1 = "Pas tous les champs obligatoires sont remplis!";
			message2 = "Il y a des valeurs qui ne sont pas correctes.(Si on va entrer des valeurs décimales, il faut les entrer enutilisant le caractère \".\" Il ne faut pas utiliser la virgule!)";
		break;
		
		case "spagnolo": 
			message1 = "No todos los campos obligatorios están llenos!";
			message2 = "Algunos valores no son correctos! (Si vienen insertados valores decimales, insertarlos utilizando las  \".\" y no la coma!)";
		break;
	}
	
	//*****************CONTROLLO CAMPI OBBLIGATORI*************************//
	
	
	//DATI ANAGRAFICI
	var strIdObb = "Nome,Cognome,Nazione,Indirizzo,Telefono,Email_Aziendale,Nome_Azienda,Come_hai_conosciuto_Imeco";
	var arrIdObb = strIdObb.split(",");
	
	for(var i=0; i<arrIdObb.length; i++)
	{
		var obj = document.getElementById(arrIdObb[i]);
		CambiaStatoCampo(arrIdObb[i],false);
		if(Trim(obj.value) == "")
		{
			errors = true;
			CambiaStatoCampo(arrIdObb[i],true);
		}
	}
	
	//TIPO DI RICHIESTA
	var tipo_richiesta_offerta = document.getElementById("tipo_richiesta_offerta");
	var tipo_richiesta_informazioni = document.getElementById("tipo_richiesta_informazioni");
	var tipo_richiesta_visita = document.getElementById("tipo_richiesta_visita");
	if ((!tipo_richiesta_offerta.checked) && (!tipo_richiesta_informazioni.checked) &&(!tipo_richiesta_visita.checked)) 
	{
		errors = true;
		CambiaStatoCampo("tipo_richiesta",true);
	}
	else
	{
		CambiaStatoCampo("tipo_richiesta",false);
		
		//OFFERTA
		if (tipo_richiesta_offerta.checked)
		{
			var oRadioGroup = document.getElementsByName("Tipologia_di_prodotto");
			
			var valueSelected = null;
								
			for(var i = 0; i<oRadioGroup.length; i++)
			{
				if(oRadioGroup[i].checked) 
					valueSelected = oRadioGroup[i].value;
			}
			
			CambiaStatoCampo("Tipologia_di_prodotto",false);
			if (valueSelected != null)
				errors = ControlloTipProd(valueSelected);
			else
			{
				errors = true;
				CambiaStatoCampo("Tipologia_di_prodotto",true);
			}
		}
		
		
		//RICHIESTA INFORMAZIONI
		if (tipo_richiesta_informazioni.checked)
		{
			var prefix = "Informazioni_"	
			var strIdInfoObb = "Nome_Prodotto,Domande"
			var arrIdInfoObb = strIdInfoObb.split(",");
						
			for(var i=0; i<arrIdInfoObb.length; i++)
			{
				var obj = document.getElementById(prefix + arrIdInfoObb[i]);
				CambiaStatoCampo(prefix + arrIdInfoObb[i],false);
				if(Trim(obj.value) == "")
				{
					bRet = true;
					CambiaStatoCampo(prefix + arrIdInfoObb[i],true);
				}
			}	
		}
		
		//VISITA ALL'AZIENDA
		if (tipo_richiesta_visita.checked)
		{
			var prefix = "Visita_"	
			var strIdVisitaObb = "motivazioni"
			var arrIdVisitaObb = strIdVisitaObb.split(",");
						
			for(var i=0; i<arrIdVisitaObb.length; i++)
			{
				var obj = document.getElementById(prefix + arrIdVisitaObb[i]);
				CambiaStatoCampo(prefix + arrIdVisitaObb[i],false);
				if(Trim(obj.value) == "")
				{
					bRet = true;
					CambiaStatoCampo(prefix + arrIdVisitaObb[i],true);
				}
			}	
				
			var objRadio1 = document.getElementById(prefix + "Ricontattato_1");
			var objRadio2 = document.getElementById(prefix + "Ricontattato_2");
			var objRadio3 = document.getElementById(prefix + "Ricontattato_3");
			var obj = document.getElementById(prefix + "Ricontattato");
			CambiaStatoCampo(prefix + "Ricontattato",false);
			if ((!objRadio1.checked) && (!objRadio2.checked) && (!objRadio3.checked))
			{
				bRet = true;
				CambiaStatoCampo(prefix + "Ricontattato",true);
			}
		}
		 
	}
	
	//INFORMATIVA PRIVACY
	var ChkPrivacy = document.getElementById("Consenso_Privacy");
	CambiaStatoCampo("Consenso_Privacy",false);
	if (!ChkPrivacy.checked)
	{
		errors = true;
		CambiaStatoCampo("Consenso_Privacy",true);
	}
	
		
	if(errors)
	{
		alert(message1);
	}
	else
	{
		var errorValori = CheckValori();
		if (errorValori)
		{
			alert(message2)	
		}
		else
			ok = true;
	}
			
	if(ok)
	{
		document.forms[0].submit();
	}
}


function CheckValori()
{
	
	var errori = false;
	var oTxt = null;
	var valore = null;
	var valueSelected = null;
	
	var txtEmailAziendale = document.getElementById("Email_Aziendale");
	CambiaContornoCampo(txtEmailAziendale,false);
	if (!ControllaMail(txtEmailAziendale.value))
	{
		errori = true;
		CambiaContornoCampo(txtEmailAziendale,true);
	}
		
	var oRadioGroup = document.getElementsByName("Tipologia_di_prodotto");
								
	for(var i = 0; i<oRadioGroup.length; i++)
	{
		if(oRadioGroup[i].checked) 
			valueSelected = oRadioGroup[i].value;
	}
	
	
	if (valueSelected!=null)
	{
		switch (valueSelected)
		{ 
			case "Insacco": 
				var prefix = "INSACCO_"
		
				oTxt = document.getElementById(prefix + "Peso_specifico")
				valore = oTxt.value;
				CambiaContornoCampo(oTxt,false);
				if ((!IsNumeric(valore)) || ((valore < 1) || (valore > 2000)))
				{
					errori = true;
					CambiaContornoCampo(oTxt,true);
				}
				
				oTxt = document.getElementById(prefix + "Peso_confezioni")
				valore = oTxt.value;
				CambiaContornoCampo(oTxt,false);
				if ((!IsNumeric(valore)) || ((valore < 1) || (valore > 2000)))
				{
					errori = true;
					CambiaContornoCampo(oTxt,true);
				}
				
				oTxt = document.getElementById(prefix + "Produzione_richiesta")
				valore = oTxt.value;
				CambiaContornoCampo(oTxt,false);
				if ((!IsNumeric(valore)) || ((valore < 1) || (valore > 5000)))
				{
					errori = true;
					CambiaContornoCampo(oTxt,true);
				}
				
				oTxt = document.getElementById(prefix + "Granulometria")
				valore = oTxt.value;
				CambiaContornoCampo(oTxt,false);
				if ((!IsNumeric(valore)) || ((valore < 2) || (valore > 20000)))
				{
					errori = true;
					CambiaContornoCampo(oTxt,true);
				}
				
				oTxt = document.getElementById(prefix + "Angolo_risposta")
				valore = oTxt.value;
				CambiaContornoCampo(oTxt,false);
				if ((!IsNumeric(valore)) || ((valore < 0) || (valore > 90)))
				{
					errori = true;
					CambiaContornoCampo(oTxt,true);
				}
					
				oTxt = document.getElementById(prefix + "Umidita")
				valore = oTxt.value;
				CambiaContornoCampo(oTxt,false);
				if ((!IsNumeric(valore)) || ((valore < 0) || (valore > 30)))
				{
					errori = true;
					CambiaContornoCampo(oTxt,true);
				}
				
				oTxt = document.getElementById(prefix + "temperatura_prodotto")
				valore = oTxt.value;
				CambiaContornoCampo(oTxt,false);
				if ((!IsNumeric(valore)) || ((valore < 5) || (valore > 50)))
				{
					errori = true;
					CambiaContornoCampo(oTxt,true);
				}
				
				break;
				
				case "Pesatura_e_controllo": 
					var prefix = "PESATURA_"	
					
					oTxt = document.getElementById(prefix + "Peso_specifico")
					valore = oTxt.value;
					CambiaContornoCampo(oTxt,false);
					if ((!IsDecimal(valore)))
					{
						errori = true;
						CambiaContornoCampo(oTxt,true);
					}
					
					oTxt = document.getElementById(prefix + "Granulometria")
					valore = oTxt.value;
					CambiaContornoCampo(oTxt,false);
					if ((!IsDecimal(valore)) || ((valore < 2) || (valore > 20000)))
					{
						errori = true;
						CambiaContornoCampo(oTxt,true);
					}
					
					oTxt = document.getElementById(prefix + "Umidita")
					valore = oTxt.value;
					CambiaContornoCampo(oTxt,false);
					if ((!IsDecimal(valore)) || ((valore < 0) || (valore > 30)))
					{
						errori = true;
						CambiaContornoCampo(oTxt,true);
					}
					
					oTxt = document.getElementById(prefix + "Portata")
					valore = oTxt.value;
					CambiaContornoCampo(oTxt,false);
					if ((!IsDecimal(valore)))
					{
						errori = true;
						CambiaContornoCampo(oTxt,true);
					}
				break; 
		
				case "Dosaggio_e_miscelazione": 
					var prefix = "DOSAGGIO_"	
					
					oTxt = document.getElementById(prefix + "Peso_specifico")
					valore = oTxt.value;
					CambiaContornoCampo(oTxt,false);
					if ((!IsDecimal(valore)))
					{
						errori = true;
						CambiaContornoCampo(oTxt,true);
					}
					
					oTxt = document.getElementById(prefix + "Granulometria")
					valore = oTxt.value;
					CambiaContornoCampo(oTxt,false);
					if ((!IsDecimal(valore)) || ((valore < 2) || (valore > 20000)))
					{
						errori = true;
						CambiaContornoCampo(oTxt,true);
					}
					
					oTxt = document.getElementById(prefix + "Umidita")
					valore = oTxt.value;
					CambiaContornoCampo(oTxt,false);
					if ((!IsDecimal(valore)) || ((valore < 0) || (valore > 30)))
					{
						errori = true;
						CambiaContornoCampo(oTxt,true);
					}
					
					oTxt = document.getElementById(prefix + "Portata_minima")
					valore = oTxt.value;
					CambiaContornoCampo(oTxt,false);
					if ((!IsDecimal(valore)))
					{
						errori = true;
						CambiaContornoCampo(oTxt,true);
					}
					
					oTxt = document.getElementById(prefix + "Portata_massima")
					valore = oTxt.value;
					CambiaContornoCampo(oTxt,false);
					if ((!IsDecimal(valore)))
					{
						errori = true;
						CambiaContornoCampo(oTxt,true);
					}
				break; 
		}
	}
			
	return errori;
	
}


function ControlloTipProd(valoreSel)
{
	var bRet = false;
	
	switch (valoreSel)
	{ 
		case "Insacco": 
			var prefix = "INSACCO_"	
			var postfix = "_altro"	
			var strIdInsaccoObb = "Nome_prodotto,Peso_specifico,Peso_confezioni,Produzione_richiesta,Caratteristiche_Fisiche,Granulometria,Angolo_risposta,Umidita,Corrosivita,Abrasivita,Tendenza_impaccare,temperatura_prodotto,Tossico"
			var arrIdInsaccoObb = strIdInsaccoObb.split(",");
						
			for(var i=0; i<arrIdInsaccoObb.length; i++)
			{
				var obj = document.getElementById(prefix + arrIdInsaccoObb[i]);
				CambiaStatoCampo(prefix + arrIdInsaccoObb[i],false);
				if(Trim(obj.value) == "")
				{
					bRet = true;
					CambiaStatoCampo(prefix + arrIdInsaccoObb[i],true);
				}
			}
			
			var strIdInsaccoAltroObb = "tipo_sacco,materiale_sacchi,Classificazione_zona"
			var arrIdInsaccoAltroObb = strIdInsaccoAltroObb.split(",");
			
			for(var i=0; i<arrIdInsaccoAltroObb.length; i++)
			{
				var obj = document.getElementById(prefix + arrIdInsaccoAltroObb[i]);
				var objAltro = document.getElementById(prefix + arrIdInsaccoAltroObb[i] + postfix);
				CambiaStatoCampo(prefix + arrIdInsaccoAltroObb[i],false);
				if(Trim(obj.value) == "")
				{
					bRet = true;
					CambiaStatoCampo(prefix + arrIdInsaccoAltroObb[i],true);
				}
				else
				{
					if (obj.value == "Altro")
					{
						if(Trim(objAltro.value) == "Specificare qui")
						{
							bRet = true;
							CambiaStatoCampo(prefix + arrIdInsaccoAltroObb[i],true);
						}	
					}
				}
			}
		break; 
			
		case "Pesatura_e_controllo": 
			var prefix = "PESATURA_"	
			
			var strIdPesaturaObb = "Nome_prodotto,Peso_specifico,Caratteristiche,Granulometria,Umidita,Portata"
			var arrIdPesaturaObb = strIdPesaturaObb.split(",");
						
			for(var i=0; i<arrIdPesaturaObb.length; i++)
			{
				var obj = document.getElementById(prefix + arrIdPesaturaObb[i]);
				CambiaStatoCampo(prefix + arrIdPesaturaObb[i],false);
				if(Trim(obj.value) == "")
				{
					bRet = true;
					CambiaStatoCampo(prefix + arrIdPesaturaObb[i],true);
				}
			}
			
			var objRadio1 = document.getElementById(prefix + "funzione_bilancia_1");
			var objRadio2 = document.getElementById(prefix + "funzione_bilancia_2");
			var obj = document.getElementById(prefix + "funzione_bilancia");
			CambiaStatoCampo(prefix + "funzione_bilancia",false);
			if ((!objRadio1.checked) && (!objRadio2.checked))
			{
				bRet = true;
				CambiaStatoCampo(prefix + "funzione_bilancia",true);
			}
		break; 
	
		case "Dosaggio_e_miscelazione": 
			var prefix = "DOSAGGIO_"	
			
			var strIdDosaggioObb = "Nome_prodotto,Peso_specifico,Caratteristiche,Granulometria,Umidita,Portata_minima,Portata_massima"
			var arrIdDosaggioObb = strIdDosaggioObb.split(",");
						
			for(var i=0; i<arrIdDosaggioObb.length; i++)
			{
				var obj = document.getElementById(prefix + arrIdDosaggioObb[i]);
				CambiaStatoCampo(prefix + arrIdDosaggioObb[i],false);
				if(Trim(obj.value) == "")
				{
					bRet = true;
					CambiaStatoCampo(prefix + arrIdDosaggioObb[i],true);
				}
			}
			break; 

		default: 
			bRet = false;
	
	}
	
	return bRet;
}



function CambiaStatoCampo(strIdSpan, bStato)
{
	var objSpan = document.getElementById(strIdSpan + "_Obb");
	
	if (bStato)
		objSpan.className = "campo_obbligatorio_attivo"
	else
		objSpan.className = "campo_obbligatorio_disattivo"
}


function CambiaContornoCampo(objCampo, bStato)
{
	if (bStato)
		objCampo.className = "input-error"
	else
		objCampo.className = ""
}


function viewBoxTipoRichiesta(sIdCheckbox, sIdTable)
{
	var oCheckbox = document.getElementById(sIdCheckbox);
	var oTable = document.getElementById(sIdTable);
	if (oCheckbox.checked)
		oTable.style.display = "block";
	else
		oTable.style.display = "none";
}

function viewBoxTipoProdotto()
{
	var oTableInsacco = document.getElementById("Insacco");
	var oTablePeC = document.getElementById("Pesatura_e_controllo");
	var oTableDeM = document.getElementById("Dosaggio_e_miscelazione");
		
	var oRadioGroup = document.getElementsByName("Tipologia_di_prodotto");
		
	var valueSelected;
	
	for(var i = 0; i<oRadioGroup.length; i++)
	{
		if(oRadioGroup[i].checked) 
			valueSelected = oRadioGroup[i].value;
	}
	
	switch (valueSelected)
	{ 
		case "Insacco": 
			oTableInsacco.style.display = "block";
			oTablePeC.style.display = "none";
			oTableDeM.style.display = "none";
		break; 

		case "Pesatura_e_controllo": 
			oTableInsacco.style.display = "none";
			oTablePeC.style.display = "block";
			oTableDeM.style.display = "none";
		break; 

		case "Dosaggio_e_miscelazione": 
			oTableInsacco.style.display = "none";
			oTablePeC.style.display = "none";
			oTableDeM.style.display = "block";
		break; 

		default: 
					
	}
}

function ctrlOnChange(sSelectId, sTxtId)
{
	var oSelect =  document.getElementById(sSelectId);
	var oTxt =  document.getElementById(sTxtId);
	
	if (oSelect.options[oSelect.selectedIndex].value == "Altro")
		oTxt.disabled = false;
	else
	{
		oTxt.value = "Specificare qui";
		oTxt.disabled = true;
	}
}

function IsNumeric(sText)
{
   var IsNumber;
   
   if ((sText != null) && (sText.length > 0))
   {
		var ValidChars = "0123456789";
		var Char;
		IsNumber = true;
		 
		for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
		}
	}
	else
		IsNumber = false;
			
	return IsNumber;
}

function IsDecimal(sText)
{
   var IsDecimal;
   
   if ((sText != null) && (sText.length > 0))
   {
		var ValidChars = "0123456789.";
		var Char;
		IsDecimal = true;
		 
		for (i = 0; i < sText.length && IsDecimal == true; i++) 
		{ 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsDecimal = false;
			}
		}
		
		if (isNaN(sText))
			IsDecimal = false;		
		
	}
	else
		IsDecimal = false;
					
	return IsDecimal;
}

//-->