/*
Autor:		Rafael Cronemberger
Descrição:	Biblioteca de funções Ajax
*/

function newAjaxObject(){
	var objAjax;

	try{
		objAjax 	= new ActiveXObject('Microsoft.XMLHTTP');
	} 
	catch(e){
		try{
			objAjax = new ActiveXObject('Msxml2.XMLHTTP');
			objAjax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		}
		catch(ex){
			try{
				objAjax = new XMLHttpRequest();
			}
			catch(exc){
				objAjax = null;
			}
		}
	}
	return objAjax;
}

function RunAjaxRequest(stMethod, stUrl, stParameters, objFunction, idElement, stTitle){
	objXmlRequest 	= newAjaxObject()
	process 		= objFunction;

	objXmlRequest.onreadystatechange = function(){
		try{
			if(!idElement){
				/* Sem parâmetros de Retorno */
				process(objXmlRequest);
				
			}else{
				/* Com parâmetros de Retorno */
				process(objXmlRequest, idElement, stTitle);
			}
		}
		catch(ex){
			alert('Um erro ocorreu ao tentar carregar os dados. Tente novamente.\nDescrição: ' + ex.message)
		}
	}

	stMethod = stMethod.toUpperCase();
	objXmlRequest.open(stMethod, stUrl, true);
	
	if(stMethod == 'POST'){
		objXmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
		objXmlRequest.setRequestHeader('Method', 'POST ' + stUrl + 'HTTP/1.1');
		objXmlRequest.setRequestHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
		objXmlRequest.setRequestHeader('Cache-Control', 'post-check=0, pre-check=0');
		objXmlRequest.setRequestHeader('Pragma', 'no-cache');
		/*
		objXmlRequest.setRequestHeader('charset','ISO-8859-1');
		objXmlRequest.setRequestHeader('encoding','ISO-8859-1');
		*/
	}
	objXmlRequest.send(stParameters);
	return objXmlRequest;
}

function LoadDropDown(stMethod, stUrl, stParameters, idDropDestiny, stTitle){
	RunAjaxRequest(stMethod, stUrl, stParameters, TrataXmlDropDown, idDropDestiny, stTitle)
}

function Teste(objXml){
	//alert("Carregou")
	//alert(objXml);
}

function LoadAjaxPage(stMethod, stUrl, stParameters, objFunction){
	RunAjaxRequest(stMethod, stUrl, stParameters, objFunction, null)
}

function TrataXmlDropDown(objXmlRequest, idDropDestiny, stTitle){
	var idFeedback					= 'obj_Feedback'
	var objDropDown 				= document.getElementById(idDropDestiny)
	var objFeedback					= document.getElementById(idFeedback)
	
	if(objFeedback){
		ShowHideElement(objFeedback, 1)
		CenterObject(objFeedback, 600, 50)
	}

	if(objDropDown) ResetDropDown(objDropDown);

	objDropDown.options[0] 			= new Option('Carregando ...','');
	objDropDown.options[0].selected	= true;

	BlockUnblockElement(objDropDown, 0)

	if(objXmlRequest.readyState == 4){
		if (objXmlRequest.status == 200){
			try{
				var objXmlResult	 	= objXmlRequest.responseXML

				/* Verificação Bug Firefox */
				var objFirstNode		= objXmlResult.childNodes[1]
				if(!objFirstNode)		objFirstNode = objXmlResult.childNodes[0]

				var objChildNode		= objFirstNode.firstChild
				var stChildNode			= objChildNode.nodeName
				//var nmTotalResults 	= objXmlRequest.responseXML.getElementsByTagName(""+stChildNode+"").length
			}

			catch(ex){
				alert('Um erro ocorreu ao tentar carregar os dados. Tente novamente.\nDescrição: ' + ex.message)
			}
			
			/* End Of File */
			if(stChildNode == 'eof'){
				objDropDown.options[objDropDown.options.length] = new Option('Dados não encontrados', '');
			}else{
				var objFieldXml = objXmlResult.getElementsByTagName(stChildNode);
				var nminc 		= 0
				var arrayNodes 	= new Array();
	
				for (i=0; i < objFieldXml.length; i++){
					for (j=0; j < objFieldXml[i].childNodes.length; j++){
						var nmNodeType = objFieldXml[i].childNodes[j].nodeType
	
						if(nmNodeType == 1){
							arrayNodes[nminc] = objFieldXml[i].childNodes[j].firstChild.nodeValue
							nminc ++
						}
					}
				}
	
				for(nmInc = 0; nmInc < arrayNodes.length; nmInc = nmInc + 2){
					var nmValue		= arrayNodes[nmInc]
					var stDisplay	= arrayNodes[nmInc + 1]
					
					stTitle
					
					if(stTitle && 	nmInc == 0) objDropDown.options[objDropDown.options.length] = new Option(stTitle, '');
					if(!stTitle && 	nmInc == 0) objDropDown.options[objDropDown.options.length] = new Option('Favor selecionar', '');
//					if(nmInc == 0) objDropDown.options[objDropDown.options.length] = new Option('Favor selecionar', '');
					objDropDown.options[objDropDown.options.length] = new Option(stDisplay, nmValue);
				}
			}
			
			Timer(2000, "EndLoadDropDown('"+idDropDestiny+"', '"+idFeedback+"')");
		}
	}
}

function EndLoadDropDown(idDropDestiny, idFeedback){
	var objDropDown 		= document.getElementById(idDropDestiny)

	BlockUnblockElement(objDropDown, 1)
	objDropDown.options[0] = null;

	FadeElement(idFeedback, 'out', 0250)
}

function buscaImagem(stParameters){
	RunAjaxRequest('POST', '../../xml/galeria-foto.asp', stParameters, retornaXmlImagem);
}

function retornaXmlImagem(objXmlRequest){
	alert('aaaa');
}

/*function buscaCep(nmCep){
	RunAjaxRequest('POST', '../../xml/logradouro-cep.asp', 'nmCep='+nmCep+'', retornaXmlCep);
}

function buscaCepCobranca(nmCep){
	RunAjaxRequest('POST', '../../xml/logradouro-cep.asp', 'nmCep='+nmCep+'', retornaXmlCepCobranca);
}

function limpaCampoCep(){
	var obj_Cep 			= document.getElementById("id_Cep");
	var obj_stLogradouro 	= document.getElementById("id_stLogradouro");
	var obj_Endereco		= document.getElementById("id_stEndereco");
	var obj_Bairro			= document.getElementById("id_Bairro");

	var obj_Cidade			= document.getElementById("id_Cidade");
	var obj_stUf			= document.getElementById("id_stUf");
	
	obj_Endereco.value		= '';
	obj_Bairro.value		= '';
	obj_Cidade.value		= '';
//	obj_Cep.value			= '';
	
	obj_stLogradouro.options[0].selected	= true;
	obj_stUf.options[0].selected			= true;
}

function retornaXmlCep(objXmlRequest){
	var obj_Cep 	= document.getElementById("id_Cep");

	if(objXmlRequest.readyState == 4){
		if(objXmlRequest.status == 200){
			var stLogradouro, obj_stLogradouro;
			var stEndereco, obj_Endereco;
			var stBairro, obj_Bairro;
			var stCidade, obj_Cidade;
			var stUf, obj_stUf;


			nmTotalResults 		= objXmlRequest.responseXML.getElementsByTagName("logradouro").length
			objXml 		    	= objXmlRequest.responseXML

			obj_stLogradouro 	= document.getElementById("id_stLogradouro");
			obj_Endereco		= document.getElementById("id_stEndereco");
			obj_Bairro			= document.getElementById("id_Bairro");
			obj_Cidade			= document.getElementById("id_Cidade");
			obj_stUf		  	= document.getElementById("id_stUf");
			
			if(nmTotalResults > 0){
				for(i = 0 ; i < nmTotalResults ; i++){
					stLogradouro = (objXml.getElementsByTagName("logradouro")[i].getElementsByTagName("stLogradouro")[0].firstChild.nodeValue)
					stEndereco   = (objXml.getElementsByTagName("logradouro")[i].getElementsByTagName("stEndereco")[0].firstChild.nodeValue)
				    stBairro     = (objXml.getElementsByTagName("logradouro")[i].getElementsByTagName("stBairro")[0].firstChild.nodeValue)
				    stCidade     = (objXml.getElementsByTagName("logradouro")[i].getElementsByTagName("stCidade")[0].firstChild.nodeValue)
				    stUf		 = (objXml.getElementsByTagName("logradouro")[i].getElementsByTagName("stUf")[0].firstChild.nodeValue)
					
					for(nmInc = 0; nmInc < obj_stLogradouro.length; nmInc ++){
						if(Trim(obj_stLogradouro[nmInc].value.toUpperCase()) == Trim(stLogradouro.toUpperCase())) obj_stLogradouro[nmInc].selected = true
					}
					
					for(nmInc = 0; nmInc < obj_stUf.length; nmInc ++){
						if(Trim(obj_stUf[nmInc].value.toUpperCase()) == Trim(stUf.toUpperCase())) obj_stUf[nmInc].selected = true
					}

					obj_Endereco.value											= stEndereco
					obj_Bairro.value											= stBairro
					obj_Cidade.value											= stCidade
				}
			}else{
				limpaCampoCep();
			}
		}
	}
}

function buscaCadastroUnico(stCpf){
	RunAjaxRequest('POST', '../../xml/cadastroUnico-dados.asp', 'stCpf='+stCpf+'', retornaXmlCadastroUnico);
}

function buscaCnpj(stCnpj){
	RunAjaxRequest('POST', '../../xml/cadastro-pj.asp', 'stCnpj='+stCnpj+'', retornaXmlCadPj);
}

function limpaCadastroUnico(){
	var	obj_stNome 			= document.getElementById("id_stNome");
	var	obj_stSobreNome		= document.getElementById("id_stSobreNome");
	//var	obj_stRg			= document.getElementById("id_stRg");
	var	obj_dtNascimento	= document.getElementById("id_dtNascimento");
	var	obj_nmDddTelefone	= document.getElementById("id_nmDddTelefone");
	var	obj_stTelefone		= document.getElementById("id_stTelefone");
	var	obj_nmDddCelular1	= document.getElementById("id_nmDddCelular1");
	var	obj_stCelular1		= document.getElementById("id_stCelular1");
	var	obj_nmDddCelular2	= document.getElementById("id_nmDddCelular2");
	var	obj_stCelular2		= document.getElementById("id_stCelular2");
	var	obj_nmDddTelComercial = document.getElementById("id_nmDddTelComercial");
	var	obj_stTelComercial	= document.getElementById("id_stTelComercial");
	var	obj_stEmail			= document.getElementById("id_stEmail");
	var	obj_stPais			= document.getElementById("id_stPais");
	var	obj_nmCep			= document.getElementById("id_Cep");
	var	obj_stSexoM			= document.getElementById("id_stSexoM");
	var	obj_stSexoF			= document.getElementById("id_stSexoF");
	
	obj_stNome.value			= "";
	obj_stSobreNome.value		= "";
	//obj_stRg.value			= "";
	obj_dtNascimento.value		= "";
	obj_nmDddTelefone.value		= "";
	obj_stTelefone.value		= "";
	obj_nmDddCelular1.value		= "";
	obj_stCelular1.value		= "";
	obj_nmDddCelular2.value		= "";
	obj_stCelular2.value		= "";
	obj_nmDddTelComercial.value	= "";
	obj_stTelComercial.value	= "";
	obj_stEmail.value			= "";
	obj_nmCep.value				= "";
	obj_stPais.value			= "";
	obj_stSexoM.checked = false;
	obj_stSexoF.checked = false;
	limpaCampoCep();
}

function retornaXmlCadastroUnico(objXmlRequest){
	var obj_Cpf 	= document.getElementById("id_cpf");
	if(objXmlRequest.readyState == 4){
		if(objXmlRequest.status == 200){
			var stNome, obj_stNome;
			var stSobreNome, obj_stSobreNome;
			var stCpf, obj_stCpf;
			var stRg, obj_stRg;
			var dtNascimento, obj_dtNascimento;
			var nmDddTelefone, obj_nmDddTelefone;
			var stTelefone, obj_stTelefone;
			var nmDddCelular1, obj_nmDddCelular1;
			var stCelular1, obj_stCelular1;
			var nmDddCelular2, obj_nmDddCelular2;
			var stCelular2, obj_stCelular2;
			var nmDddTelComercial, obj_nmDddTelComercial;
			var stTelComercial, obj_stTelComercial;
			var stEmail, obj_stEmail;
			var nmCep, obj_nmCep;
			var stPais, obj_stPais;
			var stSexo, obj_stSexoM, obj_stSexoF;

			nmTotalResults 		= objXmlRequest.responseXML.getElementsByTagName("cadastroUnico").length
			objXml 		    	= objXmlRequest.responseXML

			obj_stNome 			= document.getElementById("id_stNome");
			obj_stSobreNome		= document.getElementById("id_stSobreNome");
			obj_stRg			= document.getElementById("id_stRg");
			obj_dtNascimento	= document.getElementById("id_dtNascimento");
			obj_nmDddTelefone	= document.getElementById("id_nmDddTelefone");
			obj_stTelefone		= document.getElementById("id_stTelefone");
			obj_nmDddCelular1	= document.getElementById("id_nmDddCelular1");
			obj_stCelular1		= document.getElementById("id_stCelular1");
			obj_nmDddCelular2	= document.getElementById("id_nmDddCelular2");
			obj_stCelular2		= document.getElementById("id_stCelular2");
			obj_nmDddTelComercial = document.getElementById("id_nmDddTelComercial");
			obj_stTelComercial	= document.getElementById("id_stTelComercial");
			obj_stEmail			= document.getElementById("id_stEmail");
			obj_stPais			= document.getElementById("id_stPais");
			obj_nmCep			= document.getElementById("id_Cep");
			obj_stSexoM			= document.getElementById("id_stSexoM");
			obj_stSexoF			= document.getElementById("id_stSexoF");
			
			if(nmTotalResults > 0){
				for(i = 0 ; i < nmTotalResults ; i++){
					try{
						stNome 				= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stNome")[0].firstChild.nodeValue)
						stSobreNome			= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stSobreNome")[0].firstChild.nodeValue)
						stRg				= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stRg")[0].firstChild.nodeValue)
						dtNascimento		= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("dtNascimento")[0].firstChild.nodeValue)
						nmDddTelefone		= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("nmDddTelefone")[0].firstChild.nodeValue)
						stTelefone			= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stTelefone")[0].firstChild.nodeValue)
						nmDddCelular1		= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("nmDddCelular1")[0].firstChild.nodeValue)
						stCelular1			= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stCelular1")[0].firstChild.nodeValue)
						nmDddCelular2		= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("nmDddCelular2")[0].firstChild.nodeValue)
						stCelular2			= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stCelular2")[0].firstChild.nodeValue)
						nmDddTelComercial	= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("nmDddTelComercial")[0].firstChild.nodeValue)
						stTelComercial		= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stTelComercial")[0].firstChild.nodeValue)
						stEmail				= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stEmail")[0].firstChild.nodeValue)
						stPais				= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stPais")[0].firstChild.nodeValue)
						nmCep				= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("nmCep")[0].firstChild.nodeValue)
						stSexo				= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stSexo")[0].firstChild.nodeValue)
						obj_stNome.value			= stNome
						obj_stSobreNome.value		= stSobreNome
						obj_stRg.value				= stRg
						obj_dtNascimento.value		= dtNascimento
						obj_nmDddTelefone.value		= nmDddTelefone
						obj_stTelefone.value		= stTelefone
						obj_nmDddCelular1.value		= nmDddCelular1
						obj_stCelular1.value		= stCelular1
						obj_nmDddCelular2.value		= nmDddCelular2
						obj_stCelular2.value		= stCelular2
						obj_nmDddTelComercial.value	= nmDddTelComercial
						obj_stTelComercial.value	= stTelComercial
						obj_stEmail.value			= stEmail
						obj_stPais.value			= stPais
						nmLength					= nmCep.length
						if(stSexo == "M"){
							obj_stSexoM.checked = true;
						}else if(stSexo == "F"){
							obj_stSexoF.checked = true;
						}
						if (nmLength == 7){
							obj_nmCep.value	= "0" + nmCep;
							buscaCep(nmCep);
						}else{
							obj_nmCep.value	= nmCep;
							buscaCep(nmCep);
						}
					} catch(ex){
						alert('Um erro ocorreu ao tentar carregar os dados. Tente novamente.\nDescrição: ' + ex.message)
					}
				}	
			}
			else{
			limpaCadastroUnico();
			}
		}
	}
}

function buscaCadastroUnicoRg(stRg){
	RunAjaxRequest('POST', '../../xml/cadastroUnicoRg-dados.asp', 'stRg='+stRg+'', retornaXmlCadastroUnicoRg);
}

function retornaXmlCadastroUnicoRg(objXmlRequest){
	var obj_Rg 	= document.getElementById("id_stRg");
	var obj_Cpf	= document.getElementById("id_nmCpf");
	if(objXmlRequest.readyState == 4 && obj_Cpf.value == ""){
		if(objXmlRequest.status == 200){
			var stNome, obj_stNome;
			var stSobreNome, obj_stSobreNome;
			var dtNascimento, obj_dtNascimento;
			var nmDddTelefone, obj_nmDddTelefone;
			var stTelefone, obj_stTelefone;
			var nmDddCelular1, obj_nmDddCelular1;
			var stCelular1, obj_stCelular1;
			var nmDddCelular2, obj_nmDddCelular2;
			var stCelular2, obj_stCelular2;
			var nmDddTelComercial, obj_nmDddTelComercial;
			var stTelComercial, obj_stTelComercial;
			var stEmail, obj_stEmail;
			var nmCep, obj_nmCep;
			var stPais, obj_stPais;
			var stSexo, obj_stSexoM, obj_stSexoF;

			nmTotalResults 		= objXmlRequest.responseXML.getElementsByTagName("cadastroUnico").length
			objXml 		    	= objXmlRequest.responseXML

			obj_stNome 			= document.getElementById("id_stNome");
			obj_stSobreNome		= document.getElementById("id_stSobreNome");
			obj_dtNascimento	= document.getElementById("id_dtNascimento");
			obj_nmDddTelefone	= document.getElementById("id_nmDddTelefone");
			obj_stTelefone		= document.getElementById("id_stTelefone");
			obj_nmDddCelular1	= document.getElementById("id_nmDddCelular1");
			obj_stCelular1		= document.getElementById("id_stCelular1");
			obj_nmDddCelular2	= document.getElementById("id_nmDddCelular2");
			obj_stCelular2		= document.getElementById("id_stCelular2");
			obj_nmDddTelComercial = document.getElementById("id_nmDddTelComercial");
			obj_stTelComercial	= document.getElementById("id_stTelComercial");
			obj_stEmail			= document.getElementById("id_stEmail");
			obj_stPais			= document.getElementById("id_stPais");
			obj_nmCep			= document.getElementById("id_Cep");
			obj_stSexoM			= document.getElementById("id_stSexoM");
			obj_stSexoF			= document.getElementById("id_stSexoF");
			
			if(nmTotalResults > 0){
				for(i = 0 ; i < nmTotalResults ; i++){
					try{
						stNome 				= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stNome")[0].firstChild.nodeValue)
						stSobreNome			= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stSobreNome")[0].firstChild.nodeValue)
						dtNascimento		= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("dtNascimento")[0].firstChild.nodeValue)
						nmDddTelefone		= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("nmDddTelefone")[0].firstChild.nodeValue)
						stTelefone			= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stTelefone")[0].firstChild.nodeValue)
						nmDddCelular1		= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("nmDddCelular1")[0].firstChild.nodeValue)
						stCelular1			= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stCelular1")[0].firstChild.nodeValue)
						nmDddCelular2		= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("nmDddCelular2")[0].firstChild.nodeValue)
						stCelular2			= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stCelular2")[0].firstChild.nodeValue)
						nmDddTelComercial	= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("nmDddTelComercial")[0].firstChild.nodeValue)
						stTelComercial		= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stTelComercial")[0].firstChild.nodeValue)
						stEmail				= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stEmail")[0].firstChild.nodeValue)
						stPais				= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stPais")[0].firstChild.nodeValue)
						nmCep				= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("nmCep")[0].firstChild.nodeValue)
						stSexo				= (objXml.getElementsByTagName("cadastroUnico")[i].getElementsByTagName("stSexo")[0].firstChild.nodeValue)
						obj_stNome.value			= stNome
						obj_stSobreNome.value		= stSobreNome
						obj_dtNascimento.value		= dtNascimento
						obj_nmDddTelefone.value		= nmDddTelefone
						obj_stTelefone.value		= stTelefone
						obj_nmDddCelular1.value		= nmDddCelular1
						obj_stCelular1.value		= stCelular1
						obj_nmDddCelular2.value		= nmDddCelular2
						obj_stCelular2.value		= stCelular2
						obj_nmDddTelComercial.value	= nmDddTelComercial
						obj_stTelComercial.value	= stTelComercial
						obj_stEmail.value			= stEmail
						obj_stPais.value			= stPais
						nmLength					= nmCep.length
						if(stSexo == "M"){
							obj_stSexoM.checked = true;
						}else if(stSexo == "F"){
							obj_stSexoF.checked = true;
						}
						if (nmLength == 7){
							obj_nmCep.value	= "0" + nmCep;
							buscaCep(nmCep);
						}else{
							obj_nmCep.value	= nmCep;
							buscaCep(nmCep);
						}
					} catch(ex){
					alert('Um erro ocorreu ao tentar carregar os dados. Tente novamente.\nDescrição: ' + ex.message)
					}
				}	
			}
			else{
				limpaCadastroUnico();
			}
		}
	}
}

function retornaXmlCepCobranca(objXmlRequest){
	var obj_Cep 	= document.getElementById("id_nmCepCobranca");

	if(objXmlRequest.readyState == 4){
		if(objXmlRequest.status == 200){
			var stLogradouro, obj_stLogradouro;
			var stEndereco, obj_Endereco;
			var stBairro, obj_Bairro;
			var stCidade, obj_Cidade;
			var stUf, obj_stUf;

			nmTotalResults 		= objXmlRequest.responseXML.getElementsByTagName("logradouro").length
			objXml 		    	= objXmlRequest.responseXML

			obj_stLogradouro 	= document.getElementById("id_stLogradouroCobranca");
			obj_Endereco		= document.getElementById("id_stEnderecoCobranca");
			obj_Bairro			= document.getElementById("id_stBairroCobranca");
			obj_Cidade			= document.getElementById("id_stCidadeCobranca");
			obj_stUf		  	= document.getElementById("id_stEstadoCobranca");
			
			if(nmTotalResults > 0){
				for(i = 0 ; i < nmTotalResults ; i++){
					stLogradouro = (objXml.getElementsByTagName("logradouro")[i].getElementsByTagName("stLogradouro")[0].firstChild.nodeValue)
					stEndereco   = (objXml.getElementsByTagName("logradouro")[i].getElementsByTagName("stEndereco")[0].firstChild.nodeValue)
				    stBairro     = (objXml.getElementsByTagName("logradouro")[i].getElementsByTagName("stBairro")[0].firstChild.nodeValue)
				    stCidade     = (objXml.getElementsByTagName("logradouro")[i].getElementsByTagName("stCidade")[0].firstChild.nodeValue)
				    stUf		 = (objXml.getElementsByTagName("logradouro")[i].getElementsByTagName("stUf")[0].firstChild.nodeValue)
					
					for(nmInc = 0; nmInc < obj_stLogradouro.length; nmInc ++){
						if(Trim(obj_stLogradouro[nmInc].value.toUpperCase()) == Trim(stLogradouro.toUpperCase())) obj_stLogradouro[nmInc].selected = true
					}
					
					for(nmInc = 0; nmInc < obj_stUf.length; nmInc ++){
						if(Trim(obj_stUf[nmInc].value.toUpperCase()) == Trim(stUf.toUpperCase())) obj_stUf[nmInc].selected = true
					}

					obj_Endereco.value											= stEndereco
					obj_Bairro.value											= stBairro
					obj_Cidade.value											= stCidade
				}
			}else{
				limpaCampoCepCobranca();
			}
		}
	}
}

function limpaCampoCepCobranca(){
	var obj_Cep 			= document.getElementById("id_nmCepCobranca");
	var obj_stLogradouro 	= document.getElementById("id_stLogradouroCobranca");
	var obj_Endereco		= document.getElementById("id_stEnderecoCobranca");
	var obj_Bairro			= document.getElementById("id_stBairroCobranca");

	var obj_Cidade			= document.getElementById("id_stCidadeCobranca");
	var obj_stUf			= document.getElementById("id_stEstadoCobranca");
	
	obj_Endereco.value		= '';
	obj_Bairro.value		= '';
	obj_Cidade.value		= '';
//	obj_Cep.value			= '';
	
	obj_stLogradouro.options[0].selected	= true;
	obj_stUf.options[0].selected			= true;
}*/