function init_encuesta(id){
	
	if(consultarGalleta("encuesta"+id)){
		toggle('survey-resultados-'+id);
		toggle('survey-opciones-'+id);
		toggle('link-mais-'+id);
		document.getElementById('code-box-'+id).style.display="none";
	}
}

function ver_resultados(id){
	toggle('survey-resultados-'+id);
	toggle('survey-opciones-'+id);
	toggle('code-box-resultados-1');
	toggle('code-box-resultados-2');
}

function init_detalle_encuesta(id){
	if(consultarGalleta("encuesta"+id)){
		document.getElementById('encuestaOpciones').style.display="none";
	}else{
		document.getElementById('encuestaOpciones').style.display="block";
	}
	//document.getElementById('cajaCodigo').style.display="none";
}

function pre_init_encuesta(id){
	// me fijo si estoy en un detalle de encuesta o en una pagina
	if(document.getElementById('idEncuestaDestacada')){
		// Si estoy en la home hay que redireccionarlo al detalle de la encuesta
		// leo por gtalk
		//init_encuesta(id);
		location.href = "../../"+window.SEO_PAGINAS+"/inquerito.html?idEncuesta="+id;
	}else{
		init_detalle_encuesta(id);
	}
}

function votar(id,fun){	
	var frm      = document.getElementById("frmVotarEncuesta");
	var optError = false;
	var idEncuesta = document.getElementById('idEncuesta').value;
	var query_string = '../_post/ionline/votar_encuesta.php?';
	
	for(i = 0 ; i < frm.length ; i++ ){
		if((frm.elements[i].type == 'radio' && frm.elements[i].checked) || frm.elements[i].type != 'radio' ){
			query_string += frm.elements[i].name+"="+frm.elements[i].value+"&";
			if((frm.elements[i].type == 'radio' && frm.elements[i].checked)){
				optError=true;
			}
		}
	} 
	
	if(consultarGalleta("encuesta"+idEncuesta)){
		PopUpAlert("Você já participou no inquérito.");
		return;
	}
	 
	
	if(!optError){
		PopUpAlert("Selecione uma opo de voto");
		return;
	}
	
	if(fun==1)
	{
		show('code-box-'+id);
		hide('code-box-button-1');
		show('code-box-button-2');
	}
	
	if(fun==2)
	{
		if(document.getElementById('randomUsuario').value.trim() == ''){
			
			PopUpAlert('Digite o código');
			
		}else{
			if(optError) {
				_post(query_string);
			}
		}
	}
}


/* ******************************************** 
 * Estas funciones estan en js/ionline/function.js
 * se tuvieron que cargar aca por varios motivos
 * 1 - pq drop.php (script q carga el iframe del back para refrescar el objeto) no cargar el archivo 
 * 2 - el archivo custom genera conflitos de nombre de funciones con otros archivos JS q si cargar drop.php
 **/
function consultarGalleta(nombre){

	var buscamos = nombre + "=";
	if (document.cookie.length > 0){
		i = document.cookie.indexOf(buscamos);
		if (i != -1) {
			i += buscamos.length;
			j = document.cookie.indexOf(";", i);
			if (j == -1)
				j = document.cookie.length;
			return unescape(document.cookie.substring(i,j));
		}
	}
}

function toggle(id){
  if($(id).style.display == 'none')
		$(id).style.display = 'block';
	else
		$(id).style.display = 'none';
}