// JavaScript Document
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

function validaForm() {
	var nome = document.frmCadastro.nome;
	var codinome = document.frmCadastro.codinome;
	var email = document.frmCadastro.email;
	var login = document.frmCadastro.login;
	var senha = document.frmCadastro.senha;
	var uf = document.frmCadastro.uf;	
	var cidade = document.frmCadastro.cidade;
	var crmuf = document.frmCadastro.crmuf;
	var crmnumero = document.frmCadastro.crmnumero;
	var especialidade = document.frmCadastro.especialidade;
	
	var msg = '';
	
	if (Trim(nome.value).length <= 2) {
		msg = 'O campo Nome é inválido.\n';
	}
	if (Trim(codinome.value).length <= 2) {
		msg += 'O campo Apelido é inválido.\n';
	}
	if (Trim(email.value).length <= 2) {
		msg += 'O campo E-mail é inválido.\n';
	}	
	if (Trim(login.value).length <= 2) {
		msg += 'O campo Login é inválido.\n';
	}
	if (Trim(senha.value).length <= 2) {
		msg += 'O campo Senha é inválido.\n';
	}
	if (uf.value == '00') {
		msg += 'Selecione uma UF.\n';
	}
	if (cidade.value == '00') {
		msg += 'Selecione uma Cidade.\n';
	}
	if (crmuf.value == '00') {
		msg += 'Selecione uma UF de conselho.\n';
	}
	if (Trim(crmnumero.value).length <= 2) {
		msg += 'O campo Número de CRM é inválido.\n';
	}
	if (especialidade.value == '00') {
		msg += 'Selecione uma Especialidade.\n';
	}

	if (msg == '') {
		return true;
	}
	else {
		alert('Atenção para os campos: \n\n' + msg);
		return false;
	}
}

function validaForm_2() {
	var nome = document.frmCadastro.nome;
	var codinome = document.frmCadastro.codinome;
	var email = document.frmCadastro.email;
	var uf = document.frmCadastro.uf;	
	var cidade = document.frmCadastro.cidade;
	var crmuf = document.frmCadastro.crmuf;
	var crmnumero = document.frmCadastro.crmnumero;
	var especialidade = document.frmCadastro.especialidade;
	
	var msg = '';
	
	if (Trim(nome.value).length <= 2) {
		msg = 'O campo Nome é inválido.\n';
	}
	if (Trim(codinome.value).length <= 2) {
		msg += 'O campo Apelido é inválido.\n';
	}
	if (Trim(email.value).length <= 2) {
		msg += 'O campo E-mail é inválido.\n';
	}	
	if (Trim(crmnumero.value).length <= 2) {
		msg += 'O campo Número de CRM é inválido.\n';
	}
	if (msg == '') {
		return true;
	}
	else {
		alert('Atenção para os campos: \n\n' + msg);
		return false;
	}
}

function forceNumber(e) {
	var tecla=(window.event)?event.keyCode:e.which;
	if((tecla > 47 && tecla < 58)) return true;
	else {
		if (tecla != 8) {
			alert('Este campo só aceita números!');
			return false;
		}
		else return true;
	}
}
