
// valida formulário de cadastro de usuário
function ValCadastro(d) {
	if (d.Nome.value.length < 5) { alert('Por favor, entre com o seu Nome.'); d.Nome.focus(); return false; }
	else if (d.Email.value == '') { alert('Por favor, entre com o endereço de e-mail.'); d.Email.focus(); return false; }
	else if (vEmail(d.Email.value)) { d.Email.focus(); return false; }
	else if (d.ReEmail.value != d.Email.value) { alert('Por favor, redigite o endereço de E-mail para verificação de erros de digitação.'); d.ReEmail.focus(); return false; }
	else if (d.Usuario.value.length < 3) { alert('Por favor, entre com um Nome de Usuário válido.'); d.Usuario.focus(); return false; }
	else if (d.Senha.value.length < 3) { alert('Por favor, entre com uma Senha.'); d.Senha.focus(); return false; }
	else if (d.ReSenha.value.length < 3) { alert('Por favor, redigite a Senha para verificar possíveis erros de digitação.'); d.ReSenha.focus(); return false; }
	else if (d.Senha.value != d.ReSenha.value) { alert('Passwords digitados não-coincidentes.'); d.Senha.value = ''; d.ReSenha.value = ''; d.Senha.focus(); return false; }
	else if (d.concordo.checked != true) { alert('É necessário ler e concordar com o Termo de Uso para efetuar o cadastro.'); d.concordo.focus(); return false; }
	else { d.btn_enviar.disabled = true; return true; }
}

// formulário de seleção de tipo de classificado
function ValClassificado(d) {
	if (d.Tipo.value <= 0 || d.Tipo.value > 4) { alert('Por favor, selecione a Categoria do Classificado.'); d.Tipo.focus(); return false; }
	else { d.btn_continuar.disabled = true; return true; }
}

// formulário de validação de Classificados - Diversos
function ValClassDiversos(d) {
	if (d.idCategoria.value <= 0) { alert('Por favor, selecione a Categoria do Classificado.'); d.idCategoria.focus(); return false; }
	else if (d.Titulo.value == '') { alert('Por favor, entre com o Título do Classificado.'); d.Titulo.focus(); return false; }
	else if (d.Estado.value == '') { alert('Por favor, selecione o Estado do Item.'); d.Estado.focus(); return false; }
	else if (ValChecks(d.Comercializacao)) { alert('Por favor, ao menos uma opção de comercialização.'); d.Comercializacao[0].focus(); return false; }
	else if (d.Cidade.value == '') { alert('Por favor, entre com o nome da Cidade.'); d.Cidade.focus(); return false; }
	else if (d.UF.value == '') { alert('Por favor, selecione a UF.'); d.UF.focus(); return false; }
	else { d.btn_continuar.disabled = true; return true; }
}


function vEmail (email) {
	var BadChars = "áàâãäêéèëíìïîóòôõöúùûü*´`$#!'¨&(){}?/\^~:;,= ";
	var GoodChars = "@."; 
	var posarroba = email.indexOf ('@',0);
	
	if (email.length < 6) { return true; }
	for (var i = 0; i < email.length; i++) { if (BadChars.indexOf(email.charAt(i)) != -1) { alert('Erro 01'); return true; } }
	for (var i = 0; i < GoodChars.length; i++) {
		if (email.indexOf(GoodChars.charAt(i)) == -1) return true;
		if (email.indexOf(GoodChars.charAt(i),0) == 0) return true;
		if (email.lastIndexOf(GoodChars.charAt(i)) > email.length-3) return true;
	}
	if (email.lastIndexOf('@') > email.lastIndexOf('.')) return true;
	if (email.indexOf ('@.',0) != -1 || email.indexOf ('.@',0) != -1) return true;
	if (email.indexOf ('@',posarroba+1) != -1) return true;
	return false;
}

function Selecione(obj_select, valor) {
	if (valor != "") {
		for (i = 0; i < obj_select.options.length; i++)
			if (obj_select.options[i].value == valor) { obj_select.selectedIndex = i; break; }
	}
}

function ValContato(d) {
	if (d.Nome.value == '') { alert('Por favor, entre com o seu nome!'); d.Nome.focus(); return false; }
	else if (vEmail(d.Email.value)) { d.Email.focus(); return false; }
	else if (vEmail(d.Email.value)) { alert('E-mail inválido: ' + d.Email.value); d.Email.focus(); return false; }
	else if (d.Assunto.value.length < 5) { alert('Por favor, entre com o Assunto da Mensagem!'); d.Assunto.focus(); return false; }
	else if (d.Mensagem.value.length < 5) { alert('Por favor, entre com a Mensagem!'); d.Mensagem.focus(); return false; }
	else { return true; }
}

function BlockEdit (msg) { alert(msg); return false; }

function Abrir_Pop (pagina, coord_x, coord_y, scroll_bar, janela_nome, full_screen) {
	Janela = window.open(pagina, janela_nome,"resizable=yes,status=no,menubar=no, scrollbars=" + scroll_bar + ", directories=no, toolbar=no, fullscreen=" + full_screen + ", width=" + coord_x + ", height=" + coord_y + ", top=0, left=0");
	Janela.focus();
}

function Abrir_Foto (pagina) {
	Janela = window.open(pagina, 'Visualizar', "resizable=yes,status=yes,menubar=no, scrollbars=no, directories=no, toolbar=no, fullscreen=no, width=200, height=160, top=0, left=0");
	Janela.focus();
}

function Pag_Control (pag) {
	if (!isNaN(pag)) {
		document.form_busca.pag.value = pag;
		document.form_busca.submit();
	}
}

function Opc_Busca (obj) {
	var vatObj = document.getElementById(obj);
	if (vatObj.style.display == 'none') { vatObj.style.display = 'block'; }
	else { vatObj.style.display = 'none'; }
}
