

function send_info()
{
	document.getElementById('error_info').style.display='none';
	
	errori = new Array();
	campi = new Array();
	numerr = 0;
	
	var mail = document.form_info.email.value;
	var cognome = document.form_info.cognome.value;
	var nome = document.form_info.nome.value;
	var messaggio = document.form_info.messaggio.value;
	
	var email_reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+[\.]([a-z0-9-]+)*([a-z]{2,3})$/;
	
	if(cognome=="")
	{
		errori[numerr] = "Cognome non inserito";
		campi[numerr]='info_cogn';
		numerr = numerr+1;
	}
	if(nome=="")
	{
		errori[numerr] = "Nome non inserito";
		campi[numerr]='info_nome';
		numerr = numerr+1;
	}
	if(messaggio=="")
	{
		errori[numerr] = "Messaggio non inserito";
		campi[numerr]='camp_mess';
		numerr = numerr+1;
		
	}
	if(!email_reg.test(mail))
	{
		errori[numerr] = "Indirizzo email non valido";
		campi[numerr]='info_mail';
		numerr = numerr+1;
		
	}

	numarray = errori.length;
	
	if(numarray>0)
	{
		document.getElementById("error_info").style.display='block';
		i=0;
		
		var stringa="";
		
		for(i=0; i<numarray; i=i+1)
		{
			stringa = stringa + errori[i] + "<br>";
			blink_form(campi[i]);
		}
		
		document.getElementById("error_info").innerHTML = stringa;
			
	}
	else
	{
		creaQueryString3('form_info');
	}
	
}



function creaQueryString3(queryform)
{
	var stringa="";
	var frm = document.forms[queryform];
	var numeroElementi = frm.elements.length;
	
	for(var x = 0; x<numeroElementi; x=x+1)
	{
		if(x<numeroElementi-1)
		{
			if((frm.elements[x].name!="") && (frm.elements[x].name!=undefined))
			{
				
				stringa +=frm.elements[x].name+"="+encodeURIComponent(frm.elements[x].value)+"&";
				
			}
		}
		else
		{
			if((frm.elements[x].name!="") && (frm.elements[x].name!=undefined==true))
			{
			
				stringa +=frm.elements[x].name+"="+encodeURIComponent(frm.elements[x].value);
				
			}
		}
	}
	
	
	send_datay3(stringa,queryform);
	
}


var xmlHttp = getXmlHttpObject();


function send_datay3(dati,mioform)
{
		xmlHttp.open('POST', 'sendinfo_ajax.php', true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
		xmlHttp.onreadystatechange = function()
														{
															stateChangedsoy3(mioform); 
														}
		xmlHttp.send(dati);

}




function stateChangedsoy3(mioform) 
{

	if(xmlHttp.readyState == 4) 
	{
	
		//Stato OK
		if (xmlHttp.status == 200) 
		{
			
			var risp = xmlHttp.responseText;
	
			if(risp!="")
			{
				risp=risp.replace(/^\s*/gi,"");
				
				if(risp!='')
				{
					document.getElementById('form_info').style.display='none';
					document.getElementById('esito').style.display='block';
					document.getElementById('testo_richiesta').value=risp;
				}
			}
			
		} 
		else 
		{
			alert(xmlHttp);
		}
	}
}


function getXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

