
//reloads the window if Nav4 resized

function MM_reloadPage(init) { //OK
    if (init==true) with (navigator) {
        if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
            document.MM_pgW=innerWidth;
            document.MM_pgH=innerHeight;
            onresize=MM_reloadPage;
        }
    }
    else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
        location.reload();
}
MM_reloadPage(true);

//LOGIN HOME
function Mandic_change_FormAction(selObj) {
    document.login_form.action = selObj.options[selObj.selectedIndex].value;
    if ( selObj.selectedIndex > 1 ) {
        document.login_form.cb_auto_pass.value = "true";
    }else{
        document.login_form.cb_auto_pass.value = "0";
    }
}

// used in the body onload=tryAutoLogin
function tryAutoLogin() {
//  if ( document.login_form.auto_login_on.value != "" ) {
    if ( false ) { // para não proceder com auto login
        if ( confirm('Proceder com autologin?') ) {
            window.location = document.login_form.auto_login_on.value;
        }else{
            document.cookie = "autologin_user= ; path=/ ; domain=mandic.com.br ; expires=20";
            document.cookie = "autologin_proto= ; path=/ ; domain=mandic.com.br ; expires=20";
        }
    }
    document.login_form.login_username.focus();
}

//Login para o Webmail-beta
function validateBeta() {
  var user = document.getElementById('login_username').value;
  var pass = document.getElementById('secretkey').value;
  var u = document.getElementById('username');
  var p = document.getElementById('password');
  u.value = user;
  p.value = pass;
}

//Adicina url nos Favoritos
function addFav(){
    var url  = "http://www.mandic.com.br";
    var title  = "Mandic";
    if (window.sidebar){
        window.sidebar.addPanel(title, url,"");
    }else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }else if(document.all){
        window.external.AddFavorite(url, title);
    }
}

function adicionaPaginaInicial(){
    var pag_ini = 'http://www.mandic.com.br';
    document.body.style.behavior='url(#default#homepage)';
    document.body.setHomePage(pag_ini);
}

var titulodajanela;//guarda o titulo da janela

function efeitoCarregandoPeq(texto)
{
    var textoload = (texto) ? texto : 'carregando...';
    var img = '/imagens/icones/loadingPeq.gif';
    var imgLoadHeight = 12;

    return  '<div><img src="'+img+'" height="'+imgLoadHeight+'"/><span style="font-weight:normal;margin-top:0px">&nbsp;'+textoload+'</span></div>';
}

function efeitoCarregando(texto)
{
    var textoload = (texto) ? texto : 'carregando...';
    var textoload = 'carregando...';
    var img = '/imagens/icones/carregando2.gif';
    var imgLoadHeight = 31;
    return  '<div style=" _position: relative;_margin-left:-'+imgLoadHeight+'px;display:table;vertical-align:middle;height:100%;">' +
                '<div style=" _position: absolute; _top: 50%;display:table-cell;vertical-align:middle;height:'+imgLoadHeight+'px"><img src="'+img+'"/></div>'+
                '<div style=" _position: absolute; _top: 50%;_margin-left:'+imgLoadHeight+'px;display:table-cell;vertical-align:middle;height:'+imgLoadHeight+'px"><span style="font-weight:normal;">'+textoload+'</span></div>'+
            '</div>';
}

function loadDivVerDetalhes(){
    return '<table class="transparent_class" width="100%" border="0" cellpadding="0" cellspacing="0">'+
              '<tr><td>'+
                    '<table height="34" width="100%" background="/imagens/layout/menutopocentro.gif" border="0" cellpadding="0" cellspacing="0">'+
                        '<tr><td width="7"><img src="/imagens/layout/menutopoesq.gif" alt=""></td>'+
                            '<td id="titulodajanela" background="/imagens/layout/menutopocentro.gif">carregando...</td>'+
                            '<td id="fechar"><a href="javascript:void(0);" onclick="closePopDiv(divId);" class="bt_voltar"></a></td>'+
                            '<td width="7"><img src="/imagens/layout/menutopodir.gif" alt="">' +
                        '</td></tr>'+
                    '</table>'+
              '</td></tr>'+
              '<tr>'+
                '<td class="fundobranco">'+
                    '<table id="conteudo_borda" cellpadding="0" cellspacing="0">'+
                        '<tr><td><img src="/imagens/layout/curvasupesq.gif" alt=""></td>'+
                            '<td background="/imagens/layout/tracotopotab.gif"></td>'+
                            '<td><img src="/imagens/layout/curvasupdir.gif" alt=""></td>'+
                        '</tr>'+
                        '<tr><td height="8" width="8" background="/imagens/layout/tracolatesqtab.gif"></td>'+
                            '<td id="popup_conteudo" class="verdana_666666">'+
                                '<div>&nbsp;</div>'+
                                '<div class="conteudo_verdetalhe_load" align="center">'+
                                       efeitoCarregando()+
                                '</div>'+
                                '<div id="irprotopoPopup" class="irprotopo"><a href="javascript:void(0);" onclick="irProTopoPopup();" class="link_irprotopo">topo</a></div>'+
                            '</td>'+
                            '<td height="8" width="8" background="/imagens/layout/tracolatdirtab.gif">&nbsp;</td>'+
                        '</tr>'+
                        '<tr><td><img src="/imagens/layout/curvainfesq.gif" alt=""></td>'+
                            '<td background="/imagens/layout/tracobasetab.gif"></td>'+
                            '<td><img src="/imagens/layout/curvainfdir.gif" alt=""></td>'+
                        '</tr>'+
                    '</table>'+
                '</td>'+
              '</tr>'+
            '</table><div>&nbsp;</div><div>&nbsp;</div>';
}

//Globais
var iddivpopup = 'popup_gde'; //nome base dos IDs das divs
var idsdivpopup = new Array(); //coleção de IDs de divs

function showPopDiv(id, url)
{
    var count = idsdivpopup.length;
    idsdivpopup[count] = iddivpopup + count;
    var id = idsdivpopup[count];

    //Cria nova div popup_gde
    if(!$(id)) $('principal').innerHTML += '<div id="'+id+'" class="popupGdeClass"></div>';

    $(id).innerHTML = loadDivVerDetalhes(); //load
    mostrarPopupGde(id);
    var myAjax = new Ajax.Updater(id, url, {method: 'get'});
    
    if(id == iddivpopup + '0') ocultarConteudoGeral();
    mostraOcultaCxSelect(); //PRA OCULTAR OS COMBOX BUG:IE
    irProTopo();
}


function closePopDiv(id)
{
    divId = null;
    //if(idsdivpopup.length == 0) return window.location.href='index.php';//retorna para Home
    switch(id){
        case 'confir_envio': fechaEnvioProposta(); break;
        case 'divverdetalhes':closeDivVerDetalhes(); break;
        case 'divverdetalhes0':closeDivVerDetalhes0(); break;
        default:
            var id = idsdivpopup.pop(); //retorna e exclui o ultimo id do array
            mostraOcultaCxSelect(); //PRA OCULTAR OS COMBOX BUG:IE          
            if(id == iddivpopup + '0') mostrarConteudoGeral();
            ocultarPopupGde(id);
            if(id == 'popup_gde0')mostraHomeDestaquesNoticias();
            $(id).innerHTML = ''; //limpa o conteudo a DIV
    }
}

//verifica o navegador BUG:IE
function verificarBrowserMSIE(versao)
{
    var versoes = versao ? versao : new Array("MSIE 5","MSIE 6"); //acrescimo do "MSIE 7" a function showPopDivInst() n�o funfa no IE7

    for (var i = 0; i < versoes.length; i++){
        if( navigator.appVersion.indexOf(versoes[i]) > -1 )
            return true;
    }
    return false;
}

//PRA MOSTRAR E OCULTAR O SELECT OPTION COMBOX DO LOGIN BUG:IE
function mostraOcultaCxSelect(){
    if( verificarBrowserMSIE() && ($(iddivpopup+'1').style.display != 'block') ){
        var i = 0;
        if($('divverdetalhes')){
            var displayid = $('divverdetalhes').style.display;
            var i = (displayid != 'none') ? 1 : i;
        }
        var periodos = document.getElementsByTagName('select');
        for( i; i < periodos.length; i++ ){
            var visibilidade = periodos[i].style.visibility;
            var valor = ( visibilidade != 'hidden' ) ? 'hidden' : 'visible';
            periodos[i].style.visibility = valor;
        }
    }
}

var divId = null; //guarda o id da div aberta 
function divVerDetalhes( layout, url)
{
    var id = 'divverdetalhes';
    divId = id;
    var nomedaclasse;

    $(id).innerHTML = loadDivVerDetalhes(); //Loading
    var myAjax = new Ajax.Updater(id, url, {method: 'get'});
    posicaoDaDivVerDetalhes(id,layout);//posiciona a DIV divverdetalhes
    
    ocultaHomeDestaquesNoticias();
    closeDivVerDetalhes0();
    mostrarPopupGde(id);
    mostraOcultaCxSelect(); //PRA OCULTAR OS COMBOX BUG:IE
}

function posicaoDaDivVerDetalhes(id,layout){
    var nomedaclass = null;
    if(layout == 'voce'){
        nomedaclasse = 'verdetalhes_peqvc';
        if($('assinatura_conteudo'))$('assinatura_conteudo').style.display = 'none';
    } else {
        nomedaclasse = 'verdetalhes_peq';
        if($('proposta_conteudo'))$('proposta_conteudo').style.display = 'none';
    }   
    if(nomedaclasse) $(id).className = nomedaclasse;
}

function divVerDetalhes0( layout, url)
{
    if( $('divverdetalhes') ){
        if( !$('divverdetalhes').innerHTML )return showPopDiv('popup_gde', url);
    }        
    if( !$('divverdetalhes0') || window.location.search )  return showPopDiv('popup_gde', url);
    
    var id = 'divverdetalhes0';
    divId = id;
    var nomedaclasse;
    
    $(id).innerHTML = loadDivVerDetalhes(); //Loading
    var myAjax = new Ajax.Updater(id, url, {method: 'get'});
    posicaoDaDivVerDetalhes(id,layout);//posiciona a DIV divverdetalhes0
    mostrarPopupGde(id);
}

function closeDivVerDetalhes()
{
    if($('assinatura_conteudo'))$('assinatura_conteudo').style.display = 'block';
    if($('proposta_conteudo'))$('proposta_conteudo').style.display = 'block';

    mostraOcultaCxSelect();//PRA OCULTAR OS COMBOX BUG:IE
    mostrarConteudoGeral();
    ocultarPopupGde('divverdetalhes');
    mostraHomeDestaquesNoticias();
    $('divverdetalhes').innerHTML = ''; //limpa o conteudo a DIV

}

function closeDivVerDetalhes0()
{
    if( $('divverdetalhes0') ){
        divId = 'divverdetalhes';
        $('divverdetalhes0').innerHTML = '';
        $('divverdetalhes0').style.display = 'none'; 
    }
}


function showPopDivDestaques(div_id, url)
{
    if(url.indexOf('http') == 0){
        if(url.indexOf('http://www.mandic.com.br') == 0) window.location.href = url;
        else window.open(url);
    }else if(url.indexOf('www.') == 0){
        window.open('http://'+url);
    }else{
        if( $('divverdetalhes') ){
            if( $('divverdetalhes').style.display != 'none' )
                closeDivVerDetalhes();
        }
        if( $('divverdetalhes0') ){
            if( $('divverdetalhes0').style.display != 'none' )
               closeDivVerDetalhes0();
        }
        if( url.indexOf('&blank=true') == -1 ) url += '&blank=true';
        
        divId = null;
        showPopDiv(false, url);
        ocultaHomeDestaquesNoticias();
    }
}


//Mostra conteudo oculto ou chama do DB em uma lista de itens
function showHideContent(id, url)
{
    var el_content = $(id);
    if($('bt_'+ id )) var el_botao = $('bt_'+ id );
    var styleDisplay = el_content.style.display;

    if( styleDisplay != 'block'){
        var display = 'block';
        var classe = 'bt_fechar';    
        if( (el_content.innerHTML == '') && (url != undefined) ){
            var textoload = 'carregando...';
            var img = '/imagens/icones/carregando2.gif';
            var imgLoadHeight = 17;
            var imgLoadWidth = 17;
            el_content.innerHTML = '<p><img src="'+img+'" height="'+imgLoadHeight+'" width="'+imgLoadWidth+'"/> '+textoload+'</p>';
            var myAjax = new Ajax.Updater(id, url, {method: 'get'});
        }
    }else{
        var display = 'none';
        var classe = 'bt_saibamais';
    }   
    if($('bt_'+ id )) el_botao.className = classe;
    el_content.style.display = display;
}
function EffectPulsate(id){ new Effect.Pulsate(id);}

//oculta destaques e noticias na home
function ocultaHomeDestaquesNoticias(id)
{
    if( $('home_destaques') && $('home_noticias') ){
        $('box_center').style.visibility = 'hidden';
        //$('box_center').style.display = 'none';
        
        var browser = Array("MSIE 5","MSIE 6","MSIE 7");
        var zindex = '0';
        if ( verificarBrowserMSIE(browser) ) var zindex = '-1';
        $('left_menu').style.zIndex = zindex;
        $('right_menu').style.zIndex = zindex;

        $('home_destaques').style.display = 'none';
        $('home_noticias').style.display = 'none';
        $('footer').style.display = 'none'; 
    }
}

function mostraHomeDestaquesNoticias(id)
{
    if( $('home_destaques') && $('home_noticias') ){
        $('box_center').style.visibility = 'visible';
        //$('box_center').style.display = 'block';
        $('left_menu').style.zIndex = '50';
        $('right_menu').style.zIndex = '50';

        $('home_destaques').style.display = 'block';
        $('home_noticias').style.display = 'block';
        $('footer').style.display = 'block';
    }
}

function ocultarConteudoGeral(id)
{
    var id = id ? id : 'conteudo_geral';
    if($(id))
        $(id).style.display = 'none';
        //new Effect.Fade(id);
}

function mostrarConteudoGeral(id)
{
    var id = id ? id : 'conteudo_geral';
    if($(id))
        $(id).style.display = 'block';
        //new Effect.Appear(id);
}

function ocultarPopupGde(id)
{
    var id = id ? id : 'popup_gde0';
    if($(id))
        $(id).style.display = 'none';
        //new Effect.Fade(id);

    if((id.indexOf('popup_gde') == 0) && (id != 'popup_gde0')){
        var ids = Array();
        var count = idsdivpopup.length;
        ids = idsdivpopup[count-1];
        $(ids).style.display = 'block';
    }
}

function mostrarPopupGde(id)
{
    var id = id ? id : 'popup_gde0';
    if($(id))
        $(id).style.display = 'block';
        //new Effect.Appear(id);

    if((id.indexOf('popup_gde') == 0) && (id != 'popup_gde0')){
        var ids = Array();
        var count = idsdivpopup.length;
        ids = idsdivpopup[count-2]; //id da janela anterior 
        $(ids).style.display = 'none';

    }
}

function elementoId(id)
{
    return  $(id) ? $(id) : null;
}

var tecladoPopup = null;
function popteclado() {
    if ( tecladoPopup != null ) {
        tecladoPopup.close();
    }
    tecladoPopup = window.open("/teclado_virtual/teclado.php","teclado","toolbar=no,location=no,scrollbars=no,width=503,height=140,left=0,top=0");
}

// TECLADO VIRTUAL
function popupteclado(form_name,campo_name,close)
{
  if (close == null){close = false;}
  if (close == 'true'){
      window.open("/src/teclado.php?form_name="+form_name+"&campo_name="+campo_name+"&close=true","teclado","toolbar=no,location=no,scrollbars=no,width=503,height=140,left=0,top=0");
  }else{
      window.open("/src/teclado.php?form_name="+form_name+"&campo_name="+campo_name,"teclado","toolbar=no,location=no,scrollbars=no,width=503,height=140,left=0,top=0");
  }
}

//ASSINATURA

function Pagamento(cartao,boleto){
    
    if(!cartao && !boleto) {
        document.getElementById('fop_display').style.display = "block";
        return;
    }
    
    if(cartao) {
        document.getElementById('fop_display').style.display = "none";
        document.getElementById('cartao_display').style.display = "block";
    }
        
    if(boleto) {
        document.getElementById('fop_display').style.display = "none";
        document.getElementById('boleto_display').style.display = "block";
    }
}

function formaPagamento(on, off)
{
    hideElement(off+'_display');
    showElement(on+'_display');
}

function updateUsername(button)
{
    var username = document.getElementById('username');

    if ( username != null ){
        username.value=button.value;
        if ( username.value == '' )
            username.focus();
    }
}

/*
 * Termos de Contrato
 */
function lerTermosContrato(li_contrato, salva ){
    if( !li_contrato && salva ){
        verTermosContrato();
    }
    return false;
}

function verTermosContrato()
{
    //efeitoCarregandoPagina(id); //ocorre erro no IE6
    document.getElementById('vercontrato_vlr').checked = true;

    var id = 'termos_contrato';
    //var url = 'index.php?c=assinaturas&action=termos_contrato&blank=true';
    //var myAjax = new Ajax.Updater(id, url, {method: 'get'});

    //OCULTA DIVs
    document.getElementById('barra_close_p').style.display = 'none';
    document.getElementById('assina_lista_produtos').style.display = 'none';

    document.getElementById('assina_first').style.visibility='hidden';
    document.getElementById('assina_div').style.visibility='hidden';

    //MOSTRA DIVs
    document.getElementById('barra_close_c').style.display = 'block';
    document.getElementById('assina_contrato').style.display = 'block';
    document.getElementById(id).style.display = 'block';

    //ALTERA O TITULO DA JANELA
    titulodajanela = document.getElementById('titulodajanela').innerHTML;
    var novotitulo = document.getElementById('assinasubtitulocontrato').innerHTML;
    document.getElementById('titulodajanela').innerHTML = novotitulo;
}

function voltarAssinarListaProdutos()
{
    document.getElementById('vercontrato_vlr').checked = false;
    var id = 'termos_contrato';

    //OCULTA DIVs
    document.getElementById(id).style.display = 'none';
    document.getElementById('barra_close_c').style.display = 'none';
    document.getElementById('assina_contrato').style.display = 'none';

    //MOSTRA DIVs
    document.getElementById('barra_close_p').style.display = 'block';
    document.getElementById('assina_lista_produtos').style.display = 'block';
    document.getElementById('assina_first').style.visibility = 'visible';
    document.getElementById('assina_div').style.visibility = 'visible';

    //VOLTA O TITULO DA JANELA
    document.getElementById('titulodajanela').innerHTML = titulodajanela;

    return false;
}

function euSouCliente(cadastroOk)
{
    //return;
    var login = document.getElementById('cliente_sim').checked;
    var cadastro = document.getElementById('cliente_nao').checked;

    if(login || cadastro){

        var id_dadoslogin = 'assina_dadoslogin';
        var id_cadastro = 'assina_cadastro';
        var id_login = 'assina_login';
        var div_login_check = 'soucliente_sim';
        var div_cadastro_check = 'soucliente_nao';

        var id_cadastrologin = id_cadastro;//(cadastroOk) ? id_dadoslogin : id_cadastro;

        if(login){
            mostra_id = id_login; 
            oculta_id = id_cadastrologin;
            oculta_id1 = div_login_check;
            mostra_id1 = div_cadastro_check;
        }else{
            mostra_id = id_cadastrologin;
            oculta_id = id_login;
            oculta_id1 = div_cadastro_check;
            mostra_id1 = div_login_check;
            //document.getElementById('assinar_cadastro_bt').style.display = "block";
        }
        showElement(mostra_id1);
        document.getElementById(mostra_id).style.display = "block";
        document.getElementById(oculta_id).style.display = "none";
        document.getElementById(oculta_id1).style.display = "none";
    }
}

//PROPOSTA CONFIRMACAO E ENVIO
function envioProposta(validacao,confirmacao)
{
    var popupId = 'confir_envio';
    //proposta_conteudo

    if(validacao == 1 || confirmacao == 1){

    $(popupId).style.display = "block";
    $('proposta_conteudo').style.display = "none";
//      $('propos_botoes').style.display = "none";
//      $('barra_close').style.display = "none";
//      $('propos_produtos').style.display = "none";
//      $(popupId).style.display = "block";
    }
    if(confirmacao == 1) mensagemDeEnvio();
    var titulo = $('titulodajanela');
    if(titulo) titulo.innerHTML = 'Confirma&ccedil;&atilde;o de envio';

    divId = popupId; //divId variavel global

//  var fechar = $('fechar');
//  if(fechar) fechar.innerHTML = "<a href=\"javascript:void(0);\" onclick=\"closePopDiv('" + popupId + "');\" class=\"bt_voltar\"></a>";
}

function fechaEnvioProposta()
{
    $('proposta_conteudo').style.display = "block";
    $('confir_envio').style.display = "none";

//  $(id).style.display = 'none';
//  $('propos_produtos').style.display = "block";
//  $('propos_botoes').style.display = 'block';
//  $('barra_close').style.display = 'block';
}

function mensagemDeEnvio()
{
    var id = 'confir_envio_cont';
    var url = 'index.php?c=propostas&action=finaliza&blank=true';
    var myAjax = new Ajax.Updater(id, url, {method: 'get'});

    document.getElementById('barra_close').style.display = "none";
    document.getElementById('fechar').innerHTML = '<a href="index.php" class="bt_fechar">';
}

function hideElement(id)
{
    var ocultar = document.getElementById(id);
    if (ocultar)
        ocultar.style.display = "none";
        //new Effect.BlindUp(id);
}

function showElement(id)
{
    var mostrar = document.getElementById(id);
    if (mostrar)
        new Effect.Appear(id);
        //mostrar.style.display = "block";
        //colorElements(id);
}

function validarPlanoPagamento(lista_valida)
{
    if(!lista_valida){
        alert('Para prosseguir é necessário assinar um produto mandic:mail.');
        return false;       
    }
    
    var form = document.getElementById('form_assinar');
    var li_aceito = document.getElementById('li_aceito');
    var vercontrato = document.getElementById('vercontrato_vlr');
    var planopagamento = true;

    //alert('li_aceito.checked='+li_aceito.checked);

    for(i=0; i < form.length; i++) {
        if(form.elements[i].value == '...'){
            planopagamento = false;
            form.elements[i].focus();
        }
    }
    if( planopagamento ) {
        //if( vercontrato.checked && !li_aceito.checked){
        if( !li_aceito.checked){
            alert('Para continuar é necessário ler e aceitar os termos do contrato!');
            verTermosContrato();
            li_aceito.focus();
            return false;
        }
        vercontrato.checked = true;
        return verTermosContrato();
    }else{
        //if(vercontrato.checked){
        var texto = unescape('Por favor, preencha todos campos do plano de pagamento com uma das opções de pagamento');
        alert(texto);
        //if( li_aceito.checked ){
            voltarAssinarListaProdutos();
        //}
        return false;
    }
}

function irProTopo()
{
    window.scroll(0,0); //window.location.href = "#";
}

function MostrairProTopo()
{
    if( ((document.body.scrollHeight + 202) > screen.height)&& $('irprotopo'))
        $('irprotopo').style.display = 'block';
        //window.document.writeln('<div id="irprotopo"><a href="javascript:void(0)"; onclick="irProTopo()" class="link_irprotopo">topo</a></div>');
    return null;
}

function irProTopoPopup()
{
    var count = idsdivpopup.length -1;
    var idscrollpopup = 'scrollpopup'+ count+1;
    var divpopup = idsdivpopup[count];
    var divpopup = $(idsdivpopup[count]) ? divpopup : 'divverdetalhes';

    var texto = document.getElementById(divpopup).innerHTML;
    texto = texto.replace('<div class="conteudo_verdetalhe">','<div id="'+idscrollpopup+'" class="conteudo_verdetalhe">')
    document.getElementById(divpopup).innerHTML = texto;
    if($(idscrollpopup)) document.getElementById(idscrollpopup).scrollTop = 0;
    irProTopo();
}

//VALIDAÇÂO DE FORMULARIO

//IDENTIFICAÇÂO - CRIANDO LOGIN
function confirmarSenha()
{
    var val_password = document.getElementById('senha').value;
    var val_password_c = document.getElementById('senha_conf').value;

    if ( !val_password_c && !val_password){
    return null;
    }

    if ( !val_password_c ){
        document.getElementById('psw').innerHTML = '<span class="verdana_FC8200">*</span>';
    return null;
    }

    if ( val_password == val_password_c ){
        document.getElementById('psw').innerHTML = '<span class="form_valido">Ok</span>';
    }else{
        document.getElementById('psw').innerHTML = '<span class="form_invalido">Senha não confere!!!</span>'
        document.getElementById('senha_conf').focus();
    }
}

function isValidCreditCardNumber() {
    var numCartao = document.getElementById('n_cartao').value;
    numCartao = numCartao.split(' ').join('');
    document.getElementById('n_cartao').value = numCartao; 
    
    var numString;
    var soma = 0;
    
    //Cartão com sequencias de caracteres menor ou igual a 15 dígitos
    if (numCartao.length <= 15) {
       for(var i = 0; i <= numCartao.length; i++) {
        numString = (numCartao.substring(i,i+1));
        if (numString != "") {
            if (i % 2 == 0) {
                 soma += (parseInt(numString) * 1);
            } else {
              if ((parseInt(numString) * 2) > 9) {
                 soma += ((parseInt(numString) * 2) - 9);
               } else {
                 soma += ((parseInt(numString) * 2));
               }
            }
        }
      }
    }
    
    //Cartão com sequencias de caracteres maior ou igual a 16 dígitos
    if (numCartao.length >= 16) {
       for(var i = 0; i <= numCartao.length; i++) {
          numString = (numCartao.substring(i,i+1));
          if (numString != "") {
              if (i % 2 == 0) {                            
                 if ((parseInt(numString) * 2) > 9) {
                   soma += ((parseInt(numString) * 2) - 9);
                 } else {
                   soma += ((parseInt(numString) * 2));
                 }
              } else {
                  soma +=(parseInt(numString) * 1);
              }
          }
        }
   }

   if (soma % 10 == 0) {
      return true;
   } else {
      alert("Cartão de crédito inválido! Por favor verifique se digitou corretamente.");
      return false;
   }
}


function onLoadDivPopUp()
{
    var urlParam = new Array(); 
    var paramVar = new Array();

    var param = new Array();
    param.c=null;
    param.action=null;
    param.ver=null;
    param.itemid=null; 
    param.mandic=null;
    param.cons=0;
    param.id=null; 

    var c = null;
    var action = null;
    
    var urlString = window.location.search;
    urlString= urlString.replace('?','');
    urlParam = urlString.split('&');

    for(var i=0; i< urlParam.length; i++){
       paramVar = urlParam[i].split('=');
       param[paramVar[0]] = paramVar[1];
    }   
    if(param.cons=='pf') param.cons = 1;
    if(param.cons=='pj') param.cons = 2;
    
    if(!param.itemid || !param.ver)
        return paginasAntigas(param);

    switch(param.c){
        case 'produtos' : 
              c = param.c;
              action = param.ver ? param.ver : 'ver_detalhes';
              break;

        case 'mandicas' : 
              c = param.c;
              action = param.ver ? param.ver : 'ver_dica';
              break;

        case 'institucionais' : 
              c = param.c;
              action = param.ver ? param.ver : 'ver_institucional';
              break; 

        case 'soamandictem' : 
              c = param.c;
              action = param.ver ? param.ver : 'ver_detalhes';
              break; 

       default:
              c = 'produtos';
              action = param.ver ? param.ver : 'ver_detalhes';
              break;       
    }
    var url = 'index.php?c='+c+'&action='+ action +'&id='+ param.itemid +'&cons='+ param.cons + '&blank=true';
    if( !param.c && param.cons) onLoaddivVerDetalhes(param.cons, url); 
    else showPopDivDestaques('popup_gde', url);
}


function onLoaddivVerDetalhes(cons, url)
{
    var divCons =  (cons == 1) ? 'voce' : 'empresa';
    divVerDetalhes(divCons, url);
    mostraProdutoTipo('menuvcAcesso');
    mostraProduto('menuvcAcessodiscador_a',false);
}

//Para abrir o conteudo de uma url antiga guardada nos favoritos
function paginasAntigas(paramArray)
{
    var pg = (paramArray.mandic) ? paramArray.mandic : '';
    var cons = (paramArray.cons) ? paramArray.cons : '';
    var id = (paramArray.id) ? paramArray.id : '';
    var queryString1 = '';
    var queryString2 = '';
    if(paramArray.action == 'mandicvoce')cons = 1;
    if(paramArray.action == 'mandicempresa')cons = 2;   
   
    //pega o controller
    switch(true){
        //EM PRODUTOS//
        case (/^mail$/).test(pg): 
            if(id) queryString2 = 'c=produtos&action=ver_detalhes&id='+id;
            if(cons)queryString1 = 'c=mandic&action=mandictipo&tipo=1&cons='+cons;
            break;          
        case (/^acesso$/).test(pg): 
            if(id) queryString2 = 'c=produtos&action=ver_detalhes&id='+id;
            if(cons)queryString1 = 'c=mandic&action=mandictipo&tipo=2&cons='+cons;
            break;   
        case (/^servicos$/).test(pg): 
            if(id) queryString2 = 'c=produtos&action=ver_detalhes&id='+id;
            if(cons)queryString1 = 'c=mandic&action=mandictipo&tipo=3&cons='+cons;
            break;   
        
        //produtos
        case (/^1gb$/).test(pg): 
            if(cons == 2) id = 3;  //só tem para pessoa juridica           
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=1&cons='+cons;
            }
            break;       
        case (/^3gb$/).test(pg): 
            if(cons == 1) id = 5;
            if(cons == 2) id = 5;            
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=1&cons='+cons;
            }
            break; 
        case (/^nunca.?lota$/).test(pg): 
            if(cons == 1) id = 1; //só tem para pessoa fisica
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=1&cons='+cons;
            }
            break;           
        case (/^4ever$/).test(pg): 
            if(cons == 1) id = 6;
            if(cons == 2) id = 6;            
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=1&cons='+cons;
            }
            break;
        
        //acesso
        case (/^discador$/).test(pg): 
            if(cons == 1) id = 7;
            if(cons == 2) id = 7;            
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=2&cons='+cons;
            }
            break;              
        case (/banda.?larga/).test(pg): 
            if(cons == 1) id = 2;
            if(cons == 2) id = 8;            
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=2&cons='+cons;
            }
           break;   

        //servicos
        case ((/anjo.?(da)?.?guarda/).test(pg) && paramArray.c == 'mandic'): 
            if(cons == 1) id = 11;
            if(cons == 2) id = 83;            
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=3&cons='+cons;
            }
            break;
        case (/^ironport$/).test(pg): 
            if(cons == 1) id = 15;
            if(cons == 2) id = 15;            
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=3&cons='+cons;
            }
            break; 
        case (/^backup$/).test(pg): 
            if(cons == 1) id = 12;
            if(cons == 2) id = 12;            
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=3&cons='+cons;
            }
            break; 
        case (/^email.?registrado$/).test(pg): 
            if(cons == 1) id = 20;
            if(cons == 2) id = 20;            
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=3&cons='+cons;
            }
            break;
        case (/^mail(.)?mkt$/).test(pg): 
            if(cons == 1) id = 79;
            if(cons == 2) id = 79;            
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=3&cons='+cons;
            }
            break;
         case (/^host(ing)?$/).test(pg):
            if(cons == 1) id = 80;
            if(cons == 2) id = 80;            
            if(id && cons){
            	queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=3&cons='+cons;
            } 
            break;
         case (/^fax$/).test(pg):
            if(cons == 1) id = 85;
            if(cons == 2) id = 84;            
            if(id && cons){
                queryString2 = 'c=produtos&action=ver_detalhes&cons='+cons+'&id='+id;
                queryString1 = 'c=mandic&action=mandictipo&tipo=3&cons='+cons;
            } 
            break;
            
        //SO A MANDIC TEM
        case ( (/anjo.?(da)?.?guarda/).test(pg) && paramArray.c == 'soamandictem'):
            id = 7;
            queryString1 = 'c=soamandictem&action=ver_detalhes&id='+id;
            break; 
        case (/^gasparzinho$/).test(pg): 
            id = 4;
            queryString1 = 'c=soamandictem&action=ver_detalhes&id='+id;
            break; 
        case (/^miss.o(.)?secreta$/).test(pg): 
            id = 5;
            queryString1 = 'c=soamandictem&action=ver_detalhes&id='+id;
            break; 
        case (/^zorro$/).test(pg): 
            id = 6;
            queryString1 = 'c=soamandictem&action=ver_detalhes&id='+id;
            break; 
        case (/^imandic$/).test(pg): 
            id = 22;
            queryString1 = 'c=soamandictem&action=ver_detalhes&id='+id;
            break; 

        //MANDICAS
        case ((/anjo.?(da)?.?guarda/).test(pg) && paramArray.c == 'mandicas'):  
            id = 14;
            queryString1 = 'c=mandicas&action=ver_dica&id='+id;
            break; 
        case (/^ant(i)?(.)?spam$/).test(pg): 
            id = 7;
            queryString1 = 'c=mandicas&action=ver_dica&id='+id;
            break;         
        case (/^ant(i)?(.)?virus$/).test(pg): 
            id = 6;
            queryString1 = 'c=mandicas&action=ver_dica&id='+id;
            break;          
        case (/^central(.)?(de)?(.)?email$|^cem$/).test(pg): 
            id = 9;
            queryString1 = 'c=mandicas&action=ver_dica&id='+id;
            break; 
        case (/^assinatura(.)?digital$|^criptografia$/).test(pg): 
            id = 13;
            queryString1 = 'c=mandicas&action=ver_dica&id='+id;
            break; 

        //INSTITUCIONAL//
         case (/^hist.ria$/).test(pg): 
            id = 1;
            queryString1 = 'c=institucionais&action=ver_institucional&id='+id;
            break;
         case (/^faq(s)?$/).test(pg): 
            queryString1 = 'c=institucionais&action=faqs';
            break;
         case (/^release(s)?$/).test(pg):
            queryString1 = 'c=institucionais&action=press_releases';            
            break;
         
         //sala de imprensa            
         case (/^sala.?(de).?imprensa$/).test(pg): 
            if(id) queryString2 = 'c=institucionais&action=ver_sala_imprensa&id='+id;
            queryString1 = 'c=institucionais&action=sala_imprensa';
            break;
         case (/^fotos$/).test(pg): 
            id=5;
            queryString2 = 'c=institucionais&action=ver_sala_imprensa&id='+id;
            queryString1 = 'c=institucionais&action=sala_imprensa';
            break;        
         case (/^logos$/).test(pg): 
            id=4;
            queryString2 = 'c=institucionais&action=ver_sala_imprensa&id='+id;
            queryString1 = 'c=institucionais&action=sala_imprensa';
            break;
         case (/^midia$/).test(pg): 
            id=3;
            queryString2 = 'c=institucionais&action=ver_sala_imprensa&id='+id;
            queryString1 = 'c=institucionais&action=sala_imprensa';
            break;
         case (/^assessoria(.?(de)?.?(imprensa))?$/).test(pg): 
            id=1; 
            queryString2 = 'c=institucionais&action=ver_sala_imprensa&id='+id;
            queryString1 = 'c=institucionais&action=sala_imprensa';
            break;
         case (/^twitter$/).test(pg): 
            id=6; 
            queryString2 = 'c=institucionais&action=ver_sala_imprensa&id='+id;
            queryString1 = 'c=institucionais&action=sala_imprensa';
            break;

        //HOME//
         case (/^newsletter$/).test(pg): 
            queryString1 = 'c=mandic&action=cadastroNewsLetter';
            break;
         case (/^funcionalidade(s)?$/).test(pg):
            queryString1 = 'c=mandic&action=ver_funcionalidades&cons='+cons+'&id='+id;
            break;
         case (/^videos$/).test(pg):
            if(id == 123) id=12; //123 id antigo do iMandic
            if(id == 125) id=14; //125 id antigo do implode           
            if(id) queryString2 = 'c=mandic&action=ver_video&id='+id;
            var categ = (paramArray.categ) ? paramArray.categ : '';
            queryString1 = 'c=mandic&action=videos&categ='+categ;
            break;
         case (/^manuais$|^tutoriais$/).test(pg):
            if(id) queryString2 = 'c=mandic&action=ver_manual&id='+id;
            queryString1 = 'c=mandic&action=manuais';
            break;
         case (/^comunicado$/).test(pg):
            queryString1 = 'c=mandic&action=comunicado';
            break;
            
        default: return false;
    }
    if(!queryString1) return;
    
    //Abre a primeira janela    
    showPopDivDestaques('', 'index.php?' + queryString1 + '&blank=true');
    
    //Abre a segunda janela
    if(queryString2) showPopDiv('', 'index.php?'+ queryString2 +'&blank=true');
}


//var youTubeId1 = null;
//function listVideos()
//{
//    var youTubeId2 = null;
//    var youTubeIDArray = new Array('tuvYPoO3kTE', '0Nz3YNMJ9ss', 'CfM8M4jP2Zs', 'FOwNm5bA8eY', 'BbIyp-fu9Ww');
//    var youTubeIdDefault = youTubeIDArray[0];
//    youTubeId = (youTubeId1) ? youTubeId1 : youTubeIdDefault;
//    for (var i=0; i < youTubeIDArray.length; i++)
//    {
//        if(youTubeId == youTubeIDArray[i])
//        {
//          youTubeId2 = youTubeId;
//          youTubeId1 = ( i+1 == youTubeIDArray.length) ?  youTubeIDArray[0] : youTubeIDArray[i+1];
//        }
//    }
//    var videoHome = $('box_center').innerHTML;
//    var youTubeIDRegx = new RegExp(youTubeId,"g");
//    var videoHomeNew = videoHome;
//    videoHomeNew = videoHomeNew.replace(youTubeIDRegx, youTubeId1); 
//    //efeitoCarregando();
//    $('box_center').innerHTML = videoHomeNew;
//    //console.error('youTubeId2='+youTubeId + '   \nyouTubeId1='+youTubeId1);
//}
