//Cria uma variável booleana para checar se é uma Instância válida para o Internet Explorer
var xmlhttp = false;
	
//Verifica se está usando IE
try{
	//Se a versão do javascript é maior que 5
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
	//Se não, usa versão antiga objeto active x
	try{
		//Se está usando Microsoft
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(E){
		//Se não, deve estar usando um navegador diferente de IE
		xmlhttp = false;
	}
}

//Se está usando um navegador diferente de IE, cria instância javascript objeto
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}

//Mostra ou Esconde div alpha
function muda(){
	flut = document.getElementById('flutuante');
	if (flut.style.display == 'none'){
		flut.style.display = 'block';
	}else{
		flut.style.display = 'none';
	}
}
//Chama conteudo da pagina pelo nome do arquivo
function makerequest(serverPage, objID){
	muda();
	var obj = document.getElementById(objID);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			muda();
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

//Chama conteúdo do link passando id
function callcontent(pagina, id, objID){
	muda();
	//objID = O local no qual estamos carregando a página.
	var serverPage = pagina + ".php" + "?id=" + id;
	
	var obj = document.getElementById(objID);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			muda();
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

//Manda e-mail contato
function sendmail(){
	objID = "conteudo";
	nome = document.getElementById("nome").value;
	fone = document.getElementById("fone").value;
	email = document.getElementById("email").value;
	msg = document.getElementById("mensagem").value;
	var serverPage = "envia.php?nome="+nome+"&fone="+fone+"&email="+email+"&msg="+ msg;
	var obj = document.getElementById(objID);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			//obj.innerHTML = xmlhttp.responseText;
			alert("Olá " + nome + ", obrigado pelo seu contato. Em breve entraremos em contato.");
			window.location = "index.php";
		}
	}
	xmlhttp.send(null);
}

//Abre Janela (JS Simples)
function AbreJanela(html, largura, altura){
	window.open(html,"nova_janela","width="+largura+",height="+altura+",CenterJustify");void(0);
}
