﻿	function Trim(str){return str.replace(/^\s+|\s+$/g,"");}
	
	function eskemaFocos(obj){
		trimed = Trim(obj.value);
		if (trimed == Trim(obj.defaultValue)){
			obj.value = "";
		}
	}
	
	function eskemaBlur(obj){
		trimed = Trim(obj.value);
		if (trimed == ''){
			obj.value = obj.defaultValue;
		}
	}
	
	function checkMail(mail){
		var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
		if(typeof(mail) == "string"){
			if(er.test(mail)){
				return true;
			}
		}else if(typeof(mail) == "object"){
			if(er.test(mail.value)){
				return true;
			}
		}else{
			return false;
		}
	}
	
	$(document).ready(function(){
							   
 		$(".foco").focus(function(){
			eskemaFocos(this);			  
		});
		$(".foco").blur(function(){
			eskemaBlur(this);			  
		});
		
		$('#imprimirPag').click(function() {
			 window.print();							
		});
		
		$('#btnOkHoteis').click(function() {
			var idEstadoHoteis = $('#estado').val();
			if (idEstadoHoteis != 0 && idEstadoHoteis != "") {
				var idCidadeHoteis = $('#cidade').val();	
				ajax_hoteis(idEstadoHoteis,idCidadeHoteis)
			}
		});
		
		$('.principal').each(function() {
			$(this).hover(function(){
				$(this).find('.navigation').fadeIn(200);
				$(this).find('a.ap').addClass('navSelect');
			},function() {
				$(this).find('.navigation').fadeOut(100);
				$(this).find('a.ap').removeClass('navSelect');
			});
		});
		
	});

	
	function validaNewsletter() {	
		if ( !checkMail( $("#email").val() ) ){
			alert('Favor preencher o campo E-mail corretamente!');
			$("#email").focus();
			return false;
		}else{
			return true;
		}
	}
	
	function validaEnventos() {
		if ( $("#nome").val() == ""){
			alert('Favor preencher o campo Nome!');
			$("#nome").focus();
			return false;
		}else if ( !checkMail( $("#email").val() ) ){
			alert('Favor preencher o campo E-mail corretamente!');
			$("#email").focus();
			return false;
		} else if ($("#telefone").val() == ""){
			alert('Favor preencher o campo Telefone!');
			$("#telefone").focus();
			return false;
		} else if ($("#evento").val() == ""){
			alert('Favor fazer uma descrição de seu evento!');
			$("#evento").focus();
			return false;
		}else{
			return true;
		}
	}
	
	function validaContato() {
		var as = $("#assunto").val();
		if ( $("#nome").val() == "" || $("#nome").val() == "Nome..."){
			alert('Favor preencher o campo Nome!');
			$("#nome").focus();
			return false;
		}else if ( !checkMail( $("#email").val() ) ){
			alert('Favor preencher o campo E-mail corretamente!');
			$("#email").focus();
			return false;
		} else if (as == 'Escolha um Assunto'){
			alert('Favor selecionar um assunto!');
			$("#assunto").focus();
			return false;
		} else if ($("#comentario").val() == "" || $("#comentario").val() == "Comentario..."){
			alert('Favor preencher o campo Comentário!');
			$("#comentario").focus();
			return false;
		}else{
			return true;
		}
	}
	
	function ajax_estado(idEstado,idCidade){
		$.post("/adm002/ajax/ajax.php?funcao=ajax_estado1", { idEstado: idEstado, idCidade: idCidade }, function(retorno){
			$("#cid").html(retorno);
		});
	}
	
	function ajax_hoteis(idEstado,idCidade){
		$.post("/adm002/ajax/ajax.php?funcao=ajax_hoteis", { idEstado: idEstado, idCidade: idCidade }, function(retorno){
			$("#hot").html(retorno);
		});
	}
