function MenuOver(Img,Src){
	Img.src = Src;
}
function MenuOut(Img,Src){
	Img.src = Src;
}


function AdminLogin(){
	if (document.getElementById('Admin').AdminSenha.style.visibility == 'hidden')
		document.getElementById('Admin').AdminSenha.style.visibility='visible';
	else document.getElementById('Admin').AdminSenha.style.visibility='hidden';
}

function ConfirmarExclusao(){
	return confirm('Excluir a informação definitivamente ?\nNão será possível recuperá-la se você prosseguir.');
}


function createRequestObject(){
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer") ro = new ActiveXObject("Microsoft.XMLHTTP");
    else ro = new XMLHttpRequest();
    return ro;
}

// Variáveis
var fotos = createRequestObject();
var fotos2 = createRequestObject();
var Fotos = null;
var FotoAtual = null;
var Timer = null;

function IniciaSlides(secao){
	BuscaFotos(secao);
	document.getElementById('CabProEspFoto').innerHTML = '';
   	document.getElementById('CabProEspTexto').innerHTML = '';
   	document.getElementById('CabProEspFotoAtual').innerHTML = '0 de 0';
	clearInterval(Timer);
	Timer = window.setInterval("SelecionaFoto(FotoAtual+1)",5000);
}

function ProxFoto(){
	clearInterval(Timer);
	if(FotoAtual < Fotos.length){
		SelecionaFoto(FotoAtual+1);
	}
}
function AntFoto(){
	clearInterval(Timer);
	if(FotoAtual > 0){
		SelecionaFoto(FotoAtual-1);
	}
}

function BuscaFotos(secao){
   if(secao == 'projetos'){
   	   document.getElementById('CabProEspSub').innerHTML = '<img src="img/cab_ini_projetos_especies_sub.gif"><br>Acompanhe as fotos de alguns dos projetos executados pela <b>Eco</b>.';
   }else{
   	   document.getElementById('CabProEspSub').innerHTML = '<img src="img/cab_ini_projetos_especies_sub_1.gif"><br>Acompanhe as espécies que a <b>Eco</b> trabalha.';
   }
   fotos.open('get', 'funcoes_ajax.php?op=BuscaTodas&secao='+secao); 
   fotos.onreadystatechange = BuscaFotosR; 
   fotos.send(null);
}
function BuscaFotosR() {
   if(fotos.readyState == 4){
   		// Separa a string pelo separador ".x.", entre os códigos  e as fotos
   		
   		Fotos = fotos.responseText.split(',');
   		SelecionaFoto(0);
   }
}

// Seleciona Foto Principal
function SelecionaFoto(indice){
   if (Fotos[indice]){
   	   FotoAtual = indice;
	   fotos2.open('get', 'funcoes_ajax.php?op=SelecionaFoto&cod_dado='+Fotos[indice]); 
	   fotos2.onreadystatechange = SelecionaFotoR; 
	   fotos2.send(null);
	   
	   document.getElementById('CabProEspFotoAtual').innerHTML = parseInt(FotoAtual)+1+' de '+Fotos.length;
   }
}
function SelecionaFotoR() {
   if(fotos2.readyState == 4){
   		var retorno = fotos2.responseText;
   		
   		// Separa a string pelo separador ".x.", entre o código, a foto e a legenda
   		dados = retorno.split('.x.');
		
   		document.getElementById('CabProEspFoto').innerHTML = dados[0];
   		document.getElementById('CabProEspTexto').innerHTML = dados[1];
   		
   		//document.getElementById('FotologFotoAtual').innerHTML = parseInt(FotoAtual)+1;
   }
}
function MudaFoto(cod_dado){
	if(cod_dado){
		fotos.open('get', 'funcoes_ajax.php?op=MudaFoto&cod_dado='+cod_dado); 
	    fotos.onreadystatechange = MudaFotoR; 
	    fotos.send(null);
	   
		document.getElementById('FotoInicial').src = '';
		document.getElementById('FotoLegenda').innerHTML = '';
	}
}
function MudaFotoR(){
	var retorno = fotos.responseText;
	dados = retorno.split('.x.');
	
	document.getElementById('FotoInicial').src = dados[0];
	document.getElementById('FotoLegenda').innerHTML = dados[1];
}

function ValidaContato(){
	if(document.getElementById('Contato').ContatoNome.value == ''){
		alert('Por avor, preencha o seu Nome.')
		document.getElementById('Contato').ContatoNome.focus();
		return false;
	}
	if(document.getElementById('Contato').ContatoEmail.value == ''){
		alert('Por avor, preencha o seu Email.')
		document.getElementById('Contato').ContatoEmail.focus();
		return false;
	}
	if(document.getElementById('Contato').ContatoMensagem.value == ''){
		alert('Por avor, preencha a Mensagem.')
		document.getElementById('Contato').ContatoMensagem.focus();
		return false;
	}
	return true;
}