/* ****************************************************************** */
/* **** Funciones para validar la cookie de votacion del usuario **** */
/* **** 08/10/2002 - MCO ******************************************** */
/* **** 11/06/2008 - CSA ******************************************** */
/* ****************************************************************** */
// -----------------------------------------------------------------
function check_cookie(id) {
	var yavoto = getCookie(id); // cookie sesion
	var i=0;
	var idAlt = '';
	//alert(yavoto);
	// Si el usr ya votoesta logeado, salta directo al menu sin solicitare la clave.
	//var opciones = document.getElementById("formEnc").Rad_ENCUESTA.length;
	if (yavoto == 'yavoto' || document.getElementById("formEnc").cerrada.value=='true') {
	  for ( i=document.getElementById("formEnc").alti.value; i<=document.getElementById("formEnc").altf.value; i++) {
	    idAlt = 'Rad_ENCUESTA_'+i;
	    document.getElementById(idAlt).style.display = 'none';
	  };
	  document.getElementById("formEnc").Sbm_ACCION.style.display = 'none';
	  if ( document.getElementById("formEnc").cerrada.value == 'true' ){
	    document.getElementById('encGracias').style.display = 'none';
	    document.getElementById('encCerrada').style.display = '';
	  } else {
	    document.getElementById('encGracias').style.display = '';
	    document.getElementById('encCerrada').style.display = 'none';	    
	  };
	  return true;
	}
	else {
	  return false;
	};
}; // check_cookie.

// -----------------------------------------------------------------
function getCookie(name) {
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}; // getCookie.

// -----------------------------------------------------------------
function envia_encuesta(from,lengua) {
  //var opciones = document.formEnc.Rad_ENCUESTA.length;
  var opciones = document.getElementById("formEnc").Rad_ENCUESTA.length;
  var selecc = false;
  var vista = '';
  for (var i = 0; opciones > i; i++) {
    if (document.getElementById("formEnc").Rad_ENCUESTA[i].checked) {
      selecc = true;
      break;
    };
  };

  if (! selecc) {
    vista = getCookie('vista'); // cookie sesion
    if ( vista == 'en' || vista == 'eng'){
        alert('You must select an alternative.');
    }else{
        alert('Debe seleccionar alguna alternativa.');
    };
    return false;
  };
  
  if ( (selecc) && (from == 'port') ) {
    // document.formEnc.target = '_top';
    document.getElementById("formEnc").from.value = 'port';
    document.getElementById("formEnc").url.value = document.URL;
  };
  //return selecc;
  enc_ajax_post('/encuestas/php/encuesta_votar.php',lengua);
  return false;
  
}; // envia_encuesta.

// -----------------------------------------------------------------
function recarga_pag() {
  document.frames["enc"].location.reload();
}; // recarga_pag.


// -----------------------------------------------------------------
  function subWin(loc, nom, ancho, alto, posx, posy) {
    var options="toolbar=0,status=0,menubar=0,scrollbars=1,resizable=0,location=0,directories=0,width=" + ancho + ",height=" + alto;      
        
    win = window.open(loc, nom, options);                 
    win.focus();
    win.moveTo(posx, posy);    
  }; 
  
  
// -----------------------------------------------------------------
function verMasEncuestasSc(){
    //Muestra otras encuestas, rutina SIN cgi
    var loc = '/encuestas/port/encuesta_lista.html';
    subWin(loc, 'verMasEncuestasSc', 500, 550, 75, 50);
    //window.location.href = loc;    
};

// -----------------------------------------------------------------
function verMasEncuestasCc(leng){
    //Muestra otras encuestas, rutina CON cgi
    var loc = '/cgi-cpn/encuestas/encuesta_lista.cgi?leng='+leng;
    subWin(loc, 'verMasEncuestasCc', 510, 550, 75, 50);
    //window.location.href = loc;    
    
};


// -----------------------------------------------------------------
function verResulEncuestasSc(idEncuesta,leng){
    //Muestra resultado de encuestas, rutina php
    subWin('/encuestas/php/encuesta_resul.php?id='+idEncuesta+'&leng='+leng,'verResulEncuestasSc', 510, 550, 105, 85);
};

// -----------------------------------------------------------------
function verResulEncuestasCc(idEncuesta,leng){
    //Muestra resultado de encuestas, rutina cgi
    subWin('/cgi-cpn/encuestas/encuesta_resul.cgi?id='+idEncuesta+'&leng='+leng,'verResulEncuestasCc', 510, 550, 75, 50);
};

// -----------------------------------------------------------------
function verResultadoEncuesta(idEncuesta,leng){
    //var loc = '/encuestas/php/encuesta_resul.php?id='+idEncuesta;
    //window.location.href = loc;
    subWin('/encuestas/php/encuesta_resul.php?id='+idEncuesta+'&leng='+leng,'verResultadoEncuesta', 510, 550, 105, 85);
};

// -----------------------------------------------------------------
