﻿function toogleVisibleWidgetsLogin() {
    var div = document.getElementById('divContainerWidgetsLogin');
    if (div != null) {
        if (div.style.display == 'none') {
            div.style.display = 'block';
        }
        else {
            div.style.display = 'none';
        }
    }
}

function setVisibleWidgetLogin(pDivId, pLiButtonId) {
    var div = document.getElementById('divContainerWidgetsLogin');
    var divsLogin = div.getElementsByTagName('div');
    var lis = $('#' + pLiButtonId).parent().find('li'); //get the li's of the ul

    for (x = 0; x < lis.length; x++) {
        if (lis[x].id == pLiButtonId) {
            lis[x].className = 'selecionado';
        }
        else {
            lis[x].className = '';
        }
    }

    for (x = 0; x < divsLogin.length; x++) {
        if (divsLogin[x].id.indexOf('divLogin') > -1) {
            if (divsLogin[x].id == pDivId) {
                divsLogin[x].style.display = 'block';
            }
            else {
                divsLogin[x].style.display = 'none';
            }
        }
    }
}

function showHtmlMessageBox(pTitle, pMessage, pWidth, pHeight, pOnClosedJavascript) {
    var container = document.getElementById('ThickBoxMessageContent');

    var content = "<div id='thickBoxContent' style='display:none;'><p>" + pMessage + "</p></div>";
    content += "<a href='#TB_inline?first=true&height=" + pHeight + "&width=" + pWidth + "&inlineId=thickBoxContent' id='aThickBox' class='thickboxMessage thickbox' style='display:none;' title='" + pTitle + "'>" + pTitle + "</a>";
    container.innerHTML = content;

    tb_init('a.thickboxMessage');
    imgLoader = new Image(); // preload image
    imgLoader.src = tb_pathToImage;

    if (document.getElementById('aThickBox').dispatchEvent) {
        var e = document.createEvent("MouseEvents");
        e.initEvent("click", true, true);
        document.getElementById('aThickBox').dispatchEvent(e);
    }
    else { document.getElementById('aThickBox').click(); }

    onClosedJavascript = pOnClosedJavascript;
}


function openModalDiv(divname, title) {
    $('#' + divname).dialog({
        autoOpen: true,
        bgiframe: true,
        modal: true,
        draggable: true,
        title: title
    });
    $('#' + divname).dialog('open');
    $('#' + divname).parent().appendTo($("form:first"));
}

function closeModalDiv(divname) {
    $('#' + divname).dialog('close');
}

function tb_init(domChunk){
	$(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;
	tb_show(t,a,g);
	this.blur();
	return false;
	});
}

function tb_showInline(alink) {
    var t = alink.title || alink.name || null;
    var a = alink.href || alink.alt;
    var g = alink.rel || false;
    tb_show(t, a, g);
    this.blur();
    return false;
}


function VerificarCheckBoxSelecionado(NomeControle, Tipo, TextoConfirm) {
    /*
        NomeControle = trecho do nome do grupo de checkboxs
        Tipo = Complementa a mensagem de crítica de seleção
        TextoConfirm = texto para o confirm    
    */

    var objElements = document.getElementsByTagName("input");

    var blnSelecionado = false;
    var blnRetorno = false;

    for (var i = 0; i < objElements.length; i++) {
        if (objElements[i].name.indexOf(NomeControle, 0) > 0) {

            if (objElements[i].checked) {
                blnSelecionado = true;
                break;
            }
        }
    }

    if (blnSelecionado) {
        blnRetorno = confirm(TextoConfirm);
    }
    else {
        // alert("Selecione ao menos um" + Tipo + "!\t");

        showHtmlMessageBox("Atenção", "Selecione ao menos um" + Tipo + "!", 200, 50, '');
        
    }

    return blnRetorno;
}

function Popup(arquivo, largura, altura) {
    var janela = window.open(arquivo, "janela", "width=" + largura + "px,height=" + altura + "px");
    janela.focus();
}

function FCKUpdateLinkedField(id, ieid) {
    try {
        if (typeof (FCKeditorAPI) == "object") {
            var fckInstance = FCKeditorAPI.GetInstance(id);

            if (fckInstance == null) {
                fckInstance = FCKeditorAPI.GetInstance(ieid);
            }

            if (fckInstance == null) {
                fckInstance.UpdateLinkedField();
            }
        }
    }
    catch (err) {

    }
}

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
