IncludeJavaScript("scripts/cufon.js"); // Núcleo do Cufón
IncludeJavaScript("scripts/fontes.js"); // Fontes
IncludeJavaScript("scripts/jquery.facebox.js"); // Facebox
IncludeJavaScript("scripts/jquery.lightbox.js"); // Lightbox
IncludeJavaScript("scripts/jquery.cycle.js"); // Cycle
IncludeJavaScript("scripts/jquery.easing.js"); // Easing
IncludeJavaScript("scripts/jquery.ui.js"); // jQuery UI completo
IncludeJavaScript("scripts/jquery.em.js"); //
IncludeJavaScript("scripts/jquery.mousewhell.js"); // Smooth Scroll na tela
IncludeJavaScript("scripts/jquery.scrollto.js"); // Smooth Scroll na tela
IncludeJavaScript("scripts/jScrollPane.js"); // Smooth Scroll na tela
IncludeJavaScript("scripts/jquery.maskedinput.js"); // Máscaras para formulários 
IncludeJavaScript("scripts/jquery.menu.js"); // Flip Menu
//IncludeJavaScript("scripts/jquery.multifile.js"); // jquery.multifile
//IncludeJavaScript("scripts/jquery.form.js"); // form

$(window).load(function(){

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

	// Botoes
	$("input[type=submit]").css("cursor","pointer");
	$("input[type=button]").css("cursor","pointer");

	// Voltar
	$(".bt-voltar").click(function(){ history.back(); return false; });
	
	// Topo
	$(".bt-topo").click(function() {
		$.scrollTo( { top:0,left:0 } , 1000 );
		return false;
	});
	
	$(".facebox-home").click();
	
	// Transparencia
	$(".opac").css("opacity","0.5");
	
	//Link-opacidade
	$(".bt").css("opacity", 1.0);
    $(".bt").hover(function() {
        $(this).fadeTo("fast", 0.7);
    },function() {
        $(this).fadeTo("fast", 1.0);
    });
	
	//Link-opacidade 2
	$(".bt2").css("opacity", 0.6);
    $(".bt2").hover(function() {
        $(this).fadeTo("fast", 1.0);
    },function() {
        $(this).fadeTo("slow", 0.6);
    });

	// Reservas Online
	$('.bt-submit2').click(function(){
		$('.bt-submit2').hide();
		$('.abre-form').slideToggle('slow');
		return false;
	});
	
	//Troca de imagens na home
	$(".troca-image").cycle(function(){
		timeout: 8000;
		return false;
	});
	
	// Estiliza listas
	$(".lista li:even").addClass("even");
	$(".lista li:odd").addClass("odd");
	$(".lista li:first-child").addClass("first");
	$(".lista li:last-child").addClass("last");
	$(".paginacao a:last-child").addClass("last");
	
	// Função pra tirar o value do input e botar devolta
	var input = document.getElementsByTagName("input");
	for (var a=input.length-1; a >= 0; a--) {
		if (input[a].type != "text") { continue; }
		input[a].mask = input[a].value;
		input[a].onfocus = function() {
			if (this.value == this.mask) { this.value = ""; }
		};
		input[a].onblur = function() {
			if (this.value == "") { this.value = this.mask; }
		};
	}
	
	// Botões de checkin e checkout
	$('.icon-calendario').click(function(){
		var pegaHref = $(this).attr('href');
		var pegaPosicao = $(this).offset();
		
		$('.div-calendario').hide('slow');
		$(pegaHref).css('left', pegaPosicao.left).css('top', pegaPosicao.top).show('slow');
		
		return false;
	});
	
	$('#calendario_checkin tr td a').click(function(){
		var pegaDiaMesAno = $(this).attr('href');
		var separaCoisas = pegaDiaMesAno.split("&");
		var dia = separaCoisas[1].split("=");
		var mes = separaCoisas[2].split("=");
		var ano = separaCoisas[3].split("=");
		dataCompleta = dia[1] + '/' + mes[1] + '/' + ano[1];
		$('#res_checkin').val(dataCompleta).focus();
		$('.div-calendario').hide('slow');
		return false;
	});

	$('#calendario_checkout tr td a').click(function(){
		var pegaDiaMesAno = $(this).attr('href');
		var separaCoisas = pegaDiaMesAno.split("&");
		var dia = separaCoisas[1].split("=");
		var mes = separaCoisas[2].split("=");
		var ano = separaCoisas[3].split("=");
		dataCompleta = dia[1] + '/' + mes[1] + '/' + ano[1];
		$('#res_checkout').val(dataCompleta).focus();
		$('.div-calendario').hide('slow');
		return false;
	});

	// Cycle galeria
	$("#box-holder ul").cycle({
		fx: "scrollHorz",
		easeIn: "easeInOutBack",
		easeOut: "easeInOutBack",
		prev: ".bt-prev",
		next: ".bt-next",
		timeout: 0
	});
	
	// Reservas Online
	$('#bt-submit2').click(function(){
		$('.bt-submit2').hide();
		$('.abre-form').slideToggle('slow');
		return false;
	});

	// Reservas Online
	$('#bt-comentar').click(function(){
		$(this).hide();
		$('#form-comentarios').slideToggle('slow');
		return false;
	});
	
	$('.bt-quero-reserva').click(function(){
		$('.abre-form').slideToggle('slow');
		return false;
	});
	
	// Mascaras formularios
	if (typeof $.fn.mask != "undefined") {
		$(".masc_telefone").mask("(99) 9999-9999");
		$(".masc_cpf").mask("999.999.999-99");
		$(".masc_data").mask("99/99/9999");
		$(".masc_hora").mask("99:99");
		$(".masc_cep").mask("99999-999");
	}

	// Cufon
	//Cufon.replace('.dax', { fontFamily: 'Dax', hover: true });
});


/**
  * Função monta caixa de seleção
  * @param div DIV
  * @param id Identificador
  * @return nada
  **/
function montaCaixa(div, id) {
	$.ajax({
		type: "POST",
		url: "lib/acao-monta-caixa.php",
		data: "div=" + div + "&id=" + id ,
		success: function(txt) {
			$("#" + div).html(txt);
		}
	});
}



/**
  * Função limpa espaço
  * @param str String
  * @return nada
  **/
function getTrim(str) {
	if(typeof(str) !== "undefined"){
		return str.replace(/^\s+|\s+$/g, "");
	}else{
		return "";
	}
}

/**
  * Formata número
  * @param $campo int id
  * @param $event Evento
  * @return String
  **/
function formataNumero(campo, e) {
	t = typeof window.event != "undefined" ? window.event.keyCode : e.which;
	if((isNaN(String.fromCharCode(t)) || (t == 32)) && (t != 8 && t != 0)) {
		return false;
	}
}

/**
  * Função que valida a data
  * @param String $value data
  * @return boolean
  **/
function validaData(campo) {
    var valor = campo.split("/");
    if(valor[0] != "" && valor[1] != "" && valor[2] != "") {
        data = new Date(valor[2], valor[1]-1, valor[0], 5, 0, 0, 0);
        if (valor[2] != data.getFullYear() || valor[1] !=  data.getMonth()+1 || valor[0] != data.getDate() || valor[2] < 1902 || valor[2] > 2037) {
            return false;
        }
    }
    return true;
}

/**
  * Função Validar Formulário
  * @param form Identificador do form
  * @return Boolean
  **/
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");
		switch (relObj) {
			case "email":
				expressao = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
				if (!expressao.test(document.getElementById(form).elements[i].value)) {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].value = "";
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			case "required":
				if ((document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")) {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			case "cpf":
				if ((!validaCpf(document.getElementById(form).elements[i].value)) || (document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")) {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].value = "";
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			case "data":
				if ((!validaData(document.getElementById(form).elements[i].value)) || (document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")) {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].value = "";
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			case "radio":
			case "checkbox":
				if(getCheckedValue(document.getElementsByName(nomeObj))) {
				} else {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			default:
			break;
		}
    }
    return true;
}

/**
  * Função validar contato
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function validarContato(form) {
	if (validaForm(form)) {		
		var str = $("#" + form).serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-contato.php",
			data: str,
			beforeSend: function(){
				$(".bt-submit").attr("disabled", "disabled");
			},
			success: function(txt) {
				$(".bt-submit").attr("disabled", false);
				arr = txt.split("<!-- SEPARADOR -->");
				if (getTrim(arr[0]) == "0") {
					alert(arr[1]);
				} else if (getTrim(arr[0]) == "1") {
					alert(arr[1]);
					document.getElementById(form).reset();
				} else {
					alert(arr[1]);
				}
			}
		});
	}
}

/**
  * Função validar comentario
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function validarComentario(form) {
	if (validaForm(form)) {		
		var str = $("#" + form).serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-comentario.php",
			data: str,
			success: function(txt) {
				arr = txt.split("<!-- SEPARADOR -->");
				if (getTrim(arr[0]) == "0") {
					alert(arr[1]);
				} else if (getTrim(arr[0]) == "1") {
					alert(arr[1]);
					document.getElementById(form).reset();
					$('#form-comentarios').slideToggle('slow');
					$('#bt-comentar').show();
				} else {
					alert(arr[1]);
				}
			}
		});
	}
}


/**
  * Função validar newsletter
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function validarNewsletter(form) {
	if (validaForm(form)) {		
		var str = $("#" + form).serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-newsletter.php",
			data: str,
			success: function(txt) {
				arr = txt.split("<!-- SEPARADOR -->");
				if (getTrim(arr[0]) == "0") {
					alert(arr[1]);
				} else if (getTrim(arr[0]) == "1") {
					alert(arr[1]);
					document.getElementById(form).reset();
				} else {
					alert(arr[1]);
				}
			}
		});
	}
}

function validaReserva(form) {
	if (validaForm(form)){
		// Dados dos campos de data
		var dataCompletaCheckin = $("#res_checkin").val();
		var dataCompletaCheckout = $("#res_checkout").val();

		// Separa os campos de data em chaves num array
		var separaDiaMesAnoCheckin = dataCompletaCheckin.split("/");
		var separaDiaMesAnoCheckout = dataCompletaCheckout.split("/");

		// CHECKIN
		$("#dia").val(separaDiaMesAnoCheckin[0]);
		$("#mes").val(separaDiaMesAnoCheckin[1]);
		$("#ano").val(separaDiaMesAnoCheckin[2]);

		// CHECKOUT
		$("#dia_saida").val(separaDiaMesAnoCheckout[0]);
		$("#mes_saida").val(separaDiaMesAnoCheckout[1]);
		$("#ano_saida").val(separaDiaMesAnoCheckout[2]);

		var str = $("#" + form).serialize();

		$("#link-" + form).attr("href", "req/iframe-reserva.php?" + str);

		$("#link-" + form).click();
	}
}

function atualizaCalendario(mes, ano, id, cmd) {
		$.ajax({
			type: "POST",
			url: "lib/acao-atualiza-calendario.php",
			data: "getMes=" + mes + "&getAno=" + ano + "&id=" + id + "&cmd=" + cmd,
			success: function(txt) {
				$("#" + id).html(txt);
			}
		});
}



/**
  * Função validar envie sua foto
  * @param form Identificador do form
  * @return mensagem de erro
  **/
/*
function  validarCurriculo(form) {
	if (validaForm(form)) {		
		var str = $("#" + form).serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-curriculo.php",
			data: str,
			beforeSend: function(){
				$(".bt-submit").attr("disabled", "disabled");
			},
			success: function(txt) {
				$(".bt-submit").attr("disabled", false);
				arr = txt.split("<!-- SEPARADOR -->");
				if (getTrim(txt) == "0") {
					alert("Não foi possível enviar a mensagem, tente novamente." + txt);					
				} else if (getTrim(txt) == "1") {
                    alert("Mensagem enviada com sucesso.");
                    document.getElementById(form).reset();
                } else {
                    alert("Não foi possível enviar a mensagem, tente novamente.");
                }

			}
		});
	}
}
*/

/**
  * Função validar envie sua foto
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function  validarCurriculo(form) {
	if (validaForm(form)) {		
		$(document).ready(function() {
            $("#" + form).ajaxForm(function(txt) {
				//alert(txt);
				if (getTrim(txt) == "0") {
					alert("Não foi possível enviar a mensagem, tente novamente." + txt);					
				} else if (getTrim(txt) == "1") {
                    alert("Mensagem enviada com sucesso.");
                    document.getElementById(form).reset();
                } else {
                    alert("Não foi possível enviar a mensagem, tente novamente.");
                }
            });
        });
	}
}




