// JavaScript Document
function endereco_suposto(valor,campo){

       document.getElementById(campo).style.background = '#ffffff';
	   document.getElementById(campo).style.color = '#000000';	   
	   document.getElementById(campo).innerHTML = 'http://www.brflog.net/<b>'+valor+'</b>';	   
	   
	   return false;
}


var HttpReq = null;
function verifica_usuario(usuario){


try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }


}

xmlhttp.open("GET", "http://www.brflog.net/disponibilidade_usuario.php?usuario=" + usuario,true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
xmlhttp.setRequestHeader("Pragma", "no-cache");

xmlhttp.onreadystatechange=function() {

 if(xmlhttp.readyState==4){

  var resultado = xmlhttp.responseText;  
  var dados = resultado.split('-');
  

  
  document.getElementById('aviso_usuario').innerHTML = dados[1];
  document.getElementById('suposto_nome').style.color = '#ffffff';
  
  if(dados[0] == "erro"){
  document.getElementById('aviso_usuario').style.color = '#DB1414';   
  document.getElementById('suposto_nome').style.background = '#DB1414';
  } else if(dados[0] == "sucesso"){  
  document.getElementById('aviso_usuario').style.color = '#000000'; 
  document.getElementById('suposto_nome').style.background = '#6DB224';
  }


 }


}

xmlhttp.send(null);
return false;
}



function imagem_carregando(campo){
var img = document.getElementById(campo).appendChild(document.createElement('img'));
    img.src = 'http://www.brflog.net/imagens/carregando_cadastro.gif';
    img.id = 'img_carregando';
}


var HttpReq = null;
var campo = null;
var cidade = null;
var estado = null;

function buscacidades(valor,uf,city){

campo = valor;
cidade = city;
estado = uf;

document.getElementById(campo).innerHTML = "";

imagem_carregando(campo);

if(document.getElementById('select_cidades')){
document.getElementById(campo).removeChild(document.getElementById('select_cidades'));
}

url = 'http://www.brflog.net/cidades.xml?uf='+estado;

if (document.getElementById) {
if (window.XMLHttpRequest) {
HttpReq = new XMLHttpRequest();
HttpReq.onreadystatechange = XMLHttpRequestChange;
HttpReq.open("GET", url, true);
HttpReq.send(null);
} else if (window.ActiveXObject) {
HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
if (HttpReq) {
HttpReq.onreadystatechange = XMLHttpRequestChange;
HttpReq.open("GET", url, true);
HttpReq.send();
}
}
}
}



function XMLHttpRequestChange() {

 if (HttpReq.readyState == 4 && HttpReq.status == 200){
 
 document.getElementById(campo).removeChild(document.getElementById('img_carregando'));
 
 var result = HttpReq.responseXML;
 var cidades = result.getElementsByTagName("cidade");
 
 var select = document.getElementById(campo).appendChild(document.createElement('select'));
     select.id = 'select_cidades';
	 select.name = 'cidade';
	 
	 var des = function(){
	 destaca('campo_endereco');
	 }
     
	 
	 appendEvent('select_cidades','click',des);

     
 var opcao = null;
 
   for (var i = 0; i < cidades.length; i++) {
     opcao = select.appendChild(document.createElement("option"));
     opcao.appendChild(document.createTextNode(cidades[i].childNodes[0].data)); 
     opcao.setAttribute("value",cidades[i].getAttribute("id"));
	 opcao.id = cidades[i].getAttribute("id");
   } 
   
   if(document.getElementById(cidade)){
   document.getElementById(cidade).selected = true;
   }    
   
 }
 
}


sfFocus = function() {
	var sfEls = document.getElementsByTagName("INPUT");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfFocus);


function destaca(campo){  

      if((document.getElementById('destacado')) && (document.getElementById('destacado').value == campo)){ } else {
   
	  document.getElementById(campo).style.borderLeft = '1px solid #DAF2C2';
	  document.getElementById(campo).style.borderRight = '1px solid #DAF2C2';
	  document.getElementById(campo).style.background = '#ffffff';
	  
	  if(document.getElementById('destacado')){
	  
	  var antigo = document.getElementById('destacado').value;
	  document.getElementById(antigo).style.borderLeft = '1px solid #F8FFF1';
	  document.getElementById(antigo).style.borderRight = '1px solid #F8FFF1';
	  document.getElementById(antigo).style.background = '#F8FFF1';
	  
	  
	  } else {	  
	  var input = document.getElementsByTagName('body')[0].appendChild(document.createElement('input'));
	  input.id = 'destacado'; 
	  input.style.display = 'none'; 
	  } 
	  
	  document.getElementById('destacado').value = campo;
	  
	  }	  

}

appendEvent = function(el, evname, func) {
 if (document.getElementById(el).attachEvent) { // IE
   document.getElementById(el).attachEvent("on" + evname, func);
 } else if (el.addEventListener) { // Gecko / W3C
   document.getElementById(el).addEventListener(evname, func, true);
 } else {
   document.getElementById(el)["on" + evname] = func;
 }
};

function trocarimagem(){
    document.getElementById('antispan').removeChild(document.getElementById('img_as'));
	
	var img = document.getElementById('antispan').appendChild(document.createElement('img'));
	img.src = '';
    img.src = 'http://www.brflog.net/estatico/antispan.php';
	img.id = 'img_as';
}
 