function objetoAjax(){
	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 trim (myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

// *********************************** validar email.. ********************************************
function valEmail(valor){
    
	var re=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_.]+\.[A-Za-z0-9_.]+[A-za-z]$/;
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }
}


  
function valida_boletin()
{
	   
var nom =document.getElementById("nombre").value;
var emai = document.getElementById("email").value;

 
	 ajax=objetoAjax();
		
			if(trim(nom)== "" )
			{
				//document.getElementById("respuesta2").innerHTML = vv ; //imprimimos el Plazo
				document.getElementById("respuestaboletin").innerHTML = '* Ingrese su Nombre' ; //imprimimos la palabrita EN:
			}
			else if(trim(emai) == "" )
			{
				//document.getElementById("respuesta_envio2").innerHTML = vv ; //imprimimos el Plazo
				document.getElementById("respuestaboletin").innerHTML = ' *  Ingrese su Email' ; 
			}
			else if(valEmail(emai) == "" )
			{
				//document.getElementById("respuesta_envio2").innerHTML = vv ; //imprimimos el Plazo
				document.getElementById("respuestaboletin").innerHTML = '*  Email Invalido' ; 
			}
			else
			{
				
				
				document.getElementById("respuestaboletin").innerHTML = 'enviando ...' ; 
				
				
			ajax.open("POST", "mailer-boletin.php",true);
					ajax.onreadystatechange=function() 
					{
						if (ajax.readyState==4) {
							//mostrar resultados en esta capa
						
							var res = trim(ajax.responseText);
							 
								document.getElementById("refresca").innerHTML =res; 	
								
							 
							
							
							
							
						}
					 
					}
					//como hacemos uso del metodo GET
					//colocamos null
			
					ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
					ajax.send("nombre="+nom+"&email="+emai);

			}
		 
}
 

