// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// GLOBAIS+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


// validar email
function vlEmailAddress( theEmail ) {

	var at = "@";
	var dot = ".";
	var lat = theEmail.indexOf(at);
	var lstr = theEmail.length;
	var ldot = theEmail.indexOf(dot);

	if (theEmail.indexOf(at) == -1){
	   return false;
	}
	
	if (theEmail.indexOf(at) == -1 || theEmail.indexOf(at) == 0 || theEmail.indexOf(at) == lstr){
	   return false;
	}

	if (theEmail.indexOf(dot) == -1 || theEmail.indexOf(dot) == 0 || theEmail.indexOf(dot) == lstr){
	    return false;
	}

	 if (theEmail.indexOf(at,(lat+1)) != -1){
	    return false;
	 }

	 if (theEmail.substring(lat-1,lat) == dot || theEmail.substring(lat+1,lat+2) == dot){
	    return false;
	 }
	 if (theEmail.indexOf(dot,(lat+2)) == -1){
		return false;
	 }
		
	 if (theEmail.indexOf(" ") != -1){
	    return false;
	 }

 	 return true;		
}


// pegar valor de um radio
function getRadioButtonValue (radio) {   
    if (!radio.length) {
	if (radio.checked) {
		return radio.value;
	}
	else {
		return "";
	}
    }
    else {
	    for (var i = 0; i < radio.length; i++) {
	       if (radio[i].checked) { break }
	    }
	
	    if (i >= radio.length ) {
		return "";
	    } 
	    else {
	   	return radio[i].value;
	    }
    }
}

// funções do dreamweaver
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




// --------------------------------------------------------------------
// validações da declaração (dentista)
// --------------------------------------------------------------------


// validar o formulário de etapa 1 (aonline_dt_declaracao.php)
function vlDtDeclaracao(theForm) {

	// * validar tipo de orçamento
	if (theForm.sinistro.value == "") {
		alert("A seleção do tipo de orçamento é obrigatória!");
		theForm.sinistro.focus();
		return false;
	}

	// * validar dental card
	if (theForm.dental_card.value == "") {
		alert("Por favor digite o dental card do beneficiário!");
		theForm.dental_card.focus();
		return false;
	}

	// * validar data

	// -validar dia
	if (theForm.dt_d.value == "") {
		alert("Por favor digite a o dia do início do tratamento!");
		theForm.dt_d.focus();
		return false;
	}
	else {
		if (theForm.dt_d.value < 2) {
			alert("Verifique o dia do início do tratamento!\nO dia deve conter dois caracteres (dd)!");
			theForm.dt_d.focus();
			return false;
		}
	}

	// -validar mês
	if (theForm.dt_m.value == "") {
		alert("Por favor digite a o mês do início do tratamento!");
		theForm.dt_m.focus();
		return false;
	}
	else {
		if (theForm.dt_m.value < 2) {
			alert("Verifique o mês do início do tratamento!\nO dia deve conter dois caracteres (mm)!");
			theForm.dt_m.focus();
			return false;
		}
	}

	// -validar ano
	if (theForm.dt_y.value == "") {
		alert("Por favor digite a o ano do início do tratamento!");
		theForm.dt_y.focus();
		return false;
	}
	else {
		if (theForm.dt_y.value < 4) {
			alert("Verifique o ano do início do tratamento!\nO dia deve conter quatro caracteres (yyyy)!");
			theForm.dt_y.focus();
			return false;
		}
	}

	theForm.submit();
	return true;
}


function vlDtSolicitacao (theForm) {
	if (theForm.v_tp_sinistro.value == "") {
		alert ("Selecione o tipo de orçamento.");
		theForm.v_tp_sinistro.focus();
		return false;
	}
	theForm.submit();
	return true;
}


// validar o formulário de ausencia
function vlDtAbsent(theForm) {

	

	// * validar dental card
	if (theForm.v_codigo_dc.value == "") {
		alert("Por favor digite o dental card do beneficiário!");
		theForm.v_codigo_dc.focus();
		return false;
	}

	// * validar data

	// -validar dia
	if (theForm.dt_d.value == "") {
		alert("Por favor digite a o dia do início do tratamento!");
		theForm.dt_d.focus();
		return false;
	}
	
	// -validar mês
	if (theForm.dt_m.value == "") {
		alert("Por favor digite a o mês do início do tratamento!");
		theForm.dt_m.focus();
		return false;
	}
	

	// -validar ano
	if (theForm.dt_y.value == "") {
		alert("Por favor digite a o ano do início do tratamento!");
		theForm.dt_y.focus();
		return false;
	}
	

	theForm.submit();
	return true;
}


// validar pp_itens_main.php ( tabela de ítens da fase três )
function vlPpItens (theForm) {

	// checar se nenhum dos dois foram preenchidos
	if (theForm.in_categoria.value == "" && theForm.in_cod_item.value == "") {
		alert("Por favor selecione uma categoria,\nou digite um código de ítem!");
		theForm.in_categoria.focus();
		return false;
	}

	// checar se o dois foram selecionados
	if (theForm.in_categoria.value != "" && theForm.in_cod_item.value != "") {
		var strMsg = "Você deve selecionar uma categoria \"ou\" digitar um código de ítem!";
		strMsg = strMsg + "\n";
		strMsg = strMsg + "Deseja continuar, considerando apenas a categoria \"" + theForm.in_categoria.value + "\"?";
		if (!confirm(strMsg)) {
			return false;
		}
		else {
			theForm.in_cod_item.value = "";
		}
	}

	theForm.submit();
	return true;

}


// validar aonline_dt_alterar_senha.php e aonline_dt_alterar_senha_final.php
function vlAlterPass (theForm) { 

	if (theForm.v_senha_nova.value == "") {
		alert ( "Por favor digite a nova senha!\nA sua nova senha não pode ser em branco!");
		theForm.v_senha_nova.focus();
		return false;
	}
	else {
		if (theForm.v_senha_nova.value != theForm.v_conf_senha_nova.value) {
			alert ( "As senhas digitadas não conferem!\nPor favor certifique-se de que a senha e a confirmação estejam digitados corretamente!");
			theForm.v_senha_nova.focus();
			return false;
		}
	}
	theForm.submit();
	return true;

}


// validar aonline_dt_extrato.php ( período do extrato )
function vlPeriodoExt (theForm) {

	if (theFrom.v_dt_ini_d.value == "") {
		alert ("Por favor selecione o dia da data de início!");
		theForm.v_dt_ini_d.focus();
		return false;
	}

	v_dt_ini_y
	v_dt_end_d
	v_dt_end_m
	v_dt_end_y


}


// validar consulta de extrato
// validar o formulário de etapa 1 (aonline_dt_declaracao.php)
function vlDtExtrato(theForm) {


	// * validar data inicial

	// -validar dia
	if (theForm.v_dt_ini_d.value == "") {
		alert("Por favor selecione o dia do início do tratamento!");
		theForm.v_dt_ini_d.focus();
		return false;
	}

	// -validar mês
	if (theForm.v_dt_ini_m.value == "") {
		alert("Por favor selecione o mês do início do tratamento!");
		theForm.v_dt_ini_m.focus();
		return false;
	}

	// -validar ano
	if (theForm.v_dt_ini_y.value == "") {
		alert("Por favor selecione o ano do início do tratamento!");
		theForm.v_dt_ini_y.focus();
		return false;
	}

	// * validar data final

	// -validar dia
	if (theForm.v_dt_end_d.value == "") {
		alert("Por favor selecione o dia do fim do tratamento!");
		theForm.v_dt_end_d.focus();
		return false;
	}

	// -validar mês
	if (theForm.v_dt_end_m.value == "") {
		alert("Por favor selecione o mês do fim do tratamento!");
		theForm.v_dt_end_m.focus();
		return false;
	}

	// -validar ano
	if (theForm.v_dt_end_y.value == "") {
		alert("Por favor selecione o ano do fim do tratamento!");
		theForm.v_dt_end_y.focus();
		return false;
	}

	theForm.submit();
	return true;
}



// validar solicitação
function vlCkSolicitacao ( theForm, theRadio ) {

	if (getRadioButtonValue( theRadio ) == "") {
		alert("Selecione um orçamento para fazer a solicitação!");
		return false;
	}
	theForm.submit();
	return true;
}




// ************************
// clientes




// -> clientes e beneficiários
// obrigar o dental card ( consulta de de cadastro e cobertura )
//        --+ aonline_cl_cs_cd_abertura.php
//        --+ aonline_cl_cs_cd_abertura.php
function vlDentalCard ( theForm ) {
	if (theForm.v_dental_card.value == "") {
		alert ("O número do dental card é obrigatório!");
		theForm.v_dental_card.focus();
		return false;
	}
	theForm.submit();
	return false;


}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// RADIOGRAFIAS++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// validar formulário de envio das radiografias
function vlAssRadiografias ( theForm ) {
	if (theForm.in_categoria.value == "") {
		alert("Por favor selecione o tipo do arquivo!");
		theForm.in_categoria.focus();
		return false;
	}
	if (theForm.arquivoRadiografia.value == "") {
		alert("Por favor selecione o arquivo que você quer inserir!");
		theForm.arquivoRadiografia.focus();
		return false;
	}
	theForm.submit();
	return true;

}


// atualiazar a janela principal
function exPpRadiosOk(nTp_sinistro, nNum_sinistro, sTp_action) {
	if (sTp_action == "sol") {
		var link = 'aonline_dt_solicitacao_3.php?';
	}
	else if (sTp_action == "vis") {
		var link = 'aonline_dt_sinistros_visu.php?';
	}
	link = link + 'in_tp_sinistro=' + nTp_sinistro;
	link = link + '&in_num_sinistro=' + nNum_sinistro;
	top.opener.location = link;

}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FALE CONOSCO++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function vlFaleConosco ( theForm ) {
	if (theForm.v_cod.value == "") {
		alert ("O seu login ainda não foi validado!");
		theForm.v_cod.focus();
		return false;
	}
	if (theForm.v_telefone.value == "") {
		alert ("Por favor digite o telefone para contato!");
		theForm.v_telefone.focus();
		return false;
	}
	if (theForm.v_email.value == "") {
		alert ("Por favor digite o seu email!");
		theForm.v_email.focus();
		return false;
	}
	else {
		if (!vlEmailAddress ( theForm.v_email.value )) {
			alert ("Verifique o email digitado, pois não está correto!");
			theForm.v_email.focus();
			return false;
		}
	}
	if (theForm.v_subject.value == "") {
		alert ("Por favor selecione o assunto do contato!");
		theForm.v_subject.focus();
		return false;
	}
	if (theForm.v_obs.value == "") {
		alert ("Por favor digite a seu comentário!");
		theForm.v_obs.focus();
		return false;
	}
	theForm.submit();
	return;
}

function vlFaleConosco_NB ( theForm ) {
	if (theForm.v_nome.value == "") {
		alert ("Por favor digite o seu nome!");
		theForm.v_nome.focus();
		return false;
	}
	if (theForm.v_telefone.value == "") {
		alert ("Por favor digite o telefone para contato");
		theForm.v_telefone.focus();
		return false;
	}
	if (theForm.v_email.value == "") {
		alert ("Por favor digite o seu email!");
		theForm.v_email.focus();
		return false;
	}
	else {
		if (!vlEmailAddress ( theForm.v_email.value )) {
			alert ("Verifique o email digitado, pois não está correto!");
			theForm.v_email.focus();
			return false;
		}
	}
	if (theForm.v_subject.value == "") {
		alert ("Por favor selecione o assunto do contato!");
		theForm.v_subject.focus();
		return false;
	}
	if (theForm.v_obs.value == "") {
		alert ("Por favor digite a seu comentário!");
		theForm.v_obs.focus();
		return false;
	}
	theForm.submit();
	return;
}

function vlFaleConosco_ND ( theForm ) {
	if (theForm.v_nome.value == "") {
		alert ("Por favor digite o seu nome!");
		theForm.v_nome.focus();
		return false;
	}
	if (theForm.v_telefone.value == "") {
		alert ("Por favor digite o telefone para contato");
		theForm.v_telefone.focus();
		return false;
	}
	if (theForm.v_endereco.value == "") {
		alert ("Por favor digite o seu endereço!");
		theForm.v_endereco.focus();
		return false;
	}
	if (theForm.v_cidade.value == "") {
		alert ("Por favor digite a cidade!");
		theForm.v_cidade.focus();
		return false;
	}
	if (theForm.v_uf.value == "") {
		alert ("Por favor digite o estado!");
		theForm.v_uf.focus();
		return false;
		alert("estado");
	}
	else {
		if (theForm.v_uf.value.length < 2) {
			alert ("O estado digitado é inválido!");
			theForm.v_uf.focus();
			return false;
		}
	}
	if (theForm.v_area.value == "") {
		alert ("Por favor digite o área de atuação!");
		theForm.v_area.focus();
		return false;
	}
	if (theForm.v_email.value == "") {
		alert ("Por favor digite o seu email!");
		theForm.v_email.focus();
		return false;
	}
	else {
		if (!vlEmailAddress ( theForm.v_email.value )) {
			alert ("Verifique o email digitado, pois não está correto!");
			theForm.v_email.focus();
			return false;
		}
	}
	if (theForm.v_obs.value == "") {
		alert ("Por favor digite a seu comentário!");
		theForm.v_obs.focus();
		return false;
	}
	theForm.submit();
	return;
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




