function Bairros(id_cidade)
{
	
	xmlHttp=GetXmlHttpObject();
	url="bairros2.asp";
		var id_cidade = id_cidade;
	url = url + "?sid=" + Math.random();
	url = url + "&id_cidade="+ id_cidade;
	
	if(id_cidade == 'novo'){ /*Cidade nova */
			document.getElementById("nova_cidade").innerHTML="<input type='text' name='id_Cidade' class='required' style='width:200px;'>";
			document.getElementById("bairro_id").innerHTML="<input type='text' name='bairro_id' class='required' style='width:160px;'>";
			
	}else{
		 
		if(id_cidade != 'novo_bairro'){ /*Bairro novo */
			xmlHttp.onreadystatechange=Achou_Bairro;
		
				xmlHttp.open("GET",url,true);
				xmlHttp.send(null);
											
		}
		
	}
		 
		 
 }

function Achou_Bairro() 
	{ 
	
		if (xmlHttp.readyState==4)
			{ 
				document.getElementById("bairro_id").innerHTML=xmlHttp.responseText;
				
			}
	}

function Novo_Bairro(id_cidade)
{
	
if(id_cidade == 'novo_bairro'){ /*Bairro novo */
			document.getElementById("bairro_id").innerHTML="<input type='text' name='bairro_id' class='required' style='width:160px;'>";
			if (xmlHttp.readyState == 1) {
											 document.getElementById("bairro_id").innerHTML="Aguarde...Buscando dados....";
			                             }
}
}


function GetXmlHttpObject()
	{
	 if (window.XMLHttpRequest) {   
			   a=new XMLHttpRequest(); } //Objeto nativo (FF/Safari/Opera7.6+)  
		   else {  
			 try {   
				a=new ActiveXObject("Msxml2.XMLHTTP");  //activeX (IE5.5+/MSXML2+)  
			 }	 
			 catch(e) {  
			   try {   
				  a=new ActiveXObject("Microsoft.XMLHTTP"); //activeX (IE5+/MSXML1)  
			   }	 
			   catch(e) { /* O navegador não tem suporte */   
				  a=false;   
			   }  
			 }  
		   }   
		   return a;  
	}
