jQuery.cepFill = function(options, user_estados) {

	var defaults = {
		'cep':'111',
		'url':'http://mnsolucoes/magento/index.php/mncustomer/cepfill/buscacepxml',
		endereco:null,
		bairro:null,
		cidade:null,
		estado:null
	};
	
	var estados = {'AC':320,
			'AL':1,
			'AM':2,
			'AP':3,
			'BA':4,
			'CE':5,
			'DF':6,
			'ES':7,
			'GO':8,
			'MA':9,
			'MG':10,
			'MS':11,
			'MT':12,
			'PA':13,
			'PB':14,
			'PE':15,
			'PI':16,
			'PR':17,
			'RJ':18,
			'RN':19,
			'RO':20,
			'RR':21,
			'RS':22,
			'SC':23,
			'SE':24,
			'SP':25,
			'TO':26		
		};
    	
	var options = jQuery.extend(defaults, options);
	var estados = jQuery.extend(estados, user_estados);
	
	cep = options.cep.replace(/[^0-9]/g, "");
	
	jQuery.post(options.url, {cep: cep}, function(data) {
		$erroDescricao = jQuery(data).find("Descricao").text();
		if ($erroDescricao!="") {
			alert($erroDescricao);
			return false;
		}
		$endereco = jQuery(data).find("Endereco").text();
		$bairro = jQuery(data).find("Bairro").text();
		$cidade = jQuery(data).find("Cidade").text();
		$uf = jQuery(data).find("UF").text();
		$cep = jQuery(data).find("CEP").text();
		$iduf = estados[$uf];
		
		if (options.endereco!=null) options.endereco.attr("value", $endereco);
		if (options.bairro!=null) options.bairro.attr("value", $bairro);
		if (options.cidade!=null) options.cidade.attr("value", $cidade);
		if (options.estado!=null) options.estado.attr("value", $iduf);
	});	
	
};


