/* ****************************************************************** */
/* **** 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.
	if (yavoto == 'yavoto' || document.formEnc.cerrada.value=='true') {
	  for ( i=document.formEnc.alti.value; i<=document.formEnc.altf.value; i++) {
	    idAlt = 'Rad_ENCUESTA_'+i;
	    document.getElementById(idAlt).style.display = 'none';
	  };
	  document.formEnc.Sbm_ACCION.style.display = 'none';
	  if ( document.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) {
  var opciones = document.formEnc.Rad_ENCUESTA.length;
  var selecc = false;
  for (var i = 0; opciones > i; i++) {
    if (document.formEnc.Rad_ENCUESTA[i].checked) {
      selecc = true;
      break;
    };
  };

  if (! selecc) {
    alert('Debe seleccionar alguna alternativa');
    return false;
  };

  if ( (selecc) && (from == 'port') ) {
    // document.formEnc.target = '_top';
    document.formEnc.from.value = 'port';
    document.formEnc.url.value = document.URL;
  };

  if(window.sst7_click_encuesta) {
    sst7_click_encuesta();
  };
  //return selecc;
  enc_ajax_post('/encuestas/php/encuesta_votar.php');
  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
    //subWin('/encuestas/port/encuesta_lista.html', '', 400, 445, 75, 50);
    var loc = '/encuestas/port/encuesta_lista.html';
    top.window.location.href = loc;

};

// -----------------------------------------------------------------
function verMasEncuestasCc(){
    //Muestra otras encuestas, rutina CON cgi
    //subWin('/cgi-px/encuestas/encuesta_lista.cgi', '', 400, 445, 75, 50);
    var loc = '/cgi-px/encuestas/encuesta_lista.cgi';
    top.window.location.href = loc;

};


// -----------------------------------------------------------------
function verResulEncuestasSc(idEncuesta){
    //Muestra resultado de encuestas, rutina php
    subWin('/encuestas/php/encuesta_resul.php?id='+idEncuesta,'', 510, 460, 75, 50);
};

// -----------------------------------------------------------------
function verResulEncuestasCc(idEncuesta){
    //Muestra resultado de encuestas, rutina cgi
    subWin('/cgi-px/encuestas/encuesta_resul.cgi?id=idEncuesta','', 510, 460, 75, 50);
};

function verResultadoEncuesta(idEncuesta){
    //var loc = '/encuestas/php/encuesta_resul.php?id='+idEncuesta;
    //window.location.href = loc;
    subWin('/encuestas/php/encuesta_resul.php?id='+idEncuesta,'', 510, 460, 75, 50);
};