// JavaScript Document
function isEmpty(s){
	if (s == null || s.length == 0)
		return true;
	// The test returns true if there is at least one non-
	// whitespace, meaning the string is not empty. If the
	// test returns true, the string is empty.
		return !/\S/.test(s);
	}
	//
function looksLikeEmail(field){
	var s = field.value;
	if (isEmpty(s)){
		field.focus();
		return false;
	}
	if (/[^@]+@\w+/.test(s))
		return true;
		field.focus();
		return false;
	}
	//
function isInteger(field){
	var s = field.value;
	if (isEmpty(s)){
		return true;
	}
	if (!(/^-?\d+$/.test(s))){
		return false;
	}
return true;
}
function dataValida(field){
	var s = field.value;
	var dataArray = s.split('.');
	var dia = dataArray[0];
	var mes= dataArray[1];
	if(Number(dia)>31){
		return false;
	}else{
	if(Number(mes)>12){
		return false;
	}else{
		return true;
	}
	}
}
//
function validate(){
	//checa nome completo
	if (isEmpty(document.getElementById('nome').value)){
		document.getElementById('validator').value='Preencha o campo NOME COMPLETO!';
		return false;
	}else{
	//checa login
	if (isEmpty(document.getElementById('username').value)){
		document.getElementById('validator').value='Preencha o campo LOGIN!';
		return false;
	}else{
	//checa minimo de caracteres de senha atual
	if (document.getElementById('senhaatual').value.length<6 && !isEmpty(document.getElementById('senhaatual').value)){
		document.getElementById('validator').value='O campo SENHA ATUAL deve conter no mínimo 6 caracteres!';
		return false;
	}else{
	//checa se o campo NOVA SENHA está vazio
	if (isEmpty(document.getElementById('novasenha').value) && !isEmpty(document.getElementById('senhaatual').value)){
		document.getElementById('validator').value='Preencha o campo NOVA SENHA!';
		return false;
	}else{
	//checa minimo de caracteres de NOVA SENHA
	if (document.getElementById('novasenha').value.length<6 && !isEmpty(document.getElementById('senhaatual').value)){
		document.getElementById('validator').value='O campo NOVA SENHA deve conter no mínimo 6 caracteres!';
		return false;		
	}else{
	//confirmacao de senha
	if(document.getElementById('novasenha').value!=document.getElementById('confirmasenha').value &&  !isEmpty(document.getElementById('senhaatual').value)){
		document.getElementById('validator').value= "O campo CONFIRMAR NOVA SENHA deve ser igual ao campo NOVA SENHA!";
		return false;
	}else{
	//checa se email está vazio
	if (isEmpty(document.getElementById('email').value)){
		document.getElementById('validator').value='Preencha o campo EMAIL!';
		return false;
	}else{
	//checa se o email é válido
	if (!looksLikeEmail(document.getElementById('email'))){
		document.getElementById('validator').value='Preencha o campo EMAIL corretamente!';
		return false;
	}else{
	//checa a data dos anscimento data do nascimento
	 if (document.getElementById('datanasc').value.length<10 &&  !isEmpty(document.getElementById('datanasc').value)){
		document.getElementById('validator').value= "Preencha o campo DATA DE NASCIMENTO corretamente!";
		return false;
	}else{
	//checa a data dos anscimento data do nascimento
	 if (!dataValida(document.getElementById('datanasc'))){
		document.getElementById('validator').value= "Preencha o campo DATA DE NASCIMENTO corretamente!";
		return false;		
	}else{
	//verifica se o cep só possui números ou está vazio
	 if (!isInteger(document.getElementById('cep'))) {
		document.getElementById('validator').value= "O campo CEP só deve conter números!";
		return false;					
	}else{
	return true;
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
}
//-->


