//pessoal

function atualizarValores(){
	var total = 0;
	var valProduto = retornaValorRadio(document.form1.produtos, "produto");
	var valMiniCurso = retornaValorRadio(document.form1.minicursos, "minicurso");
	//if(valMiniCurso == undefined || valMiniCurso == "Saúde Mental na Atenção Primária" || valMiniCurso == "O NASF e as ações de Saúde Mental"){
	if(valMiniCurso == undefined){
		valMiniCurso = 0;
	}
	total = total + valMiniCurso;	
	
	if(valProduto != null){
		total = total + valProduto;
	}
	document.form1.cValor.value = total;
	escreveDiv("displayTotal", "R$"+toMoeda(total));
}

function retornaValorRadio(campo, tipo)
{
	botoes = campo.length;
	for (i=0;i<botoes;i++) {
		if (campo[i].checked) {
			for(j=0;j<arrayTabela.length;j++){
				if(arrayTabela[j].titulo == campo[i].value){
					if(tipo =="produto"){
						document.form1.cProduto.value = campo[i].value;
					}
					if(tipo == "minicurso"){
						document.form1.cMinicurso.value = campo[i].value;
					}
				return 	arrayTabela[j].valor
				}
			}
			break; 
		}
	}
}

// CONFERE INVALIDOS CARCTERES
function showhide(layer_ref, par) {

	if (par == 'hide') {
		state = 'none';
	}
	else if(par == "show") {
		state = 'block';
	}
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.display = state");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
	document.layers[layer_ref].display = state;
	}
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer_ref);
		hza.style.display = state;
	}
}
function goPage(page){
	window.location.href=page;
}
function escreveDiv(divId, valor){
	document.getElementById(divId).innerHTML = valor;	
}
function checarCheckbox(campo, mensagem)
{
	if(campo.checked == false){
		alert(mensagem);
		return true;
	}
}
//ajax
function checarRadio(campo, mensagem)
{
	preencheu = false;
	botoes = campo.length;
	for (i=0;i<botoes;i++) {
		if (campo[i].checked) {
			preencheu = true;
			break; 
		}
	}
	if (preencheu) {
		//form.submit();
		
	}
	else {
		alert(mensagem);
		return true;
	}

}
function toMoeda(val)
{
	val = val/100;
	val = val.toString();
	var aV = val.split(".");
	var real = aV[0];
	var centavos = aV[1];
	if(centavos == null){
		centavos = "00";
	}
	if(centavos.length < 2){
		centavos = centavos+"0";
	}
	return real+","+centavos;
}
function toNumber(val)
{
	if(val.charAt(0) == "R" && val.charAt(1)=="$"){
		val = val.slice(2);
	}
	var aV = val.split(",");
	var real = aV[0];
	var centavos = aV[1];
	if(centavos == null){
		centavos = "00";
	}
	val = Number(real+centavos);
	return val;
}
function problema(campo)
{
	invalidChars = "~'"
	for (i=0; i<invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i)
		if (campo.value.indexOf(badChar) != -1)
		{
			//alert(mens2+badChar+mens2A)
			campo.select();
			return true;
		}
	}	
}
// CONFERE FORMULÁRIOS
function confere (campo,alerta)
{
	if (campo.value == "")
	{
		alert(alerta);
		campo.focus();
		return true;
		return;
	}
	if (problema(campo) == true)
	{
		alert(alerta+" com caracteres válidos.");
		campo.focus();
		return true;
		return;
	}
}

function veriNumber(s,alerta)
{
	var i; 
	var dif = 0;
	for (i = 0; i < s.value.length; i++)
	{
		var c = s.value.charAt(i);
		if (!((c >= "0") && (c <= "9")))
		{
			dif = 1;
		}
	}
	if (dif == 1)
	{
		alert(alerta);
		s.focus();
		return true;
	}
	//alert(alerta);
	return false;
	
}
// LIMITA VALOES
function entre_numeros(campo,num1,num2,alerta)
{
	if (campo.value<num1 || campo.value>num2)
	{
		alert(alerta);
		campo.focus();
		return true;
		return;
	}
}
// QUANTIDADE NO CAMPO
function conta_espaco(campo,num1,num2,alerta)
{
	var dif_new=0;
	var i;
	for (i = num1; i <= num2; i++)
	{
		if (campo.value.length == i)
			{dif_new=1}
	}
	if (dif_new != 1)
	{
		alert(alerta);
		campo.focus();
		return true;
	}
}
//checar extenções arquivo
function checkExt(file,tipo,alerta)
{
	tipoArray = tipo.split(",");
	fileName = file;
	fl = fileName.length;
	fileExt = fileName.charAt(fl -4)+fileName.charAt(fl -3)+fileName.charAt(fl -2)+fileName.charAt(fl -1);
	ifdot = false;
	
	
	for(tp=0;tp<tipoArray.length;tp++){
		
		if(fileExt == tipoArray[tp] || fileExt == tipoArray[tp].toUpperCase() || fileExt == tipoArray[tp].toLowerCase()){
			return false;
		}
	}
	alert(alerta);
	return true;
}
//retorna textenção arquivo
function returnExt(file){
	fileName = file;
	fl = fileName.length;
	fileExt = fileName.charAt(fl -3)+fileName.charAt(fl -2)+fileName.charAt(fl -1);
	return 	fileExt ;
}

//desativar forms
function disabledForms(formname, imp){
	arrayImp = imp.split(",");
	for(i=0;i<arrayImp.length;i++){
		formname[arrayImp[i]].disabled = true;
	}
	return;
}
//confere email
function conferemail (campo)
{
	mens1="Por favor, coloque o seu e-mail. Você precisará dele para acessar o acesso restrito."
	mens2="Caracter "
	mens2A=" inválido no seu e-Mail."
	mens2c="Carater inválido na sua senha."
	mens3="O e-mail digitado deve possuir @"
	mens4="Mais de uma @ no seu e-Mail"
	mens5="O '.' não pode estar logo após a @ "
	mens6="Por favor, confira o seu e-mail, deve haver pelo menos um '.' após a '@'."
	mens7="Por favor, confira o seu e-mail, deve haver algum complemento após o primeiro ponto (seunome@site.com)."
	mens10="e-Mails não podem ter espaços."
	if (campo.value=="")
	{
	  alert(mens1);
	  campo.select();
	  return true;
	}
	invalidChars = "/:,;><^~{}]='%\"[¨&*|+()"
	for (i=0; i<invalidChars.length; i++)
	{
	badChar = invalidChars.charAt(i)
	
	if (campo.value.indexOf(badChar) != -1)
	
	{
	  alert(mens2+badChar+mens2A)
	  campo.select();
	  return true;
	}
	}		
	atPos = campo.value.indexOf("@")
	if (atPos == -1)
	{
	alert(mens3);
	  campo.select();
	  return true;
	}
	x = campo.value.indexOf("@");
	variavel = campo.value;
	aux_email = variavel.substring(x+1,variavel.length);
	if ( aux_email.indexOf("@") != -1)
	{
	alert(mens4);
	  campo.select();
	 return true;
	}
	
	x = campo.value.indexOf("@");
	variavel = campo.value;
	aux_email = variavel.substring(x+1,x+2);
	if ( aux_email == ".")
	{
	alert(mens5);
	  campo.select();
	  return true;
	}
	
	x = campo.value.indexOf(" ");
	if ( x != "-1")
	{
	alert(mens10);
	  campo.select();
	  return true;
	}
	
	periodPos = campo.value.indexOf(".",atPos)
	if (periodPos == -1)
	{
	alert(mens6);
	  campo.select();
	  return true;
	}
	if (periodPos+3 > campo.value.length)
	{
	alert(mens7);
	  campo.select();
	  return true;
	}
}
function valida_numeros_apenas(s,alerta)
{
	alert("jjj");
	/*var i; 
	var dif = 0;
	for (i = 0; i < s.value.length; i++)
	{
		var c = s.value.charAt(i);
		if (!((c >= "0") && (c <= "9")))
		{
			dif = 1;
		}
	}
	if (dif == 1)
	{
		alert(alerta);
		s.focus();
		return true;
	}
	//alert(alerta);*/
	return false;
	
} 