addEvent(window,'load',inicializarEventos,false);

function inicializarEventos()
{
  var ref=document.getElementById('formulario');
  addEvent(ref,'submit',enviarDatos,false);
}

function enviarDatos(e)
{
  if (window.event)
    window.event.returnValue=false;
  else
    if (e)
      e.preventDefault();
  if (document.getElementById('radio1').checked)
    enviarSeleccion(1);
  else
    if (document.getElementById('radio2').checked)
      enviarSeleccion(2);
    else
      if (document.getElementById('radio3').checked)
        enviarSeleccion(3);
		    else
      if (document.getElementById('radio4').checked)
        enviarSeleccion(4);


}


var conexion1;
function enviarSeleccion(cod) 
{
  conexion1=crearXMLHttpRequest();
  conexion1.onreadystatechange = procesarEventos;
  var aleatorio=Math.random();
  conexion1.open('GET','pagina1.php?codigo='+cod+"&aleatorio="+aleatorio, true);
  conexion1.send(null);  
}

function procesarEventos()
{
  var encuesta = document.getElementById("encuesta");
  if(conexion1.readyState == 4)
  {
       encuesta.innerHTML = '<strong>Voto Enviado-Gracias</strong><hr><img src="encuesta.png"><hr><strong>Voto Enviado-Gracias</strong>';
  } 
  else 
  {
    encuesta.innerHTML = '<img src="fotos/cargando.gif">';
  }
}



//***************************************
//Funciones comunes a todos los problemas
//***************************************
function addEvent(elemento,nomevento,funcion,captura)
{
  if (elemento.attachEvent)
  {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else  
    if (elemento.addEventListener)
    {
      elemento.addEventListener(nomevento,funcion,captura);
      return true;
    }
    else
      return false;
}

function crearXMLHttpRequest() 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}


