window.onload=setup;
//========================================================================================
//Inicialização de variáveis e conexão de gatilhos
//========================================================================================
function setup(){
    //Se o navegador não possui getElementsByClassName
    if(!document.getElementsByClassName)
        document.getElementsByClassName=getElementsByClassNameIE;
    //Navegação
    document.onkeyup = KeyCheck;       
    document.mylinks = new Links(null,"menuPrincipal");
    //Informativo
    //document.getElementById("acess").onclick = function() { return openPopup("/BOB/LINK/bobwcohm_navegacao.aspx", 592, 365) }
    panel = new Maskpanel("div_popup", "popupExterna");
    //Painel utilizado no método openPopup
    //Menus
    if (window.attachEvent) window.attachEvent("onload", over);
    //Redimensionamento
    fontResizer=new FontResizer("resizable","10","10","13","alterarFonte");
    if(fontResizer.incIcon)
        fontResizer.incIcon.onclick=function(){fontResizer.inc()}
    if(fontResizer.decIcon)
        fontResizer.decIcon.onclick=function(){fontResizer.dec()}
}
//========================================================================================
//Menus
//========================================================================================
function classOver(){
			this.className+=" over";
}
function classOut(){
			this.className=this.className.replace(new RegExp(" over\\b"), "");
}
function over() {
	var sfEls = document.getElementById("menuPrincipal").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=classOver;
		sfEls[i].onmouseout=classOut;
	}
}
//========================================================================================
//Navegação por teclado 
//========================================================================================
function KeyCheck(e)
{

   var KeyID = (window.event) ? event.keyCode : e.keyCode;
    
   var element;
   if(window.event)
        element=event.srcElement;
   else if(e.srcElement) 
        element=e.srcElement;
   else if(e.target)
        element=e.target;     
   if(element.nodeType==3) 
        element=element.parentNode;
   if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA' || element.tagName == "SELECT") 
        return;
   
   closePopup();
   switch(KeyID)

   {
      case 27:  document.mylinks.out();
                break;
      case 9:   //tab
                //Vamos precisar de um tratamento aqui?
                break;
      case 78:  document.mylinks.out();
                openPopup("/BOB/LINK/bobwcohm_navegacao.aspx", 592, 365);
                break;
      case 83:  //S
                focusOn("suaConta");
                break;
      case 66:  //B
                focusOn("redirecionamentosLink");
                break;
      case 77:  //M
                focusOn("menuPrincipal");
                document.mylinks.down();
                break;
      case 68:  //D
                focusOn("duvidas");
                break;
      case 80:  //P
                focusOn("caminho");
                break;
      case 82:  //R
                focusOn("rapida");
                break;
      case 37:
            //Arrow Left
            if(document.mylinks.vposition>=0)
                document.mylinks.left();
            break;
      
      case 38:
            //Arrow Up;
            if(document.mylinks.vposition>=0)
                document.mylinks.up();
            break;
      
      case 39:
            //Arrow Right
            if(document.mylinks.vposition>=0)
                document.mylinks.right();
            break;
      case 40:
            //Arrow Down;
            if(document.mylinks.vposition>=0)
                document.mylinks.down();
            break;
      case 107:
      case 187:
            //+
            if(fontResizer)
                fontResizer.inc();
            break;
      case 109:
      case 189:
            //-
            if(fontResizer)
                fontResizer.dec();
            break;
      case 96://NumPad 0 
      case 48:
            //KeyBoard 0
            if(fontResizer)
                fontResizer.def();
            break;
            
   }
}

function focusOn(id){
    document.mylinks.out();
    node=document.getElementById(id);
    if(node==null)
        return;
    links=node.getElementsByTagName("a");
    if(links.length>0)
        links[0].focus();
}
//========================================================================================
//Protótipo dos Objetos Links
//========================================================================================
function Links(nodes,menuId){
   if(nodes==null){
    if( menuId!=null &&
        document.getElementById(menuId)!=null &&
        document.getElementById(menuId).getElementsByTagName("UL") !=null &&
        document.getElementById(menuId).getElementsByTagName("UL")[0]!=null)
        nodes=document.getElementById(menuId).getElementsByTagName("UL")[0].childNodes;
    else
        nodes =null;    
   }
   if(nodes!=null){
       this.targets=nodes;
       this.count=this.targets.length;
   }else{
       this.targets=null; 
       this.count=0;
   }
   this.inner=null;
   this.vposition=-1;
   this.down=function(){
                if(this.inner!=null){
                    this.inner.down();
                }else{
                    if(this.vposition<this.count-1&&this.vposition>=0&&this.targets[this.vposition].className!=null)
                        this.targets[this.vposition].className=this.targets[this.vposition].className.replace(/over/gi, "");
                    if(this.vposition<this.count-1)
                        this.vposition++;
                    if(this.targets[this.vposition].nodeName!="LI"&&this.vposition<this.count-1)
                        this.down();
                    else if(this.targets[this.vposition].nodeName=="LI"){
                        this.targets[this.vposition].className+=" over";
                        this.focusLinkChild(this.targets[this.vposition]);
                    }    
                }
              }
              ;
   this.up=function(){
                if(this.inner!=null){
                    this.inner.up();
                }else{
                    if(this.vposition<this.count&&this.vposition>=0&&this.targets[this.vposition].className!=null)
                        this.targets[this.vposition].className=this.targets[this.vposition].className.replace(/over/gi, "");
                    if(this.vposition>0)
                        this.vposition--;
                    if(this.targets[this.vposition].nodeName!="LI"&&this.vposition>0)
                        this.up();
                    else if(this.targets[this.vposition].nodeName=="LI"){
                        this.targets[this.vposition].className+=" over";
                        this.focusLinkChild(this.targets[this.vposition]);
                    }
                }
              }
              ;
   this.right=function(){
                if(this.inner!=null){
                    this.inner.right();
                }else{
                    if(this.vposition>=0){
                        this.inner=new Links(this.targets[this.vposition].getElementsByTagName("LI"),null);
                        if(this.inner.targets.length>0)
                            this.inner.down();
                        else
                            this.inner=null;    
                    }    
                }
                
              };           
   this.left=function(){
                if(this.inner!=null){
                    this.inner.unFocus();
                    this.inner=null
                    this.focusLinkChild(this.targets[this.vposition]);
                }else{
                    this.unFocus();
                    this.inner=null
                }
              };
   this.unFocus=function(){
                    if(this.vposition<this.count&&this.vposition>=0&&this.targets[this.vposition].className!=null)
                        this.targets[this.vposition].className=this.targets[this.vposition].className.replace(/over/gi, "");
                };                 
   this.focusLinkChild=function(node){
                            if(node!=null&&node.nodeName=="LI"){
                                links=node.getElementsByTagName("a");
                                links[0].focus();
                            }    
                        };
   this.out=function(){
                if(this.inner!=null){
                    this.inner.out();
                    this.inner=null;
                }
                this.unFocus();
                this.vposition=-1;   
            };         
   return this;
}
//========================================================================================
//Janela de instruções
//========================================================================================
function openPopup(url, width, height) {
    panel.setParameters(url, width, height);
    panel.show();
    initPanelLocaltion(panel.classId);
    return false;
}

function openPopupEncoded(url, width, height) {
    panel.setParameters(decodeURIComponent(url), width, height);
    panel.show();
    initPanelLocaltion(panel.classId);
    return false;
}

function closePopup() {
    panel.hide();
}

function initPanelLocaltion(classId) {
    var ins=  document.getElementById(classId);
    ins.style.top = (((document.documentElement.clientHeight/2) + (window.pageYOffset || document.documentElement.scrollTop)) - (ins.offsetHeight/2))+'px';    
    ins.style.left = (((document.documentElement.clientWidth/2) + document.documentElement.scrollLeft) - (ins.offsetWidth/2))+'px';
}
//========================================================================================
//Protótipo de popup
//========================================================================================
function Maskpanel(panelName, classId)
 {
     this._divPanel;
     this._divJanelaPrincipal;
     this._iFrame;
     
     this.panelName     = panelName;
     this.classId       = classId;
     this.iFrameSrc     = "/BOB/LINK/bobwcohm_navegacao.aspx";
     this.iFrameWidth   = "592px";
     this.iFrameHeight  = "365px";
     this.setParameters=function(iFrameSrc, iFrameWidth, iFrameHeight)
     {
        this.iFrameSrc = iFrameSrc;
        this.iFrameWidth = iFrameWidth;
        this.iFrameHeight = iFrameHeight;
        
        //Se já tem a div criada
        if (this._divJanelaPrincipal) {
           
           this._divJanelaPrincipal.style.width = this.iFrameWidth + "px";
           this._divJanelaPrincipal.style.height = this.iFrameHeight + "px";
           this._iFrame.src = this.iFrameSrc;
        }
     };
     this.show=function()  
     {  
       if(!document.getElementById(this.panelName))  
       {
           /************       ESTRUTURA MONTADA PARA A APRESENTAÇÃO DA JANELA     *************
            *   <div id="div_popup" position="absolute" zIndex="10">
            *       <div id="popupExterna" style="width:iFrameWidth;height:iFrameHeight;">
            *           <div style="display:block;text-align:right;background-color:#FFFFFF;">
            *               <img id="imgFechar" src="/BOB/MULTIMIDIA/bobd99im_close.png" />
            *           </div>
            *           <iframe id="iFramePage" style="width:100%;height:92%;">
            *               <html>
            *                   ...
            *                   <div id="popupConteudo">
            *                       ...
            *                   </div>
            *               </html>
            *           </iframe>
            *       </div>
            *   </div>
            */
            
           //Cria a área com fundo escuro.
           var divNegra = document.createElement('div');
           divNegra.setAttribute("id",this.panelName);
           divNegra.style.position="absolute";
           divNegra.style.zIndex="102";
           divNegra.style.opacity=".50";
           divNegra.style.top="0px";
           divNegra.style.left="0px";
           divNegra.style.backgroundColor="#000";  
           divNegra.style.filter="alpha(opacity=50)";
           
           //Cria a janela para mostrar a informação.
           var divJanela = document.createElement('div');
           divJanela.setAttribute("id",this.classId);
           divJanela.style.width = this.iFrameWidth + "px";
           divJanela.style.height = this.iFrameHeight + "px";
           
           //Cria a barra com botão de fechar.
           var divImgClose = document.createElement('div');
           divImgClose.style.display = "block";
           divImgClose.style.textAlign = "right";
           divImgClose.style.backgroundColor = "#FFFFFF";
           
           var imgClose = document.createElement('img');
           imgClose.setAttribute("id", "imgFechar");
           imgClose.setAttribute("src", "/BOB/MULTIMIDIA/bobd99im_close.png");
           imgClose.style.padding = "2px 2px 2px 0px";
           imgClose.style.cursor = "pointer";
           imgClose.onclick = closePopup;
   
           //Cria a área onde será carregado o frame.
           var divFrame = document.createElement('iframe');
           divFrame.setAttribute("id","iFramePage");
           divFrame.setAttribute("class","iFrameClass");
           divFrame.setAttribute("frameBorder","no");
	       divFrame.src = this.iFrameSrc;
	       divFrame.zIndex = "18";
	       divFrame.style.display = "block";
           divFrame.style.position = "absolute";
           divFrame.style.zIndex = "19";
           divFrame.style.width = "100%";
           divFrame.style.height = "92%";
           divFrame.style.backgroundColor = "#FFFFFF";
           
           divImgClose.appendChild(imgClose);
           divJanela.appendChild(divImgClose);
           divJanela.appendChild(divFrame);
           
           document.body.appendChild(divNegra);
           document.body.appendChild(divJanela);
        }  
   
        this._divPanel = document.getElementById(this.panelName);  
        this._divJanelaPrincipal = document.getElementById(this.classId);  
        this._iFrame = document.getElementById("iFramePage");
          
        var dsh=document.documentElement.scrollHeight;  
        var dch=document.documentElement.clientHeight;  
        var dsw=document.documentElement.scrollWidth;  
        var dcw=document.documentElement.clientWidth;  
          
        var bdh=(dsh>dch)?dsh:dch;  
        var bdw=(dsw>dcw)?dsw:dcw;  

        this._divPanel.style.height=bdh+'px';
        this._divPanel.style.width=bdw+'px';
        this._divJanelaPrincipal.style.display="block";
        this._divPanel.style.display="block";
     };  
     this.hide=function()  
     {
         if(this._divJanelaPrincipal) {
            this._divJanelaPrincipal.style.display="none";
            this._iFrame.src="";
         }
         if(this._divPanel)
            this._divPanel.style.display="none";  
     };
 }
//========================================================================================
//Protótipo de gerenciador de fontes
//======================================================================================== 
function FontResizer(className,defaultSize,minSize,maxSize,divContainer){
    this.className=className;
    this.currentSize=Number(defaultSize);
    this.defaultSize=Number(defaultSize);
    this.minSize=Number(minSize);
    this.maxSize=Number(maxSize);
    
    this.nodes=document.getElementsByClassName(this.className);
    if(this.nodes.length > 0){
        this.divContainer=document.getElementById(divContainer);
        if(this.divContainer){
            var label=document.createElement('label');
            label.innerHTML="Texto:"
            this.divContainer.appendChild(label);
            var inc=document.createElement('a');  
            inc.setAttribute('id','incFonte');
            inc.innerHTML="A+";
            this.incIcon=inc;
            this.divContainer.appendChild(inc);
            var dec=document.createElement('a');  
            dec.setAttribute('id','decFonte');
            dec.innerHTML="A-";
            this.decIcon=dec;
            this.divContainer.appendChild(dec);  
        }
    }
    this.inc=function(){
        if(this.currentSize>=this.maxSize)
            return;
        this.currentSize++;    
        this.setSize();
    };
    this.dec=function(){
         if(this.currentSize<=this.minSize)
            return;
         this.currentSize--;
         this.setSize();
    };
    this.def=function(){
        this.currentSize=this.defaultSize;
        this.setSize();
    }
    this.setSize=function(){
        for(i=0;i<this.nodes.length;i++){
            /*this.nodes[i].style.fontSize=this.currentSize+"pt";*/
            this.nodes[i].style.fontSize=this.currentSize*10+1+"%";
        }
    };
} 

//========================================================================================
//getElementsByClassName for IE
//======================================================================================== 
 
function getElementsByClassNameIE(cl) {
    var retnode = [];
    var myclass = new RegExp('\\b'+cl+'\\b');
    var elem = this.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) {
    var classes = elem[i].className;
    if (myclass.test(classes)) retnode.push(elem[i]);
    }
    return retnode;
} 

//========================================================================================
//Setar texto de um componente
//========================================================================================

function setText (obj, texto) {
    obj.innerHTML = texto;
}

//========================================================================================
//Função para direcionar arquivos .swf
//========================================================================================

var Lista_janela = new Array(8);
var Lista_area = new Array(8);
var Lista_link = new Array(8);
var Lista_tamanho = new Array(8);

function abreswf(ID) {
    ID = ID.toLowerCase();
    for (i = 1; i <= 8; i++) {
        if (Lista_area[i] == ID) {
            if (Lista_janela[i]=="Atual") {
                window.location=Lista_link[i];
            }
            else if(Lista_janela[i]=="Popup") {
                window.open(Lista_link[i],'Banrisul','toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,menubar=no,fullscreen=no,'+Lista_tamanho[i]);
            }
            else {
                window.open (Lista_link[i],"novajanela");
            }
        }
    }
}

 /***********************************
    Adiciona evento genérico no form
 ************************************/

 function adicionaEvento(evento, funcao, form, retorno){
	if(form.attachEvent){
		form.attachEvent("on"+evento, funcao)
		return true;
	}else if(form.addEventListener){
		form.addEventListener(evento,funcao,(retorno||false))
		return true;
	}else{
		form["on"+evento] = funcao;
		return true;
	}
	return false;
 }