function abre_janela( url, largura, altura, nome, barra_ferram, barra_url, barra_links, barra_satus, barra_menu, barra_rolagem, redimencionar ) {
    
    if ( nome == null ) { nome = ''; }
    barra_ferram  = ( barra_ferram==null  || !barra_ferram )  ? 0 : 1;
    barra_url     = ( barra_url==null     || !barra_url )     ? 0 : 1;
    barra_links   = ( barra_links==null   || !barra_links )   ? 0 : 1;
    barra_satus   = ( barra_satus==null   || !barra_satus )   ? 0 : 1;
    barra_menu    = ( barra_menu==null    || !barra_menu )    ? 0 : 1;
    barra_rolagem = ( barra_rolagem==null || !barra_rolagem ) ? 0 : 1;
    redimencionar = ( redimencionar==null || !redimencionar ) ? 0 : 1;
    
    var pos_top  = (screen.height/2) - (altura/2)  - 50;
    var pos_left = (screen.width/2)  - (largura/2) - 20;
    var janela;
    
    janela = window.open(url,nome,'toolbar='+barra_ferram+',location='+barra_url+',directories='+barra_links+',status='+barra_satus+',menubar='+barra_menu+',scrollbars='+barra_rolagem+',resizable='+redimencionar+',copyhistory=0,screenX='+screen.width+',screenY='+screen.height+',top='+pos_top+',left='+pos_left+',width='+largura+',height='+altura);
    
    return janela;
    
}

function verif_navegador() {
    this.ver   = navigator.appVersion;
    this.agent = navigator.userAgent;
    this.dom   = document.getElementById ? 1 : 0;
    this.opera = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById) ? 1 : 0;
    this.ie5   = (this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera) ? 1 : 0; 
    this.ie6   = (this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera) ? 1 : 0;
    this.ie4   = (document.all && !this.dom && !this.opera)?1:0;
    this.ie    = (this.ie4 || this.ie5 || this.ie6);
    this.mac   = (this.agent.indexOf("Mac") > -1);
    this.ns6   = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0; 
    this.ns4   = (document.layers && !this.dom) ? 1 : 0;
    this.ns    = (this.ns6 || this.ns4);
    this.bw    = (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera);
    return this;
}


function redimensionar_janela( largura, altura ) {
    parent.resizeTo(largura, altura);
    var pos_top  = (screen.height/2) - (altura/2)  - 50;
    var pos_left = (screen.width/2)  - (largura/2) - 20;
    parent.moveTo(pos_left, pos_top);
}


function link_url( url ) {
    location.href = url;
}


function ativa_selecao() {
    if ( window.navigator.appVersion.indexOf("MSIE") != -1 ) {
        document.onselectstart = ativa_selecao_texto;
        document.ondragstart   = ativa_selecao_texto;
    }
}


function desativa_selecao() {
    if ( window.navigator.appVersion.indexOf("MSIE") != -1 ) {
        document.onselectstart = desativa_selecao_texto;
        document.ondragstart   = desativa_selecao_texto;
    }
}


function ativa_selecao_texto() {
    return true;
}


function desativa_selecao_texto() {
	return false;
}


function msg_erro( str ) {
    alert(str);
    return false;
}


/** 
* Exibe ou Esconde um elemento.
* @version 1.0 
*/
function show_hide_elem( elem ) {
    if ( typeof elem == 'string' ) {
        elem = document.getElementById(elem);
    }
    if ( elem==null ) {
        return;
    }
    if ( elem.style.display == 'none' ) {
        elem.style.display = '';
    } else {
        elem.style.display = 'none';
    }
}


/** 
* Adiciona eventos a "window.onload", conservando os eventos que já existem.
* @version 1.0 
*/
function add_load_event( func ) {	
	var old_onload = window.onload;
	if ( typeof window.onload != 'function' ){
    	window.onload = func;
	} else {
		window.onload = function() { old_onload(); func(); }
	}
}


/** 
* Leva a barra de rolagem até o topo com uma animação
* @version 1.0 
*/
function scroll_by_top() {
    var scrollPos = document.body.scrollTop;
    if ( scrollPos <= 0 )
        return; 
   window.scrollTo(0, scrollPos/1.2);
   setTimeout("scroll_by_top()", 10);
}
/** 
* Carrega todas as tags "<a>" que lincam uma ancora para o topo
* @version 1.0 
*/
function scroll_by_top_load_links() {
    if ( !document.getElementById )
        return;
    var url;
    var elemA=document.getElementsByTagName("a");
    for (var i=0; i<elemA.length; i++)  {
        atualElemA = elemA.item(i);
        url = atualElemA.getAttribute("href");
        if ( url.substring(url.length-1) == '#' ) {
            atualElemA.onclick = function() { scroll_by_top(); return false; };
        }
    }
}


add_load_event( scroll_by_top_load_links );

