﻿function Util() {
    this.keyAuth = new String();

    // Descobre o Scroll Width (Cross-brownser)
    this.getScrollWidth = function(){
        var w = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft;
        return w ? w : 0;
    }
    // Descobre o Scroll Height (Cross-brownser)
    this.getScrollHeight = function(){
        var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
        return h ? h : 0;
    }

    // Exibe o Div de Carregando
    this.showLoading = function() {
        // Mostra o Carregando
        // Descobre o Tamanho da Tela
        var winH = $(window).height();
        var winW = $(window).width();
        // Descobre a posicao do Scroll
        var scrollH = this.getScrollHeight();
        var scrollW = this.getScrollWidth();
        // Descobre o Top do div
        var divTop = ((winH / 2) - ($('#maskCarregando').height() / 2)) + scrollH;
        var divLeft = ((winW / 2) - ($('#maskCarregando').width() / 2)) + scrollW;
        $('#maskCarregando').css('top', divTop);
        $('#maskCarregando').css('left', divLeft);
        $('#maskCarregando').css('z-index', '9999');
        $('#mask').css({ 'width': $(window).width(), 'height': $(document).height() });
        $('#mask').fadeTo(0, 0.8);
        $('#mask').show();
        // Mostra o Carregando
        $('#maskCarregando').show();
    }
    // Esconde o Div de Carregando
    this.hideLoading = function() {
        $('#maskCarregando').hide();
        $('#mask').hide();
    }
    // Da o Submit de um Link mostrando o alerta de carregando
    this.submitLink = function(urlLink) {
        // Mostra o Carregando
        this.showLoading();
        // Da o redirect
        setTimeout(function() {
            top.location = urlLink;
        }, 20);
        // retorna void(0) para nao executar a acao de submit
        return false;
    }

    // Submit de TagCloud
    this.submitTagCloud = function(tag) {
        // Mostra o Carregando
        this.showLoading();
        setTimeout(function() {
            top.location = window.location.protocol + "//" + window.location.host + "/Busca/" + encodeURIComponent(tag.replace(".", "").replace("%", "")).replace(/%20/g, "+").replace(/%26/g, "e");
        }, 20);
        return false;
    }


    this.setKey = function(_key) {
        this.keyAuth = _key;
    }


    this.submitLinkProduto = function(pIdAnuncioProduto, pUrlDestino) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var idClickType = new Number();
        var idAnuncioProduto = new Number();
        var urlAtual = new String();
        var urlDestino = new String();
        var extra = new String();
        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        idClickType = 1
        urlAtual = window.location;
        extra = "";

        // Seta os valores das Variavies recebidas
        idAnuncioProduto = pIdAnuncioProduto;
        urlDestino = pUrlDestino;

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        lData = "authenticationKey=" + authenticationKey + "&pIdClickType=" + idClickType + "&pIdAnuncioProduto=" + idAnuncioProduto + "&pUrlAtual=" + urlAtual + "&pUrlDestino=" + urlDestino + "&pExtra=" + extra;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncioProduto.asmx/SaveClick";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            beforeSend: function(XMLHttpRequest) {
                Util.showLoading();
            },
            complete: function() {
                Util.hideLoading();
            },
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
                Util.hideLoading();
                // Da o redirect
                setTimeout(function() {
                    top.location = urlDestino;
                }, 20);
            },
            success: function(loadedContentHTML) {
                // Da o redirect
                setTimeout(function() {
                    top.location = urlDestino;
                }, 20);
            }
        });

        return false;
    }

    this.submitLinkAnuncio = function(pIdAnuncio, pUrlDestino) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var idClickType = new Number();
        var idAnuncio = new Number();
        var urlAtual = new String();
        var urlDestino = new String();
        var extra = new String();
        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        idClickType = 1
        urlAtual = window.location;
        extra = "";

        // Seta os valores das Variavies recebidas
        idAnuncio = pIdAnuncio;
        urlDestino = pUrlDestino;

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        lData = "authenticationKey=" + authenticationKey + "&pIdClickType=" + idClickType + "&pIdAnuncio=" + idAnuncio + "&pUrlAtual=" + urlAtual + "&pUrlDestino=" + urlDestino + "&pExtra=" + extra;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncio.asmx/SaveClick";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            beforeSend: function(XMLHttpRequest) {
                Util.showLoading();
            },
            complete: function() {
                Util.hideLoading();
            },
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
                Util.hideLoading();
                // Da o redirect
                setTimeout(function() {
                    top.location = urlDestino;
                }, 20);
            },
            success: function(loadedContentHTML) {
                // Da o redirect
                setTimeout(function() {
                    top.location = urlDestino;
                }, 20);
            }
        });

        return false;
    }

    this.SendSimpleMail = function(pFromEmail, pToEmail, pSubject, pFileTemplate, pNameValue, pExtraInfo) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var fromEmail = new String();
        var toEmail = new String();
        var subject = new String();
        var fileTemplate = new String();
        var nameValue = new String();
        var extraInfo = new String();
        var retorno = false;

        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        fromEmail = pFromEmail;
        toEmail = pToEmail;
        subject = pSubject;
        fileTemplate = pFileTemplate;
        nameValue = pNameValue;
        extraInfo = pExtraInfo;

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        lData = "authenticationKey=" + authenticationKey + "&pFromEmail=" + fromEmail + "&pToEmail=" + toEmail + "&pSubject=" + subject + "&pFileTemplate=" + fileTemplate + "&pNameValue=" + nameValue + "&pExtraInfo=" + extraInfo;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/util.asmx/SendSimpleMail";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            beforeSend: function(XMLHttpRequest) {
                Util.showLoading();
            },
            complete: function() {
                Util.hideLoading();
            },
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
                Util.hideLoading();
                retorno = false;
            },
            success: function(loadedContentHTML) {
                Util.hideLoading();
                retorno = true;
            }
        });

        return retorno;
    }


    // Valida se o Email é Valido
    this.isValidEmailAddress = function(emailAddress) {
        var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        return pattern.test(emailAddress);
    }

    // Move a Pagina ate a posicao do Ancora informado
    this.MoveToAnchor = function(anchorName) {
        if (anchorName != "") {
            var destination = $("#" + anchorName).offset().top;

            //alert(destination);

            $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination }, 1000);
        }
    }

    // Verifica se é IPhone ou IPod
    this.IsIPhone = function() {
        if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
            return true;
        } else {
            return false;
        }
    }

    // Submit o Link atrave do Botao "Aplicar Filtro"
    this.SubmitAplicarFiltro = function() {
        var linktoSubmit = $('#filtrosSelecionadosId .filtrosSelecionados > div > a:last').attr("link");
        Util.submitLink($('#filtroURLDefaultID').val() + linktoSubmit);
    }


    this.submitLinkDestaque = function(pIdEmpresa, pIdAnuncio, pIdProduto, pUrlDestino, pExtra) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var idClickType = new Number();
        var id = new Number();
        var urlAtual = new String();
        var urlDestino = new String();
        var extra = new String();
        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        idClickType = 6 // No Destaque (Site)
        urlAtual = window.location;

        // Seta os valores das Variavies recebidas
        urlDestino = pUrlDestino;
        extra = pExtra;

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        // Verifica se é um Produto
        if (Number(pIdProduto) != 0) {
            // É um click para Produto
            lData = "authenticationKey=" + authenticationKey + "&pIdClickType=" + idClickType + "&pIdAnuncioProduto=" + pIdProduto + "&pUrlAtual=" + urlAtual + "&pUrlDestino=" + urlDestino + "&pExtra=" + extra;
            // Seta o Caminho do WS
            caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncioProduto.asmx/SaveClick";
        } else if (Number(pIdAnuncio) != 0) {
            // É um click para Anuncio
            lData = "authenticationKey=" + authenticationKey + "&pIdClickType=" + idClickType + "&pIdAnuncio=" + pIdAnuncio + "&pUrlAtual=" + urlAtual + "&pUrlDestino=" + urlDestino + "&pExtra=" + extra;
            // Seta o Caminho do WS
            caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncio.asmx/SaveClick";
        } else {
            // É um click para Anuncio
            lData = "authenticationKey=" + authenticationKey + "&pIdClickType=" + idClickType + "&pIdEmpresa=" + pIdEmpresa + "&pUrlAtual=" + urlAtual + "&pUrlDestino=" + urlDestino + "&pExtra=" + extra;
            // Seta o Caminho do WS
            caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncio.asmx/EmpresaSaveClick";
        }

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            beforeSend: function(XMLHttpRequest) {
                Util.showLoading();
            },
            complete: function() {
                Util.hideLoading();
            },
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
                Util.hideLoading();
                // Da o redirect
                setTimeout(function() {
                    top.location = urlDestino;
                }, 20);
            },
            success: function(loadedContentHTML) {
                // Da o redirect
                setTimeout(function() {
                    top.location = urlDestino;
                }, 20);
            }
        });

        return false;
    }

    this.showFooterLastViews = function() {
        // Variaveis de Controle do AJAX
        var caminhoWS = new String();
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/util.asmx/GetFooterLastViews";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: '',
            dataType: "xml",
            success: function(loadedContentHTML) {
                $("#navBoxUltimasVisitasId").html($(loadedContentHTML).find("string").text());
            }
        });

        return false;
    }

    this.showFooterLastSearch = function() {
        // Variaveis de Controle do AJAX
        var caminhoWS = new String();
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/util.asmx/GetFooterLastSearch";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: '',
            dataType: "xml",
            success: function(loadedContentHTML) {
                $("#navUltimasBuscasID").html($(loadedContentHTML).find("string").text());
            }
        });

        return false;
    }

    this.saveFooterLastView = function(pLastView) {
        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Parametros
        lData = "pLastView=" + pLastView;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/util.asmx/SaveFooterLastView";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
            }
        });

        return false;
    }

    this.saveFooterLastSearch = function(pSearchLink, pSearchString) {
        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Parametros
        lData = "pSearchLink=" + pSearchLink + "&pSearchString=" + pSearchString;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/util.asmx/SaveFooterLastSearch";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
            }
        });

        return false;
    }

    this.SaveLogProdutoView = function(pIdAnuncioProduto, extra) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var idViewType = new Number();
        var idAnuncioProduto = new Number();
        var urlAtual = new String();
        var extra = new String();

        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        idViewType = 1
        urlAtual = window.location;
        extra = extra;

        // Seta os valores das Variavies recebidas
        idAnuncioProduto = pIdAnuncioProduto;

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        lData = "authenticationKey=" + authenticationKey + "&pIdViewType=" + idViewType + "&pIdAnuncioProduto=" + idAnuncioProduto + "&pUrlAtual=" + urlAtual + "&pExtra=" + extra;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncioProduto.asmx/SaveView";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
            },
            success: function(loadedContentHTML) {
            }
        });

        return false;
    }
    this.SaveLogEmpresaView = function(pIdEmpresa, extra) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var idViewType = new Number();
        var idEmpresa = new Number();
        var urlAtual = new String();
        var extra = new String();

        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        idViewType = 1
        urlAtual = window.location;
        extra = extra;

        // Seta os valores das Variavies recebidas
        idEmpresa = pIdEmpresa;

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        lData = "authenticationKey=" + authenticationKey + "&pIdViewType=" + idViewType + "&pIdEmpresa=" + idEmpresa + "&pUrlAtual=" + urlAtual + "&pExtra=" + extra;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/empresa.asmx/SaveView";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
            },
            success: function(loadedContentHTML) {
            }
        });

        return false;
    }

    this.PopupCenter = function(pageURL, title, w, h) {
        var left = (screen.width / 2) - (w / 2);
        var top = (screen.height / 2) - (h / 2);
        window.open(pageURL, '', 'toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, copyhistory=0, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
        return false;
    }



    this.SaveLogProdutoClick = function(pIdAnuncioProduto) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var idClickType = new Number();
        var idAnuncioProduto = new Number();
        var urlAtual = new String();
        var urlDestino = new String();
        var extra = new String();
        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        idClickType = 1
        urlAtual = window.location;
        extra = "";

        // Seta os valores das Variavies recebidas
        idAnuncioProduto = pIdAnuncioProduto;

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        lData = "authenticationKey=" + authenticationKey + "&pIdClickType=" + idClickType + "&pIdAnuncioProduto=" + idAnuncioProduto + "&pUrlAtual=" + urlAtual + "&pUrlDestino=&pExtra=" + extra;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncioProduto.asmx/SaveClick";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
            },
            success: function(loadedContentHTML) {
            }
        });

        return false;
    }

    this.SaveLogProdutoClickNewWindow = function(pIdAnuncioProduto, url) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var idClickType = new Number();
        var idAnuncioProduto = new Number();
        var urlAtual = new String();
        var urlDestino = new String();
        var extra = new String();
        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        idClickType = 1
        urlAtual = window.location;
        extra = "";

        // Seta os valores das Variavies recebidas
        idAnuncioProduto = pIdAnuncioProduto;

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        lData = "authenticationKey=" + authenticationKey + "&pIdClickType=" + idClickType + "&pIdAnuncioProduto=" + idAnuncioProduto + "&pUrlAtual=" + urlAtual + "&pUrlDestino=&pExtra=" + extra;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncioProduto.asmx/SaveClick";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
            },
            success: function(loadedContentHTML) {
                alert(url);
                window.open(url, '_blank');
            }
        });

        return false;
    }



    this.GetInfoProduto = function(idAnuncioProduto, htmlDestino) {
        try {
            Util.SaveLogProdutoClick(idAnuncioProduto);

            htmlDestino = "#" + htmlDestino;

            // Variavel que Recebe o LinkDefautl
            var linkDefault = new String();
            var caminhoWS = new String();
            var lData = new String();
            var shortcutLimpo = new Array();

            // Monta o LinkDefault com o Caminho que o Link do DHT deve Ter
            linkDefault = window.location.protocol + "//" + window.location.host + "/";
            // Seta o Caminho do WS
            caminhoWS = linkDefault + "detalheOferta.aspx?idProduto=" + idAnuncioProduto;
            // Monta a String lData
            lData = "";
            // Monta o Ajax
            $.ajax({
                type: "GET",
                url: caminhoWS,
                data: '',
                dataType: "html",
                beforeSend: function(XMLHttpRequest) {
                    Util.showLoading();
                },
                complete: function() {
                    //Util.hideLoading();
                    $('#maskCarregando').hide();
                },
                error: function(errorRequest) {
                    alert('Erro' + errorRequest);
                    Util.hideLoading();
                },
                success: function(loadedContentHTML) {
                    document.getElementById('containerDhtmlInformacaoProdutos').innerHTML = loadedContentHTML;
                    // Descobre o tamanho e posicionamento do Div
                    var winH = $(window).height();
                    var winW = $(window).width();
                    // Descobre a posicao do Scroll
                    var scrollH = Util.getScrollHeight();
                    var scrollW = Util.getScrollWidth();
                    // Descobre o Top do div
                    var divTop = ((winH / 2) - ($(htmlDestino).height() / 2)) + scrollH;
                    var divLeft = ((winW / 2) - ($(htmlDestino).width() / 2)) + scrollW;
                    $(htmlDestino).css('top', divTop);
                    $(htmlDestino).css('left', divLeft);
                    $(htmlDestino).css('z-index', '9999');
                    $(htmlDestino).show();

                    // Adiciona a Acao do Click na Mascara
                    $("#mask").click(function() {
                        // Remove todos os divs que ela "pode abrir"
                        $(htmlDestino).hide(); // DHTML de Produtos (Busca e Departamento)
                        //Efeito na Mascara		
                        $('#mask').fadeOut("fast");
                    });

                    // Adiciona a Acao do Click do botao Fechar
                    $("#detalheProdutoV102FecharID").click(function() {
                        // Remove todos os divs que ela "pode abrir"
                        $(htmlDestino).hide(); // DHTML de Produtos (Busca e Departamento)
                        $("#videoDetalheProdutoID").empty();
                        //Efeito na Mascara
                        $('#mask').fadeOut("fast");
                    });

                    // Adiciona as Imagens ao Slide
                    var playlistFotos = $('#playlistFotosID > div');
                    $(playlistFotos).each(function(index) {
                        $('#fotosPlayerExibir').append('<img width="483" height="364" src="' + $(this).find('img').attr('big') + '"/>')
                    });

                    /*Mostra o que Deve exibir*/
                    var conteudoVideo = $.trim($('#box-detalhe-produto > .content > .informacoes > .boxPlayer > #videoDetalheProdutoID').html());
                    if (conteudoVideo != "") {
                        $('#box-detalhe-produto > .content > .informacoes > .boxPlayer > #videoDetalheProdutoID').attr("style", "display: block");
                        $('#box-detalhe-produto > .content > .informacoes > .boxPlayer > #foto').attr("style", "display: none");
                        $('#playDetalheProdutoVideo').click(function() {
                            $("#videoDetalheProdutoID").empty();
                            $('#fotosPlayerExibir').empty();
                            document.getElementById("videoDetalheProdutoID").innerHTML = $('#videoDetalheProdutoHTMLID').val();
                            $('#box-detalhe-produto > .content > .informacoes > .boxPlayer > #videoDetalheProdutoID').attr("style", "display: block");
                            $('#box-detalhe-produto > .content > .informacoes > .boxPlayer > #foto').attr("style", "display: none");
                        });
                    } else {
                        $('#box-detalhe-produto > .content > .informacoes > .boxPlayer > #videoDetalheProdutoID').attr("style", "display: none");
                        $('#box-detalhe-produto > .content > .informacoes > .boxPlayer > #foto').attr("style", "display: block");
                        /*Inicia o Slide*/
                        $('#fotosPlayerExibir').cycle({
                            fx: 'scrollHorz',
                            next: '#SlideFotoAcoesProximoID',
                            prev: '#SlideFotoAcoesAnteriorID',
                            timeout: 7000,
                            delay: -2000,
                            after: onAfterSlide
                        });
                    }

                    /* Controle de Movimentacao do Slide */
                    function onAfterSlide(currSlideElement, nextSlideElement, options, forwardFlag) {
                        $('#fotosPlayerAtual').html(options.currSlide + 1);
                        $('#fotosPlayerTotal').html(options.slideCount);
                        var width = 'width: ' + ((options.currSlide + 1) / options.slideCount) * 100 + '%'
                        $('#fotosPlayerStatusBar').attr('style', width);

                        var fotos = $('#playlistFotosID > div');
                        $(fotos).each(function(index) {
                            $(this).removeClass('img-ov');
                        });
                        $(fotos).eq(options.currSlide).addClass('img-ov');
                    }
                    /* Controle de Pause e Start */
                    $('#SlideFotoAcoesPauseID').click(function() {
                        if ($('#SlideFotoAcoesPauseID').attr('status') == '1') {
                            $('#fotosPlayerExibir').cycle('pause');
                            $('#SlideFotoAcoesPauseID').attr('status', '0');
                        } else {
                            $('#fotosPlayerExibir').cycle('resume', true);
                            $('#SlideFotoAcoesPauseID').attr('status', '1');
                        }
                    });

                    $('#playlistFotosID > div > img').click(function() {
                        $('#box-detalhe-produto > .content > .informacoes > .boxPlayer > #videoDetalheProdutoID').attr("style", "display: none");
                        $('#box-detalhe-produto > .content > .informacoes > .boxPlayer > #videoDetalheProdutoID').empty();
                        $('#box-detalhe-produto > .content > .informacoes > .boxPlayer > #foto').attr("style", "display: block");
                        $('#fotosPlayerExibir').empty();
                        var playlistFotos = $('#playlistFotosID > div');
                        $(playlistFotos).each(function(index) {
                            $('#fotosPlayerExibir').append('<img width="483" height="364" src="' + $(this).find('img').attr('big') + '"/>')
                        });

                        /*Inicia o Slide*/
                        $('#fotosPlayerExibir').cycle({
                            fx: 'scrollHorz',
                            next: '#SlideFotoAcoesProximoID',
                            prev: '#SlideFotoAcoesAnteriorID',
                            timeout: 7000,
                            delay: -2000,
                            after: onAfterSlide
                        });
                    });
                }
            });
        }
        catch (e) {
            throw (e);
            return false;
        }
    }


    this.SaveLogDestaqueEmpresaClick = function(pIdEmpresa, pUrlDestino, pLinkTargetBlank) {
        // Cria as Variaveis de Controle
        var authenticationKey = new String();
        var idClickType = new Number();
        var idEmpresa = new Number();
        var urlAtual = new String();
        var urlDestino = new String();
        var extra = new String();
        var linkTarget = new Boolean();
        // Seta o valor das Variaveis Automaticos
        authenticationKey = this.keyAuth;
        idClickType = 6
        urlAtual = window.location;
        extra = "";
        linkTargetBlank = pLinkTargetBlank;
        // Seta os valores das Variavies recebidas
        idEmpresa = pIdEmpresa;
        urlDestino = pUrlDestino;

        // Variaveis de Controle do AJAX
        var lData = new String();
        var caminhoWS = new String();

        // Seta os Dados a Enviar
        lData = "authenticationKey=" + authenticationKey + "&pIdClickType=" + idClickType + "&pIdEmpresa=" + idEmpresa + "&pUrlAtual=" + urlAtual + "&pUrlDestino=" + urlDestino + "&pExtra=" + extra;
        // Seta o Caminho do WS
        caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncio.asmx/EmpresaSaveClick";

        // Monta o Ajax
        $.ajax({
            type: "POST",
            url: caminhoWS,
            data: lData,
            dataType: "html",
            beforeSend: function(XMLHttpRequest) {
                Util.showLoading();
            },
            complete: function() {
                Util.hideLoading();
            },
            error: function(errorRequest) {
                alert('Erro' + errorRequest);
                Util.hideLoading();
                // Da o redirect
                if (linkTargetBlank) {
                    window.open(urlDestino, '_blank');
                } else {
                    setTimeout(function() {
                        top.location = urlDestino;
                    }, 20);
                }
            },
            success: function(loadedContentHTML) {
                // Da o redirect
                if (linkTargetBlank) {
                    window.open(urlDestino, '_blank');
                } else {
                    setTimeout(function() {
                        top.location = urlDestino;
                    }, 20);
                }
            }
        });

        return false;
    }

    this.salvaBannerClick = function(link, id, blank) {
        // Verifica se Abre em nova janela
        var linkTarget = new Boolean();
        if (blank == "0") {
            linkTarget = false;
        } else {
            linkTarget = true;
        }
        if (id != "" && id != "0") {
            // Chama WebService que Grava o Contador
            //Util.SaveLogDestaqueEmpresaClick(id, link, linkTarget);
            // Cria as Variaveis de Controle
            var authenticationKey = new String();
            var idClickType = new Number();
            var idEmpresa = new Number();
            var urlAtual = new String();
            var urlDestino = new String();
            var extra = new String();
            var linkTarget = new Boolean();
            // Seta o valor das Variaveis Automaticos
            authenticationKey = this.keyAuth;
            idClickType = 6
            urlAtual = window.location;
            extra = "";
            linkTargetBlank = linkTarget;
            // Seta os valores das Variavies recebidas
            idEmpresa = id;
            urlDestino = link;

            // Variaveis de Controle do AJAX
            var lData = new String();
            var caminhoWS = new String();

            // Seta os Dados a Enviar
            lData = "authenticationKey=" + authenticationKey + "&pIdClickType=" + idClickType + "&pIdEmpresa=" + idEmpresa + "&pUrlAtual=" + urlAtual + "&pUrlDestino=" + urlDestino + "&pExtra=" + extra;
            // Seta o Caminho do WS
            caminhoWS = window.location.protocol + "//" + window.location.host + "/" + "ws/anuncio.asmx/EmpresaSaveClick";
            // Monta o Ajax
            $.ajax({
                type: "POST",
                url: caminhoWS,
                data: lData,
                dataType: "html",
                beforeSend: function(XMLHttpRequest) {
                    Util.showLoading();
                },
                complete: function() {
                    Util.hideLoading();
                },
                error: function(errorRequest) {
                    alert('Erro' + errorRequest);
                    Util.hideLoading();
                    // Da o redirect
                    if (linkTargetBlank) {
                        window.open(urlDestino, '_blank');
                    } else {
                        top.location = urlDestino;
                    }
                },
                success: function(loadedContentHTML) {
                    // Da o redirect
                    if (linkTargetBlank) {
                        window.open(urlDestino, '_blank');
                    } else {
                        top.location = urlDestino;
                    }
                }
            });
            //return false;
        } else {
            if (linkTarget) {
                window.open(link, '_blank');
                //return false;
            } else {
                top.location = link;
                //return false;
            }
        }
    }			
    
}