function valida_usuario() {
    Form = document.usuario;

    if (Form.nome_usuario.value.length == 0) {
        alert("O nome do usuário é um campo obrigatório !");
        Form.nome_usuario.focus();
        return false;
    }

    if (Form.email_usuario.value.length == 0) {
        alert("O e-mail do usuário é um campo obrigatório !");
        Form.email_usuario.focus();
        return false;
    }

    if (Form.email_usuario.value.indexOf('@', 0) == -1 || Form.email_usuario.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail."); 
        Form.email_usuario.focus();
        return false;
    }

}


function valida_usuario_admin() {
    Form = document.usuario;

    if (Form.nome_usuario.value.length == 0) {
        alert("O nome do usuário é um campo obrigatório !");
        Form.nome_usuario.focus();
        return false;
    }

	if (Form.usuario.value.length == 0) {
        alert("Usuário é um campo obrigatório !");
        Form.usuario.focus();
        return false;
    }

    if (Form.email_usuario.value.length == 0) {
        alert("O e-mail do usuário é um campo obrigatório !");
        Form.email_usuario.focus();
        return false;
    }

    if (Form.email_usuario.value.indexOf('@', 0) == -1 || Form.email_usuario.value.indexOf('.', 0) == -1) {
        alert("Por favor, preencha corretamente o campo e-mail."); 
        Form.email_usuario.focus();
        return false;
    }

}

function valida_tipoDocumento() {
    Form = document.tipoDocumento;

    if (Form.documentoTipo.value.length == 0) {
        alert("Tipo é um campo obrigatório !");
        Form.documentoTipo.focus();
        return false;
    }

}

function valida_documento() {
    Form = document.documento;

    if (Form.descDocumento.value.length == 0) {
        alert("Detalhes é um campo obrigatório !");
        Form.descDocumento.focus();
        return false;
    }

    if (Form.nomDocumento.value.length == 0) {
        alert("Arquivo é um campo obrigatório !");
        Form.nomDocumento.focus();
        return false;
    }

}

function valida_altera_documento() {
    Form = document.documento;

    if (Form.descDocumento.value.length == 0) {
        alert("Detalhes é um campo obrigatório !");
        Form.descDocumento.focus();
        return false;
    }

}

function confirma_apagar() {
    var resposta;
    resposta = confirm("Tem certeza que deseja apagar ?");
    if (resposta == true) 
        return true;
    else
        return false;
}

function valida_login() {
    Form = document.admin;

    if (Form.usuario.value.length == 0) {
        alert("Por favor, informe o usuário !");
        Form.usuario.focus();
        return false;
    }

    if (Form.acao.checked == false) {
        if (Form.senha.value.length == 0) {
            alert("Por favor, informe a senha !");
            Form.senha.focus();
            return false;
        }
    }

    return true;
}

function valida_senha(Form) {

    var i;
    var num = 0, carac = 0;

    if (Form.senha.value.length == 0) {
        alert("Por favor, defina a nova senha!");
        Form.senha.focus();
        return false;
    }
    
	
    if (Form.senha2.value.length == 0) {
        alert("Por favor, confirme a nova senha!");
        Form.senha2.focus();
        return false;
    }

    
    if (Form.senha.value != Form.senha2.value) {
        alert("As senhas não são iguais !");
        Form.senha.focus();
        return false;
    }
    
	for (i = 0; i < Form.senha.value.length; i++) {
				var c = Form.senha.value.charAt(i);
				// ha um numero
				if (((c >= "0") && (c <= "9"))) {
					num++;
				}
				if (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z"))) {
					carac++;
				}
				if (c == "'" || c == "`" || c == "~" || c == '"' || c == '^') {
					alert("Campo com caracteres inválido!!");
					Form.senha.focus();
					return false;
				}
			}
			

			if (Form.senha.value.length < 6) {
				alert("A senha deve ter no mínimo 6 caracteres !");
				Form.senha.focus();
				return false;
			}

			if (Form.senha.value.length > 14) {
				alert("A senha deve ter no máximo 14 caracteres !");
				Form.senha.focus();
				return false;
			}

			
			var s;
			s = Form.senha.value
			hoje = new Date()
			ano = hoje.getYear()
			for (f=-2; f<=2; f++){
				n = s.indexOf(ano + f,0)
				if (n > -1){
					alert("Não é permitido colocar o ano como senha.");
					Form.senha.focus();
					return false;
				}
			}
    
    return true;

}

function valida_senha_adm(Form) {
			var i;
			var num = 0, carac = 0;
			
			if (Form.senha_atual.value.length == 0 || Form.nova_senha.value.length == 0 || Form.confirma_nova_senha.value.length == 0) {
				alert("As senhas são obrigatórias !");
				return false;
			}
			
			for (i = 0; i < Form.nova_senha.value.length; i++) {
				var c = Form.nova_senha.value.charAt(i);
				// ha um numero
				if (((c >= "0") && (c <= "9"))) {
					num++;
				}
				if (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z"))) {
					carac++;
				}
				if (c == "'" || c == "`" || c == "~" || c == '"' || c == '^') {
					alert("Campo com caracteres inválido!!");
					Form.nova_senha.focus();
					return false;
				}
			}
			

			if (Form.nova_senha.value.length < 6) {
				alert("A senha deve ter no mínimo 6 caracteres !");
				Form.nova_senha.focus();
				return false;
			}

			if (Form.nova_senha.value.length > 14) {
				alert("A senha administrativa deve ter no máximo 14 caracteres !");
				Form.nova_senha.focus();
				return false;
			}

			if (Form.nova_senha.value != Form.confirma_nova_senha.value) {
				alert("As senhas não são iguais !");
				Form.nova_senha.focus();
				return false;
			}
			
			var s;
			s = Form.nova_senha.value
			hoje = new Date()
			ano = hoje.getYear()
			for (f=-2; f<=2; f++){
				n = s.indexOf(ano + f,0)
				if (n > -1){
					alert("Não é permitido colocar o ano como senha.");
					Form.nova_senha.focus();
					return false;
				}
			}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' tem que conter um endereço de email válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+nm+' só pode conter números.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' tem que conter um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é obrigatório.\n'; }
  } if (errors) alert('Ocorreram os seguintes erros:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}
function confirmacao(inform)
{
if (confirm("tem certeza que deseja deletar o registro")){
window.location=inform;
}
}

function abre(site)
{
window.open(site,"_Blank","scrollbars=yes,top=50,left=200,width=600, height=400");
}