function inicializa_xhr() {
var navega_version=["MSXML2.XHTMLHttp.5.0","MSXML2.XHTMLHttp.4.0","MSXML2.XHTMLHttp.3.0","MSXML2.XHTMLHttp","Microsoft.XHTMLHttp",];
  if(window.XMLHttpRequest) {
    var peticion_http = new XMLHttpRequest();
  }
  else if(window.ActiveXObject) {
  for(a=0;$a<navega_version.length;$a++){  
		  try { 
			var peticion_http = new ActiveXObject(navega_version[a]);
		 } 
		 catch (e) { 
		 alert('El navegador utilizado no está soportado'); 
		 } 
  }
  } 
  return peticion_http;
}

function mandatos_suma(numeroid,operacion) {
   if(operacion=="suma"){
     var cuenta="mas";
   }else{
    var cuenta="menos";
   }
  return "cuenta=" + encodeURIComponent(cuenta) +
         "&numero="+numeroid+
         "&nocache=" + Math.random();
}

function suma(operacion,bbdd){
  //1.Instanciar objeto peticion_http
  peticion_http=inicializa_xhr();
 
 
  //3-  Realizar peticion HTTP al servidor
    peticion_http.open("POST", "http:include/ajax/cargador.php", true);
    peticion_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	
  //2.- Preparar la funcion de respuesta
  peticion_http.onreadystatechange = function() {
    if(peticion_http.readyState == 4) {
      if(peticion_http.status == 200){
	    document.getElementById("cargador_"+bbdd).style.display="none";
	      var dondesuma=document.getElementById("votos_"+bbdd);
		  var trocito=dondesuma.innerHTML.split("&nbsp;");
		  var trocea=parseInt(trocito[0]);
		  if(operacion=="suma"){
		    dondesuma.innerHTML=(trocea+1)+"&nbsp;Votos";
		  }else{
		    dondesuma.innerHTML=(trocea-1)+"&nbsp;Votos";
		  }
		  quitasuma=document.getElementById("suma_"+bbdd);
		  quitaresta=document.getElementById("resta_"+bbdd);
		  quitasuma.parentNode.removeChild( quitasuma );
		  quitaresta.parentNode.removeChild( quitaresta );
      }
    }else{
	    document.getElementById("cargador_"+bbdd).style.display="block";
	}
   }

    var query_string = mandatos_suma(bbdd,operacion);
    peticion_http.send(query_string);   
}


function olvido_con(){
  //1.Instanciar objeto peticion_http
  peticion_http=inicializa_xhr();
 
 
  //3-  Realizar peticion HTTP al servidor
    email=document.getElementById("email_olvi").value;
	emaildos=email.replace("@","a09a0");
	emailfin=emaildos.replace(".","a15a1");
    peticion_http.open("POST", "http:include/ajax/olvido.php?cual="+ emailfin +"", true);
    peticion_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

  //2.- Preparar la funcion de respuesta
  peticion_http.onreadystatechange = function() {
    
		if(peticion_http.readyState==1){
            document.getElementById('cargador').style.display = "block"; 
		}
		else if(peticion_http.readyState == 4){ 
			if(peticion_http.status==200){	
				document.getElementById('cargador').style.display = "none"; 		
				respuesta = peticion_http.responseXML;
				var existe=respuesta.getElementsByTagName("p").item(0).firstChild.data;
					if (existe=="true"){
					document.getElementById("olvido_hecho").style.display = "block";
					}else{
					document.getElementById("olvido_error").style.display = "block";
					}
			}	
		}
   }

    peticion_http.send(null);   
}

// removes the custom alert from the DOM
function quitalerta() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("Container_grande"));
}

function mandatos_jug(nom,equi) {
  return "club="+nom+"&equipo="+equi+"&nocache=" + Math.random();
}
