function js_start(){
    startList(); // Hack para ie6 do menu drop down
    getTooltip(); // inicia o processo sobre as tooltips (getTooltip.js e MouseCoord.js necessrios)
    oquevcprecisa(); // inicia a navegao do item "o que voc precsia" no menu institucional
    openExternalPages(); //Abre todas as pginas setadas como externas em novas janelas e pop-ups
    /*
    area_cliente_login = document.getElementById('area_cliente_login').value;
    area_cliente_senha = document.getElementById('area_cliente_senha').value;
    navegacao_senha = document.getElementById('navegacao_senha').value;
    
    if(area_cliente_login==''){
        document.getElementById('area_cliente_login').value = 'login';
    }
    if(area_cliente_senha==''){
        document.getElementById('area_cliente_senha').value = 'senha';
    }
    if(navegacao_senha==''){
        document.getElementById('navegacao_senha').value = 'sua senha';
    }
    */
}

window.onload = function(){
    js_start();
}

/*
START (para pginas externas e popups)
*/
function start()
{
    window.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
    window.document.write('<html xmlns="http://www.w3.org/1999/xhtml">')
    window.document.write('<head>');
    window.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
    window.document.write('<title>DirectCall</title>');
    window.document.write('<script language="javascript" src="../js/AC_RunActiveContent.js"></script>');
    window.document.write('<script language="javascript" src="../js/MouseCoord.js"></script>')
    window.document.write('<script language="javascript" src="../js/getTooltip.js"></script>')
    window.document.write('</head>');
    window.document.write('<body onload="js_start()">');
}

/*
STOP (para pginas externas e popups)
*/
function stop(){
    window.document.write('</body>');
    window.document.write('</html>');
}

/*
HACK PARA IE6 DO MENU DROPDOWN
Agradecimentos a Maurcio Sami Silva (www.maujor.com.br)
*/

function startList()
{
    if ( document.all && document.getElementById )
    {
        navRoot = document.getElementById("institucional");
        if ( navRoot )
        {
            for ( var i = 0; i < navRoot.childNodes.length; i++ )
            {
                node = navRoot.childNodes[i];
                if ( node.nodeName == "LI" )
                {
                    node.onmouseover = function() {
                        this.className+=" over";
                    }
                    node.onmouseout = function() {
                        this.className=this.className.replace(" over", "");
                    }
                }
            }
        }
    }
}

/*
PGINAS EXTERNAS
*/

function openExternalPages()
{
    var links = document.getElementsByTagName("A");
    
    for ( var a = 0; a < links.length; a++ )
    {
        var href = links[a].getAttribute("href").split('.com.br/');
        //href = href[1];
        if ( href[1] == 'cidades' )
        {
            links[a].onclick = function()
            {
                popup('http://www.directcall.com.br/cidades/1', 795, 600);
                return false;
            }
        }
    }
    
    for ( var a = 0; a < links.length; a++ )
    {
        if ( links[a].getAttribute('rel') )
        {
            switch ( links[a].getAttribute('rel') )
            {
                case 'popup':
                case '_popup':
                {
                    links[a].setAttribute('title', 'Este link abrirá um pop-up');
                    links[a].onclick = function() {
                        popup(this.getAttribute('href'), 850, 550);
                        return false;
                    }
                    break;
                }
                
                case 'blank':
                case '_blank':
                {
                    links[a].setAttribute('title', 'Este link abrirá uma nova janela');
                    links[a].onclick = function(){
                        window.open(this.getAttribute('href'));
                        return false;
                    }
                    break;
                }
                
                case 'dcsoft':
                case '_dcsoft':
                case 'softweb':
                case '_softweb':
                {
                    links[a].setAttribute('title', 'Este link abrirá o DirectCall SoftWeb');
                    links[a].onclick = function(){
                        popup(this.getAttribute('href'), 785, 535);
                        return false;
                    }
                    break;
                }
                
                case '0800web':
                case '_0800web':
                case '0800ip':
                case '_0800ip':
                {
                    links[a].setAttribute('title', 'Este link abrirá o 0800 IP');
                    links[a].onclick = function() {
                        //popup(this.getAttribute('href'), 690, 410);
                        popup(this.getAttribute('href'), 785, 535);
                        return false;
                    }
                    break;
                }
                
                case 'parent':
                case '_parent':
                {
                    links[a].setAttribute('title', 'Este link abrirá a página na janela anterior');
                    links[a].onclick = function() {
                        window.opener.location.href = this.getAttribute('href');
                        return false;
                    }
                    break;
                }
            }
        }
    }
}

/*
POP-UPS
*/
function popup(url, w, h)
{
    if(!w){ var w = 785; }
    if(!h){ var h = 535; }
    var screenW = screen.width;
    var screenH = screen.height;
    var left = (screenW-w)/2;
    var top = (screenH-h)/2;
    
    window.open(url,'popup2', [
        'width=' + w,
        'height=' + h,
        'top=' + top,
        'left=' + left,
        'scrollbars=yes',
        'status=no',
        'toolbar=no',
        'location=no',
        'directories=no',
        'menubar=no',
        'resizable=no',
        'fullscreen=no'
        ].join(',')
    );
}

function popup2(url, w, h)
{
    if(!w){ var w = 785; }
    if(!h){ var h = 535; }
    var screenW = screen.width;
    var screenH = screen.height;
    var left = (screenW-w)/2;
    var top = (screenH-h)/2;
    
    window.open(url,'popup2', [
        'width=' + w,
        'height=' + h,
        'top=' + top,
        'left=' + left,
        'scrollbars=yes',
        'status=no',
        'toolbar=no',
        'location=yes',
        'directories=no',
        'menubar=no',
        'resizable=no',
        'fullscreen=no'
        ].join(',')
    );
}

/*
MUDA A CLASSE DE DETERMINADO ELEMENTO BASEADO NO SEU ID
*/
function muda_classe(origem, destino) {
    document.getElementById(origem).className=destino;
}

/*
EXIBE UM ELEMENTO BASEADO EM SEU ID
*/
function show(id) {
    document.getElementById(id).style.display = 'block';
}

/*
ESCONDE UM ELEMENTO BASEADO EM SEU ID
*/
function hide(id) {
    document.getElementById(id).style.display = 'none';
}

/*
ESCONDE OU EXIBE UM ELEMENTO BASEADO EM SEU ID E ESTADO
*/
function show_hide(id)
{
    var elemento = document.getElementById(id);
    if ( elemento )
    {
        if ( !elemento.style.display || elemento.style.display == 'none' ) {
            elemento.style.display = 'block';
        } else {
            elemento.style.display = 'none';
        }
    }
}

/*
MUDA O ID DE DE DETERMINADO ELEMENTO
*/
function mudaId(origem, destino) {
    document.getElementById(origem).id = destino;
}

/*
MUDA A CLASSE DE UM ELEMENTO BASEADO EM SEU ID
*/
function mudaClasse(id, classe)
{
    var elemento = document.getElementById(id);
    if ( elemento.className != classe ) {
        elemento.className = classe;
    } else {
        elemento.className = '';
    }
}

/*
FAZ A NAVEGAO DO TEM "O QUE VOC PRECISA"
*/
function oquevcprecisa()
{
    var browser = navigator.appName;
    var r = document.getElementById('oquevcprecisa');
    var retorno = document.getElementById('conteudo');
    if ( r )
    {
        var rs = r.childNodes;
        
        function limpaLinhas() {
            for ( i = 0; i < rs.length; i++) {
                if ( rs[i].tagName=='LI' ) {
                    rs[i].childNodes[2].style.display = 'none';
                    rs[i].childNodes[0].className = '';
                }
            }
        }
        
        for ( a = 0; a < rs.length; a++ )
        {
            if ( rs[a].tagName == 'LI' )
            {
                rs[a].childNodes[2].style.display = 'none';
                rs[a].childNodes[0].onclick = function()
                {
                    limpaLinhas();
                    var href = this.getAttribute('href', 2);
                    href = href.replace(/#/, '');
                    this.id = 'href_' + href;
                    show_hide(href);
                    mudaClasse(this.id, 'aberto');
                    return false;
                }
            }
        }
        
        retorno.onmouseover = function() {
            limpaLinhas();
        }
    }
}


/*
ABRE AS ABAS DO FAQ (PERGUNGAS FREQUENTES);
*/
function faq(categoria, pagina)
{
    document.getElementById('cat1').className = '';
    document.getElementById('cat2').className = '';
    document.getElementById('cat3').className = '';
    document.getElementById(categoria).className = 'aberto';
    
    document.getElementById('operacionais').className = 'faq';
    document.getElementById('mobilidade').className = 'faq';
    document.getElementById('gerais').className = 'faq';
    document.getElementById(pagina).className = 'faq aberto';
    
    faq_pergunta('');
    return false;
}

/*
ABRE AS PERGUNTAS DO FAQ (PERGUNGAS FREQUENTES)
*/
function faq_pergunta(abre)
{
    var p = document.getElementById(abre);
    
    if ( p )
    {
        if ( p.className != 'aberto' ) {
            p.className = 'aberto';
        } else {
            p.className = '';
        }
    }
}


/*
INJETA UM VALOR EM DETERMINADO ELEMENTO
*/
function set_value(elemento, inicial, final)
{
    v = document.getElementById(elemento);
    if ( v.value == '' ) {
        v.value = final;
    }
    if ( v.value == inicial ) {
        v.value = final;
    }
}

/* CONTROLA A PGINA DE VERSES */
function versoes(versao)
{
    document.getElementById("tradicional").style.display = 'none';
    document.getElementById("ver_tradicional").className = '';
    document.getElementById("gateway").style.display = 'none';
    document.getElementById("ver_gateway").className = '';
    document.getElementById("ip").style.display = 'none';
    document.getElementById("ver_ip").className = '';
    
    var aba = "ver_"+versao;
    
    document.getElementById(versao).style.display = 'block';
    document.getElementById(aba).className = 'aberto';
}

/* MENU DE ESTADOS DO BRASIL */
function estados()
{
    var e = document.getElementById('estados');
    for ( a = 0; a < e.childNodes.length; a++ )
    {
        if ( e.childNodes[a].tagName == 'LI' )
        {
            if ( e.childNodes[a].childNodes[0].tagName == 'A' )
            {
                var tabelas = e.childNodes[a].childNodes[0].getAttribute("href", 2);
                tabelas = tabelas.replace(/#/, '');
                show_hide(tabelas);
                show_hide(tabelas);
                e.childNodes[a].childNodes[0].onclick = function()
                {
                    var link = this.getAttribute("href", 2);
                    link = link.replace(/#/, '');
                    show_hide(link);
                    return false;
                };
            }
        }
    }
}

/**/
function show_paises() {
    document.write('<p><a href="#ramalGlobal_testeJa" onclick="hide(\'ramalGlobal_testeJa\'); show(\'ramalGlobal_testeJa_abrir\'); return false">Fechar</a></p>');
}

function hide_paises() {
    document.write('<p><a href="#paises" onclick="hide(\'paises\'); return false">Fechar</a></p>');
}

function show_teste() {
    document.write('<p id="ramalGlobal_testeJa_abrir"><a href="#ramalGlobal_testeJa" onclick="show_hide(\'ramalGlobal_testeJa\'); hide(\'ramalGlobal_testeJa_abrir\'); return false">Clique aqui, teste já!</a></p>');
}

function jump(val) {
    location.href = "http://www.directcall.com.br/" + val.value;
}

