function getElm(id) {
	return(document.all&&document.getElementById)?document.all[id]:document.getElementById(id);
}

function checkBrowser() {
	var T=this;
	var b=navigator.appName;
	var v=navigator.appVersion;
	var u=navigator.userAgent;
	if(u==null)return;
	if(b=='Netscape')T.b='ns';
	else if(b=='Microsoft Internet Explorer')T.b='ie';
	else T.b=b;
	T.v=parseInt(v);
	T.ns=(T.b=='ns'&&T.v>=4);
	T.ns4=(T.b=='ns'&&T.v==4);
	T.ns5=(T.b=='ns'&&T.v==5);
	T.ns6=(T.b=='ns'&&T.v==5);
	T.ie=(T.b=='ie'&&T.v>=4);
	T.ie4=(u.indexOf('MSIE 4')>0);
	T.ie5=(u.indexOf('MSIE 5.0')>0);
	T.ie55=(u.indexOf('MSIE 5.5')>0);
	T.ie6=(u.indexOf('MSIE 6.0')>0);
	if(T.ie5)T.v=5;
	if(T.ie55)T.v=5.5;
	if(T.ie6)T.v=6;
	T.min=(T.ns||T.ie);
	T.dom=(T.v>=5);
	T.win=(u.indexOf('Win')>0);
	T.mac=(u.indexOf('Mac')>0);
}
is = new checkBrowser();

// popup hotsite verao
function openPopupImg(imagem){
 if(screen.width <= 800 || screen.height <= 600){
  var tWidth = 650;
  var theight = 434;
  var caminho = "800x600/"; 
 }
 
 else if(screen.width >= 1024 || screen.height >= 768){
  var tWidth = 900;
  var theight = 600;
  var caminho = "1024x768/";
 }
 
 attr = 'top = 0, left = 0, menubar = 0, toolbar = 0, location = 0,' + 'directories = 0, scrollbars=0, status = yes,' + 'resizable = 0, width = ' + tWidth + ', height = ' + theight + '';
 
 popWin = open('about:blank', 'new_window', attr);
 popWin.document.open();
 popWin.document.write('<html>');
  popWin.document.write('<head>');
  popWin.document.write('<title>Bradescompleto</title>');
  popWin.document.write('</head>');
  popWin.document.write('<body bgcolor="#F1F1F1" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">');
   popWin.document.write('<img src=' + caminho + imagem + ' alt="" title="" />');
  popWin.document.write('</body>');
 popWin.document.write('</html>');
 popWin.document.close();
};


// relogio
function showtimenew() {
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds()
	var timeValue = "" + ((hours < 10) ? "0" : "") + hours
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds
	document.getElementById('relogio').value = timeValue;
	timerID = setTimeout("showtimenew()",1000);
}

// funcoes para os botoes recursos						
function fn_bt_recursos(elem1,elem2,elem3,elem4) {
    // desativa todos os botões e setas
    for(x=0;x<elem2.length;x++) {
    	elem2[x].style.backgroundPosition = "0 0";
    	elem2[x].parentNode.className = 'seta_off';				
    }
    
    // ativa o botão clicado e seta				
    elem1.style.backgroundPosition = "0 -21px";
    elem1.parentNode.className = 'seta_on';
    
    // parse para descobrir o num do botao
    var parse_obj_link = new String(elem1.className);
    var re = /[0-9]+/;
    var parse_obj_link = re.exec(parse_obj_link);
    
    // injeta o titulo 
    var titdesc = document.getElementById(elem4);
    var titulo = titdesc.parentNode;
    titulo.style.display = 'block';
    titdesc.childNodes[0].nodeValue = tits[parse_obj_link];
    var str_url = new String('url(../img/bt'+parse_obj_link+'.gif) 25px 0 no-repeat');				
    titdesc.style.background = str_url;
    
    // injeta o descritivo
    var descritivo = document.getElementById(elem3);
    descritivo.style.display = "block";
    descritivo.innerHTML = descs[parse_obj_link];
}
						
function fn_add_bt_recursos(elem1,elem2,elem3) {
    var bts = document.getElementById(elem1).getElementsByTagName('a');
    for(x=0;x<bts.length;x++) {
    	bts[x].onclick = function() { fn_bt_recursos(this,bts,elem2,elem3) };					
    }								
}
            
// abre uma popup centralizada
function openPopup(u,n,w,h,o,c){
	var l=t=18;
	if(c){l=(screen.availWidth-w)/2;t=(screen.availHeight-h)/2;}
	p=window.open(u,'pop_'+n,'left='+l+',top='+t+',width='+w+',height='+h+',scrollbars=0'+((o)?','+o:''));
}

// abre popups 
function AbreRede(pag){
	openPopup(pag,'_blank',699,409,'scrollbars=0',true);
}

// diversas
function LePagina(url) {
	window.open(url);
}

function HomeRasa(url) {
	if(url!='') window.open(url);
}

function PromocoesCartoes() {
	window.open('http://www.bradesco.com.br/br/redirect/destaques/promocao_varejo.html','PromocoesCartoes','toolbar=0.location=0.directories=0.status=0.menubar=0.scrollbars=0.width=735,height=480,top=10,left=50');
}


/* AJAX - USO GERAL */

// esta funcao verifica e retorna de acordo com o browser do usuario o objeto XMLHTTP
function ajax_init() {
    try{
        xmlhttp = new XMLHttpRequest();
    }catch(ee){
        try{
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                xmlhttp = false;
            }
        }
    }
    return xmlhttp;
}

// instanciando o objeto XMLHTTP
var xmlHttp = ajax_init();


/* AJAX - IMPLEMENTACAO BOX ATUALIZAR COTACAO */

function atualizar_resultado() {  
	getElm('agestado').style.display = 'none';
	getElm('carregando').style.display = 'block';
	var d = new Date();
	//envia getSeconds pra nao dar problemas de cache
	var url = "../inc/xmlgenerator.asp?t=" + d.getSeconds();
	xmlHttp.open('GET', url, true);
	xmlHttp.onreadystatechange = AtualizaCotacao;
	xmlHttp.send(null);
	setTimeout(atualizar_resultado,1800000);
}

// funcao que realiza o ajax
function AtualizaCotacao(){
	// verifica se está ok
	if (xmlHttp.readyState == 4){
		var xmlResp = xmlHttp.responseXML.documentElement;
		
		//atribui valores buscando os nos pela funcao
		getElm('ibovespa').innerHTML = getChild('ativo', 'var', xmlResp, 0);
		getElm('dolar').innerHTML = getChild('ativo', 'valor', xmlResp, 1);
		getElm('euro').innerHTML = getChild('ativo', 'valor', xmlResp, 2);

		getElm('carregando').style.display = 'none';
		getElm('agestado').style.display = 'block';
	}
}

function getChild(vTagNamePai, vTagNameFilho, xmlResp, ind){
	return xmlResp.getElementsByTagName(vTagNamePai)[ind].getElementsByTagName(vTagNameFilho)[0].firstChild.data;
}


/* AJAX - IMPLEMENTACAO BOX NOSSA REDE DE ATENDIMENTO */

function fn_add_combo_estado(obselect,obcidades,obajax) {
    var uf = document.getElementById(obselect);
    if(uf) {
        uf.onchange = function() { fn_combo_estado(this.options[this.selectedIndex].value,obcidades,obajax); }
    }
}

function fn_add_combo_cidade(obselect,obtelefones,obajax) {
    var cid = document.getElementById(obselect);
    if(cid) {
        cid.onchange = function() { fn_combo_cidade(this.options[this.selectedIndex].value,obtelefones,obajax); }
    }
}

function fn_combo_cidade(idcidade,obtelefones,obajax) {
   xmlhttp = obajax;
   var phone=document.getElementById(obtelefones);     
   if(phone) {
        phone.childNodes[0].nodeValue = "Aguarde...";
        
        xmlhttp.open("get", "info_telefone.asp?ID_CIDADE="+idcidade, true);
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState==4){
                var xmlResp = xmlhttp.responseXML.documentElement;
                var telefone = xmlResp.getElementsByTagName('numero')[0];
if(telefone != null) {
                    phone.childNodes[0].nodeValue = telefone.childNodes[0].nodeValue;
                } else {
                    phone.childNodes[0].nodeValue = "";
                }
            } 
        }
        xmlhttp.send(null);
      
   }
   
}

function fn_combo_estado(idestado,obcidades,obajax) {
	 var phone=document.getElementById('numero-telefone');
		 phone.childNodes[0].nodeValue = "";
    xmlhttp = obajax;
    var city=document.getElementById(obcidades);
    if(city) {
        while(city.options.length>0) { 
            city.options[0]=null ;
        }
        city.options[0]=new Option("Aguarde...","Aguarde")
        
        xmlhttp.open("get", "combo_cidade.asp?ID_ESTADO="+idestado, true);

        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState==4){
                var xmlResp = xmlhttp.responseXML.documentElement;
                var cidades = xmlResp.getElementsByTagName('cidade');
                
                // limpa o select
                while(city.options.length>0) { 
                    city.options[0]=null ;
                }
                
                for(x=0;x<cidades.length;x++) {
                    city.options[city.options.length]=new Option(cidades[x].getElementsByTagName('nome')[0].firstChild.nodeValue,cidades[x].getElementsByTagName('id')[0].firstChild.nodeValue);
                }
            } 
        }
        xmlhttp.send(null);
    }
}


