var testEmail         = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
var cnn;

function start_ajax_CONTACTO()
{ // alert(datosFrmDatosCONTACTO());

   cnn=createXMLHttpRequest();
   cnn.open("POST","Contacto.ajax.php",true);
   cnn.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   cnn.send(datosFrmDatosCONTACTO());

   cnn.onreadystatechange=function()
   {  if(cnn.readyState==4 && cnn.status==200)
      {  var respuesta=cnn.responseText;

		 document.getElementById("dataFormCONTACTO").style.display="none";
		 document.getElementById("completedCONTACTO").style.display="inline";
		 document.getElementById("respuestaCONTACTO").innerHTML=respuesta;

		 //alert(cnn.responseText);
	  }
   }

}

function datosFrmDatosCONTACTO()
{  var datos="nombre="+encodeURIComponent(document.getElementById("frmDatosCONTACTO").txtNombre.value);
   datos=datos+"&email="+encodeURIComponent(document.getElementById("frmDatosCONTACTO").txtEmail.value);
   datos=datos+"&empresa="+encodeURIComponent(document.getElementById("frmDatosCONTACTO").txtEmpresa.value);
   datos=datos+"&telefono="+encodeURIComponent(document.getElementById("frmDatosCONTACTO").txtFono.value);   
   datos=datos+"&pais="+encodeURIComponent(document.getElementById("frmDatosCONTACTO").txtPais.value);   
   datos=datos+"&tema="+encodeURIComponent(document.getElementById("frmDatosCONTACTO").txtTema.value);
   datos=datos+"&mensaje="+encodeURIComponent(document.getElementById("frmDatosCONTACTO").txtMensaje.value);

   return(datos);
}

function validateFrmDatosCONTACTO()
{  var nombre=document.getElementById("frmDatosCONTACTO").txtNombre.value;
   var email=document.getElementById("frmDatosCONTACTO").txtEmail.value;
   var institucion=document.getElementById("frmDatosCONTACTO").txtEmpresa.value;
   var telefono=document.getElementById("frmDatosCONTACTO").txtFono.value;
   var pais=document.getElementById("frmDatosCONTACTO").txtPais.value;
   var tema=document.getElementById("frmDatosCONTACTO").txtTema.value;   
   var mensaje=document.getElementById("frmDatosCONTACTO").txtMensaje.value;

   var sw=1;   //todo esta bien
   var msg="";

   if(nombre=="")
   {  msg=msg+"\nSu Nombre no ha sido proporcionado";
      sw=0;
   }
   if(email=="")
   {  msg=msg+"\nEl email no ha sido proporcionado";
      sw=0;
   }
   if(telefono=="")
   {  msg=msg+"\nEl telefono no ha sido proporcionado";
      sw=0;
   }
   if(institucion=="")
   {  msg=msg+"\nEl nombre de su empresa no ha sido proporcionado";
      sw=0;
   }
   if(mensaje=="")
   {  msg=msg+"\nEl Mensaje no ha sido proporcionado";
      sw=0;
   }

   if(sw==1)
   {  if(testEmail.test(email))
      {  start_ajax_CONTACTO();
      }
      else
      {  alert("Correo electronico no valido");
         document.getElementById("frmDatosCONTACTO").txtEmail.focus();
      }
   }
   else
   {  alert("Faltan datos por ingresar:\n"+msg);
   }
}