function createXMLHttpRequest()
{
  try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
  try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
  try { return new XMLHttpRequest(); } catch(e) {}
  alert("XMLHttpRequest not supported");
  return null;
}
function ajax_encode(texto)
{
	texto = texto.toString();
	utftexto = ""
	for (var n = 0; n < texto.length; n++)
	{
		var c = texto.charCodeAt(n);
		if(c >= 128)
			utftexto += "&#"+c+";";
		else
			utftexto += String.fromCharCode(c);
	}
	utftexto = utftexto.replace(/\u2019/,"'");
	utftexto = utftexto.replace(/\u201C/,"\"");
	utftexto = utftexto.replace(/\u201D/,"\"");
	utftexto = encodeURIComponent(utftexto);
	return utftexto;
}

function cep(cep) {
	var cep = cep.value;
	var resposta = GOL.request("GET", "/especial/gol/ajax/ajax_cep.php?cep="+ cep + "&formato=ajax");
	if(resposta)
	{
		resposta = resposta.split(";");
		if(GetObject("cad[estado]").type != "text")
		{
			for(i=0;i<GetObject("cad[estado]").options.length;i++)
			{
				if(GetObject("cad[estado]").options[i].value == resposta[0])
					GetObject("cad[estado]").options[i].selected = true;
			}
		}
		else{
			GetObject("cad[estado]").value = resposta[1] // Estado
		}
		GetObject("cad[cidade]").value = resposta[2] // Cidade
		GetObject("cad[bairro]").value = resposta[3] // Bairro
		GetObject("cad[endereco]").value = resposta[4] // Endereco
		return true;
	}
	else
	{
		return false;
	}

	void(0);
}
