// JavaScript Document
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 enviar_suscripcion(email){
	var aleatorio= generar_aleatorio();
	var email=email;
	
	divContenido=document.getElementById('td_contenido');
	divContenido2=document.getElementById('div_gracias');
	divContenido3=document.getElementById('div_formulario');	
 
	ajax=objetoAjax();
 	ajax.open("GET","includes/enviar_suscripcion.php?p_email="+email+"&aleatorio="+aleatorio);
 	divContenido.innerHTML='Enviando';
 	ajax.onreadystatechange=function() {
		if (ajax.readyState==4){
			respuesta=ajax.responseText;
			//alert(respuesta);
		 	divContenido.innerHTML='';
			divContenido2.innerHTML=respuesta;
			divContenido2.style.display='';
			document.form_suscribete.email.value="Email";
			divContenido3.style.display='none';
		}
	}
	ajax.send(null)
}

function generar_aleatorio(){
	var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  	var pass  = "";
	var length= new Number(6) * 1;
  	for(var x=0; x < length; x++){
		var i = Math.floor(Math.random() * 62);
    	pass += chars.charAt(i);
  	}
  	return pass;
}

function ocultar_gracias(){
	divContenido2=document.getElementById('div_gracias');
	divContenido3=document.getElementById('div_formulario');
		
	divContenido2.innerHTML="";
	divContenido2.style.display='none';
	divContenido3.style.display='';
}
