function AcaoEnquete(botao, opcao){
	var id = document.enquete.id.value;
	if(botao == 2) // se é para ver resultado
	{
		carregaConteudo('div_enquete','enquete_resultado.php?id='+id);
		/*
		window.open(,'janela_enquete','status=yes,scrollbars=yes,resizable=no,width=350,height=250,location=no,status=yes,menubar=no');
		document.enquete.action = "enquete_resultado.php?id="+id;
		document.enquete.target = "janela_enquete";
		return false;
		*/
	}
	if(botao == 1)
	{
		var form = document.enquete;
		var x, selecionados = 0;
		// percorre verificando os op checados e dá um valor ao selecionados
		for( x=0; x < opcao; x++ )
		{
			if( form.op[x].checked )
			{
				selecionados++;
			}
		}
			// caso nenhum for checado
		if( selecionados == 0 )
		{
			alert("Escolha alguma opção");
			return false;
		} // se houver algum checado
		else
		{
			var i, op_selecionado = 0;
			for( i=0; i < opcao; i++ )
			{
				if(form.op[i].checked)
				{
					op_selecionado = form.op[i].value;
				}
			}
			carregaConteudo('div_enquete','enquete_doresponder.php?id='+id+'&op='+op_selecionado);
			/*
			window.open('enquete_doresponder.php?id='+id+'&op='+op_selecionado,'janela_enquete','status=yes,scrollbars=yes,resizable=no,width=350,height=250,location=no,status=yes,menubar=no');
			document.enquete.action = "enquete_doresponder.php?id="+id+"&op="+op_selecionado;
			document.enquete.target = "janela_enquete";
			return false;
			*/
		}
	}
	return false;
}

function carregaConteudo(elemento, url){
		/* inicia a função com 2 argumentos o "elemento" que será onde o conteudo do outro argumento ("pagina") será posto o segundo argumento é a página que irá ser requirida*/
		//showLoading(true); /* imprime no elemento uma div chamada carregando com texto escrito "carregando..." */
		var ajax; /* variável ajax será a variável que irá obter o método de requisição das páginas */
		try
		{ // tente
			ajax = new XMLHttpRequest(); /* ajax = new XMLHttpRequest é o método de obter requisições no firefox,safari etc */
		} // fecha o try
		catch(e)
		{ /* se caso o try não tiver voltado true ele irá executar */
			try
			{ // tente
				ajax = new ActiveXObject("Msxml2.XMLHTTP"); /* ajax = new ActiveXObject("Msxml2.XMLHTTP")é o método de obter requisições no internet explorer */
			} // fecha o try
			catch(e)
			{ // se não retornou true tenta esse
				try
				{ //tente
					ajax = new ActiveXObject("Microsoft.XMLHTTP");/* ajax = new ActiveXObject("Microsoft.XMLHTTP")é o método de obter requisições no internet explorer */
				} // fecha o try
				catch(e)
				{ /* não retornou true e agora? Ele não tem suporte a AJAX */
					alert("Seu navegador não tem suporte AJAX.");/* Então avisamos */
					return false; /* retorna false */
				} // fecha o 3 catch
			} // fecha 2 catch
		} // fecha o 1 catch
		//ajax.open("GET",(url+'?'+get),true);
		ajax.open("GET",url,true); /* ajax.open() tem 3 parâmetros que é o método,a página, e um valor boolean que identifica vai trazer o conteúdo de forma assícrona*/
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
		ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate"); 
		ajax.setRequestHeader("encoding", "utf-8");//"ISO-8859-1");
		ajax.onreadystatechange = function (){ /*Aqui fazemos outra função para executar a requisição */
			if(ajax.readyState == 4){ /* ajax.readyState == 4 significa dizer que o processo de requisição está completo */
				if (ajax.status==200){
					var dv_el=document.getElementById(elemento);
					dv_el.innerHTML = unescape(ajax.responseText);
					dv_el.style.display='block';
					//showLoading(false);
				}else{
					alert(aja.status+' - Erro!');
				}
			} // fecha o if
		} // fecha a function
	ajax.send(null); // inicia a transferência
} // fecha a função funcaoAjax();


function showLoading(show){
	if (show){
		var dv=document.createElement('DIV');
		dv.style.backgroundColor='#666666';
		dv.style.filter='Alpha(Opacity=10)';
		dv.style.width='100%';
		dv.style.height='100%';
		dv.style.position='absolute';
		dv.style.top=document.body.scrollTop+'px';
		dv.style.left='0px';
		dv.id='DivLoading';
		dv.align='center';
		dv.innerHTML="&nbsp;";//'<img style="position:relative;top:200px;" src="images/carregando.gif">';
		document.body.appendChild(dv);
	}else{
		document.body.removeChild(document.getElementById('DivLoading'));
	}
}
