﻿///////////////////////////////////////////////////////////////////////////////////////////////////////////
function AlterBackgroundColor(objeto, color1, color2) 
{
    if (document.getElementById(objeto).style.backgroundColor == color2) 
    {
        document.getElementById(objeto).style.backgroundColor = color1;
    }
    else 
    {
        document.getElementById(objeto).style.backgroundColor = color2;
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function AlterBackgroundColorMenuHome(objeto1,objeto2, color1, color2) {
    if (document.getElementById(objeto2).style.backgroundColor == color2) {
        document.getElementById(objeto1).style.backgroundColor = color1;
        document.getElementById(objeto2).style.backgroundColor = color1;
    }
    else {
        document.getElementById(objeto1).style.backgroundColor = color2;
        document.getElementById(objeto2).style.backgroundColor = color2;
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function AlterBackgroundImage(objeto, image1, image2) {
    if (document.getElementById(objeto).style.backgroundImage == image2) {
        document.getElementById(objeto).style.backgroundImage = image1;
        
    }
    else {
        document.getElementById(objeto).style.backgroundImage = image2;
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function AlterColor(objeto, color1, color2) {
    if (document.getElementById(objeto).style.color == color2) {
        document.getElementById(objeto).style.color = color1;
    }
    else {
        document.getElementById(objeto).style.color = color2;
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Mascaras(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; }
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//Campos de busca (Limpa no GotFocus() e Reescreve no LostFocus())
function TextOnFocus(txt) {
    txt.value = "";
}
function TextLostFocus(txt, texto) {
    if (txt.value == "") {
        txt.value = texto;
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//Mostra o Loading antes do processamento, o hidden deverá ser passado após na página mesmo.
function ShowObjeto(objeto) {

    document.getElementById(objeto).style.visibility = "visible";
}
//MENU Click /////////////////////////////////////////////////////////////////////////////////////////////
function MenuClick(objeto) 
{
    if (document.getElementById(objeto).style.display == "none") 
    {
        document.getElementById(objeto).style.display = "block";
    }
    else 
    {
        document.getElementById(objeto).style.display = "none";
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function openWin(URL, titulo, w, h) {
    /*********************************************************************************
    openWin( URL, objeto, width, height );
    Abre jánela nova no centro da tela
    Exemplo de como chamar a função:
    <a href="#" onclick="return openWin('www.site.com.br','nome_da_Janela', 500, 500)">link</a>
    ***********************************************************************************/
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=auto';

    var win = window.open(URL, titulo, winprops);
    return win;
}    
