function nuevoAjax()
{
	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 validateEmailv2(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function Enviar()
{
	//valores de las cajas de texto 
	var nombre=document.getElementById("nombre").value;
	var email=document.getElementById("email").value;
	var copia=document.getElementById("copia").checked;
	var asunto=document.getElementById("asunto").value;
	var mensaje=document.getElementById("mensaje").value;

	if (!nombre) {
		alert("Ingrese su Nombre\nEnter your name");
		document.getElementById('nombre').focus();
		return false;
	}
	if (!email) {
		alert("Ingrese su Correo Electronico\nEnter your E-mail");
		document.getElementById('email').focus();
		return false;
	}
	if (!validateEmailv2(email)) {
		alert("Ingrese un Correo Electronico Valido\nEnter a Valid E-mail");
		document.getElementById('email').focus();
		return false;
	}
	if (!mensaje) {
		alert("Ingrese su Mensaje\nEnter your message");
		document.getElementById('mensaje').focus();
		return false;
	}

	//donde se mostrará lo resultados
	divResultado = document.getElementById('texto');
	divResultado.innerHTML='<div style="width:500px;" align="center"><img src="images/loading_bar.gif"><br />Sending/Enviando...</div>';

	//instanciamos el objetoAjax
	ajax=nuevoAjax();
	
	//uso del medoto POST 
	//archivo que realizará la operacion
	ajax.open("POST", "abm_contacto.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("accion=enviar&nombre="+nombre+"&email="+email+"&mensaje="+mensaje+"&asunto="+asunto+"&copia="+copia);

	ajax.onreadystatechange=function() 
	{
		if (ajax.readyState==4)
		{ 
			divResultado.innerHTML='<div style="width:500px;" align="center"><b>Mensaje enviado correctamente, en breve le responderemos<br />Message sent correctly, shortly we will respond</b></div>';
		} 
	}
}

function Limpiar()
{
	document.getElementById("nombre").value = "";
	document.getElementById("email").value = "";
	document.getElementById("asunto").value = "";
	document.getElementById("mensaje").value = "";
	document.getElementById("contador").value = "800";
}
