<!--
// funções de Javascript





//AJAX_________________________________________

function cria_ajax()
	{
	var xmlhttp;
	try
		{
		xmlhttp = new XMLHttpRequest();
		}
	catch(ee)
		{
		try
			{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch(e)
			{
			try
				{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(E)
				{
				xmlhttp = false;
				}
			}
		}
	return xmlhttp;
	}
	
	



function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function



function checa_form(formulario) {
	check_concordo = document.getElementById('check_concordo');
	if(!check_concordo.checked) {
		alert('Para ter acesso a esta área, é necessário marcar a declaração de veracidade das informações enviadas, na última linha do cadastro.');
		return false;
	} else {
		return checar(formulario);
	}
}

function checar(formulario)
{
for(var i=0;i<formulario.elements.length;i++)
     {
	 
	 var campo=formulario.elements[i];
	 
	 if(campo.type=="text" || campo.type=="hidden" || campo.type=="select" || campo.type=="select-one" || campo.type=="password" || campo.type=="file" || campo.type=="textarea" || campo.type=="radio")
	      {
	 	  var obriga=campo.getAttribute('obrigatorio');
	 	  var nomecampoatual=campo.getAttribute('nomecampo');
		  
		  if(campo.type=="radio" && obriga==1)
		       {
			   var meuradio=document.getElementsByName(campo.getAttribute('name'));
			   var preencheu = false;
			   for (var k=0; k<meuradio.length; k++) 
			             {
						 //alert(k + "- teste: " + meuradio[k].value + " está " + meuradio[k].checked);
						 
						 if (meuradio[k].checked)
						           {
								   preencheu = true;
								   }
  						 }
			  if (preencheu==false)
			            {
						alert("Ao menos uma das opções do campo '" + nomecampoatual + "' deve ser selecionada.");
			   			return false;
						break;
						}
			   }
		  else if(obriga==1 && trim(campo.value)=="")
		       {
			   alert("O campo '" + nomecampoatual + "' não pode ficar vazio.");
			   campo.focus();
			   return false;
			   break;
			   }
		  }
	 }
return true;
}



function barra(objeto){
	if (objeto.value.length == 2 || objeto.value.length == 5 ){
		objeto.value = objeto.value+"/";
	}
}




function limita_texto(field, countfield, maxlimit) 
     {
	 if (field.value.length > maxlimit) // if too long...trim it!
	      {
		  field.value = field.value.substring(0, maxlimit);
		  }
     else 
	      {
		  countfield.innerHTML = maxlimit - field.value.length;
		  }
     }




function checkAll(theForm, nome_classe) {
	for (i=0,n=theForm.elements.length;i<n;i++) 
		if (theForm.elements[i].className.indexOf(nome_classe) !=-1) 
			theForm.elements[i].checked = !theForm.elements[i].checked;
}




function define_profissao() {
	var div_dados=$('dados_profissao');
	var span_rotulo=$('rotulo_documento');
	var id_profissao=$('id_profissao').value;

	if(!id_profissao) {
		div_dados.hide();
	} else {
		if(id_profissao==1)	{
			$('div_especialidade').show();
			span_rotulo.innerHTML='CRM';
		} else if(id_profissao==2) {
			$('div_especialidade').hide();
			span_rotulo.innerHTML='CRO';
		} else if(id_profissao==3) {
			span_rotulo.innerHTML='CRF';
			$('div_especialidade').hide();
		} else {
			span_rotulo.innerHTML='';
			$('div_especialidade').hide();
		}
		div_dados.show();
		/*
		var xmlhttp=cria_ajax();
		xmlhttp.open("GET", "ferramentas/ajax_profissoes.php?id_profissao=" + id_profissao, true);
		xmlhttp.onreadystatechange=function()
			{
			if(xmlhttp.readyState==4)
				{
				var texto=xmlhttp.responseText;
				texto=texto.replace(/\+/g," ");
				texto=unescape(texto);
				var dados=eval(texto);
				var erro=dados[0];
				var mensagem_retorno=dados[1];
				
				
				if(erro!=0)
					{
					alert(mensagem_retorno);
					}
				else
					{
					if(id_profissao==1)	{
						$('div_especialidade').show();
					} else {
						$('div_especialidade').hide();
					}
					
					var rotulo=dados[2];
					span_rotulo.innerHTML=rotulo + ":";
					div_dados.show();
					}
				}
			}
		xmlhttp.send(null);
		delete xmlhttp;
		*/
	}
}




function define_profissao_login() {
	var div_dados=$('dados_profissao');
	var span_rotulo=$('rotulo_documento');
	var id_profissao=$('id_profissao').value;

	if(!id_profissao) {
		div_dados.hide();
	} else {
		if(id_profissao==1)	{
			span_rotulo.innerHTML='CRM';
		} else if(id_profissao==2) {
			span_rotulo.innerHTML='CRO';
		} else if(id_profissao==3) {
			span_rotulo.innerHTML='CRF';
		} else {
			span_rotulo.innerHTML='';
		}
		div_dados.show();
	}
}




-->