// JavaScript Document
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

function validaForm() {
	var nome = document.frmCadastro.nome;
	var email = document.frmCadastro.email;
	var login = document.frmCadastro.login;
	var senha = document.frmCadastro.senha;
	var senhare = document.frmCadastro.senhare;
	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(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 (Trim(senha.value) != Trim(senhare.value)) {
		msg += 'Verifique sua senha. Campos Senha e Confirmação de senha não conferem.\n';
	}
	if (uf.value == '00') {
		msg += 'Selecione uma UF.\n';
	}
	if (cidade.value == '00') {
		msg += 'Selecione uma Cidade.\n';
	}
	if (uf.value != 'ZZ') {
		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 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(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 validaFormEstudante() {
	var nome = document.frmCadastro.nome;
	var email = document.frmCadastro.email;
	var login = document.frmCadastro.login;
	var senha = document.frmCadastro.senha;
	var senhare = document.frmCadastro.senhare;
	var uf = document.frmCadastro.uf;	
	var cidade = document.frmCadastro.cidade;
	var cpf = document.frmCadastro.cpf;
	var formaturames = document.frmCadastro.formaturames;
	var formaturaano = document.frmCadastro.formaturaano;
	
	var msg = '';
	
	if (Trim(nome.value).length <= 2) {
		msg = 'O campo Nome é 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 (Trim(senha.value) != Trim(senhare.value)) {
		msg += 'Verifique sua senha. Campos Senha e Confirmação de senha não conferem.\n';
	}
	if (Trim(cpf.value).length <= 2) {
		msg += 'O campo Número de CPF é inválido.\n';
	}
	if (uf.value == '00') {
		msg += 'Selecione uma UF.\n';
	}
	if (formaturames.value == '00') {
		msg += 'Selecione um mês para sua formatura.\n';
	}
	if (formaturaano.value == '00') {
		msg += 'Selecione um ano para sua formatura.\n';
	}

	if (msg == '') {
		return true;
	}
	else {
		alert('Atenção para os campos: \n\n' + msg);
		return false;
	}
}


function verificarCPF(c){
	var i; 
	s = c;
	var c = s.substr(0,9); 
	var dv = s.substr(9,2); 
	var d1 = 0; 
	var v = false;
	for (i = 0; i < 9; i++) 
	{ 
		d1 += c.charAt(i)*(10-i); 
	} 
	if (d1 == 0){ 
		alert("CPF Inválido. \nDigite somente números.\nLembre-se de incluir o DV.") 
		v = true; 
		return false; 
	} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(0) != d1) 
	{ 
		alert("CPF Inválido. \nDigite somente números.\nLembre-se de incluir o DV.") 
		v = true;
		return false; 
	} 
	
	d1 *= 2; 
	for (i = 0; i < 9; i++) 
	{ 
		d1 += c.charAt(i)*(11-i); 
	} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(1) != d1) 
	{ 
		alert("CPF Inválido. \nDigite somente números.\nLembre-se de incluir o DV.") 
		v = true;
		return false; 
	} 
	if (!v) {
		return true; 
	}
}

function forceNumber(e) {
	var tecla=(window.event)?event.keyCode:e.which;
	if((tecla > 47 && tecla < 58) || (tecla == 46)) return true;
	else {
		if (tecla != 8) {
			alert('Este campo só aceita números!');
			return false;
		}
		else return true;
	}
}

function showPanel(event) {
	var x = event.clientX;
    var y = event.clientY;
	document.getElementById("pnlEspecialidades").style.position = 'absolute';
	document.getElementById("pnlEspecialidades").style.visibility='visible';
	//document.getElementById("pnlEspecialidades").style.left = x + 'px';
	//document.getElementById("pnlEspecialidades").style.top = y + 'px'; 
	//document.getElementById("pnlEspecialidades").style.left = document.getElementById("comboEspecialidades").offsetLeft + 'px';
	//document.getElementById("pnlEspecialidades").style.top = document.getElementById("comboEspecialidades").offsetTop + 'px';

	//	var coordX = document.getElementById("comboEspecialidades").style.left;
	//	var coordY = document.getElementById("comboEspecialidades").style.top;
	//	document.getElementById("pnlEspecialidades").style.left = coordX + 'px';
	//	document.getElementById("pnlEspecialidades").style.top = coordY + 'px';
}
function hidePanel() {
	document.getElementById("pnlEspecialidades").style.visibility='hidden';
}

function pos(){
	posX = event.clientX;
	posY = event.clientY;
	window.status = "X = " + posX + " : Y = " + posY; 
	//document.captureEvents(Event.CLICK);
	//document.onclick=mouse;
	
}

function posicao() {
	if (document.all){}
	else document.captureEvents(Event.CLICK);
	document.onclick=mouse;
}
function mouse(e) {
	if (navigator.appName == 'Netscape'){
		xcurs = e.pageX;
		ycurs = e.pageY;
	} 
	else {
		xcurs = event.clientX;
		ycurs = event.clientY;
	}
	alert("x:"+xcurs+" y:"+ycurs);
}	
	




function info(acao,div){
    var div_info = document.getElementById( div );
    var acao = acao.substring(0,6);
    var x = event.clientX;
    var y = event.clientY;
   
    if(acao == "abrir"){
        div_info.style.left = x;
        div_info.style.top = y;
        div_info.style.display = "block";
    }else{
        div_info.style.display = "none";
    }
}
