﻿/********************************************************************
'*	Criado em: 27/04/2011			Por: MARCELO ANDERSON DE OLIVEIRA
********************************************************************/

$(".vejaMais").live("click", function() {
    var dvSecoes = $(this).prev();
    if (dvSecoes.children("ul").children("li").length > 3) {
        $(this).animate({ opacity: 0.0 }, 500);
        dvSecoes.animate({ height: dvSecoes.children("ul").height() + 'px' }, 500);
    }
});

jQuery(document).ready(function() {

    /* INI MENU LATERAL */
    $('.dvSecoes').each(function() {
        var itHeight = 0;
        if ($(this).children('ul').children('li').length > 3) {
            for (i = 0; i < 3; i++) {
                itHeight += $(this).children('ul').children('li').eq(i).height();
            }

            $(this).height(itHeight + 7 + 'px');

            $(this).next().show().css('display', 'block');
        }
    });

    $('.menuDepto').animate({ opacity: 1.0 }, 1000);
    /* FIM MENU LATERAL */

    // scroll to top
    $('a.top').click(function() {
        $.scrollTo(0, 800);
        return false;
    });

    $('.slidedeck').slidedeck({
        autoPlayInterval: 4000,
        autoPlay: true,
        cycle: true,
        complete: function(deck) {
            var i = deck.current;
            var arrayID = $('.slide').eq($('.slide').index(i)).find('input').attr('idBanner').split("_");
            var idBanner = arrayID[arrayID.length - 1].split('-')[0];
            var idDepartamento = arrayID[arrayID.length - 1].split('-')[1];
           // alert(arrayID.length);
            $.ajax({
                type: "POST",
                url: "Codigos/WebMethods.aspx/GeraViewDisclaimer",
                data: "{idBanner:" + idBanner + ", idDepartamento:" + idDepartamento + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function() {
                },
                success: function() {
                    //alert('ok');
                },
                error: function(xhr, msg) {
                }
            });
        }

    });

    jQuery('.ultimosVisualizados').jcarousel({
        scroll: 4
    });

    jQuery('.prodVisualLateral').jcarousel({
        vertical: true,
        scroll: 1
    });
});



function alertDialog(vc_mensagem, vc_title, vc_funcoes, it_width, vc_dialog) {

    $(document).ready(function() {

        if (!vc_dialog) {
            vc_dialog = 'dialog';
        }
        if (vc_dialog == '') {
            vc_dialog = 'dialog';
        }
        $('#' + vc_dialog).dialog("destroy");


        var obj = getDivDialog(vc_dialog);
        if (vc_mensagem != '') {
            vc_mensagem = vc_mensagem.replace(/\n/gi, '<br />');
            obj.innerHTML = vc_mensagem;
        }

        // valores padrao caso nao receba esses valores
        if (typeof (vc_title) == "undefined" || vc_title == null) {
            vc_title = "ATENÇÃO!";
        }

        if (typeof (it_width) == "undefined" || it_width == null) {
            it_width = 450;
        }

        if (typeof (vc_funcoes) == "undefined" || vc_funcoes == null) {
            vc_funcoes = "void(0);";
        }


        // Dialog Propriedades
        $('#' + vc_dialog).dialog({
            autoOpen: false,
            modal: true,
            overlay: { backgroundColor: '#000', opacity: 0.95 },
            title: '<span class=\'ui-icon ui-icon-alert\'>&nbsp;</span>&nbsp;' + vc_title,
            width: it_width,
            position: "center",
            hide: "slide",
            buttons: { "fechar": function() { $(this).dialog("close"); } },
            close: function() { eval(vc_funcoes); }

        });

        //hover states on the static widgets
        $('#' + vc_dialog + '_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);

        $('#' + vc_dialog).dialog("open");
    });
}

function fecharDialog() {
    $("#dialog").dialog("close");
}

function alertDialogSemButton(vc_mensagem, vc_title, vc_funcoes, it_width, vc_classe) {

    $(document).ready(function() {
        $('#dialog').dialog("destroy");

        var obj = getDivDialog('dialog');
        if (vc_mensagem != '') {
            //vc_mensagem = vc_mensagem.replace(/\n/gi, '<br />');
            obj.innerHTML = vc_mensagem;
        }

        // valores padrao caso nao receba esses valores
        if (typeof (vc_title) == "undefined" || vc_title == null) {
            vc_title = "ATENÇÃO!";
        }

        if (typeof (it_width) == "undefined" || it_width == null) {
            //it_width = 450;
            it_width = 422;
        }

        if (typeof (vc_funcoes) == "undefined" || vc_funcoes == null) {
            vc_funcoes = "void(0);";
        }



        // Dialog Propriedades
        $('#dialog').dialog({
            autoOpen: false,
            modal: true,
            overlay: { backgroundColor: '#000', opacity: 0.95 },
            title: '<span class=\'ui-icon ui-icon-alert\'>&nbsp;</span>&nbsp;' + vc_title,
            width: it_width,
            position: "center",
            hide: "slide",
            close: function() { eval(vc_funcoes); },
            dialogClass: vc_classe

        });

        //hover states on the static widgets
        $('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);

        $("#dialog").dialog("open");
    });
}

function getDivDialog(idDialog) {

    var tmpDiv = (document.getElementById(idDialog)) ? document.getElementById(idDialog) : document.createElement('div');
    if (document.getElementById(idDialog)) {
        return document.getElementById(idDialog)
    }
    else {
        var tmpDiv = document.createElement('div');

        with (tmpDiv) {
            className = 'dialog';
            setAttribute('id', idDialog);
            setAttribute('title', 'Atenção!');
            style.display = 'none';
        }

        $('body').append(tmpDiv);
        return tmpDiv;
    }
}

function carregaDialogPaginaSemButton(vc_url, vc_title, it_width, it_height, vc_classe) {
    alertDialogSemButton("<iframe src=\"" + vc_url + "\" width=\"100%\" height=\"" + it_height + "\" style=\"border:none;\" border=\"0\" frameborder=\"no\" allowtransparency=\"true\"></iframe>", vc_title, '', it_width, vc_classe);
}

function addEvent() {
    // dropDown de Departamento
    $('.ddlDepto').change(function() {
        $(this).next().text($(this).children("option:selected").text());
    });

    $('.lblSelect').each(function() {
        $(this).text($(this).prev().children("option:selected").text());
    });


    // dropDown de mes e ano
    $('.ddlMesAno').change(function() {
        $(this).next().text($(this).children("option:selected").text());
    });

    $('.lblSelectMesAno').each(function() {
        $(this).text($(this).prev().children("option:selected").text());
    });

    // dropDown UF
    $('.ddlUF').change(function() {
        $(this).next().text($(this).children("option:selected").text());
    });

    $('.lblUF').each(function() {
        $(this).text($(this).prev().children("option:selected").text());
    });

    // dropDown Conheceu
    $('.ddlConheceu').change(function() {
        $(this).next().text($(this).children("option:selected").text());
    });

    $('.lblConheceu').each(function() {
        $(this).text($(this).prev().children("option:selected").text());
    });

    // dropDown de mes e ano pagamento
    $('.ddlMes').change(function() {
        $(this).next().text($(this).children("option:selected").text());
    });

    $('.ddlAno').change(function() {
        $(this).next().text($(this).children("option:selected").text());
    });

    $('.lblSelectMesAno').each(function() {
        $(this).text($(this).prev().children("option:selected").text());
    });
    
}

$(document).ready(function() {
    addEvent();
});

/*******************************************************************************
Desenvolvido em:    05/11/2008							Autor:	CARLOS MONTEIRO
Funcionalidade:	    Permite digitar apenas números
*******************************************************************************/
function SoNumeros(evtKeyPress) {
    var nTecla;

    nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;

    if ((nTecla > 47 && nTecla < 58) || nTecla == 8 || nTecla == 9) {
        return true;
    }
    else {
        return false;
    }
}

/****************************************************************
'*	Criado em: 02/02/2011			Por: DENILSON SANTOS
****************************************************************/
function FormatarCep(e, src, mask) {
    if (window.event) { _TXT = e.keyCode; }
    else if (e.which) { _TXT = e.which; }
    if (_TXT > 47 && _TXT < 58) {
        var i = src.value.length; var saida = mask.substring(0, 1); var texto = mask.substring(i)
        if (texto.substring(0, 1) != saida) { src.value += texto.substring(0, 1); }
        return true;
    } else {
        if (_TXT != 8) { return false; }
        else { return true; }
    }
}

function contaCaracter(it_caracter, it_limite, vc_campo) {
    var cont = document.getElementById(it_caracter);
    if (vc_campo.value.length > it_limite) {
        vc_campo.value = vc_campo.value.substring(0, it_limite);
    } else {
        cont.innerHTML = it_limite - vc_campo.value.length;
    }
}

function SoNumeros(evtKeyPress) {
    var nTecla;

    nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;

    if ((nTecla > 47 && nTecla < 58) || nTecla == 8 || nTecla == 9) {
        return true;
    }
    else {
        return false;
    }
}

/*# MASCARA MOEDA #*/
function mascaraMoeda(valor, cx, evtKeyPress) {
    var nTecla;

    nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
    if (valor) {
        var objID = document.getElementById(cx);
        var doc = null
        if (typeof (objID) != 'undefined') {
            doc = objID
        } else {
            doc = eval('document.all.' + cx);
        }

        if (nTecla == 110 || nTecla == 188 || nTecla == 190 || nTecla == 194) {
            doc.value = valor.substr(0, (valor.length - 1));
        } else {
            valor = mascararCentavo(valor);

            if (mascararCentavo(valor).length > 2) {
                str = valor.replace(".", "");
                doc.value = str.substr(0, (str.length - 2)) + "." + str.substr((str.length - 2), str.length);
            } else {
                valor = mascararCentavo(valor);

                if (valor.length == 1) {
                    doc.value = "0.0" + valor;
                } else {
                    doc.value = "0." + valor;
                }
            }
        }
    }
}

/*# MASCARA CENTAVO #*/
function mascararCentavo(mn_valor) {
    if (mn_valor.indexOf('0') == 0) {
        mn_valor = mn_valor.replace('0.', '');
        mn_valor = mn_valor.replace('0.0', '');
    }

    mn_valor = mn_valor.replace('.', '');

    return mn_valor;
}


/****************************************************************************
'  Criado em 25/08/2011   Ailton Lopes
****************************************************************************/

$(document).ready(function() {
   // $('.fields select').easySelectBox();
});

function setarFocusCep(txtPrefixCep, itMaxLenght, txtSulfixCep) {
    if (txtPrefixCep.value.length == itMaxLenght) {
        document.getElementById("ctl00_cphContainer_txtCep2").focus();
    }
}

function setarFocusTel(txtDDD, itMaxLenght, txtTel) {
    if (txtDDD.value.length == itMaxLenght) {
        document.getElementById("ctl00_cphContainer_txtTelSuf").focus();
    }
}
