<!--

String.prototype.trim = function()
{
	var x=this;
	x=x.replace(/^\s*(.*)/, "$1");
	x=x.replace(/(.*?)\s*$/, "$1");
	return x;
}

function checkRequired()
{
	var pass=true;
	for(var intLoop = 0; intLoop<document.infoForm.length; intLoop++)
	{
		if (document.infoForm.elements[intLoop].className=='sfondo' ||
			document.infoForm.elements[intLoop].className=='sfondoL'||
			document.infoForm.elements[intLoop].className=='sfondoM'||
			document.infoForm.elements[intLoop].className=='sfondoS')
		{
			var str =document.infoForm.elements[intLoop].value;
			str=str.trim();
			document.infoForm.elements[intLoop].value=str;
			if(str=='')
			{
				pass=false;
				break;
			}
		}
	}

	if(!pass)
	{
		return false;
	} else {
		return true;
	}
}

function CheckRichiesta()
{
	var val=document.infoForm.richiesta.length;
	if(document.infoForm.richiesta.value!="")
	{
		for(i=0;i<document.infoForm.richiesta.length;i++)
		{
			if(document.infoForm.richiesta[i].checked==true) { val=i }
		}
	} else {
		for(i=0;i<document.infoForm.richiesta.length;i++)
		{
			if(document.infoForm.richiesta[i].checked==true){ val=i}
		}
	}

	if( val==document.infoForm.richiesta.length)
	{
		return false;
	} else {
		return true;
	}
}

function CheckConsento()
{
	var radio_choice = false;
	for (counter = 0; counter < document.infoForm.consenso.length; counter++)
	{
		if (document.infoForm.consenso[counter].checked)
			if(document.infoForm.consenso[counter].value=='si')
				 return true;
	}

	return false;
}

function ControllaDati()
{
	var OK=CheckConsento();

	if(OK)
	{

		if(CheckRichiesta())
		{
			if(checkRequired())
			{
				email=window.document.getElementById('postael').value;
				if (email.indexOf('@', 0) == -1 ||email.indexOf('.', 0) == -1)
				{
					alert("Attenzione, Indirizzo e-mail non valido"); window.document.getElementById('postael').focus(); return;
				} else {
					document.infoForm.submit();
					return true;
				}
			} else {
					alert("Attenzione, per proseguire compila tutti i campi obbligatori!");
					return false;
			}
		} else {
			alert("Attenzione, per proseguire devi scegliere se desideri essere contattato da un agente o se desideri ricevere un catalogo!");
			return false;
		}
	} else {
		alert("Attenzione, per proseguire devi consentire il trattamento dei dati rif. L.G.S. 196 del 30.06.2003!");
		return false;
	}
}

//-->
