function configParaTodos(donoMidia, mensagem)
{
	var campoIdComentarioResposta = document.getElementById('idComentarioResposta');	
	var lblPara = document.getElementById('lblPara');
	var chkPara = document.getElementById('chkPara');
	lblPara.innerHTML = mensagem;
	chkPara.disabled = !donoMidia;	

	if(campoIdComentarioResposta != null)
	{
	 campoIdComentarioResposta.value = '';
	}		
  mySetStyleDisplay('divPara',(donoMidia?'':'none'));	
}
function incluirComentario(abrirForm,donoMidia,mensagemPara)
{
  configParaTodos(donoMidia, mensagemPara);
	if(abrirForm) {
    mySetStyleDisplay('divComentario','');
    mySetStyleDisplay('incluirComentario','none');
  }
  var url = location.href.split("#",2);
  location.href = url[0] + "#comentarios";

	var campoComentario = document.getElementById('comentario');
	if(campoComentario != null) campoComentario.focus();		
}
var dir = './fo'+'t'+'os/m';
function clicouPara(campo, donoMidia, mensagem)
{
	if(!campo.checked) configParaTodos(donoMidia, mensagem);
}

function responderComentario(idComentario, mensagem)
{
	var campoIdComentarioResposta = document.getElementById('idComentarioResposta');
	var lblPara = document.getElementById('lblPara');
	var chkPara = document.getElementById('chkPara');
	
	chkPara.checked = true;
	chkPara.disabled = false;
  
  incluirComentario(true, true);	
	if(campoIdComentarioResposta != null) {
	  campoIdComentarioResposta.value = idComentario;
	}
	if(lblPara != null) {
		lblPara.innerHTML = mensagem;
	}
}
function mySetStyleDisplay (myDiv2, myStyle3)
{
  if (document.getElementById)
  {
    var obj = document.getElementById(myDiv2);
    obj.style.display = myStyle3;
  }
  else if (document.all)
  {
    var obj = document.all(myDiv2);
    obj.style.display = myStyle3;
  } else {alert (Err_Browser);}
}
function getFoto() { return 'getImagem.php?f='; }
function getDir(idFoto)
{
	var dir = ('00000'+Math.floor(idFoto/1000));
	return dir.substring(dir.length-4, dir.length);
}
function carregar(divFoto,idFoto,params,possuiGrande)
{
	var imgFoto = '<IMG id="imgFoto" style="margin-top:0px" class="foto" src="'+dir+getDir(idFoto)+'/'+idFoto+'.jpg">';
	if(possuiGrande)
	{
		var abrelinkFotoGrande = '<A href="fotogrande.php?f='+idFoto+'" rel="nofollow" target="_blank">';
		var fechaLinkFotoGrande = '</A>';
  	imgFoto = abrelinkFotoGrande+imgFoto+fechaLinkFotoGrande;
	}	
	imgFoto.replace("XYZ",dir+Math.ceil(idFoto/1000)*1000+'/'+idFoto+'.jpg');	
	document.getElementById(divFoto).innerHTML = imgFoto;
}
function OnBlurEspecie(field,label)
{
	if(field.value == "")
	{
	  field.value = label;
	  field.style.color = "gray";
	  if(document.getElementById(field.name+'_hidden')) document.getElementById(field.name+'_hidden').value="";
	  if(document.getElementById(field.name+'_nome')) document.getElementById(field.name+'_nome').innerHTML="";
	  if(document.getElementById('sexo')) document.getElementById('sexo').disabled = true;
	  if(document.getElementById('idade')) document.getElementById('idade').disabled = true;
	}
	else
	{
		field.style.color = "black";
	  if(document.getElementById('sexo')) document.getElementById('sexo').disabled = false;
	  if(document.getElementById('idade')) document.getElementById('idade').disabled = false;
	}
}

function OnFocusEspecie(field, label)
{
	if(field.value == label)
	{
	  field.value = "";
	}
	if(field.style.color == "gray")
	{
	  field.style.color = "black";
	}
}
function OnSelectEspecie(fieldName)
{
	if(document.getElementById(fieldName))
	{
		var nome = document.getElementById(fieldName).value;
		nome = nome.replace(String.fromCharCode(160)," ");
		var nomes = nome.split(" ");
		var nomeCientifico = "";
		var nomePopular = "";

		if(nomes.length > 2) 
		{
      nomeCientifico = nomes[nomes.length-2]+" "+nomes[nomes.length-1];
      nomePopular = nome.replace(nomeCientifico,"");
    }
    else
    {
    	try {
      	nomeCientifico = nome;
      	nomePopular = "";      		
    	} catch(e){}    		
    } 
    document.getElementById(fieldName).value = nomeCientifico;
	  if(document.getElementById(fieldName+'_nome')) document.getElementById(fieldName+'_nome').innerHTML =nomePopular;
	  if(document.getElementById('sexo')) document.getElementById('sexo').disabled = false;
	  if(document.getElementById('idade')) document.getElementById('idade').disabled = false;
	}
}