function attivaRichiesta(email)
{
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   	if (Filtro.test(trim(email)))
    {
		document.getElementById('moduloInformazioni').style.display = 'block';
		document.informazioni.checkEmail.value = 'OK';
	}
	else
    {
    	document.getElementById('moduloInformazioni').style.display = 'none';
		document.informazioni.checkEmail.value = 'Inserire un indirizzo valido.';
    }
	
}

function attivaPreventivo(email)
{
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   	if (Filtro.test(email))
    {
		document.getElementById('moduloPreventivo').style.display = 'block';
		document.preventivo.checkEmail.value = 'OK';
	}
	else
    {
    	document.getElementById('moduloPreventivo').style.display = 'none';
		document.preventivo.checkEmail.value = 'Inserire un indirizzo valido.';
    }
	
}

function inviaRichiesta(url,fieldName,formName)
{
	res = false;
	if(formName=="informazioni")
		res = checkCampiInfo();
	else
		res = checkCampiPrev();
	if(res)
	{
		element = document.forms[formName].elements[fieldName];	
		if(typeof XMLHttpRequest != "undefined") 
		{ 
				x = new XMLHttpRequest();
		}
		else 
		{ 
			try { x = new ActiveXObject("Msxml2.XMLHTTP");} 
			catch (e) { try { x = new ActiveXObject("Microsoft.XMLHTTP");} catch (e){x = null;}}
		}
		if (x) 
		{
			element.value = "Invio richiesta in corso...";
			x.onreadystatechange = function() 
			{
				if (x.readyState == 4 && (x.status == 200))
				{
					element.value = x.responseText;
				}
			}
			x.open("GET", url + caricaForm(formName), true);
			x.send(null);
		}
	}
}

function checkCampiInfo()
{
	result = true;
	if(trim(document.informazioni.email.value)=="")
	{
		document.informazioni.checkEmail.value = 'Indirizzo Email obbligatorio.';
		result = false;
	}
	if(trim(document.informazioni.nome.value)=="")
	{
		document.informazioni.checkNome.value = 'Nome e Cognome obbligatorio.';
		result = false;
	}
	if(!result)
		document.informazioni.result.value = "Inserire campi obbligatori.";	
	return result;
}

function checkCampiPrev()
{
	result = true;
	if(trim(document.preventivo.email.value)=="")
	{
		document.preventivo.checkEmail.value = 'Indirizzo Email obbligatorio.';
		result = false;
	}
	if(trim(document.preventivo.nome.value)=="")
	{
		document.preventivo.checkNome.value = 'Nome e Cognome obbligatorio.';
		result = false;
	}
	if(!result)
		document.preventivo.result.value = "Inserire campi obbligatori.";	
	return result;
}

function checkNotEmpty(field,resField)
{
	if(field.value!="")
		resField.value = "OK";
	else
		resField.value = "*";
}

function caricaForm(formName)
{
	returnString = "";
    formElements=document.forms[formName].elements;
    returnString += "?" +formElements[0].name+"="+formElements[0].value;
    for(i=1;i<formElements.length;i++) {
		if(formElements[i].type != "button" && formElements[i].type != "reset")
                returnString+="&"+formElements[i].name+"="+formElements[i].value;
     }
     return returnString;
}

function trim(stringa)
{
	return stringa.replace(/^\s*/, "").replace(/\s*$/, "");
}
