﻿/*
CSS Browser Selector v0.3.4 (Sep 29, 2009)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u) { var ua = u.toLowerCase(), is = function (t) { return ua.indexOf(t) > -1; }, g = 'gecko', w = 'webkit', s = 'safari', o = 'opera', h = document.getElementsByTagName('html')[0], b = [(!(/opera|webtv/i.test(ua)) && /msie\s(\d)/.test(ua)) ? ('ie ie' + RegExp.$1) : is('firefox/2') ? g + ' ff2' : is('firefox/3.5') ? g + ' ff3 ff3_5' : is('firefox/3') ? g + ' ff3' : is('gecko/') ? g : is('opera') ? o + (/version\/(\d+)/.test(ua) ? ' ' + o + RegExp.$1 : (/opera(\s|\/)(\d+)/.test(ua) ? ' ' + o + RegExp.$2 : '')) : is('konqueror') ? 'konqueror' : is('chrome') ? w + ' chrome' : is('iron') ? w + ' iron' : is('applewebkit/') ? w + ' ' + s + (/version\/(\d+)/.test(ua) ? ' ' + s + RegExp.$1 : '') : is('mozilla/') ? g : '', is('j2me') ? 'mobile' : is('iphone') ? 'iphone' : is('ipod') ? 'ipod' : is('mac') ? 'mac' : is('darwin') ? 'mac' : is('webtv') ? 'webtv' : is('win') ? 'win' : is('freebsd') ? 'freebsd' : (is('x11') || is('linux')) ? 'linux' : '', 'js']; c = b.join(' '); h.className += ' ' + c; return c; }; css_browser_selector(navigator.userAgent);

function navegarBlank(url) {

    window.open(url, "janela", "");

}

function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {

            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
}

// Somente numeros
function onlyNumber(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;

    if ((parseInt(charCode) >= 48 && parseInt(charCode) <= 57) || (charCode >= 96 && charCode <= 105) || (charCode >= 8 && charCode <= 9)) {
        status = "";
        return true;
    } else {
        status = "Este campo aceita somente números.";
        evt.returnValue = false;
        return false;
    }
}





function showmenu(elmnt) { document.getElementById(elmnt).style.display = "block"; }
function hidemenu(elmnt) { document.getElementById(elmnt).style.display = "none"; }
var fadeInterval = "";
var xxx = 0;
function fadeOut(id, time) {
    clearInterval(fadeInterval);
    fadeInterval = "";
    target = document.getElementById(id);
    alpha = 100;
    timer = time;
    if (xxx > 0) {
        alpha = xxx;
        fadeInterval = setInterval(
              function () {
                  if (alpha <= 0) {
                      clearInterval(fadeInterval);
                      fadeInterval = "";
                      target.style.display = "none";
                  } else
                      setAlpha(id, alpha);

                  alpha -= 10;
              }, timer);
    }
    else
        fadeInterval = setInterval(
          function () {
              xxx = alpha;
              if (alpha <= 0) {
                  clearInterval(fadeInterval);
                  fadeInterval = "";
                  target.style.display = "none";
              } else
                  setAlpha(id, alpha);
              alpha -= 10;
          }, timer);
}

function fadeIn(id, time) {
    clearInterval(fadeInterval);
    fadeInterval = "";
    target = document.getElementById(id);
    target.style.display = "block";
    alpha = 0;
    timer = time;
    setAlpha(id, 0);
    if (xxx > 0) {
        xxx = 0;
        alpha = 0;
        zeraFade();
        fadeIn(id, time)
    }
    else
        if (fadeInterval == "") {
            fadeInterval = setInterval(
                  function () {
                      xxx = alpha;
                      if (alpha >= 100) {
                          clearInterval(fadeInterval);
                          fadeInterval == "";
                      } else
                          setAlpha(id, alpha);
                      alpha += 10;
                  }, timer);
        } else {
            //     checkFadeOut(id,time);
            //     checkFadeIn(id,time);
        }
}
function checkFadeIn(id, time) {
    var xx = setInterval(function () {
        if (fadeInterval == "") {
            clearInterval(xx);
            xx = "";
            fadeIn(id, time);
        }
    }, 1);
}
function checkFadeOut(id, time) {
    var xx = setInterval(function () {
        if (fadeInterval == "") {
            clearInterval(xx);
            xx = "";
            fadeOut(id, time);
        }
    }, 1);
}
function keepFade(id) {
    clearInterval(fadeInterval);
    target = document.getElementById(id);
    target.style.display = "block";
    setAlpha(id, 100);
}
function zeraFade() {
    for (var i = 1; i <= 7; i++) {
        setAlpha('s' + i, 0);
        if (document.getElementById('s' + i) != null)
            document.getElementById('s' + i).style.display = "none";
    }
}
function setAlpha(id, alpha) {
    if (document.getElementById(id) != null) {
        target = document.getElementById(id);
        target.style.filter = "alpha(opacity=" + alpha + ")";
        target.style.opacity = alpha / 100;
    }
}

function showmenu2(elmnt) { document.getElementById(elmnt).style.display = "block"; }
function hidemenu2(elmnt) { document.getElementById(elmnt).style.display = "none"; }

function clickButton(e, buttonid) {

    var evt = e ? e : window.event;

    var bt = document.getElementById(buttonid);

    if (bt) {

        if (evt.keyCode == 13) {

            bt.click();

            return false;

        }
    }
}

// Método que faz canal de busca em outra página //
function fGetRequestXml() {
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) http_request.overrideMimeType('text/xml');
    } else if (window.ActiveXObject) {
        try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { /* Faz nada */ }
        if (!http_request) {
            try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { /* Faz nada */ }
        }
    }
    if (!http_request) alert('Sem suporte há esta funcionalidade');
    else return http_request;
}

// Conteudo //
function fAjax_ConteudoDinamicoEstatistica(xmlHttp, url) {
    xmlHttp.open("GET", url, false);
    xmlHttp.send(null);
}

function limparPadrao(campo) {
    if (campo.value == campo.defaultValue) {
        campo.value = "";
    }
}

function escreverPadrao(campo) {
    if (campo.value == "") {
        campo.value = campo.defaultValue;
    }
}


function disableEnterKey(e) {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; //firefox     

    return (key != 13);
}


function Formatadata(Campo, teclapres) {
    var tecla = teclapres.keyCode;
    var vr = new String(Campo.value);
    vr = vr.replace("-", "");
    tam = vr.length + 1;
    if (tecla != 8) {
        if (tam == 6)
            Campo.value = vr.substr(0, 5) + '-' + vr.substr(5, 5);
    }
}


function MascaraCPF(campo) {
    var vr = new String(campo.value);
    vr = vr.replace(".", "");
    vr = vr.replace("/", "");
    vr = vr.replace("-", "");
    tam = vr.length + 1;
    if (tam == 4)
        campo.value = vr.substr(0, 3) + '.';
    if (tam == 7)
        campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.';
    if (tam == 11)
        campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(7, 3) + '-' + vr.substr(11, 2);
}

function MascaraCNPJ(campo) {
    var vr = new String(campo.value);
    vr = vr.replace(".", "");
    vr = vr.replace("/", "");
    vr = vr.replace("-", "");
    tam = vr.length + 1;
    if (tam == 3)
        campo.value = vr.substr(0, 2) + '.';
    if (tam == 6)
        campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.';
    if (tam == 10)
        campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
    if (tam == 15)
        campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);

}
var servicoProx = 1;
function MudaServicoProx(pref, tot) {
    if (servicoProx < tot) {
        servicoProx++;
        for (var i = 1; i <= tot; i++) {
            div = pref + i;
            document.getElementById(div).style.display = "none";
            if (servicoProx == i) {
                document.getElementById(div).style.display = "block";
            }
        }
    }
}

function MudaServicoAnt(pref, tot) {
    if (servicoProx > 1) {
        servicoProx--;
        for (var i = tot; i >= 1; i--) {
            div = pref + i;
            document.getElementById(div).style.display = "none";
            if (servicoProx == i) {
                document.getElementById(div).style.display = "block";
            }
        }
    }
}

function validaCaracter(val) {
    var c = val.value.split('');
    var reg = /[a-z0-9\s]/gi;
    var v = '';
    for (i = 0; i < c.length; i++) {
        bo = c[i].match(reg);
        if (bo) {
            v += c[i];
        }
    }
    val.value = v;
    //alert(reg.test(fromCharCode(key)));
}
function validaDominioFull(val) {
    var c = val.value.split('');
    var reg = /[a-z0-9\.\-]/gi;
    var v = '';
    for (i = 0; i < c.length; i++) {
        bo = c[i].match(reg);
        if (bo) {
            v += c[i];
        }
    }
    val.value = v;
    //alert(reg.test(fromCharCode(key)));
}

function validaDominio(val) {
    // Torna o valor em array //
    var c = val.value.split('');
    var reg = /([a-z0-9\-])/gi;
    var v = '';
    for (i = 0; i < c.length; i++) {
        bo = c[i].match(reg);
        if (bo) v += c[i];

    }
    val.value = v;
}

function fechar_floater() {
    if (document.getElementById('Floater') != null) {
        document.getElementById('Floater').style.display = 'none';
        document.getElementById('Floater_fechar').style.display = 'none';
    }
}

function fIdentificacaoAcesso(pActionPC, pActionWM) {
    if (document.forms[0].rdoTipoAcesso[0].checked) {
        fLogarPainelControle(pActionPC);
    } else {
        fLogarWebMail(pActionWM);
    }
}

function fLogarPainelControle(pAction) {
    var vOldAction = document.forms[0].action;
    document.forms[0].action = pAction;
    document.forms[0].target = '_blank';
    document.forms[0].submit();
    document.forms[0].target = '';
    document.forms[0].action = vOldAction;
}

function fLogarWebMail(pAction) {
    document.forms[0].ctl00$MPH$txtUserName.value = document.forms[0].pCustomerPorta_Login.value;
    document.forms[0].ctl00$MPH$txtPassword.value = document.forms[0].pCustomerPorta_Senha.value;
    document.forms[0].__EVENTTARGET.value = 'ctl00$MPH$LoginImageButton';
    var vOldAction = document.forms[0].action;
    document.forms[0].action = pAction;
    document.forms[0].target = '_blank';
    document.forms[0].submit();
    document.forms[0].target = '';
    document.forms[0].action = vOldAction;
}

function tipoAcesso() {
    var rdo = document.getElementsByName("rdoTipoAcesso");
    for (i = 0; i < rdo.length; i++) {
        if (rdo[i].checked)
            if (rdo[i].value == 'WEBMAIL') {
                document.getElementById("divPainel").style.display = 'none';
                document.getElementById("divWeb").style.display = 'block';
            }
            else {
                document.getElementById("divPainel").style.display = 'block';
                document.getElementById("divWeb").style.display = 'none';
            }
    }
}

function retornaQtdeMaxima(c, v) {
    if (parseInt(c.value) > parseInt(v)) {
        alert('Quantidade máxima permitida: ' + v);
    }
}
