function limpa_linhas(v){
	var nova = v.replace('\r\n','');
	nova = nova.replace('\n','');
	nova = nova.replace('\r','');
	nova = nova.replace('\n\r','');	
	return nova;
}

function trava() {
document.cadastra.Enviar.disabled = true;
document.cadastra.submit();
}

function trava_proprietario(id_proprietario) {
	if (document.cadastra.cliente_vinculado.value=='XXX'){
		document.cadastra.Sprop_nome.disabled = false;
		document.cadastra.Sprop_endereco.disabled = false;
		document.cadastra.Sprop_numero.disabled = false;
		document.cadastra.Sprop_cep.disabled = false;	
		document.cadastra.Sprop_bairro.disabled = false;	
		document.cadastra.Sprop_cidade.disabled = false;	
		document.cadastra.Sprop_estado.disabled = false;	
		document.cadastra.Sprop_email.disabled = false;	
		document.cadastra.Sprop_fone.disabled = false;	
		document.cadastra.Sprop_celular.disabled = false;	
		document.cadastra.Sprop_rg.disabled = false;	
		document.cadastra.Sprop_celular.disabled = false;	
		document.cadastra.Sprop_cpf.disabled = false;	
		retorna_usuario(id_proprietario);
		
	}else{
		retorna_usuario(id_proprietario);
		//alert(document.cadastra.cliente_vinculado.value);
		document.cadastra.Sprop_nome.disabled = true;
		document.cadastra.Sprop_endereco.disabled = true;
		document.cadastra.Sprop_numero.disabled = true;
		document.cadastra.Sprop_cep.disabled = true;	
		document.cadastra.Sprop_bairro.disabled = true;	
		document.cadastra.Sprop_cidade.disabled = true;	
		document.cadastra.Sprop_estado.disabled = true;	
		document.cadastra.Sprop_email.disabled = true;	
		document.cadastra.Sprop_fone.disabled = true;	
		document.cadastra.Sprop_celular.disabled = true;	
		document.cadastra.Sprop_rg.disabled = true;	
		document.cadastra.Sprop_celular.disabled = true;	
		document.cadastra.Sprop_cpf.disabled = true;	
		
	}
}


		function objXMLHttp(){
		if (window.XMLHttpRequest){ //monzila, safari
			var objetoXMLHttp = new XMLHttpRequest();
			return objetoXMLHttp;
		}else if (window.ActiveXObject){ //ie
			//todas as versoes de ie
			var versoes = ["MSXML2.XMLHttp.6.0","MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp.2.0","Microsoft.XMLHttp"];
		
					for ( var i=0; i<versoes.length; i++){
							try{
							var objetoXMLHttp = new ActiveXObject(versoes[i]);
							return objetoXMLHttp;
							} catch(ex){
							//nada aqui //kuroleweb design
							}//end try
					}//end for	
		}			
		return false;	
		} // end objXMLHttp
		
		
function retorna_usuario(formulario){
				
		var dados = "id_proprietario="+formulario;
		
		var oXMLHttp = objXMLHttp();
			oXMLHttp.open("POST", "add_retorna_proprietario.php", true);
			oXMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			oXMLHttp.onreadystatechange = function(){
				if (oXMLHttp.readyState == 4){
					if (oXMLHttp.status == 200){
						
						var results = oXMLHttp.responseText.split(",");		
						//$novo_resultado = (results.length-1);

								var string = results[1].split( "|" );
								
	
								if (string[0] == "nome"){
									window.document.forms[0].Sprop_nome.value = string[1];
								}else{
									window.document.forms[0].Sprop_nome.value = "";
								}
								var string = results[2].split( "|" );
								if (string[0] == "endereco"){
									window.document.forms[0].Sprop_endereco.value = string[1];
								}else{
									window.document.forms[0].Sprop_endereco.value = "";
								}						
								var string = results[3].split( "|" );
								if (string[0] == "numero"){
									window.document.forms[0].Sprop_numero.value = string[1];
								}else{
									window.document.forms[0].Sprop_numero.value = "";
								}
								var string = results[4].split( "|" );
								if (string[0] == "cep"){
									window.document.forms[0].Sprop_cep.value = string[1];
								}else{
									window.document.forms[0].Sprop_cep.value = "";
								}
								var string = results[5].split( "|" );
								if (string[0] == "bairro"){
									window.document.forms[0].Sprop_bairro.value = string[1];
								}else{
									window.document.forms[0].Sprop_bairro.value = "";
								}						
								var string = results[6].split( "|" );
								if (string[0] == "cidade"){
									window.document.forms[0].Sprop_cidade.value = string[1];
								}else{
									window.document.forms[0].Sprop_cidade.value = "";
								}
								var string = results[7].split( "|" );
								if (string[0] == "estado"){
									window.document.forms[0].Sprop_estado.value = string[1];
								}else{
									window.document.forms[0].Sprop_estado.value = "";
								}														
								var string = results[8].split( "|" );
								if (string[0] == "email"){
									window.document.forms[0].Sprop_email.value = string[1];
								}else{
									window.document.forms[0].Sprop_email.value = "";
								}	
								var string = results[9].split( "|" );
								if (string[0] == "fone"){
									window.document.forms[0].Sprop_fone.value = string[1];
								}else{
									window.document.forms[0].Sprop_fone.value = "";
								}
								var string = results[10].split( "|" );
								if (string[0] == "celular"){
									window.document.forms[0].Sprop_celular.value = string[1];
								}else{
									window.document.forms[0].Sprop_celular.value = "";
								}
								var string = results[11].split( "|" );
								if (string[0] == "rg"){
									window.document.forms[0].Sprop_rg.value = string[1];
								}else{
									window.document.forms[0].Sprop_rg.value = "";
								}
								var string = results[12].split( "|" );
								if (string[0] == "cpf"){
									window.document.forms[0].Sprop_cpf.value = string[1];
								}else{
									window.document.forms[0].Sprop_cpf.value = "";
								}
								
					
					}else{
						//window.alert('Erro ao adicionar!');
						//mensagem("Ocorreu um erro: "+oXMLHttp.statusText);
					}
				}
			};//end function onreadystatechange
			oXMLHttp.send(dados);
			return false;
	
	}//end function enviar formulario
	
	
//modelo 2 de fromatar valor
//chamada da funcao
//onKeyDown="Formata_VALOR(this,11,event,2)"
//kurolewebdesign kurole@kurole.com.br

function Limpar(valor, validos) {
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
	aux = validos.indexOf(valor.substring(i, i+1));
	if (aux>=0) {
	result += aux;
	}
	}
	return result;
}


function Formata_VALOR(campo,tammax,teclapres,decimal) {
	
	var tecla = teclapres.keyCode;

	var vr = Limpar(campo.value,"0123456789");
	var tam = vr.length;
	var dec=decimal
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
	
	if (tecla == 8 )
	{ tam = tam - 1 ; }
	
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
	{
	
	if ( tam <= dec )
	{ campo.value = vr ; }

	if ( (tam > dec) && (tam <= 5) ){
	campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 6) && (tam <= 8) ){
	campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
	}
	
	if ( (tam >= 9) && (tam <= 11) ){
		campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 12) && (tam <= 14) ){
		campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 15) && (tam <= 17) ){
		campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
	}	

}	

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function cep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function cnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}

function romanos(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
    //Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
        v=v.replace(/.$/,"")
    return v
}

function site(v){
    //Esse sem comentarios para que você entenda sozinho ;-)
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}

//////////////////////////////////////////////////// Adicionado dia 25/11/2011 por Renan /////////////////////////////////////////////////

function proximo_campo_cep(cep_next){
	if (cep_next.length == 5){
		document.forms[0].cep_2.focus();
		document.forms[0].cep_2.value = '';
	}
}
	
function proximo_campo_cep_2(cep_next){
	if (cep_next.length == 3){
		window.document.forms[0].numero.focus();
		retorna_cep_interno(document.forms[0].cep_1.value+document.forms[0].cep_2.value);
	}
}

/////////////////////////////////////////////////////////////// CEP CORREIOS DA TABELA DO IMOVEL	
	
function retorna_cep_CORREIOS_ADD_IMOVEIS(cep){
	var dados = "cep="+cep;
	var oXMLHttp = objXMLHttp();
	oXMLHttp.open("POST", "ajax/ajax_mostra_cep_correios.php", true);
	oXMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	oXMLHttp.onreadystatechange = function(){
		if (oXMLHttp.readyState == 4){
			if (oXMLHttp.status == 200){
				var xmldoc = oXMLHttp.responseXML;
				
				if(xmldoc.getElementsByTagName('logradouro').item(0)){
					if(xmldoc.getElementsByTagName('logradouro').item(0).childNodes.length != 0){
						var logradouro = xmldoc.getElementsByTagName('logradouro').item(0).firstChild.data;
						if(xmldoc.getElementsByTagName('tipo_logradouro').item(0).childNodes.length != 0){
							var tipo_logradouro = xmldoc.getElementsByTagName('tipo_logradouro').item(0).firstChild.data;
						}else{
							var tipo_logradouro = "";
						}
						window.document.getElementById('endereco').value 		= (tipo_logradouro != "" ? tipo_logradouro+" " : "")+logradouro;
					}else{
						window.document.getElementById('endereco').value = "";
					}
				}
				if(xmldoc.getElementsByTagName('bairro').item(0)){
					if(xmldoc.getElementsByTagName('bairro').item(0).childNodes.length != 0){
						window.document.getElementById('bairro').value 		= xmldoc.getElementsByTagName('bairro').item(0).firstChild.data;
					}else{
						window.document.getElementById('bairro').value = "";
					}
				}
				if(xmldoc.getElementsByTagName('cidade').item(0)){
					if(xmldoc.getElementsByTagName('cidade').item(0).childNodes.length != 0){
						window.document.getElementById('imovel_cidade').value 		= xmldoc.getElementsByTagName('cidade').item(0).firstChild.data;
					}else{
						window.document.getElementById('imovel_cidade').value = "";
					}
				}
				if(xmldoc.getElementsByTagName('uf').item(0)){
					if(xmldoc.getElementsByTagName('uf').item(0).childNodes.length != 0){
						window.document.getElementById('estado').value 		= xmldoc.getElementsByTagName('uf').item(0).firstChild.data;
					}else{
						window.document.getElementById('estado').value = "";
					}
				}
				document.getElementById('multiplo_informacao').innerHTML = '<font color=blue>Tabela Correios</font>';
				//finaliza o preload
				window.document.getElementById('carrega_preload').innerHTML='';
			}else{
				//window.alert('Erro ao adicionar!');
				//mensagem("Ocorreu um erro: "+oXMLHttp.statusText);
			}
		}
	};//end function onreadystatechange
	oXMLHttp.send(dados);
	return false;
}//end function enviar formulario	
	
	
	
	
function carregando_preloader(){
		return "<img src='http://www.imobiliariapiramide.com.br/kurole-sistema-imobiliario-homologado-piramid-imoveiS/img/carregando.gif' border=0>";
}	
	
	
	
	function retorna_cep_interno(cep){
		//preload
		window.document.getElementById('carrega_preload').innerHTML=carregando_preloader();		
		
		var dados = "cep="+cep;

		var oXMLHttp = objXMLHttp();
			oXMLHttp.open("POST", "ajax/ajax_mostra_cep.php", true);
			
			
			oXMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			oXMLHttp.onreadystatechange = function(){
				if (oXMLHttp.readyState == 4){
					//alert(oXMLHttp.status);
					if (oXMLHttp.status == 200){
						var results = oXMLHttp.responseText.split("^");	


								//##############################################
								//vamos utilizar a cidade... caso a cidade retorne vazia vamos chamar a funcao que procura o cep nos correios.....
								/**/	var string = results[2].split( "|" );
								/**/	if (string[0] == "cidade"){
								/**/		//tira todos os espacos da string
								/**/			//alert(limpa_linhas(string[1]));
								/**/		if (limpa_linhas(string[1]) == ''){
								/**/			window.document.getElementById('carrega_preload').innerHTML=carregando_preloader();	
								/**/			//aqui a funcao que chama de fora...
								/**/			retorna_cep_CORREIOS_ADD_IMOVEIS(cep);	
								/**/		}
								/**/	}								
								// FIM DA FUNCAO CHAMA OS CEPS DOS CORREIOS (EXTERNOS)
								
	
								var string = results[1].split( "|" );
								if (string[0] == "endereco"){
									window.document.forms[0].endereco.value = string[1];
								}else{
									window.document.forms[0].endereco.value = "";
								}						

								
								var string = results[2].split( "|" );
								if (string[0] == "cidade"){
									window.document.forms[0].imovel_cidade.value = string[1];
								}else{
									window.document.forms[0].imovel_cidade.value = "";
								}
								
								var string = results[3].split( "|" );
								if (string[0] == "bairro"){
									window.document.forms[0].bairro.value = string[1];
								}else{
									window.document.forms[0].bairro.value = "";
								}						
							
								var string = results[4].split( "|" );
								if (string[0] == "estado"){
									window.document.forms[0].estado.value  = string[1]
								}else{
									window.document.forms[0].estado.value = "";
								}
								
								var string = results[5].split( "|" );
								if (string[0] == "multiplo"){
									document.getElementById('multiplo_informacao').innerHTML = string[1];
								}
								
								var string = results[6].split( "|" );
								if (string[0] == "setor"){
									window.document.forms[0].setor.value = string[1];
								}else{
									window.document.forms[0].setor.value = "";
								}
								//finalizar o preload
								window.document.getElementById('carrega_preload').innerHTML='';
								//zera os campos quando for alterar no cadastrar clientes....
									if (window.document.forms[0].unidade){
										window.document.forms[0].unidade.value 		= 0;
									}
								window.document.forms[0].complemento.value 	= '';
								window.document.forms[0].setor.value 		= '';
								window.document.forms[0].numero.value 		= '';
					
					}else{
						//window.alert('Erro ao adicionar!');
						//mensagem("Ocorreu um erro: "+oXMLHttp.statusText);
					}
				}
			};//end function onreadystatechange
			oXMLHttp.send(dados);
			return false;
	
	}//end function enviar formulario
	
	
/////////////////////////////////////////////////////////////// FIM CEP CORREIOS DA TABELA DO IMOVEL	

function retorna_cep_CLIENTES_correios(cep_correios, url){
		
		window.document.getElementById('carrega_preload_cliente').innerHTML=carregando_preloader();			
		
		var dados_correio = "cep="+cep_correios;
		
		
	
		if (url.indexOf('../ajax/ajax_mostra_cep') != -1){
			var url_envia =	"../ajax/ajax_mostra_cep_correios.php";
		}else{
			var url_envia =	"ajax/ajax_mostra_cep_correios.php";	
		}
		
		
		var oXMLHttp = objXMLHttp();
			oXMLHttp.open("POST", url_envia, true);
			oXMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			oXMLHttp.onreadystatechange = function(){
				if (oXMLHttp.readyState == 4){
					//alert(oXMLHttp.status);
					if (oXMLHttp.status == 200){
								var xmldoc = oXMLHttp.responseXML;
						if(xmldoc.getElementsByTagName('logradouro').item(0)){		
							if(xmldoc.getElementsByTagName('logradouro').item(0).childNodes.length != 0){
								var logradouro = xmldoc.getElementsByTagName('logradouro').item(0).firstChild.data;
								if(xmldoc.getElementsByTagName('tipo_logradouro').item(0).childNodes.length != 0){
									var tipo_logradouro = xmldoc.getElementsByTagName('tipo_logradouro').item(0).firstChild.data;
								}else{
									var tipo_logradouro = "";
								}
								window.document.getElementById('Sprop_endereco').value 		= (tipo_logradouro != "" ? tipo_logradouro+" " : "")+logradouro;
							}else{
								window.document.getElementById('Sprop_endereco').value = "";
							}
						}
						if(xmldoc.getElementsByTagName('bairro').item(0)){
							if(xmldoc.getElementsByTagName('bairro').item(0).childNodes.length != 0){
								window.document.getElementById('Sprop_bairro').value 		= xmldoc.getElementsByTagName('bairro').item(0).firstChild.data;
							}else{
								window.document.getElementById('Sprop_bairro').value = "";
							}
						}
						if(xmldoc.getElementsByTagName('cidade').item(0)){
							if(xmldoc.getElementsByTagName('cidade').item(0).childNodes.length != 0){
								window.document.getElementById('Sprop_cidade').value 		= xmldoc.getElementsByTagName('cidade').item(0).firstChild.data;
							}else{
								window.document.getElementById('Sprop_cidade').value = "";
							}
						}
						if(xmldoc.getElementsByTagName('uf').item(0)){
							if(xmldoc.getElementsByTagName('uf').item(0).childNodes.length != 0){
								window.document.getElementById('Sprop_estado').value = xmldoc.getElementsByTagName('uf').item(0).firstChild.data;
								//window.document.getElementById('Sprop_estado').text = xmldoc.getElementsByTagName('uf').item(0).firstChild.data;
							}else{
								window.document.getElementById('estado').value = "";
							}
						}
						document.getElementById('multiplo_informacao').innerHTML = '<font color=blue>Tabela Correios</font>';
						//finaliza o preload
						window.document.getElementById('carrega_preload').innerHTML='';
					
					}else{
						//window.alert('Erro ao adicionar!');
						//alert("Ocorreu um erro: "+oXMLHttp.statusText);
					}
				}
			};//end function onreadystatechange
			oXMLHttp.send(dados_correio);
			return false;
	
	}//end function enviar formulario
	
	
	
	
	
	
	
	
	
	
	
	function retorna_cep_CLIENTES(cep2, url){

		//chama o carregando.....
		window.document.getElementById('carrega_preload_cliente').innerHTML=carregando_preloader();		
		
		if (url != ''){
			var url_envia =	url;		
		}else{
			var url_envia =	"ajax/ajax_mostra_cep.php";	
		}
		
		var dados = "cep="+cep2;
		var oXMLHttp = objXMLHttp();
			oXMLHttp.open("POST", url_envia, true);
			oXMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");	
			oXMLHttp.onreadystatechange = function(){
				if (oXMLHttp.readyState == 4){
					//alert(oXMLHttp.status);
					if (oXMLHttp.status == 200){
						var results = oXMLHttp.responseText.split("^");		
						//$novo_resultado = (results.length-1);

				//	alert(results[0].length);
				/*		if (results[0].length > 5){
							var string = results[0].split( "|" );
							desabilita_campos();
							ajax_mostra_proprietario2(string[0]);
						}

					*/			
					
					
								var string = results[1].split( "|" );
						
								//##############################################
								//vamos utilizar a cidade... caso a cidade retorne vazia vamos chamar a funcao que procura o cep nos correios.....
								/**/	var string = results[2].split( "|" );
								/**/	if (string[0] == "cidade"){
								/**/		//tira todos os espacos da string
								/**/			
								/**/		if (limpa_linhas(string[1]) == ''){
								/**/			
								/**/			//chama o carregando.....
								/**/			window.document.getElementById('carrega_preload_cliente').innerHTML=carregando_preloader();	
								/**/			//alert(cep2+'-'+url_envia);	
								/**/			//aqui a funcao que chama de fora...
								/**/			retorna_cep_CLIENTES_correios(cep2, url_envia);	
								/**/		}
								/**/	}								
								// FIM DA FUNCAO CHAMA OS CEPS DOS CORREIOS (EXTERNOS)
	
								var string = results[1].split( "|" );
								if (string[0] == "endereco"){
									window.document.forms[0].Sprop_endereco.value = string[1];
								}else{
									window.document.forms[0].Sprop_endereco.value = "";
								}						

								
								var string = results[2].split( "|" );
								if (string[0] == "cidade"){
									window.document.forms[0].Sprop_cidade.value = string[1];
								}else{
									window.document.forms[0].Sprop_cidade.value = "";
								}
								
								var string = results[3].split( "|" );
								if (string[0] == "bairro"){
									window.document.forms[0].Sprop_bairro.value = string[1];
								}else{
									window.document.forms[0].Sprop_bairro.value = "";
								}						
								
								
								var string = results[4].split( "|" );
								if (string[0] == "estado"){
									window.document.forms[0].Sprop_estado.value  = string[1]
								}else{
									window.document.forms[0].Sprop_estado.value = "";
								}
								/*
								var string = results[5].split( "|" );
								if (string[0] == "multiplo"){
									document.getElementById('multiplo_informacao').innerHTML = string[1];
								}
								
								var string = results[6].split( "|" );
								if (string[0] == "setor"){
									window.document.forms[0].setor.value = string[1];
								}else{
									window.document.forms[0].setor.value = "";
								}
								*/
								/*if (document.getElementsByName('Sprop_unidade').length != 0){
									window.document.forms[0].Sprop_unidade.value = "";
								}*/
								
								if (document.getElementsByName('Sprop_complemento').length != 0){	
									window.document.forms[0].Sprop_complemento.value = "";
								}

								window.document.forms[0].Sprop_numero.value = "";
								//finaliza o carregando.....
								window.document.getElementById('carrega_preload_cliente').innerHTML='';	
					
					}else{
						//window.alert('Erro ao adicionar!');
						//mensagem("Ocorreu um erro: "+oXMLHttp.statusText);
					}
				}else{
				//	alert('Falha tente novamente: '+oXMLHttp.responseText);	
				}
			};//end function onreadystatechange
			oXMLHttp.send(dados);
			return false;
	
	}//end function enviar formulario
