function mostrarResultados(id){
	if(document.getElementById(id).style.display == 'table-row'){
		document.getElementById(id).style.display="none";
		document.getElementById("link"+id).src = document.getElementById("link"+id).src.replace('menos.png', 'mais.png');
	}
	else{
		document.getElementById(id).style.display="table-row";
		document.getElementById("link"+id).src = document.getElementById("link"+id).src.replace('mais.png', 'menos.png');
	}
}

function mostrarExtra(id)
{
	// Parece que deixando vazio o navegador faz a coisa certa, seja IE, Firefox ou Chrome
	document.getElementById("extra"+id).style.display = "";
/*
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ 
		document.getElementById("extra"+id).style.display="table-row";
	}
	else{
		document.getElementById("extra"+id).style.display="block";
	}
*/
}

function esconderExtra(id){
	if(document.getElementById("extra"+id)){
		document.getElementById("extra"+id).style.display="none";
		document.getElementById("filhaResposta"+id).value="";
	}
}

function mostrarEsconderExtra(id, checkado){
	if(document.getElementById(id)){
		if(checkado == true){
			mostrarExtra(id);
		}
		else{
			esconderExtra(id);
		}
	}
}

//abre a div flutuante 
function displayInfo (event, id, conteudo) {
	var divInfo = document.getElementById("info");
	divInfo.innerHTML = conteudo; 
	theObject = document.getElementById(id);
	var posx = 0;
	var posy = 0;
	posx = event.clientX + document.body.scrollLeft + 10;
	posy = event.clientY + document.body.scrollTop + 10;
	
	theObject.style.display = "block";
	theObject.style.position = 'fixed';
	theObject.style.left = posx + "px";
	theObject.style.top = posy + "px";
}

//fecha uma div flutuante
function closeInfo (id){
	theObject = document.getElementById(id);
	theObject.style.display = "none";
}

function setValor(alvo, valor){
	if(document.getElementById(alvo)){
		document.getElementById(alvo).value="";
		document.getElementById(alvo).value=valor;
	}
}

function limpar(campo1, campo2){
	document.getElementById(campo1).value = "";
	document.getElementById(campo2).value = "";
}

function conta(origem, destino){
       document.getElementById(destino).caracteres.value=document.getElementById(origem).length;
} 

function contaChar(totalval, origem, alvo){
	alvo = alvo+""+origem;
	origem = "chars"+origem;
	origem=document.getElementById(origem);
	alvo=document.getElementById(alvo);
	var tot=totalval;
	var l=(origem.value).length;
	if(l<=totalval){
		alvo.value= tot-l;
	}
	else{
		alert( "A resposta não pode conter mais que "+ totalval +" caracteres.");
		setmaxch(origem,totalval);
		alvo.value=  totalval-(origem.value).length;
		origem.focus();
	}
	return true;
}

function setmaxch(id, noOfChar){
	if (id.value.length >= noOfChar){
		id.value = id.value.substring(0, noOfChar);
	}
}

function setarEmail(object, li){
	var valoradicional = li.conteudo;
	var valorOriginal = object.value;
	if(valorOriginal.indexOf(valoradicional) < 0){
		if(valorOriginal.length == 0){
			object.value=valoradicional;
		}
		else{
			object.value=unescape(valorOriginal)+'\n'+valoradicional;
		}
		li.className="current_item";
	}
	else{
		var parts = valorOriginal.split('\n');
		valorNovo='';
		for (var i=0; i<parts.length; i++){
			if(parts[i] == valoradicional){
				li.className="";
			}
			else{
				if(valorNovo == ''){
					valorNovo += parts[i];
				}
				else{
					valorNovo += '\n'+parts[i];
				}
			}
		}
		object.value=unescape(valorNovo);		
	}
}

/*function testarEmails(emails){
	var valores = emails.value;
	var parts = valores.split('\n');
	for (var i=0; i<parts.length; i++){
		if(document.getElementById(parts[i])){
			document.getElementById(parts[i]).className="current_item";
		}
	}
}*/

function gerarGrafico(path, pergunta, tipo, publico){
	if(tipo=="graficoGeral"){
		var peso=pergunta;
		var valorTipo = document.getElementById("graficoPercentualGeral").value;
		if(valorTipo == ""){
			alert('Escolha um gráfico!');
			return false;
		}
		else{
			var w = screen.availWidth;
			var h = screen.availHeight;
			window.open(path+"/"+peso+"/"+valorTipo, "graficoGeral","width="+w+",height="+h+",scrollbars=YES") 
		}
	}
	else{
		var valorTipo = document.getElementById(tipo+pergunta).value;
		if(valorTipo == ""){
			alert('Escolha um gráfico!');
			return false;
		}
		else{
			var w = screen.availWidth;
			var h = screen.availHeight;
			window.open(path+"/"+pergunta+"/"+valorTipo+"/"+publico, "grafico"+pergunta+tipo,"width="+w+",height="+h+",scrollbars=YES") 
		}
	}
}

function mostrarFiltros(){
	if(document.getElementById('filtros').style.display == 'table-row'){
		document.getElementById('filtros').style.display="none";
		document.getElementById("linkfiltro").src = document.getElementById("linkfiltro").src.replace('menos.png', 'mais.png');
	}
	else{
		document.getElementById('filtros').style.display="table-row";
		document.getElementById("linkfiltro").src = document.getElementById("linkfiltro").src.replace('mais.png', 'menos.png');
	}
	return false;
}

function setPdf(pdf, paisagem){
	//criar um novo form de filtros - oculto
	var form = document.createElement('form');
	form.id = 'pdfForm';
	form.method = 'get';
	form.style.display = 'none';
	var index = window.location.href.indexOf('?');
	if(index<0){
		index = window.location.href.length;
	}
	form.action = window.location.href.substring(0, index);
	
	var newin = document.createElement('input');
	newin.id='pdf';
	newin.name='pdf';
	newin.value='true';
	newin.type='hidden';
	form.appendChild(newin);
	form.target='_blank';
	
	if(paisagem)
	{
		var newin = document.createElement('input');
		newin.id='paisagem';
		newin.name='paisagem';
		newin.value='true';
		newin.type='hidden';
		form.appendChild(newin);
	}
	
	//adiciona todos os inputs que estão na tela e são da classe filtro no form de filtros criado
	document.getElementById("principal").appendChild(form);
	form.submit();	
	return false;
	
}

var mostra=false;
function aguarde(mostra){
	var mostra=mostra;
	if(mostra)
	{
		document.getElementById("botaoPublicar").disabled="disabled";
	    document.getElementById("botaoPublicar").value="Aguarde, enviando...";
	}
	else
	{
		document.getElementById("botaoPublicar").disabled="";
	    document.getElementById("botaoPublicar").value="Publicar";
	}
}

