function trim(value) {
	return value.replace(/\s/g, '');
}

function validaCEP() {
	var cep = $F('cep');
	var cep = cep.replace(/\s/g, '');
	if (cep.length == 9) {
		var url = '/cons/cep.api.php';
		var params = 'cep=' + cep;
		//alert('carregando cep...');
		var ajax = new Ajax.Updater('dadosCep', url, {method: 'get', parameters: params, onComplete: carregaDadosXml});
		//document.getElementById('dadosCep').style.display = 'none';
	}
}

function carregaDadosXml(req) {
	var d = req.responseText;
	var root;
	if (window.DOMParser) {
		//alert(d);
		var xmldom = new DOMParser();
		var dom = xmldom.parseFromString(d, "application/xml");
		if (!dom) return;
		var root = dom;
	} else if (window.ActiveXObject) {
		xmldom = new ActiveXObject("Microsoft.XMLDOM");
		xmldom.async = false;
		g = document.getElementById('dadosCep').childNodes[0].nodeValue;
		xmldom.loadXML(d);
		var root = xmldom;
	} else {
		alert('Desculpe, mas não é possível fazer a inscrição neste momento. Entre em contato conosco.');
	}
	
	var x = root.documentElement;
	
	var tipoLog = x.getElementsByTagName('tipoLog')[0].childNodes[0].nodeValue;
	var endereco = tipoLog+' '+x.getElementsByTagName('endereco')[0].childNodes[0].nodeValue;
	var bairro = x.getElementsByTagName('bairro')[0].childNodes[0].nodeValue;
	var cidade = x.getElementsByTagName('cidade')[0].childNodes[0].nodeValue;
	var estado = x.getElementsByTagName('estado')[0].childNodes[0].nodeValue;

	document.getElementById('endereco').value = endereco;
	document.getElementById('bairro').value = bairro;
	document.getElementById('cidade').value = cidade;
	
	var s = document.getElementById('uf');
	for (var i=0; i<s.length; i++) {
		if (s[i].value == estado) {
			s[i].selected = "select";
		}
	}
}
