function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validaForm (theForm) {
	if (theForm.mail_senderName.value == "") {
		alert("Por favor digite seu nome.");
		theForm.mail_senderName.focus();
		return false;
	}
	if (theForm.mail_sender.value == "") {
		alert("Por favor digite seu email.");
		theForm.mail_sender.focus();
		return false;
	}
	else {
		  if (!isEmailAddr(theForm.mail_sender.value)){
			alert("Por favor digite corretamente o seu email.\nO formato correto é: seunome@dominio.com");
			theForm.mail_sender.focus();
			return false;
		  }
	}
	if (theForm.v_id_destinatario.value == "") {
		alert("Por favor selecione o assunto da mensagem.");
		theForm.v_id_destinatario.focus();
		return false;
	} 
	if (theForm.mail_description.value == "") {
		alert("Por favor digite a mensagem.");
		theForm.mail_description.focus();
		return false;
	}
    return true;
}

function validaFormBene ( theForm ) {

    // chama função q valida campos padrão
    if (!validaForm(theForm)) {
        return false;
    }
    
    // validar campos incomuns
    
    if (theForm.num_car.value == "") {
    	alert("Por favor digite o número da carteirinha do plano de saúde.");
		theForm.num_car.focus();
		return false;
    } else if (theForm.num_car.value.length != 15) {
    	alert("O número da carteirinha deve conter 15 digitos.");
		theForm.num_car.focus();
		return false;
    }
    
    if (theForm.cidade.value == "") {
    	alert("Por favor digite a cidade.");
		theForm.cidade.focus();
		return false;
    }

    if (theForm.estado.value.length < 2) {
    	alert("Por favor informe o estado corretamente.");
		theForm.estado.focus();
		return false;
    }
    
    if (theForm.telefone.value == "") {
    	alert("Por favor informe um telefone para contato.");
		theForm.telefone.focus();
		return false;
    }
    
    return true;
}


function validaFormRede ( theForm ) {

    // chama função q valida campos padrão
    if (!validaForm(theForm)) {
        return false;
    }
    
    // validar campos incomuns
    
    if (theForm.razao_social.value == "") {
    	alert("Por favor digite a Razão Social.");
		theForm.razao_social.focus();
		return false;
    }
    
    if (theForm.num_cpf_cgc.value == "") {
    	alert("Por favor digite o número do CPF/CGC.");
		theForm.num_cpf_cgc.focus();
		return false;
    }
    
    if (theForm.cidade.value == "") {
    	alert("Por favor digite a cidade.");
		theForm.cidade.focus();
		return false;
    }    

    if (theForm.estado.value.length < 2) {
    	alert("Por favor informe o estado corretamente.");
		theForm.estado.focus();
		return false;
    }
    
    if (theForm.telefone.value == "") {
    	alert("Por favor informe um telefone para contato.");
		theForm.telefone.focus();
		return false;
    }
    
    return true;
}


function validaFormInstit ( theForm ) {

    // chama função q valida campos padrão
    if (!validaForm(theForm)) {
        return false;
    }
    
   return true;
}


function validaFormEmp ( theForm ) {

    // chama função q valida campos padrão
    if (!validaForm(theForm)) {
        return false;
    }
    
   return true;
}

function validaFormCurr ( theForm ) {

    if (theForm.v_nome_completo.value == "") {
    	alert("Por favor digite o seu nome completo.");
		theForm.v_nome_completo.focus();
		return false;
    }
    
    if (theForm.v_curriculo.value == "") {
    	alert("Por selecione o arquivo do currículo.");
		theForm.v_curriculo.focus();
		return false;
    }
    
    return true;
}