var form;

function setForm(objForm) {
	this.form	= objForm;
}


function cep_carregar() {
	form.statusVC.value				= 'Digite o CEP e aguarde.';
}

function cep_enable() {
	cep_erase();
	
	with(form) {
		enderecoVC.disabled			= false;
		numeroVC.disabled			= false;
		complementoVC.disabled		= false;
		bairroVC.disabled			= false;
		cidadeVC.disabled			= false;
		estadoVC.disabled			= false;
	}
}

function cep_readonly() {
	with(form) {
		enderecoVC.readOnly			= true;
		numeroVC.readOnly			= false;
		complementoVC.readOnly		= false;
		bairroVC.readOnly			= true;
		cidadeVC.readOnly			= true;
		estadoVC.readOnly			= true;
	}
}

function cep_disabled() {
	with(form) {
		enderecoVC.disabled			= true;
		numeroVC.disabled			= true;
		complementoVC.disabled		= true;
		bairroVC.disabled			= true;
		cidadeVC.disabled			= true;
		estadoVC.disabled			= true;
	}
}

function cep_erase() {
	with(form) {
		enderecoVC.value				= '';
		numeroVC.value					= '';
		complementoVC.value				= '';
		bairroVC.value					= '';
		cidadeVC.value					= '';
		estadoVC.value					= '';
	}
}

function contar_cep(frmName, evtKeyPress) {
	setForm(frmName);

	if (form.cepVC.value.length == 5) {
		form.cepVC.value		= form.cepVC.value + '-';
	} else if (form.cepVC.value.length > 8) {
		form.statusVC.value		= 'Aguarde! Pesquisando...';
			
		iframeVirtual('../temp/cep.asp?cep='+form.cepVC.value)


	}
	
//	var it_tecla;
//	it_tecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
//	if(it_tecla == 13) return false;	// ñ deixa submeter o form ao pressionar [ENTER] no campo CEP
}

function contar_cep_localidade(frmName, evtKeyPress) {
	setForm(frmName);

	if (form.cepVC.value.length == 5) {
		form.cepVC.value		= form.cepVC.value + '-';
	} else if (form.cepVC.value.length > 8) {
		form.statusVC.value		= 'Aguarde! Pesquisando...';
		iframeVirtual('../temp/cep.asp?cep='+form.cepVC.value+'&itFlagLocalidade=1')

	}
	
//	var it_tecla;
//	it_tecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
//	if(it_tecla == 13) return false;	// ñ deixa submeter o form ao pressionar [ENTER] no campo CEP
}

function cep_preencher(vc_informacoes) {
	if (vc_informacoes != 0) {
		var vc_informacao				= vc_informacoes.split("#");
		
		cep_enable();
		
		with(form) {
			statusVC.value				= 'CEP encontrado!';
			enderecoVC.value			= vc_informacao[0];
			numeroVC.value				= '';
			complementoVC.value			= '';
			bairroVC.value				= vc_informacao[1];
			cidadeVC.value				= vc_informacao[2];
			estadoVC.value				= vc_informacao[3];
		}
		
//		cep_readonly();

		form.numeroVC.focus();

	} else {
		cep_enable();
		
		form.statusVC.value			= 'CEP não encontrado!';
		form.enderecoVC.focus();
	}
}

function cep_preencher_localidade(vc_informacoes) {
	if (vc_informacoes != 0) {
		var vc_informacao				= vc_informacoes.split("#");
		
		cep_enable();
		
		with(form) {
			statusVC.value				= 'CEP encontrado!';
			document.getElementById('sp_localidade').innerHTML	= '<b>Localidade:</b> ' + vc_informacao[2] + ' - ' + vc_informacao[3];
		}
		
//		cep_readonly();

//		form.numeroVC.focus();

	} else {
		cep_enable();
		
		form.statusVC.value			= 'CEP não encontrado!';
//		form.enderecoVC.focus();
	}
}