var xmlHttp;

function pegaNomeBanco(numeroBanco){
		
	if (numeroBanco != ''){
		var url = "./ajax_nome_banco.php?numero="+numeroBanco;
		xmlHttp=GetXmlHttpObject(ajaxNomeBanco);
		xmlHttp.open("GET", url , true);
		xmlHttp.send(null);
	}else{
		document.getElementById("nomebanco").innerHTML=''; 
		document.getElementById("stnomebanco").value=''; 
	}
	
}


function ajaxNomeBanco(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		if (xmlHttp.responseText == '-1'){
			document.getElementById("nomebanco").innerHTML='Banco Inexistente'; 
			document.getElementById("stnomebanco").value=''; 			
		}else{
			document.getElementById("nomebanco").innerHTML=xmlHttp.responseText; 
			document.getElementById("stnomebanco").value=xmlHttp.responseText; 
		}
	}

	if (xmlHttp.readyState==2){ 
		document.getElementById("nomebanco").innerHTML='Carregando, aguarde...';
	}		
}


function carregaCidades(uf,cidade){						
	
	if (cidade != ''){		
		var url= "./ajax_cidades.php?estado=" + uf + "&cidade=" + cidade;
	}else{
		var url= "./ajax_cidades.php?estado=" + uf;
	}					
	
	xmlHttp=GetXmlHttpObject(ajaxCidades);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);	
}

function ajaxCidades(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("cidade").innerHTML=xmlHttp.responseText; 
	}

	if (xmlHttp.readyState==2){ 
		document.getElementById("cidade").innerHTML='Carregando, aguarde...';
	}		
} 

function GetXmlHttpObject(handler){ 
	var objXmlHttp=null;
	
	if (navigator.userAgent.indexOf("Opera")>=0){
		alert("This example doesn't work in Opera");
		return; 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0){ 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
			strName="Microsoft.XMLHTTP";
		} 
		try{ 
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onreadystatechange=handler; 
			return objXmlHttp;
		} 
		catch(e){ 
			alert("Error. Scripting for ActiveX might be disabled"); 
			return; 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0){
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler; 
		return objXmlHttp;
	}
}
