function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false;
	try
	{
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			// Creacion del objet AJAX para IE
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
		}
	}
	return xmlhttp; 
}



function Sobre(id)
{
	document.getElementById(id).style.background="#add8f6";
}
	

function validax(valor,id)
{
	
	if (valor=="") 
		{
		document.getElementById(id+"Failed").style.display="block";
		document.getElementById(id+"Failed").style.font="12px Verdana";	
		document.getElementById(id+"Failed").style.color="#4682B4";
		document.getElementById(id).style.background="#FAFAD2";
		//document.getElementById(id).focus();
		}
		
	else
	    {
		document.getElementById(id).style.border="1px solid #CCCCCC";
		document.getElementById(id).style.background="#ffffff";
		document.getElementById(id+"Failed").style.display="none";
		}
}

function validaCorreo(valor)
{
	var reg=/(^[a-zA-Z0-9._-]{1,30})@([a-zA-Z0-9.-]{1,30}$)/;
	if(reg.test(valor)) return true;
	else return false;
}

function IngresaCometariox()
{

//  ------------------- Valida el Nombre -------------------------	
	JNombre = document.getElementById("Nombre").value;
	if (JNombre=="")
	{
     validax(JNombre,"Nombre");
	 document.getElementById("Nombre").focus();
	 return;  
	}
	
	//  ------------------- Valida Direccion -------------------------	
	JDireccion = document.getElementById("Direccion").value;
	if (JDireccion=="")
	{
     validax(JDireccion,"Direccion");
	 document.getElementById("Direccion").focus();
	 return;  
	}
//  ------------------- Valida Email1 -------------------------	
	JEmail = document.getElementById("Email").value;
	if (JEmail=="")
	{
     validax(JEmail,"Email");
	 document.getElementById("Email").focus();
	 return;  
	}
	else
	{
		if(validaCorreo(JEmail)==false)
		{
		 	validax(JEmail,"Email");
	 		document.getElementById("Email").focus();
	 		alert("Error Email Invalido");
			return;  
		}
	}	
	
	
	
//  ------------------- Valida Telefono -------------------------	
	JTelefono = document.getElementById("Fono").value;
	if (JTelefono=="")
	{
     validax(JTelefono,"Fono");
	 document.getElementById("Fono").focus();
	 return;  
	}




	

	
	//  ------------------- Valida Comentario -------------------------	
	JMensaje = document.getElementById("Mensaje").value;
	//alert(JComentario);
	if (JMensaje=="")
	{
     validax(JMensaje,"Mensaje");
	 document.getElementById("Mensaje").focus();
	 return;  
	}	
	
	
	
	
	
	contenedor=document.getElementById("label_informacion");
	ajax=nuevoAjax();

	var aleatorio=Math.random(); 
	
	
	ajax.open("GET","EnviaContacto.php?Nombre="+JNombre+"&Direccion="+JDireccion+"&Telefono="+JTelefono+"&Email="+JEmail+"&Mensaje="+JMensaje+"&nocache="+aleatorio,true);
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				contenedor.innerHTML="Validando Informacion ...";
				//selectDestino.appendChild(nuevaOpcion); selectDestino.disabled=true;	
			}		
		if (ajax.readyState==4) 
			{
						if (ajax.responseText=='OK')
						   {
							  message = document.getElementById("formulario");
  							// muestra el error o bien oculta el error
  							message.className = "hidden";
							contenedor.innerHTML=" <br /> Mensaje enviado con exito";
							//document.getElementById("formulario_Ok").display="none";
						   }
						   
						 if (ajax.responseText=='ERROR: EL EMAIL ES INVALIDO')
						   {
							  //message = document.getElementById("formulario");
  							// muestra el error o bien oculta el error
  							//message.className = "hidden";
							contenedor.innerHTML=" <br /> ERROR: EL EMAIL ES INVALIDO O ESTA MAL ESCRITO";
						   }
						 if (ajax.responseText=='ERROR: EL EMAIL YA ESTA  INGRESADO')
						   {
							  //message = document.getElementById("formulario");
  							// muestra el error o bien oculta el error
  							//message.className = "hidden";
							contenedor.innerHTML=" <br /> ERROR: EL EMAIL YA SE ENCUENTRA AGREGADO EN NUESTRA BASE DE DATOS";
						   }
						
						
	 		}
	}
ajax.send(null);
}
	
	
	


