$(document).ready(function(){

	// Acessibilidade
	$('#bt-voltar, #bt-contato').css("cursor", "pointer");
	$('#bt-voltar').click(function(){
		history.go(-1);
	});

	$('#pop-isis').click(function(){
		window.open('http://www.isisbrasil.com.br/hotsite/hotsite.html', '', 'width=668, height=516');
	});

	// Flash
	$('#logo').flash({
	    src: 'swf/logotipo.swf',
	    width: '100%',
	    height: 105,
		wmode: 'transparent',
		expressInstall: true
	});
	$('#flash').flash({
	    src: 'swf/header.swf',
	    width: '100%',
	    height: 400,
		wmode: 'transparent',
		expressInstall: true
	});
	$('#flash-en').flash({
	    src: 'swf/header-en.swf',
	    width: '100%',
	    height: 400,
		wmode: 'transparent',
		expressInstall: true
	});
	$('#mapa-mundi').flash({
	    src: 'swf/mapa-mundi.swf',
	    width: 700,
	    height: 296,
		wmode: 'transparent',
		expressInstall: true
	});

	//Slide UP/DOWN DIV's
	/*$("#eventos .box-title a").click(function(){
		$(".box-conteudo").slideUp("fast");
		$("#"+$(this).attr('rel')).slideDown("fast");
		$(".box-title a").removeClass('setaUp').addClass("setaDown");
		$(this).removeClass('setaDown').addClass("setaUp");
	});
	$("#eventos .box-title, .proximo").click(function(){
		$(".box-conteudo").slideUp("fast");
		$("#"+$(this).attr('rel')).slideDown("fast");
		$(".box-title a").removeClass('setaUp').addClass("setaDown");
		$("#"+$(this).attr('id')+" a").removeClass('setaDown').addClass("setaUp");
	});
	
	$("#faq .pergunta a").click(function(){
		$(".resposta").slideUp("fast");
		$("#"+$(this).attr('rel')).slideDown("fast");
		$(".pergunta a").removeClass('setaDown').addClass("setaUp");
		$(this).removeClass('setaUp').addClass("setaDown");
	});
	$("#faq .pergunta, .proximo").click(function(){
		$(".resposta").slideUp("fast");
		$("#"+$(this).attr('rel')).slideDown("fast");
		$(".pergunta a").removeClass('setaDown').addClass("setaUp");
		$("#"+$(this).attr('id')+" a").removeClass('setaUp').addClass("setaDown");
	});

	*/
	
	//Links externos
	$("a[rel=externo]").attr('target','_blank');

	// Ativa janelas modal
	$(".dialog-box").dialog({
		autoOpen: false,
	    modal: true,
		resizable: false,
		width: 600,
		height: 450,
	    overlay: {
	        opacity: 0.5,
	        background: "black"
	    }
	});

	// Botoes janelas modal
	$(".dialog-bt").click(function(){		
		var v = $(this).find('span:first').attr('rel');
		$(".id-pub").attr('value',v);		
		var rel = $(this).attr('rel');
		$(rel).dialog("open");
		$(".ui-dialog-overlay").click(function(){
			$(rel).dialog("close");
		});
	});

	// Acessibilidade
	$('#bt-voltar').css("cursor", "pointer");
	$('#bt-voltar').click(function(){
		history.go(-1);
	});
	
	// Mascaras
	$("#data, #hotel_data_chegada, #hotel_data_saida, #passagem_data_chegada, #passagem_data_saida, #dataIda, #dataVolta").mask('99/99/9999');
	$("#traslado_pessoas, #qtd, #passagem_adultos, #passagem_criancas, #traslado_pessoas, #passeios_pessoas").mask('99');
	$("#tel").mask("(99) 9999-9999")

	// EVENTOS
	$('.upAndDown').click(function(){
		
		if($(this).hasClass('abas-active')){
			$('.upAndDown').removeClass('abas-active');
			$('#'+$(this).find('a').attr('href')).slideUp(250);
		}else{
			$('.upAndDown').removeClass('abas-active');
			$(this).addClass('abas-active');
			$('.box-conteudo').slideUp(250);
			$('#'+$(this).find('a').attr('href')).slideDown(500);
		}
		return false;
		
	});
	
	// EVENTOS
	$('.proximo').click(function(){
		$($(this)+':parent').removeClass('abas-active');
		$('.box-conteudo').slideUp(250);
		$('#'+$(this).attr('href')).slideDown(500);
		return false;
	});
	
	// FAQ
	$('.pergunta').click(function(){
	
		if($(this).hasClass('pergunta-active')){
			$('.pergunta').removeClass('pergunta-active');
			$('#'+$(this).attr('href')).slideUp(250);
		}else{
			$('.pergunta').removeClass('pergunta-active');
			$(this).addClass('pergunta-active');
			$('.resposta').slideUp(250);
			$('#'+$(this).attr('href')).slideDown(500);
		}
		return false;
		
	});

	
});

/**
  * Função validar formulario
  * @param 
  * @return nada
  **/
function validaForm(form) {
    for (var i = 0; i < document.getElementById(form).elements.length; i++) {        
        var nomeObj = document.getElementById(form).elements[i].name;
        var idObj 	= document.getElementById(form).elements[i].id;
		var relObj 	= document.getElementById(form).elements[i].getAttribute('rel');				
		if ((relObj == "email")) {
			expressao = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
			if (!expressao.test(document.getElementById(form).elements[i].value)){
				$.getErro(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].value = "";
				document.getElementById(form).elements[i].className = document.getElementById(form).elements[i].className + " campo-requerido";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		} else if (relObj == "required") {
			if((document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "") || (document.getElementById(form).elements[i].value == "Digite aqui sua busca")){
				$.getErro(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].className = document.getElementById(form).elements[i].className + " campo-requerido";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}
    }
    return true;
}

/**
  * Função validar como presentear
  * @param 
  * @return nada
  **/
function validarComoPresentear() {
	if (validaForm("formComoPresentear")) {	
		var str = $("#formComoPresentear").serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao_como_presentear.php",
			data: str,
			beforeSend: function() {
			},
			success: function(txt) {
				$.getSucesso("Mensagem enviada com sucesso! Obrigado!");
				document.getElementById("formComoPresentear").reset();
			},
			error: function(txt) {
				$.getSucesso("Erro: " + txt);
			}
		});
	}
}

/**
  * Função validar envie anuncio
  * @param 
  * @return nada
  **/
function validarEnvieAnuncio() {
	if (validaForm("formClassificados")) {	
		var str = $("#formClassificados").serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao_envie_anuncio.php",
			data: str,
			beforeSend: function() {
			},
			success: function(txt) {
				$.getSucesso("Mensagem enviada com sucesso! Obrigado!");
				document.getElementById("formClassificados").reset();
			},
			error: function(txt) {
				$.getSucesso("Erro: " + txt);
			}
		});
	}
}

/**
  * Função validar contato
  * @param idioma Idioma
  * @return nada
  **/
function validarContato(idioma) {
	if (validaForm("formContato")) {	
		var str = $("#formContato").serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao_contato.php",
			data: str,
			beforeSend: function() {
			},
			success: function(txt) {
				if (idioma == "2") {
					$.getSucesso("Message sent successfully! Thank you!");
				} else {
					$.getSucesso("Mensagem enviada com sucesso! Obrigado!");
				}
				document.getElementById("formContato").reset();
			},
			error: function(txt) {
				$.getSucesso("Erro: " + txt);
			}
		});
	}
}

/**
  * Função validar solicitacao de pacote
  * @param idioma Idioma
  * @return nada
  **/
function validarSolicitacaoPacote(idioma) {
	if (validaForm("formPacotes")) {	
		var str = $("#formPacotes").serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao_solicitacao_pacote.php",
			data: str,
			beforeSend: function() {
			},
			success: function(txt) {
				if (idioma == "2") {
					$.getSucesso("Message sent successfully! Thank you!");
				} else {
					$.getSucesso("Mensagem enviada com sucesso! Obrigado!");
				}
				document.getElementById("formPacotes").reset();
			},
			error: function(txt) {
				$.getSucesso("Erro: " + txt);
			}
		});
	}
}

/**
  * Função validar solicitacao de destinos
  * @param 
  * @return nada
  **/
function validarSolicitacaoDestino() {
	if (validaForm("formDestinos")) {	
		var str = $("#formDestinos").serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao_solicitacao_destino.php",
			data: str,
			beforeSend: function() {
			},
			success: function(txt) {
				$.getSucesso("Mensagem enviada com sucesso! Obrigado!");
				document.getElementById("formDestinos").reset();
			},
			error: function(txt) {
				$.getSucesso("Erro: " + txt);
			}
		});
	}
}

/**
  * Função trocar foto
  * @param caminho
  * @param legenda 
  * @return nada
  **/
function trocarFoto(caminho, legenda) {
	document.getElementById("div_imagem").src = caminho;
	document.getElementById("div_imagem").alt = legenda;
	document.getElementById("div_imagem_legenda").innerHTML = legenda;
}

/**
  * Função validar plan your trip
  * @param 
  * @return nada
  **/
function validarPlanYourTrip() {
	if (validaForm("formPlan")) {	
		var str = $("#formPlan").serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao_plan_your_trip.php",
			data: str,
			beforeSend: function() {
			},
			success: function(txt) {
				$.getSucesso("Message sent successfully! Thank you!");
				document.getElementById("formPlan").reset();
			},
			error: function(txt) {
				$.getSucesso("Erro: " + txt);
			}
		});
	}
}

/**
  * Função validar newsletter
  * @param idioma
  * @return nada
  **/
function validarNews(idioma) {
	if (validaForm("formNews")) {	
		var str = $("#formNews").serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao_news.php",
			data: str,
			beforeSend: function() {
			},
			success: function(txt) {
				if (idioma == "2") {
					$.getSucesso("Message sent successfully! Thank you!");
				} else {
					$.getSucesso("Mensagem enviada com sucesso! Obrigado!");
				}
				document.getElementById("formNews").reset();
			},
			error: function(txt) {
				$.getSucesso("Erro: " + txt);
			}
		});
	}
}

/**
  * Função mostrar hoteis
  * @param id
  * @return nada
  **/
function mostraHotel(id) {
	$.ajax({
		type: "POST",
		url: "lib/acao_hotel.php",
		data: "id=" + id,
		beforeSend: function() {
		},
		success: function(txt) {
			$("#div-sobre-hotel").html(txt);
		},
		error: function(txt) {
			$.getSucesso("Erro: " + txt);
		}
	});
}

/**
  * Função mostrar passeio
  * @param id
  * @return nada
  **/
function mostraPasseio(id) {
	$.ajax({
		type: "POST",
		url: "lib/acao_passeio.php",
		data: "id=" + id,
		beforeSend: function() {
		},
		success: function(txt) {
			$("#div-sobre-passeio").html(txt);
		},
		error: function(txt) {
			$.getSucesso("Erro: " + txt);
		}
	});
}

/**
  * Função mostrar transfer
  * @param id
  * @return nada
  **/
function mostraTransfer(hotel) {
	//alert(hotel);
	$.ajax({
		type: "POST",
		url: "lib/acao_transfer.php",
		data: "hotel=" + hotel,
		beforeSend: function() {
		},
		success: function(txt) {
			$("#div-transfer").html(txt);
		},
		error: function(txt) {
			$.getSucesso("Erro: " + txt);
		}
	});
}

/**
  * Função validar solicitacao evento
  * @param idioma
  * @return nada
  **/
function validarSolicitacaoEvento() {	
	var flag = false;
	for (i = 0; i < document.getElementsByName("hotel_reserva").length; i++) {		
		if (document.getElementsByName("hotel_reserva")[i].checked == true) {
			flag = true;
		}
	}
	if (validaForm("formEventos")) {		
		if (!flag){	
			$.getErro("Selecione um hotel");
		} else {		
			var str = $("#formEventos").serialize();
			$.ajax({
				type: "POST",
				url: "lib/acao_eventos.php",
				data: str,
				beforeSend: function() {
				},
				success: function(txt) {				
					$.getSucesso("Mensagem enviada com sucesso! Obrigado!");				
					document.getElementById("formEventos").reset();
				},
				error: function(txt) {
					$.getSucesso("Erro: " + txt);
				}
			});
		}
	}
}
