/* Inicia uma conexão externa
 *
 * Atraves dessa conexão é possivel executar outras paginas em back ground
 *
 */
function RequestHttp(){
	var xmlhttp;
	try {
		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		   xmlhttp = false;
		}
	}		
	
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

function enviaVoto() {
	var xmlHttpRequest = new RequestHttp();
	var voto = parseInt(document.getElementById('opcaoVoto').value);
	//var confirmacao = parseInt(document.getElementById('confirmacao').checked);
	
	if (voto == 0) {
		alert("Escolha uma opção!");
		return false;
	}	
						
	var container = document.getElementById("conteudo_enquete");
	container.removeChild(document.getElementById('tabelaEnquete'));
	
	var newdiv = document.createElement("div");
	newdiv.setAttribute("id", "processando");
	newdiv.innerHTML = "<div>Processando seu voto. <br />"+
						"<br />Por favor aguarde...<br /><br />"+
						"<center><img src=\"images/loading.gif\" /></center>"+
						"</div>";
	container.appendChild(newdiv);
		
	xmlHttpRequest.onreadystatechange=function() {
		if (xmlHttpRequest.readyState == 4) {
			var container = document.getElementById("conteudo_enquete");
			container.removeChild(document.getElementById('processando'));
			var newdiv = document.createElement("div");
			newdiv.innerHTML = xmlHttpRequest.responseText;			
			container.appendChild(newdiv);			
		}
	}
		
	xmlHttpRequest.open("GET", "/sistemas/enquete/controle/ajaxEnquete.php?voto="+voto, true);	
	xmlHttpRequest.send(null);
}
