function votar( idEncuesta ,idVotada )
{
	if(conexion){
		conexion.abort()
		conexion = false
	}
	encuesta = document.getElementById(idEncuesta).value
	
	res = '';
	for(i= 0; i<idVotada.length; i++){
		if(idVotada[i].checked)
			res = idVotada[i].value
	}
	
	iniciaVoto( encuesta ,res  );
}
function iniciaVoto( idEncuesta ,idVotada ){
	//repuesta = document.getElementById(idVotada)
	
	if(conexion == false)
		Conexion();
			 
	if(conexion){
		conexion.open("GET","votar.php?idEncuesta=" + idEncuesta +"&respuesta=" + idVotada , true);	
		/*document.getElementById('load').style.visibility = 'visible'
		document.getElementById('load').style.display = 'block'*/
		conexion.onreadystatechange = function(){
					
			if(conexion.readyState == 4){				
				/*document.getElementById('load').style.visibility = 'hidden'
				document.getElementById('load').style.display = 'none'*/
				if(conexion.status == 200){					
					if(conexion.responseText){												
       					//content  = conexion.responseText
						document.getElementById('opciones').innerHTML = conexion.responseText
						conexion = false
					}					
				}
			}
		}
		
		conexion.send(null);
	}	

}

function muestra(){
	mes = document.getElementById('selectMeses').value;
	anio = document.getElementById('selectAnio').value;
	if(mes && anio){
		if(conexion){
			conexion.abort()
			conexion = false
		}

		obtenEncuesta( mes , anio );
		document.getElementById('mensajeError').innerHTML = "";
	}else{		
		document.getElementById('mensajeError').innerHTML = "Selecciona correctamente la fecha";
	}
}

function obtenEncuesta( mes , anio ){
	if(conexion == false)
                Conexion();
        if(conexion){
                conexion.open("GET","votar.php?mes=" + mes +"&anio=" + anio , true);
                /*document.getElementById('load').style.visibility = 'visible'
                document.getElementById('load').style.display = 'block'*/
                conexion.onreadystatechange = function(){

                        if(conexion.readyState == 4){
                                /*document.getElementById('load').style.visibility = 'hidden'
                                document.getElementById('load').style.display = 'none'*/
                                if(conexion.status == 200){
                                        if(conexion.responseText){                                                                                                                                    //content  = conexion.responseText
                                                document.getElementById('encuestaSeleccionda').innerHTML = conexion.responseText
                                                conexion = false
                                        }
                                }
                        }
                }

                conexion.send(null);
        }

}
function procesa(id){
	  conexion.open("GET","votar.php?id=" + id , true);
                /*document.getElementById('load').style.visibility = 'visible'
                document.getElementById('load').style.display = 'block'*/
                conexion.onreadystatechange = function(){

                        if(conexion.readyState == 4){
                                /*document.getElementById('load').style.visibility = 'hidden'
                                document.getElementById('load').style.display = 'none'*/
                                if(conexion.status == 200){
                                        if(conexion.responseText){                                                                                                                                    //content  = conexion.responseText
                                                document.getElementById('encuestaSeleccionda').innerHTML = conexion.responseText
                                                conexion = false
                                        }
                                }
                        }
                }

                conexion.send(null);
}
function siguiente(id){
	if(conexion == false)
                Conexion();
        if(conexion){
              procesa(id);
        }
}
function anterior(id){
	if(conexion == false)
                Conexion();
        if(conexion){
              procesa(id);
        }
}


