// JavaScript Document

function toggle(id,speed)
{
	$("#"+id).toggle(speed);
}

function fade(id,speed){
	display = document.getElementById(id).style.display;
	if(display == 'none' )
	{
		$("#"+id).fadeIn(speed);
	}
	else
	{
		$("#"+id).fadeOut(speed);
	}
}

function show_hide(id,speed){
	display = document.getElementById(id).style.display;
	if(display == 'none' )
	{
		$("#"+id).show(speed);
	}
	else
	{
		$("#"+id).hide(speed);
	}
}

function animate(id,speed)
{
	display = document.getElementById(id).style.display;
	if(display == 'none' )
	{
		$("#"+id).animate({width:'657', opacity: 1, height: 'show'}, speed);
		
	}
	else
	{
		$("#"+id).animate({width:'300', opacity: 0, height: 'hide'}, speed);
	}
}

function animate_smarter(id,speed)
{
	display = document.getElementById(id).style.display;
	conteudo = document.getElementById(id).innerHTML;
	if(display == 'none' )
	{
		$("#"+id)
		.html(conteudo+'<div class="bla" style="position:absolute; top:0; left:0; width:100%; height:100%; background:#333"></div>')
		.animate({width:'140', opacity: 0, height: '140'}, 0)
		.animate({width:'469', opacity: 1, height: '313'}, speed, 
			function() 
			{
				$('.bla').fadeOut(140);
			});
	}
	else
	{
		$("#"+id)
		.html(conteudo+'<div class="bla" style="position:absolute; top:0; left:0; width:100%; height:100%; background:#333"></div>')
		.animate({width:'140', height: '140'}, speed)
		.animate({opacity: 0}, 140, 
			function()
			{
				$("#"+id)
				.html(conteudo)
				.css('display', 'none');
			});
	}
}


pag_atual = 1;
function galeria(direction, distancia, num_scroll, total, speed, alvo)
{
	pag_total = Math.ceil(total/num_scroll);
	//alert('tt:'+pag_total+'at:'+pag_atual);
	if(direction == 'L' && pag_total > pag_atual)
	{
		$("#"+alvo)
		.animate({left: '-='+distancia+'px'}, speed, 'easeInOutQuart');
		pag_atual++;
	}
	else if(direction == 'R' && pag_atual > 1)
	{
		$("#"+alvo).animate({left: '+='+distancia+'px'}, speed, 'easeInOutQuart');
		pag_atual--;
	}	
}

function galeria_home(direction, distancia, num_scroll, total, speed, alvo)
{
	pag_total = Math.ceil(total/num_scroll);
	//alert('tt:'+pag_total+'at:'+pag_atual);
	if(direction == 'L' && pag_total > pag_atual)
	{
		$("#"+alvo)
		.animate({left: '-='+distancia+'px'}, speed);
		pag_atual++;
	}
	else if(direction == 'R' && pag_atual > 1)
	{
		$("#"+alvo).animate({left: '+='+distancia+'px'}, speed);
		pag_atual--;
	}	
}


//********************************************************************************//

















// INICIO MUDA A COR DA LINHA DA TABELA QND O MOUSE ESTA EM CIMA
function linhaTabela1(n,col)
{
	w=0;
	while(w<col)
	{
	i= "n"+n+"_"+w;
	document.getElementById(i).style.backgroundColor = "#1363a1";
	w++;
	}
}

function linhaTabela1_2(n,col)
{
	w=0;
	while(w<col)
	{
	i= "n"+n+"_"+w;
	document.getElementById(i).style.backgroundColor = "#ddd";
	document.getElementById(i).style.color = "#000";
	w++;
	}
}

function linhaTabela2(n,col)
{
	w=0;
	while(w<col)
	{
	i= "n"+n+"_"+w;
	document.getElementById(i).style.backgroundColor = "";
	w++;
	}
}

function linhaTabela2_2(n,col)
{
	w=0;
	while(w<col)
	{
	i= "n"+n+"_"+w;
	document.getElementById(i).style.backgroundColor = "";
	document.getElementById(i).style.color = "#666666";
	w++;
	}
}
// FIM MUDA A COR DA LINHA DA TABELA QND O MOUSE ESTA EM CIMA

// INICIO FUNÇÃO DE DELETAR
function deletar(id,tb)
{
var r=confirm("Tem certeza que deseja excluir este item e tudo que estiver relacionado a ele?");
if (r==true)
  {
  window.location="../sistema/delete.sis.php?id="+id+"&tb="+tb;
  }
}
// FIM FUNÇÃO DE DELETAR

// INICIO FUNÇÃO DE DELETAR
function deletar_foto(id,img,tb)
{
var r=confirm("Tem certeza que deseja excluir esta imagem?");
if (r==true)
  {
	window.location="../sistema/delete.sis.php?id="+id+"&img="+img+"&tb="+tb;
  }
}
// FIM FUNÇÃO DE DELETAR

function irpara(destino)
{
  window.location= destino;
}


// INICIO FUNÇÃO LIMPA CAMPO
function limpar(id, padrao)
{
	valor = document.getElementById(id).value;
	if(valor == padrao)
	document.getElementById(id).value = '';
}
// FIM FUNÇÃO LIMPA CAMPO

function voltar(num)
{
	history.go(-num);
}


function limit_click(id, max_char)
{// INICIO FUNÇÃO QUE LIMITA A QUANTIDADE DE CARACTESRES NO TEXTAREA
	if(document.getElementById(id).value.length > max_char)
	{
		event.returnValue = false;
	}
	else
	{
		event.returnValue = true;
	}
}// FIM FUNÇÃO QUE LIMITA A QUANTIDADE DE CARACTESRES NO TEXTAREA


