﻿var f = {
    //variaveis

    ie: ($.browser.msie), // se é internet explorex
    ver: ($.browser.version), // versao do browser
    ie7: false,
    go: true,

    //verifica se é ie7
    validaIe: function () {

        if (f.ie && f.ver == "7.0") { f.ie7 = true; }
    },
    // verifica a maior altura do li e adiciona esta altura a todos os li da lista obj = classe ou id da lista
    liSize: function (obj) {
        var tul = 0;
        $(obj + '> li').each(function () {
            var tv = $(this).height();

            if (tul <= tv) {
                tul = tv;
            }
        });
        $(obj + '> li').css('height', tul);
    },
    // chamada para todas as paginas
    init: function () {
        f.navTopHover();
        f.defaultDropDown();
        f.validaIe();
        f.criancaIdade();
    },
    // chamada para as funções padrões para todas as paginas
    defaultDropDown: function () {
        //$("#ctl00_date1 , #ctl00_date2").datepicker({ showOn: "button", buttonImage: "../../_img/calendar.gif", buttonImageOnly: true, dateFormat: 'dd/mm/yy', dayNamesMin: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'], monthNames: ['Janeiro', 'Fevereio', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'], buttonText: 'Selecione uma data' });
        //$("#dtSaida , #dtEntrada").datepicker({ showOn: "button", buttonImage: "../../_img/calendar.gif", buttonImageOnly: true, dateFormat: 'dd/mm/yy', dayNamesMin: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'], monthNames: ['Janeiro', 'Fevereio', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'], buttonText: 'Selecione uma data' });
        $('#qtdCriancas').singleDrop({ largura: 32 });
        $('#qtdAdultos').singleDrop({ largura: 32 });
        $('#selCidade').singleDrop({ largura: 120 });
        $('#selHotel').singleDrop({ largura: 178 });
        $('#cidadeHotel').doubleDrop();

        $("#date2").datepicker({ minDate: 1,  dateFormat: 'dd/mm/yyyy', dayNamesMin: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'], monthNames: ['Janeiro', 'Fevereio', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'], buttonText: 'Selecione uma data' });
        $("#date1").datepicker({
            minDate: 1,
            dateFormat: 'dd/mm/yyyy',
             dayNamesMin: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'], monthNames: ['Janeiro', 'Fevereio', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro']
		    ,
            onSelect: function (dateStr) {
                var date = $(this).datepicker('getDate');
                if (date) {
                    date.setDate(date.getDate() + 1);
                    var ndate = date.getDate();
                    var nmonth = date.getMonth();
                    nmonth++;
                    var nyear = date.getFullYear();
                    var newDate = (ndate + "/" + nmonth + "/" + nyear);
                    $("#date2").datepicker("destroy")
                    $("#date2").datepicker({
                        /*minDate: newDate + 3, 		
                        dateFormat: 'dd/mm/yyyy', 
                        altFormat:'dd/MM/yyyy'	*/
                        minDate: newDate + 1,
                        altFormat: 'dd/mm/yyyy',
                        dateFormat: 'dd/mm/yyyy', dayNamesMin: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'], monthNames: ['Janeiro', 'Fevereio', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'], buttonText: 'Selecione uma data'
                    });
                    $("#date2").val(newDate);
                }
            }
        });

    },
    // chamada para as box filtro de buscas
    filtroBusca: function () {
        $('#slMes').singleDrop({ largura: 195 });
        $('#slDestino').singleDrop({ largura: 195 });
        $('#slEvento').singleDrop({ largura: 195 });
    },
    // chamada para as box filtro de buscas
    filtroDestino: function () {
        $('#slCidade2').singleDrop({ largura: 195 });
        $('#slNumP').singleDrop({ largura: 195 });
    },

    // função para os expansível exp = ação de abrir ret = acao de fechar
    exp: function (exp, ret) {
        var open = '.ItemOpen', close = '.ItemClose';
        $(exp).click(function (e) {
            var itm = $(this).parents('.lstBoxExp');
            if (f.ie7) {
                itm.find('li:not(.static)').hide();
                itm.next().show();
            } else {
                itm.find('li:not(.static)').animate({ height: 'toggle' })
                itm.next().animate({ height: 'toggle' })
            }
            e.preventDefault();
        });
        $(ret).click(function (e) {
            var itm = $(this).parents('.lstBoxExp');
            if (f.ie7) {
                itm.prev().find('li:not(.static)').show();
                itm.hide();
            } else {
                itm.prev().find('li:not(.static)').animate({ height: 'toggle' })
                itm.animate({ height: 'toggle' })
            }


            e.preventDefault();
        });
        $(document).ready(function () { $(close).animate({ height: 'toggle' }) })
    },
    // função expansivel galeria de imagens
    expGaleria: function (bt) {
        $('.' + bt).click(function (e) {
            var exp = $(this).attr('href');
            $(this).toggleClass(bt + 'Atv');
            $(exp).animate({ height: 'toggle' }, function () { f.dinamicIni(exp); })
            e.preventDefault();
        })
    },
    // função do menu hover superior
    navTopHover: function () {
        var ini = $('.lstLk').css('background-position'), title = null;
        if ($.browser.msie) {
            ini = $('.lstLk').css('background-position-x') + ' ' + $('.lstLk').css('background-position-y')
        }

        $('.lstLk li a').hover(
            function () {
                $('.nav .canvas').removeClass('hover');
                title = $(this).attr("title");
                switch (title) {
                    case "Home":
                        $('.lstLk').css('background-position', '0 0');
                        break;
                    case "Hotéis":
                        $('.lstLk').css('background-position', '0 -37px');
                        break;
                    case "Promoções":
                        $('.lstLk').css('background-position', '0 -74px');
                        break;
                    case "Feiras e Congressos":
                        $('.lstLk').css('background-position', '0 -111px');
                        break;
                    case "Eventos":
                        $('.lstLk').css('background-position', '0 -148px');
                        break;
                    case "Agências":
                        $('.lstLk').css('background-position', '0 -185px');
                        break;
                    case "Sobre nós":
                        $('.lstLk').css('background-position', '0 -222px');
                        break;
                    case "Contatos":
                        $('.lstLk').css('background-position', '0 -259px');
                        break;
                }
            }, function () {
                $('.lstLk').css('background-position', ini);
            }
        )
    },
    according: function () {
        lastBlock = $(".itm01");
        maxWidth = 600;
        minWidth = 40;

        $(".according li").click(
          function (e) {

              var l = $(this).width();
              if (l < 60) {
                  $(lastBlock).animate({ width: minWidth + "px" }, { queue: true, duration: 400 });
                  $(this).animate({ width: maxWidth + "px" }, { queue: true, duration: 400 });
                  lastBlock = this;
              }
              e.preventDefault();
          }
        );
    },
    // menu flutuante
    floatNav: function () {
        $('.lstSubNav li:odd').addClass('odd');
        $('.lstSubNav li a').click(function () {
            $('.lstSubNav li a').removeClass('atv');
            $(this).addClass('atv');
        })

        floatingMenu.add('menuFloat',
        {
            targetTop: 0,
            prohibitXMovement: true,
            snap: true
        });
    },
    // carrosel navegação
    lnkGaleria: function () {
        $('.carrosel > ul > li > a').live('click', function (e) {
            var _url = $(this).attr('href'), _leg = $(this).attr('title'), _tpo = $(this).attr('rel'), _zB = $(this).parents('.boxGaleria').find('.zoomBox'), _this = $(this), _bI = _zB.find('.boxImage'), _bL = _zB.find('.legenda');
            $(this).parents('ul').find('li').each(function () { $(this).find('a').removeClass('ativo') });
            _this.addClass('ativo');
            _bL.animate({ height: 'toggle' }, function () {
                _bI.animate({ opacity: 'toggle' }, function () {
                    if (_tpo == "image") {
                        _url = '<img src="' + _url + '" width="624px" height="468px" alt="' + _leg + '" />'
                    }
                    _bI.html(_url);
                    _bI.animate({ opacity: 'toggle' }, function () {
                        _bL.html(_leg);
                        _bL.animate({ height: 'toggle' });
                    });
                });
            })
            e.preventDefault();
        })
    },
    // invocando o script para a galeria de tour

    salaIni: function () {
        var _cr = $("#eventosFotos .carroselContent .carrosel"), _tpo = $("#eventosFotos .carroselContent .carrosel").find('a:first').attr('rel'), _leg = $("#eventosFotos .carroselContent .carrosel").find('a:first').attr('title'), _url = $("#eventosFotos .carroselContent .carrosel").find('a:first').attr('href'), _bZ = $("#eventosFotos .zoomBox");
        _cr.find('a:first').addClass('ativo');
        _bZ.find('.legenda').html(_leg);
        if (_tpo == "image") {
            _url = '<img src="' + _url + '" width="624px" height="468px" alt="' + _leg + '" />'
        }
        _bZ.find('.boxImage').html(_url);

        var qt = _cr.find('li').size()

        if (f.go) {
            if (qt > 4) {
                _cr.jCarouselLite({
                    btnNext: "#eventosFotos .carroselContent .btNext",
                    btnPrev: "#eventosFotos .carroselContent .btPrev",
                    visible: 4
                });
            } else {
                $('#eventosFotos .carroselContent .btNext').hide();
                $('#eventosFotos .carroselContent .btPrev').hide();
            }
            f.go = false;
        }
    },
    tourIni: function () {
        var _cr = $(".tour .carroselContent .carrosel"), _tpo = $(".tour .carroselContent .carrosel").find('a:first').attr('rel'), _leg = $(".tour .carroselContent .carrosel").find('a:first').attr('title'), _url = $(".tour .carroselContent .carrosel").find('a:first').attr('href'), _bZ = $(".tour .zoomBox");
        _cr.find('a:first').addClass('ativo');
        _bZ.find('.legenda').html(_leg);
        if (_tpo == "image") {
            _url = '<img src="' + _url + '" width="624px" height="468px" alt="' + _leg + '" />'
        }
        _bZ.find('.boxImage').html(_url);

        var qt = _cr.find('li').size()
        if (qt > 4) {
            _cr.jCarouselLite({
                btnNext: ".tour .carroselContent .btNext",
                btnPrev: ".tour .carroselContent .btPrev",
                visible: 4
            });
        } else {
            $('.tour .carroselContent .btNext').hide();
            $('.tour .carroselContent .btPrev').hide();
        }

    },
    // invoca dinamicamente o carrosel a ser expandido
    dinamicIni: function (obj) {
        var c = $(obj).parents('li').find('.carroselGaleria'), z = $(obj).parents('li').find('.carroselGaleria').find('.zoomBox'), url = c.find('.carrosel').find('a:first').attr('href'), leg = c.find('.carrosel').find('a:first').attr('title'), tpo = c.find('.carrosel').find('a:first').attr('rel');
        c.find('.carrosel').find('a:first').addClass('ativo');
        z.find('.legenda').html(leg);
        if (tpo == "image") {
            url = '<img src="' + url + '" width="624px" height="468px" alt="' + leg + '" />'
        }
        z.find('.boxImage').html(url);
        var qt = c.find('.carrosel').find('li').size();
        if (qt > 4) {
            c.find('.carrosel').jCarouselLite({
                btnNext: c.find('.btNext'),
                btnPrev: c.find('.btPrev'),
                visible: 4
            });
        } else {
            c.find('.btPrev').hide();
            c.find('.btNext').hide();
        }
    },
    // função para o select dos hoteis.
    selectHotel: function () {
        $('#outrasGalerias .list_drop li a').click(function () {
            _v = $(this).attr('href');

            $(this).parents('li').find('> div:not(.topoContent)').hide();

            var c = $(_v).find('.carroselGaleria'), z = $(_v).find('.carroselGaleria').find('.zoomBox'), url = c.find('.carrosel').find('a:first').attr('href'), leg = c.find('.carrosel').find('a:first').attr('title'), tpo = c.find('.carrosel').find('a:first').attr('rel');
            c.find('.carrosel').find('a:first').addClass('ativo');
            z.find('.legenda').html(leg);
            if (tpo == "image") {
                url = '<img src="' + url + '" width="624px" height="468px" alt="' + leg + '" />'
            }
            z.find('.boxImage').html(url);
            var qt = c.find('.carrosel').find('li').size();

            $(_v).show();

            _q = $(_v).find('li').size()
            //alert(_q)
            if (_q > 4) {
                $(_v).find('.carrosel').jCarouselLite({
                    btnNext: $(_v).find('.btNext'),
                    btnPrev: $(_v).find('.btPrev'),
                    visible: 4
                });
            } else {
                $(_v).find('.btPrev').hide();
                $(_v).find('.btNext').hide();
            }


        })

    },

    hotelTip: function () {
        var timer, h;

        $('.tbHoteis tr:odd td').addClass('odd');

        $('.tbHoteis td > div').hover(function () {
            var _this = $(this);
            var p = _this.position().left;
            p = Math.round(p)

            if (p > "494") {
                _this.addClass('tLeft');
            }

            timer = setTimeout(function () {

                $('.tbHoteis td > div').css('z-index', '0');
                _this.css('z-index', '50');

                _this.find('> div').animate({ opacity: ['toggle', 'swing'], "top": "-=100px" }, 500);
            }, 500)
            timer;
        },
        function () {
            var v = $(this).find('> div').is(':visible');
            //alert(v);
            if (v) {
                $(this).find('> div').animate({ opacity: ['toggle', 'swing'], "top": "+=100px" }, 500);
            } else {
                clearInterval(timer)
            }
        });
    },
    marcaNav: function (i) {
        $('.lstSubNav li:eq(' + i + ') a').addClass('atv');

    },
    // box idade criancas
    criancaIdade: function() {
        var g = true, l;

        $('#qtdCriancas ul li a').click(function() {

        //$('.boxIdade').css('top', '35px').css('right', '-5px');
        $('.boxIdade').css('top', '180px').css('left', '450px');

            var q = $(this).text(), d = $('.formContent ul'), x, i;
            if (q != "00") {
                if (g == true) {
                    l = $('.formContent ul').clone().html();
                }
                g = false;
                d.find('li').remove();
                function formataInput(t) {
                    i = $('.formContent > ul > li:last')
                    i.find(' > label').text('Criança' + x).next().attr('id', 'idCrianca' + x).find('input[type=hidden]').attr('id', 'hCrianca' + x);
                    $('#idCrianca' + x).singleDrop({ largura: 80 });
                    $('#idCrianca' + x).parent().css('z-index', (30 - x));
                    //$('#idCrianca' + x).css('z-index', (30 + x));
                }
                for (x = 1; x <= q; x++) {
                    if (x == 1) {
                        d.wrapInner(l);
                        formataInput();
                    } else {
                        d.find('> li:last').after(l);
                        formataInput();
                    }
                }
                // insere os valores no inputHidden
                $('.boxIdade .btoOK').click(function(e) {
                    var vlr = null, o = 1, vlr, idN = "";
                    $('.formContent > ul > li:not(first)').each(function() {
                        vlr = $('.formContent #hCrianca' + o).val()
                        vlr = vlr.substring(0, 2)
                        //alert(vlr)

                        if (o == 1) {
                            idN += vlr;
                        } else {
                            idN += ',' + vlr;
                        }
                        o++
                    })
                    $('#idadeTotal').val(idN)
                    e.preventDefault();

                    //fecha
                    $('.boxIdade').css('top', '-10000px').css('left', '-10000px');
                    //$('.boxIdade').css('top', '10000px').css('right', '-10000px');
                    //$('#qtdCriancas .txtVlr').text('00').next().attr('value','00')
                }
                )

            } else {
            $('.boxIdade').css('top', '10000px').css('left', '-10000px');
            }
            // botao de fechar
            $('.boxIdade .closeBox').click(function() {
            $('.boxIdade').css('top', '10000px').css('left', '-10000px');
                $('#qtdCriancas .txtVlr').text('00').next().attr('value', '00')
            })
        })
        //},
    }
    // fim script
}






function buscaBE() {

    var URL = 'http://reservas.slavierohoteis.com.br/modulos/admin/testereservas.aspx';  //document.getElementById("ctl00_hddURLBE").value;    
    var erro = "";    
	
	var cidade = document.getElementById("cmbCidade").value;
    var hotel = document.getElementById("cmb_hotel").value;
    var idadeTotal = document.getElementById("idadeTotal").value
    var a ="";
    var b="";
    //alert(idadeTotal);
    
    /*
    if (hotel == "") {
        erro = "Selecione um hotel";
    }*/


    if (cidade == "") {
        erro = "Selecione uma cidade";
    }

    //URL = URL + "?strHotelName=" + hotel.replace(' ', '');
    //URL = URL + "&strHotelCidade=&adultos=" + document.getElementById("qtdAdulto").value.replace('0', '');
	URL = URL + "?strHotelName=&strHotelCidade=&adultos=" + document.getElementById("qtdAdulto").value.replace('0', '');
    
    if (document.getElementById("criancas").value == "00") {
        URL = URL + "&criancas=0";
    } else {
        URL = URL + "&criancas=" + document.getElementById("criancas").value.replace('0', '');
         a=document.getElementById("criancas").value.replace('0', '');
         if(idadeTotal.replace(' ', '')){
             b=idadeTotal.replace(' ', '').split(",");
         }else{
             b=idadeTotal.replace(' ', '');
         }
        if(a == b.length){
        URL = URL + "&idadeCrianca=" + idadeTotal.replace(' ', '');
        }else{
            erro = "Selecione a idade da Criança e clique no OK";
        }
        
    }

    
        URL = URL + "&codigo=" + cidade;
   

    var data = document.getElementById("date1").value;
    var data2 = document.getElementById("date2").value;

    data1Split = data.split('/');
    data2Split = data2.split('/');

    dia = data1Split[0];
    if (dia.length == 1) {
        dia = '0' + dia;
    }
    mes = data1Split[1];
    if (mes.length == 1) {
        mes = '0' + mes;
    }

    data = dia + '/' + mes + '/' + data1Split[2].substring(0, 4);

    dia = data2Split[0];
    if (dia.length == 1) {
        dia = '0' + dia;
    }
    
    mes = data2Split[1];
    if (mes.length == 1) {
        mes = '0' + mes;
    }
    data2 = dia + '/' + mes + '/' + data2Split[2].substring(0, 4);

    

    //Criar bloqueio para que saída não possa ser menor que dois dias depois da chegada
    /*if (erro == "") {
        //chegada
        var novaData = somadias(data, 2);

        data1Split = novaData.split('/');
        data2Split = data2.split('/');

        data1Valida = data1Split[2] + data1Split[1] + data1Split[0];
        data2Valida = data2Split[2] + data2Split[1] + data2Split[0];

        if (data2Valida < data1Valida) {
            erro = "A data de saída dever ser no mínimo 2 dias após a data de chegada.";
        }

    }*/


    URL = URL + "&start-date=" + data; //.replace('/', '-').replace('/', '-');
    URL = URL + "&end-date=" + data2; //.replace('/', '-').replace('/', '-');


    //alert(URL);
    if (erro != "") {
        alert(erro);
    } else {
        //window.open(URL);
        //alert(URL);
        document.location.href = URL;
    }
}



function numdias(mes, ano) {
    if ((mes < 8 && mes % 2 == 1) || (mes > 7 && mes % 2 == 0)) return 31;
    if (mes != 2) return 30;
    if (ano % 4 == 0) return 29;
    return 28;
}

function somadias(data, dias) {
    data = data.split('/');
    diafuturo = parseInt(data[0]) + dias;
    mes = parseInt(data[1]);
    ano = parseInt(data[2]);
    while (diafuturo > numdias(mes, ano)) {
        diafuturo -= numdias(mes, ano);
        mes++;
        if (mes > 12) {
            mes = 1;
            ano++;
        }
    }

    if (diafuturo < 10) diafuturo = '0' + diafuturo;
    if (mes < 10) mes = '0' + mes;

    return diafuturo + "/" + mes + "/" + ano;
}

function buscaEventos() {
    var erro = "";

    var destino = document.getElementById("hddNumDestinoBusca").value;
    var pessoas = document.getElementById("pessoas").value;


    if (erro == "") {
        document.location.href = "default.aspx?busca=S&pessoas=" + pessoas + "&destino=" + destino;
    } else {
        alert(erro);
    }

}

function abreGaleria(id) {

    try {
        var i = 0;
        for (i = 0; i <= 200; i++) {
            if (document.getElementById("galeriaFotos" + i) != null) {
                document.getElementById("galeriaFotos" + i).style.display = "none";
            }
        }
    }
    catch (err) {
        //Handle errors here
    }
    document.getElementById("galeriaFotos" + id).style.display = "block";
    /*
    document.getElementById("hddURL").value = document.getElementById("hddURL" + id).value;
    if (document.getElementById("hddURL").value == "") {
        document.getElementById("linkTour").style.display = "none";
    } else {
        document.getElementById("linkTour").style.display = "block";
    }*/
    
}

function urlTour() {
    //alert(document.getElementById("ctl00_main_content_hddURL").value)
    var url = document.getElementById("ctl00_main_content_hddURL").value;
    //alert(url);
    if (url != "") {
        url = "../../arquivos/tour/" + url;
        window.open(url, 'tour', 'height = 500, width = 500');
    }
}

function eventosClique(area) {
    document.getElementById("eventosFotos").style.display = "none";
    document.getElementById("link_eventosFotos").className = "btCorner";

    document.getElementById("eventosSalas").style.display = "none";
    document.getElementById("link_eventosSalas").className = "btCorner";

    document.getElementById(area).style.display = "block";
    document.getElementById("link_" + area).className = "btCorner1";
}
