function getCV(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function readCookie(name) {  
    var cookiename = name + "=";  
    var ca = document.cookie.split(';');  
    //alert('ca='+ca);
	for(var i=0;i < ca.length;i++)  
    {  
        var c = ca[i];  
        while (c.charAt(0)==' ') c = c.substring(1,c.length);  
        if (c.indexOf(cookiename) == 0) return c.substring(cookiename.length,c.length);  
    }  
    return null;  
}  

function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCV(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return "";
}

function setCookie(name,value) {
	var FechaCookie = new Date();
	FechaCookie.setFullYear(FechaCookie.getFullYear() + 1);
	document.cookie = name + "=" + escape(value) +
					  "; expires=" + FechaCookie.toGMTString(); 
	//alert('SetCookie='+document.cookie);				  
}

function deleteCookie(name) {
	document.cookie = name + "=" + "" + "; expires=Thu,01-Jan-70 00:00:01 GMT";
}

function document_onLoad() {
  if (getCookie("IdencuestaSMA")!="null") {
     document.FormEncuesta.idencuesta1.value = String(getCookie("IdencuestaSMA"));
	 //alert('document_onLoad='+document.FormEncuesta.idencuesta1.value);
  }
   
 }
 
function check_document() {
  /*if (getCookie("Idencuesta")!="null") {
   document.FormEncuesta.idencuesta1.value = String(getCookie("Idencuesta"));
   //alert('getCookie='+document.FormEncuesta.idencuesta1.value);
  }*/
  if (readCookie("IdencuestaSMA")!="null") {
   document.FormEncuesta.idencuesta1.value = String(readCookie("IdencuestaSMA"));
   //alert('readCookie='+document.FormEncuesta.idencuesta1.value);
  }
} 

function voto(nro_consignas,nrovoto) { 
  //alert('voto');
  check_document();
  if (parseInt(document.FormEncuesta.idencuesta.value) != parseInt(document.FormEncuesta.idencuesta1.value)) {
    //setCookie("Idencuesta",String(document.FormEncuesta.idencuesta.value));
	document.FormEncuesta.proc.value = '1';
  }
  else { 
  	document.FormEncuesta.proc.value = '0';
  }	
  //document.FormEncuesta.submit();
  idencuesta1=document.FormEncuesta.idencuesta1.value;
  idencuesta=document.FormEncuesta.idencuesta.value;
  proc=document.FormEncuesta.proc.value;
  //conf=huella();
  //for (count = 0; count < nro_consignas; count++) {
  //  if (document.FormEncuesta.voto[count].checked) { 	  
  //    nrovoto=document.FormEncuesta.voto[count].value;
  //    document.FormEncuesta.voto[count].blur();
  //  }  
  //}
  //window.alert("voto:"+nrovoto);
  ingresasPOPComentario("../encuesta/autorizar-voto.php?idencuesta1="+idencuesta1+"&idencuesta="+idencuesta+"&proc="+proc+"&voto="+nrovoto, 484, 420);
  //VentanaAbrir("../encuesta/autorizar-voto.php?idencuesta1="+idencuesta1+"&idencuesta="+idencuesta+"&proc="+proc+"&voto="+nrovoto,"Encuesta",640,470,'yes');	
}

function valido(nro_consignas) { 
  //alert('valido');
  var hay_seleccion = false;
  for (count = 0; count < nro_consignas; count++) {
    if (document.FormEncuesta.voto[count].checked) { 
	  hay_seleccion = true; 
	  nrovoto = document.FormEncuesta.voto[count].value;
	}  
  }
  if ( hay_seleccion == true ) { 
    //voto(nro_consignas,nrovoto); 
    check_document();
    if (parseInt(document.FormEncuesta.idencuesta.value) != parseInt(document.FormEncuesta.idencuesta1.value)) {
      //setCookie("Idencuesta",String(document.FormEncuesta.idencuesta.value));
	  document.FormEncuesta.proc.value = '1';
    }
    else { 
  	  document.FormEncuesta.proc.value = '0';
    }	
    //document.FormEncuesta.submit();
    idencuesta1=document.FormEncuesta.idencuesta1.value;
    idencuesta=document.FormEncuesta.idencuesta.value;
    proc=document.FormEncuesta.proc.value;
   
//document.FormEncuesta.action="../encuesta/autorizar-voto.php?idencuesta1="+idencuesta1+"&idencuesta="+idencuesta+"&proc="+proc+"&voto="+nrovoto;
   }
  else { 
  	window.alert("Seleccione una Opción ..."); 
  	//Aca tengo que cancelar el submit del form.
	
  }

  //asignar_huella();

  return hay_seleccion;
}


