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

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(); 
}

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

function document_onLoad() {
  if (getCookie("Idencuesta")!="null")
   document.Form.idencuesta1.value = String(getCookie("Idencuesta"));
   
 }
 
function check_document() {
  if (getCookie("Idencuesta")!="null") {
   document.Form.idencuesta1.value = String(getCookie("Idencuesta")); 
  }
} 

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

function valido(nro_consignas) { 
  hay_seleccion = false;
  for (count = 0; count < nro_consignas; count++) {
    if (document.Form.voto[count].checked) { hay_seleccion = true; }  
  }
  if ( hay_seleccion == true ) { voto(nro_consignas); }
  else { window.alert("Seleccione una Opción ..."); 
  }
}