
function Complementa(comp,onde){
	var string = comp.id						//pega o id
	var busca_str = string.lastIndexOf("_");	//procura o campo do id
		busca_str++								//pega onde esta campo string do numero do id
	var pega_str = string.charAt(busca_str);	//pega o id atual
	var local = onde+pega_str;
	
	//alert(local);
	
	var Local = document.getElementById(local);
	var complemento = Local.getElementsByTagName('span');
	//alert(complemento)
	if(complemento.length){
		complemento[0].innerHTML = comp.value;		
	} 

}

function insere_complemento(comp,local){
	var comp = document.getElementById(comp);
	if(comp.value != ""){
		Complementa(comp,local);
	}
	
	enabledForm("theform");
}

function BuscaCep(cep,local,valor_ant,complemento,addList){
	
	var string_cep = cep.id							//pega o id
	var busca_str = string_cep.lastIndexOf("_");	//procura o campo do id
	busca_str++										//pega onde esta campo string do numero do id
	var pega_str = string_cep.charAt(busca_str);	//pega o id atual
	
	var local_1 = local+pega_str;					//muda o id
	var valor_ant_1 = valor_ant+pega_str;			//muda o id
	var complemento = complemento+pega_str;
	var valor_ant_2 = document.getElementById(valor_ant_1);
	var complemento = document.getElementById(complemento);
	///alert(cep.value.length)
	if(cep.value != "" && cep.value.length == 9 && cep.value != valor_ant_2.value){
		//alert('ok')
		if(!addList){
			valor_ant_2.value = cep.value;
			ajax("Library/resultado_cep.php","text_cep="+cep.value,local_1,null,null,null,"insere_complemento('"+complemento.id+"','"+local+"')");
		}else{
			AddListFunctions("ajax('Library/resultado_cep.php','text_cep="+cep.value+"',"+local_1+",null,null,null,\"insere_complemento('"+complemento.id+"','"+local+"')\");");
		}
	} else {
		return false;
	}
}

	
