/*||||||||||||||||||||||
|| Funções JS Ajax ---
--------------------------*/
<!--
//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();
}

//Chama conteudo da pagina pelo nome do arquivo
function makerequest(serverPage, objID){
	var obj = document.getElementById(objID);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

//Chama conteúdo do link passando id
function callcontent(pagina, id, objID){
	//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){
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}
//Abre Popup
function abre_janela(width, height, nome, scrollbar){
	var top; 
	var left;
	top = ( (screen.height/2) - (height/2) )
	left = ( (screen.width/2) - (width/2) )
	window.open('',nome,'width='+width+',height='+height+',scrollbars='+scrollbar+',toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}
/*|||||||||||||||||||||||||||||||||||||
|| Funções JS pertinentes ao sistema ||
|||||||||||||||||||||||||||||||||||||*/

//Cadastrando Nome cliente e email na tabela usuarios (HOME)
function f_cad_news(){
	var nome = document.getElementById("nome").value;
	var email = document.getElementById("email").value;
	if(nome == "" || email == ""){
		alert("Para completar o cadastro é necessário preencher os campos.");
	}else{
		if (document.getElementById("email").value.match(/(\w+)@(.+)\.(\w+)$/) == null){
			alert('E-mail incorreto');
			document.getElementById("email").focus();
			document.getElementById("email").select();
		}else{
			var serverPage = "f_cad_news.php?nome="+ nome +"&email="+ email;
			var obj = document.getElementById("msg");
			obj.innerHTML = "<img src='image/loading.gif' border='0' width='15'/>";
			xmlhttp.open("GET", serverPage);
			xmlhttp.onreadystatechange = function(){
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
					obj.innerHTML = xmlhttp.responseText;
					//alert(nome+", seu nome e e-mail foram cadastrados com sucesso.");
					var intervalo = window.setInterval(location(), 5000);
					function location(){
						window.location = "assina_news.php";
					}
					clearInterval(intervalo);
				}
			}
			xmlhttp.send(null);
		}
	}
}
//Pegar valor de um checkbox
function checkone(nome){
	if(document.getElementById(nome).checked){
		var valor = 1;
	}else{
		var valor = 0;
	}
	return valor;
}

//Pega valor do Radio (OURO)
function getCheckedRadio(ident){
	var radioButtons = document.getElementsByName(ident);
	for (var x = 0; x < radioButtons.length; x ++){
		if (radioButtons[x].checked){
			return radioButtons[x].value;
		}
	}
}
//mostra campo outro na pesquisa
function mostraCampoOutro(){
	var escolha = getCheckedRadio("escolha");
	var escolhaOutro = document.getElementById("escolhaOutro");
	var txtQuais = document.getElementById("txtQuais");
	
	if(escolha == "Outros"){
		escolhaOutro.style.display="block";
		txtQuais.style.display="block";
	}else{
		escolhaOutro.style.display="none";
		txtQuais.style.display="none";
	}
}
//Envia e-mail pesquisa - sac
function f_env_pesquisa(){
	var nome = document.getElementById("nome").value;
	var email = document.getElementById("email").value;
	var telefone = document.getElementById("telefone").value;
	var data = document.getElementById("data").value;
	var escolha = getCheckedRadio("escolha");
	var escolhaOutro = document.getElementById("escolhaOutro").value;
	var visita = document.getElementById("visita").value;
	var tempodeespera = getCheckedRadio("tempodeespera");
	var atencaocordialidade = getCheckedRadio("atencaocordialidade");
	var clarezanasinformacoes = getCheckedRadio("clarezanasinformacoes");
	var atencaoecordialidade = getCheckedRadio("atencaoecordialidade");
	var assistenciaprestada = getCheckedRadio("assistenciaprestada");
	var chamadasatendidasprontamente = getCheckedRadio("chamadasatendidasprontamente");
	var clarezanasorientacoes = getCheckedRadio("clarezanasorientacoes");
	var apresentacaodofuncionario = getCheckedRadio("apresentacaodofuncionario");
	var qualidadedasrefeicoes = getCheckedRadio("qualidadedasrefeicoes");
	var temperaturadasrefeicoes = getCheckedRadio("temperaturadasrefeicoes");
	var opcoesdecardapio = getCheckedRadio("opcoesdecardapio");
	var confortodoquarto = getCheckedRadio("confortodoquarto");
	var higienedoquarto = getCheckedRadio("higienedoquarto");
	var limpezadasareascomuns = getCheckedRadio("limpezadasareascomuns");
	var apresentacaodasarrumadeiras = getCheckedRadio("apresentacaodasarrumadeiras");
	var manutencaodasinstalacoes = getCheckedRadio("manutencaodasinstalacoes");
	var vcindicaria = getCheckedRadio("vcindicaria");
	var sugestoes = document.getElementById("sugestoes").value;
		
	var serverPage = "f_env_pesquisa.php?nome="+ nome +"&email="+ email +"&telefone="+ telefone +"&data="+ data +"&escolha="+ escolha +"&escolhaOutro="+ escolhaOutro +"&visita="+ visita +"&tempodeespera="+ tempodeespera +"&atencaocordialidade="+ atencaocordialidade +"&clarezanasinformacoes="+ clarezanasinformacoes +"&atencaoecordialidade="+ atencaoecordialidade +"&assistenciaprestada="+ assistenciaprestada +"&chamadasatendidasprontamente="+ chamadasatendidasprontamente +"&clarezanasorientacoes="+ clarezanasorientacoes +"&apresentacaodofuncionario="+ apresentacaodofuncionario +"&qualidadedasrefeicoes="+ qualidadedasrefeicoes +"&temperaturadasrefeicoes="+ temperaturadasrefeicoes +"&opcoesdecardapio="+ opcoesdecardapio +"&confortodoquarto="+ confortodoquarto +"&higienedoquarto="+ higienedoquarto +"&limpezadasareascomuns="+ limpezadasareascomuns +"&apresentacaodasarrumadeiras="+ apresentacaodasarrumadeiras +"&apresentacaodasarrumadeiras="+ apresentacaodasarrumadeiras +"&manutencaodasinstalacoes="+ manutencaodasinstalacoes +"&vcindicaria="+ vcindicaria +"&sugestoes="+ sugestoes;
	
	var obj = document.getElementById("load");
	obj.innerHTML = "<img src='images/loading.gif' border='0' width='18'/>";
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			obj.innerHTML = "";
			alert(nome+', obrigado pelo seu contato.');
		}
	}
	xmlhttp.send(null);
		
	
}
//Envia e-mail Fale Conosco
function f_env_fale(){
	var nome = document.getElementById("nome").value;
	var email = document.getElementById("email").value;
	var ddd = document.getElementById("ddd").value;
	var fone = document.getElementById("fone").value;
	var mensagem = document.getElementById("mensagem").value;
	var news = checkone("news");
	
	if(nome == "" || email == "" || ddd == "" || fone == "" || mensagem == ""){
		alert("Favor preencher os campos obrigatórios.");
	}else{
		if (document.getElementById("email").value.match(/(\w+)@(.+)\.(\w+)$/) == null){
			alert('E-mail incorreto');
			document.getElementById("email").focus();
		}else{
			var serverPage = "f_env_fale.php?nome="+ nome +"&email="+ email +"&ddd="+ ddd +"&fone="+ fone +"&msg="+ mensagem +"&news="+ news;
			var obj = document.getElementById("load");
			obj.innerHTML = "<img src='images/loading.gif' border='0' width='18'/>";
			xmlhttp.open("GET", serverPage);
			xmlhttp.onreadystatechange = function(){
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
					obj.innerHTML = "";
					alert(nome+', obrigado pelo seu contato.');
				}
			}
			xmlhttp.send(null);
		}
	}
}
//Envia e-mail Trabalhe Conosco
function f_env_trabalheConosco(){
	var passed = false;
	var nome = document.getElementById("nome").value;
	var email = document.getElementById("email").value;
	var ddd = document.getElementById("ddd").value;
	var fone = document.getElementById("fone").value;
	var areaAtuacao = document.getElementById("areaAtuacao").value;
	var mensagem = document.getElementById("mensagem").value;
	var news = checkone("news");
	
	if(nome == "" || email == "" || ddd == "" || fone == "" || mensagem == ""){
		alert("Favor preencher os campos obrigatórios.");
		/*
	}else{
		if (document.getElementById("email").value.match(/(\w+)@(.+)\.(\w+)$/) == null){
			alert('E-mail incorreto');
			document.getElementById("email").focus();
		}else{
			var serverPage = "f_env_trabalheConosco.php?nome="+ nome +"&email="+ email +"&ddd="+ ddd +"&fone="+ fone +"&areaAtuacao="+ areaAtuacao +"&msg="+ mensagem +"&news="+ news;
			var obj = document.getElementById("load");
			obj.innerHTML = "<img src='images/loading.gif' border='0' width='18'/>";
			xmlhttp.open("GET", serverPage);
			xmlhttp.onreadystatechange = function(){
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
					obj.innerHTML = "";
					alert(nome+', obrigado pelo seu contato.');
				}
			}
			xmlhttp.send(null);
		}*/
	}else{
		if (document.getElementById("email").value.match(/(\w+)@(.+)\.(\w+)$/) == null){
			alert('E-mail incorreto');
			document.getElementById("email").focus();
		}else{
			passed = true;
		}
	}
	return passed;
}
//Envia e-mail Pre-cadastro
function f_env_preCadastro(){
	var nome = document.getElementById("nome").value;
	var datanascim = document.getElementById("datanascim").value;
	var sexo = document.getElementById("sexo").value;
	var estadocivil = document.getElementById("estadocivil").value;
	var rg = document.getElementById("rg").value;
	var cpf = document.getElementById("cpf").value;
	var ddd = document.getElementById("ddd").value;
	var fone = document.getElementById("fone").value;
	var dddCel = document.getElementById("dddCel").value;
	var foneCel = document.getElementById("foneCel").value;
	var nomepai = document.getElementById("nomepai").value;
	var nomemae = document.getElementById("nomemae").value;
	var nomerespons = document.getElementById("nomerespons").value;
	var convenio = document.getElementById("convenio").value;
	var numcarteirinhaevalidade = document.getElementById("numcarteirinhaevalidade").value;
	var tipoacomodacao = document.getElementById("tipoacomodacao").value;
	var datacirurgia = document.getElementById("datacirurgia").value;
	var medico = document.getElementById("medico").value;
	var news = checkone("news");
	
	if(nome == "" || datanascim == "" || sexo == "0" || estadocivil == "" || rg == "" || cpf == "" || ddd == "" || fone == "" || dddCel == "" || foneCel == "" || nomepai == "" || nomemae == "" || nomerespons == "" || convenio == "" || numcarteirinhaevalidade == "" || tipoacomodacao == "" || datacirurgia == "" || medico == ""){
		alert("Favor preencher os campos obrigatórios.");
	}else{
		var serverPage = "f_env_preCadastro.php?nome="+ nome +"&datanascim="+ datanascim +"&sexo="+ sexo +"&estadocivil="+ estadocivil +"&rg="+ rg +"&cpf="+ cpf +"&ddd="+ ddd +"&fone="+ fone +"&dddCel="+ dddCel +"&foneCel="+ foneCel +"&nomepai="+ nomepai +"&nomemae="+ nomemae +"&nomerespons="+ nomerespons +"&convenio="+ convenio +"&numcarteirinhaevalidade="+ numcarteirinhaevalidade +"&tipoacomodacao="+ tipoacomodacao +"&datacirurgia="+ datacirurgia +"&medico="+ medico +"&news="+ news;
		var obj = document.getElementById("load");
		obj.innerHTML = "<img src='images/loading.gif' border='0' width='18'/>";
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
				obj.innerHTML = "";
				alert(nome+', obrigado pelo seu contato.');
			}
		}
		xmlhttp.send(null);
	}
}
//Limpa Campos Fale Conosco
function limpa_campos(){
	document.getElementById("nome").value = "";
	document.getElementById("email").value = "";
	document.getElementById("ddd").value = "";
	document.getElementById("fone").value = "";
	document.getElementById("mensagem").value = "";
}
