// JavaScript Document
//###################################################################################
// pop ups
//###################################################################################
function PopUp(url, nome, largura, altura, sroll)
{
	var esq     = (screen.width - largura) / 2;
	var top    = (screen.height - altura) / 2;
	var janela = window.open(''+ url +'',''+ nome +'','width=' + largura + ',height=' + altura + ',top=' + top + ',left=' + esq + ',scrollbars='+ sroll +'');
	if (janela == null)
	{
		window.alert('POPUP BLOQUEADA.\n\nIdentificamos que você possui um bloqueador de popup, configure-o\npara aceitar popups do sistema.\n\nObrigado!');
	}
	else
	{
		janela.focus();
	}
}
//######################################################################################
//    validar login aluno
//######################################################################################
function ValidarLogin(f)
{
	 if (f.usuario.value.length == 0) {
        alert("Por favor, informe o usu\xE1rio !");
		f.usuario.focus();
        return false;
    }

    if (f.acao.checked == false) {
        if (f.senha.value.length == 0) {
            alert("Por favor, informe a senha !");
			f.senha.focus();
            return false;
        }
  }
}

//######################################################################################
//    validar email
//######################################################################################
function validaEmail(email)
{
  var emailInvalido = false
  var stringTemp = new String(email)
  var index = stringTemp.indexOf("@");
  if (index > 0)
  {
    var pindex = stringTemp.indexOf(".",index);
    if ((pindex > index+1) && (stringTemp.length > pindex+1))
	emailInvalido = true;
  }
  return emailInvalido;
} 
//######################################################################################
//    Mascara entradas
//######################################################################################
function mascaraEntrada(objeto, sMask, evtKeyPress) // onkeypress="javascript:return mascaraEntrada(this,'99999-999',event);"
{
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

	if (document.all)         { nTecla = evtKeyPress.keyCode; }
	else if (document.layers) { nTecla = evtKeyPress.which; }
	else                      { nTecla = evtKeyPress.which; if (nTecla == 8) { return true; } }

	sValue = objeto.value;

	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( ":", "" );
	sValue = sValue.toString().replace( ":", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( " ", "" );
	sValue = sValue.toString().replace( " ", "" );
	fldLen = sValue.length;
	mskLen = sMask.length;

	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;

	while (i <= mskLen)
	{
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
		if (bolMask)
		{
			sCod += sMask.charAt(i);
			mskLen++;
		}
		else
		{
			sCod += sValue.charAt(nCount);
			nCount++;
		}
		i++;
	}

	objeto.value = sCod;

	if (nTecla != 8)
	{
		if (sMask.charAt(i-1) == "9")
		{
			return ((nTecla > 47) && (nTecla < 58));
		}
		else { return true; }
	}
	else { return true; }
}
//######################################################################################
//    funcoes mascara valor
//######################################################################################
function soNumero(nro)
{
	var valid    = "0123456789";
	var numerook = "";
	var temp;
	for(var i = 0; i < nro.length; i++)
	{
		temp = nro.substr(i, 1);
		if (valid.indexOf(temp) != -1)
			numerook = numerook + temp;
	}
	return(numerook);
}

function mascaraValor(objeto, e, tammax, decimais)
{
	var tecla  = (window.Event) ? e.which : e.keyCode;
	var tamObj = objeto.value.length;

	if ((tecla == 8) && (tamObj == tammax))
		tamObj = tamObj - 1;

	vr = soNumero(objeto.value);
	tam = vr.length;

	if (((tecla == 8) || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105)) && (parseInt(tamObj) + 1 <= parseInt(tammax)))
	{
		if ((tam < tammax) && (tecla != 8))
			tam = vr.length + 1;
		if ((tecla == 8) && (tam > 1))
			tam = tam - 1;

		if (tam <= decimais)
			objeto.value = ("0," + vr);
		if ((tam == (decimais + 1)) && (tecla == 8))
			objeto.value = vr.substr(0, (tam - decimais)) + "," + vr.substr((tam - decimais), tam);
		if ((tam > (decimais + 1)) && (tam <= (decimais + 3)) && (vr.substr(0,1) == "0"))
			objeto.value = vr.substr(1, (tam - (decimais+1))) + "," + vr.substr(tam - (decimais), tam);
		if ((tam > (decimais + 1)) && (tam <= (decimais + 3)) && (vr.substr(0,1) != "0"))
			objeto.value = vr.substr(0, (tam - decimais)) + "," + vr.substr(tam - decimais, tam);
		if ((tam >= (decimais + 4)) && (tam <= (decimais + 6)))
			objeto.value = vr.substr(0, tam - (decimais + 3)) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
		if ((tam >= (decimais + 7)) && (tam <= (decimais + 9)))
			objeto.value = vr.substr(0, tam - (decimais + 6)) + "." + vr.substr(tam - (decimais + 6), 3) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
		if ((tam >= (decimais + 10)) && (tam <= (decimais + 12)))
			objeto.value = vr.substr(0, tam - (decimais + 9)) + "." + vr.substr(tam - (decimais + 9), 3) + "." + vr.substr(tam - (decimais + 6), 3) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
		if ((tam >= (decimais + 13)) && (tam <= (decimais + 15)))
			objeto.value = vr.substr(0, tam - (decimais + 12)) + "." + vr.substr(tam - (decimais + 12), 3) + "." + vr.substr(tam - (decimais + 9), 3) + "." + vr.substr(tam - (decimais + 6), 3) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
	}
	else if((tecla != 8) && (tecla != 9) && (tecla != 13) && (tecla != 18) && (tecla != 35) && (tecla != 36) && (tecla != 37) && (tecla != 39))
	{
		return false;
	}
}
//######################################################################################
//    campo numérico
//######################################################################################
function isNumber(caracter) // onkeypress="javascript:return isNumber(event);"
{
	var tecla = (window.Event) ? caracter.which : caracter.keyCode;
	if (tecla > 47 && tecla < 58)
	{
		return true;
	}
	else
	{
		if (tecla != 8 && tecla != 13 && tecla != 0)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

//######################################################################################
//    validar contato
//######################################################################################
function validarContato(f)
{
	if (f.nome.value == '')
	{
		window.alert('Por favor, digite seu Nome.');
		f.nome.focus();
		return false;
	}
	if (f.endereco.value == '')
	{
		window.alert('Por favor, digite seu Endereço.');
		f.endereco.focus();
		return false;
	}
	if (f.cidade.value == '')
	{
		window.alert('Por favor, digite sua Cidade');
		f.cidade.focus();
		return false;
	}
	if (f.estado.value == '')
	{
		window.alert('Por favor, selecione seu Estado');
		f.estado.focus();
		return false;
	}
	if (f.cep.value.length < 9)
	{
		window.alert('Por favor, digite seu CEP corretamente.');
		f.cep.focus();
		return false;
	}
	if (f.telefone.value == '')
	{
		window.alert('Por favor, digite seu Telefone.');
		f.telefone.focus();
		return false;
	}
	if (!validaEmail(f.email.value))
	{
		window.alert('Por favor, digite seu E-mail.');
		f.email.focus();
		return false;
	}
	if (f.mensagem.value == '')
	{
		window.alert('Por favor, digite sua Mensagem.');
		f.mensagem.focus();
		return false;
	}
}
//######################################################################################
//    validar busca
//######################################################################################
function validarBusca(f) {

    if (f.palavra.value.length == 0) {
	   window.alert('Favor digitar a palavra para busca');
	   f.palavra.className = "textreq";
       f.palavra.focus();
		return false;
	}

    if (f.palavra.value.length < 3) {
		window.alert('A palavra para busca deve ter no m\xEDnimo 3 d\xEDgitos');
	   f.palavra.className = "textreq";
       f.palavra.focus();
		return false;
	}
}
//***********************************************************************************************
// limpar string deixando só números
//***********************************************************************************************
function limpa_string(S){ 
// Deixa so' os digitos no numero 
var Digitos = "0123456789"; 
var temp = ""; 
var digito = ""; 

for (var i=0; i<S.length; i++) { 
digito = S.charAt(i); 
if (Digitos.indexOf(digito)>=0) { 
temp=temp+digito } 
} //for 

return temp 
} 
//***********************************************************************************************
// validar CNPJ
//***********************************************************************************************
function valida_CNPJ(s)
{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}
//***********************************************************************************************
// validar orçamento
//***********************************************************************************************
function validarOrcamento(f)
{
	if (f.nome_empresa.value == '')
	{
		window.alert('Por favor, digite o Nome da Empresa.');
		f.nome_empresa.focus();
		return false;
	}
	if (f.razao_empresa.value == '')
	{
		window.alert('Por favor, digite a Razão Social da Empresa.');
		f.razao_empresa.focus();
		return false;
	}
		var cnpj1 = limpa_string(f.cnpj.value);
	if ((cnpj1.length !== 14))
	{
		window.alert("Por favor, informe o CNPJ da empresa.");
		f.cnpj.focus();
		return false;
	}
	
	if ((cnpj1.length == 14) && (valida_CNPJ(cnpj1) == false))
	{
		window.alert("Por favor, informe um CNPJ v\xE1lido.");
		f.cnpj.focus();
		return false;
	}
	if (f.cidade.value == '')
	{
		window.alert('Por favor, digite sua Cidade');
		f.cidade.focus();
		return false;
	}
	if (f.estado.value == '')
	{
		window.alert('Por favor, selecione seu Estado');
		f.estado.focus();
		return false;
	}
	if (f.nome_contato.value == '')
	{
		window.alert('Por favor, informe o nome para contato');
		f.nome_contato.focus();
		return false;
	}
	if (f.nome_cargo.value == '')
	{
		window.alert('Por favor, informe o cargo do contato na Empresa');
		f.nome_cargo.focus();
		return false;
	}
	if (f.nome_epecialidade.value == '')
	{
		window.alert('Por favor, informe a especialidade da Empresa');
		f.nome_epecialidade.focus();
		return false;
	}
	if (f.software_interesse.value == '')
	{
		window.alert('Por favor, selecione o Software de Interesse');
		f.software_interesse.focus();
		return false;
	}
	if (f.telefone.value == '')
	{
		window.alert('Por favor, digite seu Telefone.');
		f.telefone.focus();
		return false;
	}
	if (!validaEmail(f.email.value))
	{
		window.alert('Por favor, digite seu E-mail.');
		f.email.focus();
		return false;
	}
	if (f.mensagem.value == '')
	{
		window.alert('Por favor, digite o Comentário.');
		f.mensagem.focus();
		return false;
	}
}
//***********************************************************************************************
// validar trabalhe conosco
//***********************************************************************************************
function validarTrabalhe(f)
{
	if (f.nome.value == '')
	{
		window.alert('Por favor, digite seu Nome.');
		f.nome.focus();
		return false;
	}
	if (!validaEmail(f.email.value))
	{
		window.alert('Por favor, digite seu E-mail.');
		f.email.focus();
		return false;
	}
	if (f.endereco.value == '')
	{
		window.alert('Por favor, digite seu Endereço.');
		f.endereco.focus();
		return false;
	}
    if (f.bairro.value == '')
	{
		window.alert('Por favor, digite o Bairro.');
		f.bairro.focus();
		return false;
	}
	
	if (f.cidade.value == '')
	{
		window.alert('Por favor, digite sua Cidade');
		f.cidade.focus();
		return false;
	}
	if (f.estado.value == '')
	{
		window.alert('Por favor, selecione seu Estado');
		f.estado.focus();
		return false;
	}
	if (f.cep.value.length < 9)
	{
		window.alert('Por favor, digite seu CEP corretamente.');
		f.cep.focus();
		return false;
	}
	if (f.telefone.value == '')
	{
		window.alert('Por favor, digite seu Telefone.');
		f.telefone.focus();
		return false;
	}
	if ((f.sexo[0].checked==false) && (f.sexo[1].checked==false)) {
	    window.alert("Por favor, selecione seu sexo.");
		return false;
	}
	if (f.idade.value == '')
	{
		window.alert('Por favor, informe sua idade');
		f.idade.focus();
		return false;
	}
	if (f.data_nascimento.value == '')
	{
		window.alert('Por favor, informe a data de nascimento');
		f.data_nascimento.focus();
		return false;
	}
	if ((f.empregado[0].checked==false) && (f.empregado[1].checked==false)) {
	    window.alert("Por favor, selecione se está empregado ou n\xE3o.");
		return false;
	}
	if (f.profissao.value == '')
	{
		window.alert('Por favor, selecione a profissão');
		f.profissao.focus();
		return false;
	}
	if (f.escolaridade.value == '')
	{
		window.alert('Por favor, selecione sua Escolaridade');
		f.escolaridade.focus();
		return false;
	}
	if (f.experiencia.value == '')
	{
		window.alert('Por favor, informe sua experiência.');
		f.experiencia.focus();
		return false;
	}
	if (f.cargo_pretendido.value == '')
	{
		window.alert('Por favor, informe o cargo pretendido.');
		f.cargo_pretendido.focus();
		return false;
	}
	if (f.salario.value == '')
	{
		window.alert('Por favor, informe o salario pretendido.');
		f.salario.focus();
		return false;
	}
	if (f.outras_qualificacoes.value == '')
	{
		window.alert('Por favor, informe outras qulificações.');
		f.outras_qualificacoes.focus();
		return false;
	}
	if ((f.exp_newhosp[0].checked==false) && (f.exp_newhosp[1].checked==false)) {
	    window.alert("Por favor, informe se vc tem experiência com o software New Hosp.");
		return false;
	}
	if ((f.exp_newhosp[0].checked) && (f.temp_exp_newhosp.value == ''))
	{
		window.alert("Por favor, informe o tempo de experiência com o News Hosp.");
		f.temp_exp_newhosp.focus();
		return false;
	}
	if ((f.exp_newhosp[0].checked) && (f.trab_exp_newhosp.value == ''))
	{
		window.alert("Por favor, informe em que departamento(s) da clínica.");
		f.trab_exp_newhosp.focus();
		return false;
	}
	if ((f.cert_newhosp[0].checked==false) && (f.cert_newhosp[1].checked==false)) {
	    window.alert("Por favor, informe se vc é certificado New Hosp.");
		return false;
	}
	if ((f.cert_newhosp[0].checked) && (f.quando_exp_newhosp.value == ''))
	{
		window.alert("Por favor, informe desde que ano vc é certificado.");
		f.quando_exp_newhosp.focus();
		return false;
	}
	if ((f.outro_newhosp[0].checked==false) && (f.outro_newhosp[1].checked==false)) {
	    window.alert("Por favor, informe se vc conhece outros softwares de gestão além do New Hosp.");
		return false;
	}
	if ((f.outro_newhosp[0].checked) && (f.quais_outros_newhosp.value == ''))
	{
		window.alert("Por favor, informe quais outros softwares vc conhece.");
		f.quais_outros_newhosp.focus();

		return false;
	}
	if ((f.exp_newfis[0].checked==false) && (f.exp_newfis[1].checked==false)) {
	    window.alert("Por favor, informe se vc tem experiência com o software NewFis.");
		return false;
	}
	if ((f.exp_newfis[0].checked) && (f.temp_exp_newfis.value == ''))
	{
		window.alert("Por favor, informe o tempo de experiência com o NewsFis.");
		f.temp_exp_newfis.focus();
		return false;
	}
	if ((f.exp_newfis[0].checked) && (f.trab_exp_newfis.value == ''))
	{
		window.alert("Por favor, informe em que departamento(s) da clínica.");
		f.trab_exp_newfis.focus();
		return false;
	}
	if ((f.cert_newfis[0].checked==false) && (f.cert_newfis[1].checked==false)) {
	    window.alert("Por favor, informe se vc é certificado NewFis.");
		return false;
	}
	if ((f.cert_newfis[0].checked) && (f.quando_exp_newfis.value == ''))
	{
		window.alert("Por favor, informe desde que ano vc é certificado.");
		f.quando_exp_newfis.focus();
		return false;
	}
	if ((f.outro_newfis[0].checked==false) && (f.outro_newfis[1].checked==false)) {
	    window.alert("Por favor, informe se vc conhece outros softwares de gestão além do NewFis.");
		return false;
	}
	if ((f.outro_newfis[0].checked) && (f.quais_outros_newfis.value == ''))
	{
		window.alert("Por favor, informe quais outros softwares vc conhece.");
		f.quando_exp_newfis.focus();
		return false;
	}
}