//FUNÇÕES QUE CONTROLAM O MENU

//menu da esquerda
function mOver01(id){
	document.getElementById('menu'+id).className = 'menu01Over';
}
function mOut01(id){
	document.getElementById('menu'+id).className = 'menu01Out';
}

//demais menus
function mOver(id){
	var menu = document.getElementById('menu'+id);
	var submenu = document.getElementById('submenu'+id);
	menu.className = 'menuOver';
	submenu.style.display = 'block';
}
function mOut(id){
	var menu = document.getElementById('menu'+id);
	var submenu = document.getElementById('submenu'+id);
	menu.className = 'menuOut';
	submenu.style.display = 'none';
}

//submenus
function mOverSub(id){
	document.getElementById(id).className = 'subSelecionado';
}
function mOutSub(id){
	document.getElementById(id).className = 'subNaoSelecionado';
}
//FUNÇÕES QUE CONTROLAM O MENU-----------------------------------


function irPara(pg){
	window.location = raiz+pg;
}

function mudaTelefone(){
	document.getElementById('foneCentral').innerHTML = document.getElementById('selectCentralVendas').value;;
}

//galeria de imagens
function mOverSubImagem(id){
	document.getElementById(id).className = 'linkImagemOver';
}
function mOutSubImagem(id){
	document.getElementById(id).className = 'linkImagemOut';
}

function mostraDuvida(id){
	 document.getElementById('duvida'+id).style.display = document.getElementById('duvida'+id).style.display == '' ? 'none' : '';
}

function mostraClipping(id){
	 document.getElementById('clipping'+id).style.display = document.getElementById('clipping'+id).style.display == '' ? 'none' : '';
}

function irURL(pg){
	window.location = pg;
}

function recomendar(pg){
	$.post(raiz+"/inc/ajax.php?funcao=recomendar",
		{pg: pg},
		function(data) {
			if(data == 1){}
				window.location = '/recomende-aos-amigos';
		}
	)
	
}

function enviarContatoSite(){
	var nome = document.getElementById('cad[nome]').value;
	var telefone = document.getElementById('cad[telefone]').value;
	var email = document.getElementById('cad[email]').value;
	var msg = document.getElementById('cad[msg]').value;
	
	
	if(nome == '' || email == '' || msg == ''){
		alert(unescape("Preencha os campos obrigatórios!"));
	} else {
		$.post(raiz+"/inc/ajax.php?funcao=enviarContatoSite",
			{_nome: nome,
			 _telefone: telefone,
			 _email: email,
			 _msg: msg},
			function(data) {
				if(data == 1){
					alert("E-mail enviado com sucesso!");
					document.getElementById('cad[nome]').value = '';
					document.getElementById('cad[telefone]').value = '';
					document.getElementById('cad[email]').value = '';
					document.getElementById('cad[msg]').value = '';
				}
				else
					alert("Erro ao enviar e-mail!");
			}
		)
	}
}

function tabalheConosco(){
	var nome = document.getElementById('contato[nome]').value;
	var cpf = document.getElementById('contato[cpf]').value;
	var cidade = document.getElementById('contato[cidade]').value;
	var id_estado = document.getElementById('contato[id_estado]').value;
	var email = document.getElementById('contato[email]').value;
	var telefone = document.getElementById('contato[telefone]').value;
	var resumo = document.getElementById('contato[resumo]').value;
	var setor = document.getElementById('contato[setor]').value;
	var id_cidade_pretendida_1 = document.getElementById('contato[id_cidade_pretendida_1]').value;
	var id_cidade_pretendida_2 = document.getElementById('contato[id_cidade_pretendida_2]').value;
	var id_cargo_pretendido_1 = document.getElementById('contato[id_cargo_pretendido_1]').value;
	var id_cargo_pretendido_2 = document.getElementById('contato[id_cargo_pretendido_2]').value;
	var curriculo = document.getElementById('curriculo').value;
	
	if(nome == '' || cpf == '' || cidade == '' || id_estado == '0' || email == '' || telefone == '' || id_cidade_pretendida_1 == '0' || id_cargo_pretendido_1 == '0' || cidade == '' || cidade == '' || resumo == '' || resumo == '' || curriculo == ''){
		alert("Preencha os campos obrigatórios!");
	} else {
		document.getElementById('formContato').submit();
	}
}

function sejaFornecedor(){
	var tipo_aux = document.getElementById('contato[tipo_aux]').value;
	var empresa = document.getElementById('contato[empresa]').value;
	var contato = document.getElementById('contato[contato]').value;
	var endereco = document.getElementById('contato[endereco]').value;
	var cidade = document.getElementById('contato[cidade]').value;
	var id_estado = document.getElementById('contato[id_estado]').value;
	var email = document.getElementById('contato[email]').value;
	var telefone = document.getElementById('contato[telefone]').value;
	var mensagem = document.getElementById('contato[mensagem]').value;
	
	if(tipo_aux == '0' || empresa == '' || contato == '' || endereco == '' || cidade == '' || id_estado == '0' || email == '' || telefone == '' || mensagem == ''){
		alert("Preencha os campos obrigatórios!");
	} else {
		document.getElementById('formContato').submit();
	}
}

function enviaContato(){
	var nome = document.getElementById('contato[nome]').value;
	var endereco = document.getElementById('contato[endereco]').value;
	var cidade = document.getElementById('contato[cidade]').value;
	var id_estado = document.getElementById('contato[id_estado]').value;
	var email = document.getElementById('contato[email]').value;
	var telefone = document.getElementById('contato[telefone]').value;
	var mensagem = document.getElementById('contato[mensagem]').value;
	
	if(nome == '0' || endereco == '' || cidade == '' || id_estado == '0' || email == '' || telefone == '' || mensagem == ''){
		alert("Preencha os campos obrigatórios!");
	} else {
		document.getElementById('formContato').submit();
	}
}

function enviaNamorados(){
	var nome = document.getElementById('contato[nome]').value;
	var endereco = document.getElementById('contato[endereco]').value;
	var cidade = document.getElementById('contato[cidade]').value;
	var id_estado = document.getElementById('contato[id_estado]').value;
	var email = document.getElementById('contato[email]').value;
	var telefone = document.getElementById('contato[telefone]').value;
	var cpf = document.getElementById('contato[cpf]').value;
	
	if(nome == '0' || endereco == '' || cidade == '' || id_estado == '0' || email == '' || telefone == '' || cpf == ''){
		alert("Preencha os campos obrigatórios!");
	} else {
		document.getElementById('formContato').submit();
	}
}

function loginRestrito(){
	var usuario = document.getElementById('cad[usuario]').value;
	var senha = document.getElementById('cad[senha]').value;
	
	if(usuario == '' || senha == ''){
		alert("Preencha os campos obrigatórios!");
	} else {
		$.post(raiz+"/inc/ajax.php?funcao=loginRestrito",
			{usuario: usuario,
			 senha: senha},
			function(data) {
				if(data == 1)
					window.location = '/area-restrita-arquivos';
				else
					alert("Login incorreto");
			}
		)
	}
}

/***** POPUP PARA ASSISTIR VÍDEO *****/
function popupFoto(id, w, h){
	if(!w) w = 500;
	if(!h) h = 500;
	window.open(raiz+'/imagem/'+id, 'imagem', 'width='+w+', height='+h+', scrollbars=no, resizable=no');
}

/***** POPUP PARA ASSISTIR VÍDEO *****/
function popupGaleria(id, w, h){
	if(!w) w = 500;
	if(!h) h = 500;
	window.open(raiz+'/galeria/'+id, 'imagem', 'width='+w+', height='+h+', scrollbars=yes, resizable=auto');
}

/***** POPUP PARA ASSISTIR VÍDEO *****/
function popupClipping(id, w, h){
	if(!w) w = 500;
	if(!h) h = 500;
	window.open(raiz+'/imagem/'+id, 'imagem', 'width='+w+', height='+h+', scrollbars=no, resizable=no');
}

function init(){

	//window.open(raiz+'/news_inicio.jpg', 'imagem', 'width='+595+', height='+525+', scrollbars=no, resizable=no');
}

function mudaDestino(){
	setDestinos();
	document.getElementById('select25')[0].text = "Chegando em...";
}

function mudaBebe(){
	mudouPaxAdultos()
	var total = document.getElementById('select32').length;
	for(i=0; i<total; i++){
		document.getElementById('select32')[i].text = document.getElementById('select32')[i].value;
	}
}

function formReceba(){
	var nome = document.getElementById('prospect[nome]').value;
	var endereco = document.getElementById('prospect[endereco]').value;
	var bairro = document.getElementById('prospect[bairro]').value;
	var cidade = document.getElementById('prospect[cidade]').value;
	var id_estado = document.getElementById('prospect[id_estado]').value;
	var nascimento = document.getElementById('prospect[data_nascimento]').value;
	var cargo = document.getElementById('prospect[cargo]').cargo;
	var email = document.getElementById('prospect[email]').value;
	
	if(nome == '' || endereco == '' || bairro == '' || cidade == '' || id_estado == '0' || email == '' || nascimento == ''){
		alert("Preencha os campos obrigatórios!");
	} else {
		document.getElementById('formCad').submit();
	}
}

function formDescadastrar(){
	var nascimento = document.getElementById('descad[data_nascimento]').value;
	var email = document.getElementById('descad[email]').value;
	
	if(email == '' || nascimento == ''){
		alert("Preencha os campos obrigatórios!");
	} else {
		document.getElementById('formDescadastrar').submit();
	}
}

function enviarParaAmigo(){
	var nome = document.getElementById('cad[nome]').value;
	var email = document.getElementById('cad[email]').value;
	var nome2 = document.getElementById('cad[nome2]').value;
	var email2 = document.getElementById('cad[email2]').value;
	
	if(nome == '' || email == '' || nome2 == '' || email2 == ''){
		alert("Preencha os campos obrigatórios!");
	} else {
		document.getElementById('enviarParaAmigo').submit();
	}
}

function votarEnquete(formulario, div, funcao, bt){
	var metodo = document.getElementById(formulario).method.toUpperCase();
    var action = document.getElementById(formulario).action+"?";
	var camposPreenchidos = 0;
	var tipoInput = '';
	var variaveis = "id="+document.forms[formulario].elements[0].value+"&";
	
	for (var i=0;i<document.getElementById(formulario).length;i++){
		
		 tipoInput = document.forms[formulario].elements[i].type.toUpperCase();
 		 if (tipoInput == "RADIO"){
			if (document.forms[formulario].elements[i].checked == true){
				camposPreenchidos++;
				variaveis += "opcao="+escape(document.forms[formulario].elements[i].value)+"&";
			}			 
		 }
	}
	
	if (camposPreenchidos > 0){
		//document.getElementById(div).innerHTML = '<img src="'+raiz+'/img/diversos/loader.gif"> Aguarde...';
		$.post(raiz+"/action/votar_enquete.php?"+variaveis,
			{},
			function(data) {
				var div = 'divEnquete';
				var titulo_caixa = 'SOL Linhas Aéreas';
				if (data == 1){ // envio com sucesso formulário fale conosco
					document.getElementById('formEnquete').reset();
					alert('Voto registrado com sucesso.');
				} else if (data == 2){ // erro ao enviar mensagem
					alert('Erro ao votar');
				} else if (data == 3){
					alert('Você já votou hoje.');
				}
			}
		)
	} else {
		alert('Escolha uma opção!');
	}
}
