
function PrendiDatiAVideo()
{
	var DV=new Array();
	//prendo dati a video
	doc=document.getElementById("nome");
	if (doc)
		DV["nome"]=doc.value;
	doc=document.getElementById("cognome");
	if (doc)
		DV["cognome"]=doc.value;
	doc=document.getElementById("email");
	if (doc)	
		DV["email"]=doc.value;
	doc=document.getElementById("oggetto");
	if (doc)
		DV["oggetto"]=doc.value;
	doc=document.getElementById("oggetto_email");
	if (doc)
		DV["oggetto_email"]=doc.value;
	doc=document.getElementById("azienda");
	if (doc)
		DV["azienda"]=doc.value;
	return DV;
}
function InviaMail()
{
	var mandavia=new Array();
	var rispostamail="";
	mandavia=PrendiDatiAVideo();
	var incoerenze=ControllaCoerenzaMail(mandavia);
	var rendo=0;
	if (incoerenze==0)
	{
		rendo=CheckErroreMail();
		MandaErrore(rendo);
//		rispostamail=SynchPOSTRequestA("mail/inviomail.php",mandavia);
		//alert("rispostamail: "+rispostamail);
	}
	else
		MandaErrore(incoerenze);
}
function ControllaCoerenzaMail(vettore)
{
	if (is_array(vettore))
	{
		if (vettore["nome"]=="")
			return 1;
		if (vettore["cognome"]=="")
			return 2;
		if (vettore["email"]=="")
			return 3;
		if (CheckEmail(vettore["email"])!="OK")
			return 4;	
	}
	return 0;
}
function MandaErrore(quale)
{
	var attualmenteinonda="";
	doc=document.getElementById("nome");
	if (doc)
	{
		doc.style.border="1px solid #eeeeee";
	}
	doc=document.getElementById("cognome");
	if (doc)
	{
		doc.style.border="1px solid #eeeeee";
	}
	doc=document.getElementById("email");
	if (doc)
	{
		doc.style.border="1px solid #eeeeee";
	}
	doc=document.getElementById("avvisi");
	if (quale>0)
	{
		
		if (doc)
		{
				testoerrore="<table  align=\"center\" cellspacing=0  style=\" width:500px;\" >\
				<tr>\
					<td align=\"center\">\
						<br>\
						<font  color=\"red\"><b>&nbsp;&nbsp;Attenzione </b></font>";
				if (quale!=4)		
					testoerrore+="<font color=\"red\"><br>Riempire i campi obbligatori</font>";
				else
					testoerrore+="<font color=\"red\"><br>Inserire un Indirizzo email valido</font>";
				testoerrore+="</td>\
				</tr>\
				</table>";
				doc.innerHTML=testoerrore;
				doc.style.display="block";
				doc.style.visibility="visible";
			//javascript:Loader('mail/contatti.html','display_large',false);
		}
		switch (quale)
		{
			case (1):
			{
				doc=document.getElementById("nome");
				if (doc)
				{
					doc.style.border="2px solid red";
				}
			}
			break;
			case (2):
			{
				doc=document.getElementById("cognome");
				if (doc)
				{
					doc.style.border="2px solid red";
				}
			}
			break;
			case (3):
			{
				doc=document.getElementById("email");
				if (doc)
				{
					doc.style.border="2px solid red";
				}
			}
			break;
			case (4):
			{
				doc=document.getElementById("email");
				if (doc)
				{
					doc.style.border="2px solid red";
				}
			}
			break;
		}
	}

	if (quale==0 )
	{
		
		doc.innerHTML="";
		rilevatoerrore=0;
		javascript:Loader('mail/grazie.htm','display_large',true);
	}
}
function CheckEmail(email)
{
  AtPos = email.indexOf("@")
  StopPos = email.lastIndexOf(".")
  Message = "OK";

  if (email == "")
  {
    return "";
  }

  if (AtPos == -1 || StopPos == -1)
  {
    Message = "Not a valid email address";
  }

  if (StopPos < AtPos)
  {
    Message = "Not a valid email address";
  }

  if (StopPos - AtPos == 1)
  {
    Message = "Not a valid email address";
  }
  return Message;
}
function CheckErroreMail()
{
//	var errore = 0;
	var chece="";
	doc=document.getElementById("framerispostamail");
	if (doc)
	{
		chece=doc.innerHTML;
	}
	else 	alert("nulla!! ");
//	alert("che ho trovato: "+chece);
	//errore=parseInt(chece);
	//alert("CheckErroreMail "+errore);
	return chece;
}
