//---------------------------------------------------------------------------------
//  Intercode Ltda
//  Arquivo: val_sucom_cadastro.js
//  Módulo: SUCOMN 2004
//  Propósito: Validação para Formulário Cadastro
//---------------------------------------------------------------------------------

// Validata Email
 function check_email(e) {
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

    for(i=0; i < e.length ;i++){
    if(ok.indexOf(e.charAt(i))<0){
    return (false);
    }
    }

    if (document.images) {
    re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
    re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if (!e.match(re) && e.match(re_two)) {
    return (-1);
    }
    }
 }


function getYear(d) {
  return (d < 1000) ? d + 1900 : d;
}

function val_faleconosco() {
   var errors='';
   var tipo = '';
   
   if(document.form1.depto_def.value==1) {
	    for(i=0; i < 3 ;i++){
            if(document.form1.depto[i].checked == true){
            tipo = 'S'; } }
   if (tipo == ''){
	       errors+='"Tipo de Contato" deve ser preenchido!\n';	 
   }   }
   
   if (document.form1.nm_completo.value == '') {
     errors+='"Nome" deve ser preenchido!\n';
   }
    if(document.form1.depto_def.value==1){
      if (document.form1.emp_instit.value == '') {
     errors+='"Empresa" deve ser preenchido!\n';
      }
   }
      
   if(document.form1.depto_def.value==2){
      if (document.form1.emp_instit.value == '') {
     errors+='"Intituição" deve ser preenchido!\n';
      }
   }
   if (document.form1.de_email.value == '') {
     errors+='"Email" deve ser preenchido!\n';
   } else {
     if(!check_email(document.form1.de_email.value)){
       errors+='"Email" inválido!\n';
     }
   }
   if (document.form1.assunto.value == '') {
     errors+='"Assunto" deve ser preenchido!\n';
   }
   if (document.form1.recado.value == '') {
     errors+='"Mensagem" deve ser preenchido!\n';
   }

   if (errors){
      alert ('Os seguintes erros foram encontrados!\n\n' + errors);
   }
   document.MM_returnValue = (errors == '');
}