﻿/*----------------------------------------------------------------------------------------------------------------------------------
Todas as funções que forem funcionar APÓS o carregamento do DOM, inserir DENTRO desta declaração  ' $(document).ready(function(){) '  
----------------------------------------------------------------------------------------------------------------------------------*/
$(document).ready(function () {

/*-------------------------------------------------
  	Funcionalidade de abas
  	---------------------------------------------------*/
	$(".Tabs ul.Header").tabs(".Tabs div.Container > div");
 	
  	/*-------------------------------------------------
  	Funcionalidade para "Geração" de titulos dinâmicos
  	---------------------------------------------------*/
	jQuery("p.Titulo").text(jQuery("a.Ativo:first span, a.Ativo:first",jQuery(".Superior,.Publico")).eq(0).text());
	
	/*------------------------------------------------
	  Remove o título da área de atendimentos
	-------------------------------------------------*/
	if($('.Centro h1').html() != null)
	{
		if(($('.Centro h1').html().trim() == 'Atendimento')||($('.Centro h1').html().indexOf('Destinos') > -1))
    		$('.Centro h1').hide();
    }
 	
	/*-------------------------------------------------
	Funcionalidade da seleção de idiomas
	---------------------------------------------------*/  
    var ulPaises = $('div.Paises ul');var divPaises = $('div.Paises');var liItem = $('div.Paises ul li');ulPaises.hide();divPaises.hover(function(){ulPaises.show();},function(){ulPaises.hide();});
    
    /* DropDown de Países */
	$('.Paises').hover(function(){
		$('.Header .Content .Destaque a').attr('enabled', 'false');
	});


	$('.Paises').mouseleave(function(){
		$('.Header .Content .Destaque a').attr('enabled', 'true');
	});

	/*---------------------------------------------------
	Manipulador de Ultimos itens de listas e tabelas
	---------------------------------------------------*/
	$(".Destinos-Abas-Internas table tr td:last-child").css("background", "none");
	$(".Box > .Content > .GridView > tbody > tr > td:last-child").css("border-right", "none");
	$(".Box > .Content > .GridView > tbody > tr:last-child > td").css("border-bottom", "none");
	$(".Festa > .Separador:last-child").css("display", "none");
	$('.GridView td:last').children(".Separador").remove();
	       	
	/*------------------------------------------------------------
	Compartilhe Facebook
	------------------------------------------------------------*/
	var URL_SITE = "http://www.facebook.com/GOLLinhasAereasInteligentes";
	jQuery("<iframe/>", {
		allowtransparency: "True",
		src: "http://www.facebook.com/plugins/like.php?href="+URL_SITE+"&send=false&layout=button_count&width=100&show_faces=true&action=like&colorscheme=light&font&height=21",
        overflow: "hidden",
        style: "border: none; max-width:105px; height:22px; background: transparent none",
        frameborder: "0",
        scrolling: "no"        
    }).prependTo(jQuery(".Ferramentas > ul li.Facebook"));  
    /*------------------------------------------------------------
	Navegação de Serviços - COMENTADO PARA SMILES E GOLLOG
	------------------------------------------------------------*/	
    //Esconde o menu e o titulo da sub-home de serviços
    /*if(window.location.pathname.toLowerCase().indexOf("servicos/paginas/default.aspx" || "servicos/pages/default.aspx" )>-1 )
    {
        $(".Main h1").hide();
        $(".Secundario").hide();        
    }
    //Atribui um blank em um item de MossMenu: Seguros
    if(window.location.pathname.toLowerCase().indexOf("servicos")>-1 )
    {
        $('.Nav .Secundario a:last').attr('target','_blank')      
    }*/
    /*------------------------------------------------------------
	Imprensa
	------------------------------------------------------------*/	
	$('.Nav .Publico a[title="Imprensa"]').attr('target','_blank')
	/*------------------------------------------------------------
	Destinos
	------------------------------------------------------------*/
	//Quando não conter imagem, retirar a estrutura de cantos arredondados
	$('.Destinos .Imagem').each(function()
	{ 
	    if ($(this).find('img').size() == 0)
	    {
	        $(this).remove();
	    }
	});
	/*------------------------------------------------------------
	Paises
	------------------------------------------------------------*/
	$('.Paises ').mouseenter(function() {
		$('.Paises .Lista').show();
	});
	$('.Paises ').mouseleave(function() {
		$('.Paises .Lista').hide();
	});
	/*------------------------------------------------------------
	Função para Link de Resumo em outros idiomas
	------------------------------------------------------------*/
    var PtBR = window.location.pathname.toLowerCase().toString().indexOf("/pt-br/");
    var EsAr = window.location.pathname.toLowerCase().toString().indexOf("/es-ar/");
    var EsBo = window.location.pathname.toLowerCase().toString().indexOf("/es-bo/");
    var EsCl = window.location.pathname.toLowerCase().toString().indexOf("/es-cl/");
    var EsCo = window.location.pathname.toLowerCase().toString().indexOf("/es-co/");
    var EsPy = window.location.pathname.toLowerCase().toString().indexOf("/es-py/");
    var EsPe = window.location.pathname.toLowerCase().toString().indexOf("/es-pe/");
    var EsDo = window.location.pathname.toLowerCase().toString().indexOf("/es-do/");
    var EsUy = window.location.pathname.toLowerCase().toString().indexOf("/es-uy/");
    var EsVe = window.location.pathname.toLowerCase().toString().indexOf("/es-ve/");
    var EnUS = window.location.pathname.toLowerCase().toString().indexOf("/en-us/");
    if (PtBR > -1 || window.location.pathname.toLowerCase().toString().indexOf("/gollog/") > -1) { var CurrentLaguage = "/pt-br"; }
    else if (EsAr > -1) { var CurrentLaguage = "/es-ar"; }
    else if (EsBo > -1) { var CurrentLaguage = "/es-bo"; }
    else if (EsCl > -1) { var CurrentLaguage = "/es-cl"; }
    else if (EsCo > -1) { var CurrentLaguage = "/es-co"; }
    else if (EsPy > -1) { var CurrentLaguage = "/es-py"; }
    else if (EsPe > -1) { var CurrentLaguage = "/es-pe"; }
    else if (EsDo > -1) { var CurrentLaguage = "/es-do"; }
    else if (EsUy > -1) { var CurrentLaguage = "/es-uy"; }
    else if (EsVe > -1) { var CurrentLaguage = "/es-ve"; }
    else if (EnUS > -1) { var CurrentLaguage = "/en-us"; }
        
    if (PtBR > -1 || window.location.pathname.toLowerCase().toString().indexOf("/gollog/") > -1) {
        $('.Lang .es-es').remove();
        $('.Lang .en-us').remove();
        //Mudança nos links do Rodapé
        $('.Footer .Change a').each(function () {
            var hrefinicial = $(this).attr('href');
            var Novohref = CurrentLaguage + hrefinicial;
            $(this).attr({ 'href': Novohref });
        });
        $('.Footer .ChangeSmiles a').each(function () {
            var hrefinicial = $(this).attr('href');
            var Novohref = "/smiles" + CurrentLaguage + hrefinicial;
            $(this).attr({ 'href': Novohref });
        });
        	var urlatual = window.location.pathname.indexOf('sao-paulo-congonhas.aspx');
		if(urlatual == '24'){
		        $('h1.Titulo').replaceWith('<h1 class="Titulo">SÃO PAULO - SP</h1>');
		}
			var urlatual = window.location.pathname.indexOf('sao-paulo-guarulhos.aspx');
		if(urlatual == '24'){
		        $('h1.Titulo').replaceWith('<h1 class="Titulo">SÃO PAULO - SP</h1>');
		}
		$('.Lang .pt-br').css({ 'display': 'block' });
    }
    if (EsAr > -1 || EsBo > -1 || EsCl > -1 || EsCo > -1 || EsPy > -1 || EsPe > -1 || EsDo > -1 || EsUy > -1 || EsVe > -1) {
        $('.Lang .pt-br').remove();
        $('.Lang .en-us').remove();
        //Mudança nos links do Rodapé
        $('.Footer .Change a').each(function () {
            var hrefinicial = $(this).attr('href');
            var Novohref = CurrentLaguage + hrefinicial;
            $(this).attr({ 'href': Novohref });
        });
        $('.Footer .ChangeSmiles a').each(function () {
            var hrefinicial = $(this).attr('href');
            var Novohref = "/smiles/es-ar" + hrefinicial;
            $(this).attr({ 'href': Novohref });
        });
       		var urlatual = window.location.pathname.indexOf('sao-paulo-congonhas.aspx');
		if(urlatual == '24'){
		        $('h1.Titulo').replaceWith('<h1 class="Titulo">SAN PABLO - SP</h1>');
		}
			var urlatual = window.location.pathname.indexOf('sao-paulo-guarulhos.aspx');
		if(urlatual == '24'){
		        $('h1.Titulo').replaceWith('<h1 class="Titulo">SAN PABLO - SP</h1>');
		}
		if(EsBo > -1 || EsCl > -1 || EsCo > -1 || EsPy > -1 || EsPe > -1 || EsDo > -1 || EsUy > -1 || EsVe > -1){
			$('.Nav .Superior ul li.Promocoes').remove(); 
		}
		$('.Lang .es-es').css({ 'display': 'block' });
    }
    if (EnUS > -1) {
        $('.Lang .pt-br').remove();
        $('.Lang .es-es').remove();
        //Mudança nos links do Rodapé
        $('.Footer .Change a').each(function () {
            var hrefinicial = $(this).attr('href');
            var Novohref = CurrentLaguage + hrefinicial;
            $(this).attr({ 'href': Novohref });
        });
        $('.Footer .ChangeSmiles a').each(function () {
            var hrefinicial = $(this).attr('href');
            var Novohref = "/smiles" + CurrentLaguage + hrefinicial;
            $(this).attr({ 'href': Novohref });
        });
        	var urlatual = window.location.pathname.indexOf('sao-paulo-congonhas.aspx');
		if(urlatual == '24'){
		        $('h1.Titulo').replaceWith('<h1 class="Titulo">SÃO PAULO - SP</h1>');
		}
			var urlatual = window.location.pathname.indexOf('sao-paulo-guarulhos.aspx');
		if(urlatual == '24'){
		        $('h1.Titulo').replaceWith('<h1 class="Titulo">SÃO PAULO - SP</h1>');
		}
        $('.Lang .en-us').css({ 'display': 'block' });
    }
    $("[placeholder]").focus(function() {
	  var input = $(this);
	  if (input.val() == input.attr("placeholder")) {
	    input.val("");
	    input.removeClass("placeholder");
	  }
	}).blur(function() {
	  var input = $(this);
	  if (input.val() == "" || input.val() == input.attr("placeholder")) {
	    input.addClass("placeholder");
	    input.val(input.attr("placeholder"));
	  }
	}).blur();

});

/*------------------------------------------------------------------------------------------------------
  Função para estilização de backgrounds 
------------------------------------------------------------------------------------------------------*/
function SetBackgroundProperties(idDefinicaoFundo, container, posicaoX, posicaoY, imageUrl, backgroundColor, repeatMode)
{   
    if(idDefinicaoFundo != 0)
    {
        var elemento;
        
        //Tenta recuperar o elemento passado por parâmetro
        elemento = $(container);
        
        //Se não existe o elemento
        if(elemento.size() == 0)
            //Tenta recuperá-lo como classe
            elemento = $("." + container);
        
        //Se não encontrou elemento
        if(elemento.size() == 0) 
            //Tenta recuperá-lo como Id
            elemento = $("#" + container);
           
        //Se existe o elemento   
        if(elemento.size() > 0)     
        { 
            //Se 'backgroundColor' for vazio
            if(backgroundColor == "")
            
                //Seta com a cor branca
                backgroundColor = "#fff";
            
            //Seta as propriedades CSS do elemento passado como parâmetro
            elemento.css('background-image', 'url(' + imageUrl + ')');
            elemento.css('background-position', posicaoX + ' ' + posicaoY);
            elemento.css('background-repeat', repeatMode);
            elemento.css('background-color', backgroundColor);
        }
    }
}

/*---------------------------
  Busca do Site
---------------------------*/
function Buscar()
{
	idioma = GetLanguageSmiles();
	id = $('input[id*=txtBusca]').attr('id');
	window.location= "/"+idioma+'/busca/Paginas/resultado-da-busca.aspx?PC=' + document.getElementById(id).value;
}
  
function tecla_enter(e) 
{ 
    var codigo = e.keyCode;
    if (codigo == 13)
    { 
    	Buscar();
    }
}

function GetLanguageSmiles()
{
	var regex = new RegExp('^[a-zA-Z]{2}-[a-zA-Z]{2}$');
	
	var language = window.location.href.split('/')[4];
	
	if(regex.exec(language))
	    return language;
	return 'pt-br';
}

/*-----------------------------------------------------------
		Function Troca cultura na URL de check-in
-----------------------------------------------------------*/
$(document).ready(function(){
	$('#ItemCultura').each(function(){
		var idioma = window.location.pathname.split('/',3).toString().substring("8");
		hrefatual = $(this).attr('href');
		hreffinal = hrefatual + '?culture=' + idioma
		$(this).attr('href',hreffinal);
	});
});
