// JavaScript Document

<!--
function isEmpty(s)
{ return ((s == null) || (s.length == 0)); }
function isSpace(c)
{ return ((c == "\n") || (c == " ") || (c == "\b") || (c == "\t")); }
function isWhiteSpace(s)
{ for(i=0; i<s.length; i++)
  if(!isSpace(s.charAt(i))) return false;
  return true;
}
function warning(f,s)
{ 
/*  border-color:336699;
  border-style:inset;
  border-width:2px;
  color:FFFFFF;*/
  document.getElementById(f).style.borderColor="#FF0000";
  setTimeout("quita_color(\""+f+"\")",3000);
  document.getElementById(s).style.display="block";
  setTimeout("quita_error(\""+s+"\")",3000);
  return false;
}
function isEmail(email)
{
  if(isEmpty(email)) return false;
  if(isWhiteSpace(email)) return false;
  invalidChars = " /:,;";
  for(i=0; i<invalidChars.length; i++)
  {
    badChar = invalidChars.charAt(i);
    if(email.indexOf(badChar,0) > -1) return false; 
  }
  atPos = email.indexOf("@",1);
  if(atPos == -1) return false; 
  if(email.indexOf("@",atPos+1) > -1) return false; 
  periodPos = email.indexOf(".",atPos);
  if(periodPos == -1) return false; 
  if(periodPos+3 > email.length) return false; 
 return true;
}

function limpiar()
{
	  document.getElementById('nombre').value="";
      document.getElementById('email').value="";
      document.getElementById('comentarios').value="";
}
function validar()
{
  var nombre = document.getElementById('nombre').value;
  var email = document.getElementById('email').value;
  var comentarios = document.getElementById('comentarios').value;
  
  
  
  
  if(isEmpty(nombre))
    return (warning("nombre","error_nombre"));
	
  if(!isEmail(email))
    return (warning("email","error_correo"));
	
  if(isEmpty(comentarios))
    return (warning("comentarios","error_comentarios"));
  

  return enviar();
}

function nuevoAjax(){
var xmlhttp=false;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

function desaparece()
{
document.getElementById('confirmacion').style.display="none";
}
function quita_color(d)
{
document.getElementById(d).style.borderColor="";
}
function quita_error(m)
{
document.getElementById(m).style.display="none";
}
function enviar(){
	var nombre = document.getElementById('nombre').value;
    var email = document.getElementById('email').value;
    var comentarios = document.getElementById('comentarios').value;
    var contenedor = document.getElementById('confirmacion');

contenedor.innerHTML = "Enviando...";
ajax=nuevoAjax();
ajax.open("GET", "contactForm.jsp?nombre="+nombre+"&email="+email+"&comentarios="+comentarios,true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4)
{
      document.getElementById('confirmacion').style.display="block";
	  contenedor.innerHTML = ajax.responseText
	  setTimeout("desaparece()",3000);
  	  document.getElementById('nombre').value="";
      document.getElementById('email').value="";
      document.getElementById('comentarios').value="";
}
}
ajax.send(null)
}

function validar_anunciate()
{
  var nombre = document.getElementById('nombre').value;
  var email = document.getElementById('email').value;
  var empresa = document.getElementById('empresa').value;
  var telefono = document.getElementById('telefono').value;
  var comentarios = document.getElementById('comentarios').value;
 
  
  if(isEmpty(nombre))
    return (warning("nombre","error_nombre"));
	
  if(isEmpty(empresa))
    return (warning("empresa","error_empresa"));

  if(isEmpty(telefono))
    return (warning("telefono","error_telefono"));

  if(!isEmail(email))
    return (warning("email","error_correo"));
	
  if(isEmpty(comentarios))
    return (warning("comentarios","error_comentarios"));
  

  return enviar_anunciate();
}

function enviar_anunciate(){
	var nombre = document.getElementById('nombre').value;
    var empresa = document.getElementById('empresa').value;
    var telefono = document.getElementById('telefono').value;
    var email = document.getElementById('email').value;
    var comentarios = document.getElementById('comentarios').value;
    var contenedor = document.getElementById('confirmacion');

contenedor.innerHTML = "Enviando...";
ajax=nuevoAjax();
ajax.open("GET", "contactFormAnunciate.jsp?nombre="+nombre+"&empresa="+empresa+"&telefono="+telefono+"&email="+email+"&comentarios="+comentarios,true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4)
{
      document.getElementById('confirmacion').style.display="block";
	  contenedor.innerHTML = ajax.responseText
	  setTimeout("desaparece()",3000);
  	  document.getElementById('nombre').value="";
      document.getElementById('email').value="";
      document.getElementById('comentarios').value="";
      document.getElementById('empresa').value="";
      document.getElementById('telefono').value="";

}
}
ajax.send(null)
}
-->
