﻿/****************************************************************
'*	Criado em: 02/09/2010			Por: THIAGO DE ASSIS LUCA
****************************************************************/

function alertDialog(vc_mensagem, vc_title, vc_funcoes, it_width) {
    
    $(document).ready(function() {
    
        
        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;
        }

        if (typeof (vc_funcoes) == "undefined" || vc_funcoes == null) {
            vc_funcoes = "void(0);";
        }

        //$('#dialog').dialog("destroy");
            
        // Dialog Propriedades
        $('#dialog').dialog({
            autoOpen: false,
            modal: true,
            overlay: { backgroundColor: '#000', opacity: 0.95 },
            title:  vc_title,
            width: it_width,
            position: "center",
            hide: "hide",
            buttons: { "Ok": function() { $(this).dialog("close"); } },
            close: function() { eval(vc_funcoes); }

        });
        
        //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 fecharDialog() {
   $("#dialog").dialog("close");
}

function alertDialogSemButton(vc_mensagem, vc_title, vc_funcoes, it_width,vc_class) {
    
    $(document).ready(function() {
    
    
        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;
        }
               
        if (typeof (vc_funcoes) == "undefined" || vc_funcoes == null) {
            vc_funcoes = "void(0);";
        }

        if (typeof (vc_class) == "undefined" || vc_class == null) {
            vc_class = "";
        }
        //$('#dialog').dialog("destroy");

        // Dialog Propriedades
        $('#dialog').dialog({
            autoOpen: false,
            modal: true,
            overlay: { backgroundColor: '#FFF', opacity: 0.75 },
            title: vc_title,            
            width: it_width,
            position: "center", 
            hide: "hide",                      
            close: function() { eval(vc_funcoes); },
            dialogClass: vc_class

        });

        //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_class) {
    alertDialogSemButton("<iframe src=\"" + vc_url + "\" width=\"100%\" height=\"" + it_height + "\" style=\"border:none;\" border=\"0\" frameborder=\"no\"></iframe>", vc_title, '', it_width,vc_class);
}

function carregaDialogConteudo(id_div) {
    var obj_div = document.getElementById(id_div);
    var tx_html = obj_div.innerHTML.replace("\n", "");
    var vc_title = null;

    if (obj_div.title.length > 0) {
        vc_title = obj_div.title;
    }


    alertDialog(tx_html, vc_title, '', 700);


}

function carregaDialogPagina(vc_url, vc_title, it_width, it_height) {
    alertDialog("<iframe src=\"" + vc_url + "\" width=\"100%\" height=\"" + it_height + "\" style=\"border:none;\" border=\"0\" frameborder=\"no\" allowtransparency=\"true\"></iframe>", vc_title, '', it_width);
}

function setarFocusCep(txtPrefixCep, itMaxLenght, txtSulfixCep) {
    if (txtPrefixCep.value.length == itMaxLenght) {
        document.getElementById("ctl00_cphContent_tabelaProdutos_txtCepSulfixo").focus();
    }
}

function exibeImagem(id_imagem, vc_acao, vc_tipo_obj) {
    var obj_img = document.getElementById(id_imagem);
    var obj_link = document.getElementById("lk_imagem");

    if (vc_acao == "in") {
        obj_img.style.display = "block";

        if (vc_tipo_obj == "input") {
            obj_link.onmouseover = function() { }
            obj_link.onmouseout = function() { }
        }

    } else if (vc_acao == "out") {
        obj_img.style.display = "none";

        if (vc_tipo_obj == "input") {
            obj_link.onmouseover = function() { exibeImagem('im_codigo_seguranca', 'in', 'img') }
            obj_link.onmouseout = function() { exibeImagem('im_codigo_seguranca', 'out', 'img') }
        }

    }
}


$(document).ready(function(){
    if($(".departamentos map").length > 0){
        var lastDepartamento = $('.departamentos map').prev().attr("src"); 
        if(lastDepartamento.indexOf("Small") == -1){   
            $('.departamentos map area:eq(0)').hover(
                function(){
                    if(lastDepartamento.indexOf("../") == -1){
                        $(this).parent().prev().attr("src","imagens/layout/menuDepartamentosMontanha.png");           
                    }
                    else{
                        $(this).parent().prev().attr("src","../imagens/layout/menuDepartamentosMontanha.png");           
                    }   
                },
                function(){
                    $(this).parent().prev().attr("src",lastDepartamento);
                }
            );   
            
            $('.departamentos map area:eq(1)').hover(
                 function(){
                    if(lastDepartamento.indexOf("../") == -1){
                        $(this).parent().prev().attr("src","imagens/layout/menuDepartamentosCidade.png");           
                    }
                    else{
                        $(this).parent().prev().attr("src","../imagens/layout/menuDepartamentosCidade.png");           
                    }   
                },
                function(){
                    $(this).parent().prev().attr("src",lastDepartamento);
                }
            );   
            
            $('.departamentos map area:eq(2)').hover(
                 function(){
                    if(lastDepartamento.indexOf("../") == -1){
                        $(this).parent().prev().attr("src","imagens/layout/menuDepartamentosKids.png");           
                    }
                    else{
                        $(this).parent().prev().attr("src","../imagens/layout/menuDepartamentosKids.png");           
                    }   
                },
                function(){
                    $(this).parent().prev().attr("src",lastDepartamento);
                }
            );
        }
    }   
});
