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("contactos").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").nombre.value);
   datos=datos+"&email="+encodeURIComponent(document.getElementById("frmDatosCONTACTO").email.value);
   datos=datos+"&sitio="+encodeURIComponent(document.getElementById("frmDatosCONTACTO").sitio.value);
   datos=datos+"&comentario="+encodeURIComponent(document.getElementById("frmDatosCONTACTO").comentario.value);

   return(datos);
}

function validateFrmDatosCONTACTO()
{  var nombre=document.getElementById("frmDatosCONTACTO").nombre.value;
   var email=document.getElementById("frmDatosCONTACTO").email.value;
   var sitio=document.getElementById("frmDatosCONTACTO").sitio.value;
   var comentario=document.getElementById("frmDatosCONTACTO").comentario.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+"\nSu email no ha sido proporcionado";
      sw=0;
   }
   if(sitio=="")
   {  msg=msg+"\nSu sitio web no ha sido proporcionado";
      sw=0;
   }   
   if(comentario=="")
   {  msg=msg+"\nEl comentario 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").email.focus();
      }
   }
   else
   {  alert("Faltan datos por ingresar:\n"+msg);
   }
}
