// JavaScript Document

/* INICIALIZACAO DE FUNCOES */
jQuery(document).ready(function() {

	//Remove border link when clicked
	jQuery("a").focus( function() {
		if(this.blur)this.blur();
	});
	
	//Forum -
	jQuery("#registrarSubmit").click( function(){
		jQuery("#registrar").submit();
	});
	
	jQuery("#logarSubmit").click( function(){
		jQuery("#logar").submit();
	});
	
	jQuery("#abaForumRegistrar").click( function(){
		jQuery("#abaRegistrar").hide();
		jQuery("#abaLogin").fadeIn("def");
	});
	
	jQuery("#abaForumLogin").click( function(){
		jQuery("#abaLogin").hide();
		jQuery("#abaRegistrar").fadeIn("def");
	});

								
	// fade in para os conteudos
	jQuery("#recentes").fadeIn('slow');
	jQuery("#coluna1_text").fadeIn('slow');
	jQuery("#coluna2_text").fadeIn('slow');
	jQuery("#fique-por-dentro").fadeIn('slow');
	jQuery("#forum-do-cfo").fadeIn('slow');
	jQuery("#jornal-do-cfo").fadeIn('slow');
	jQuery("#sidebar_text").fadeIn('slow');
	jQuery("#enquete").fadeIn('slow');
	jQuery("#saiu-na-imprensa").fadeIn('slow');

	/* elementos da home */
	jQuery("#recentesImage").click( function() {
		abas("recentes");
	});
	jQuery("#lidasImage").click( function() {
		abas("lidas");
	});
	
	/* elementos da home - ATOS NORMATIVOS e PROFISSIONAIS*/
	jQuery("#atosImage").click( function() {
		alternar_abas( "#atos", "#profissionais", "#atosImage", "#profissionaisImage", "/imagens/home/atos_normativos.gif", "/imagens/home/profissionais2.gif" )
	});
	jQuery("#profissionaisImage").click( function() {
		alternar_abas( "#profissionais", "#atos", "#profissionaisImage", "#atosImage", "/imagens/home/profissionais.gif", "/imagens/home/atos_normativos2.gif" )
	});

	/* elementos de atos normativos */
	jQuery("#recentesImage2").click( function() {
		abas("recentes", 'internas');
	});
	jQuery("#lidasImage2").click( function() {
		abas("lidas", 'internas');
	});
	
	/* elementos de noticias */
	jQuery("#recentesImage3").click( function() {
		abas("recentes", 'internas-noticias');
	});
	jQuery("#lidasImage3").click( function() {
		abas("lidas", 'internas-noticias');
	});	
	
	jQuery("#submit_formulario").click( function() {
		jQuery("#formulario_atos_normativos").submit();
	});
	
	/* jornal do CFO and Links */	
	jQuery('#cat').change( function() {
		if ( jQuery('#cat').attr("value") != "-1") {
			jQuery("#formulario_edicoes_anteriores").submit();
		}
	});
	
	jQuery('#enviar_formulario_faculdades').change( function() {
		jQuery("#formulario_faculdades").submit();
	});
	
	/* jornal do CFO yellow bar */
	// miniatura
	var jornal_thumb = jQuery("#temp_jornal_thumb").attr("value");
	jQuery("#jornal-thumb-img").attr("src", jornal_thumb);
	// ano
	var jornal_ano = jQuery("#temp_jornal_ano").attr("value");
	jQuery("#jornal-ano").html(jornal_ano);
	// data
	var jornal_data = jQuery("#temp_jornal_data").attr("value");
	jQuery("#jornal-data").html(jornal_data);
	// exemplares
	var jornal_exemplares = jQuery("#temp_jornal_exemplares").attr("value");
	jQuery("#jornal-exemplares").html(jornal_exemplares);
	// link do pdf
	var jornal_pdf = jQuery("#temp_jornal_pdf").attr("value");
	jQuery("#jornal-pdf").attr("href", jornal_pdf);
	
	/* ENDERECO COMERCIAL - CHECKBOX */
	jQuery("#check-endereco").click( function() {
		if ( jQuery("#endereco-comercial").is(":hidden") ) {
			jQuery("#endereco-comercial").slideDown("slow");
		}else{
			jQuery("#endereco-comercial").slideUp("slow");
		}
	});

});

// retirando o "nessa sessao" para a sessao jornal
function retirar_h1(){
	jQuery("#coluna1_content h1").remove();
	jQuery("#coluna1_content").css({'margin-top' : '-10px'});
}

function hover(id, opcao) {
		
	var menuhover = document.getElementById("menuhover")
	menuhover = menuhover.getElementsByTagName("div")
	var submenu = "submenu-" + ( id + 1 )
	
	switch(opcao){
		case "hover":
			menuhover[id].style.display = "block"
			document.getElementById(submenu).style.display = "block"
/*			submenu1 = document.getElementById(submenu)
			jQuery(submenu1).slideDown("fast")*/
		break
		case "out":
			menuhover[id].style.display = "none"
			document.getElementById(submenu).style.display = "none"
		break
	}
}

function hoverferramentas(id, imagem, opcao){
	if(opcao == 'hover'){
		// MODIFICAR ESSE ENDEREÇO LOGO APÓS SUBIR O SITE !!!
		document.getElementById(id).src = tp_dir+"/imagens/internas/" + imagem + "-hover.gif"
	}else{
		document.getElementById(id).src = tp_dir+"/imagens/internas/" + imagem + ".gif"
	}
}

function resize() {
	var tamanho = document.getElementById("coluna2_text").offsetHeight
	/*document.getElementById("coluna1_text").style.height = (tamanho + 12) + "px"*/
	/*document.getElementById("sidebar_content").style.height = (tamanho + 69) + "px"*/
}

var elemento_ativo =  "recentes";
var elemento_inativo =  "lidas";

function abas ( elemento_desejado, pagina )
{
	
	if ( elemento_ativo != elemento_desejado )
	{
		num_imagem = '';
		noticias = '';
		elemento_inativo = elemento_ativo;
		elemento_ativo = elemento_desejado;
		
		if ( pagina == null )
		{
			pagina = 'home';
		}
		
		switch ( pagina )
		{
			
			case 'home':
				//num_imagem = '';
				//noticias = '';
				//pagina = 'home';
			break;
			
			case 'internas':
				num_imagem = '2';
				//noticias = '';
				//pagina = 'internas';
			break;
			
			case 'internas-noticias':
				num_imagem = '3';
				noticias = '-noticias';
				pagina = 'internas';
			break;
			
			default:
				// Caso este alerta seja exibido, crie um novo elemento no case acima.
				alert("Defina o nome e caminho da imagem!");
			break;
			
		}
		
		caminho = tp_dir+"/imagens/"+pagina+"/+";
		
		jQuery('#'+elemento_ativo).fadeIn('def'); // Caixa
		jQuery('#'+elemento_ativo+"Image"+num_imagem).attr("src",caminho+elemento_ativo+noticias+'.gif'); // Imagem
	
		jQuery('#'+elemento_inativo).hide(); // Caixa
		jQuery('#'+elemento_inativo+"Image"+num_imagem).attr("src",caminho+elemento_inativo+'2'+noticias+'.gif'); // Imagem
		
	}

}



/*
* Param: elemento_a- esse e a div a quem eu quero que apareca
* Param: elemento_b- esse e a div a quem eu quero ocultar
* Param: imagem_a- muda para caminho_a
* Param: imagem_b- muda para caminho_b
*/

/*RECENTES*/ /*- '#recentes', '#lidas', '#profissionaisImage', '#atosImage', '/imagens/internas/+recentes-noticias.gif', 'imagens/internas/+lidas2-noticias.gif'*/
/*LIDAS*/ /*- '#lidas', '#recentes', '#atosImage', '#profissionaisImage', '/imagens/internas/+lidas-noticias.gif', 'imagens/internas/+recentes2-noticias.gif'*/

function alternar_abas( elemento_a, elemento_b, imagem_a, imagem_b, caminho_a, caminho_b )
{

	if ( jQuery(elemento_a).is(":hidden") )
	{
		jQuery(elemento_a).fadeIn('def');
		jQuery(elemento_b).hide();
		jQuery(imagem_a).attr("src",tp_dir+caminho_a);
		jQuery(imagem_b).attr("src",tp_dir+caminho_b);
	}
}

function super_show(id, subtitle, content) {
	var obj = jQuery(id);
	if ( jQuery(id).is(":hidden") ) {
		obj.show();
		if(subtitle)jQuery(subtitle).fadeIn("slow");
		if(content)jQuery(content).fadeIn("slow");
	} else {
		if(subtitle)jQuery(subtitle).fadeOut("def");
		if(content)jQuery(content).fadeOut("def");
		/*if(content)jQuery(content).css({'display': 'none' });*/
		obj.fadeOut("def");
	}
}

/* função responsável por fazer hover em imagens (DREAMWEAVER CS4) */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function dadosEstatisticos(id) {
	if( jQuery(id).is(":hidden") ) {
		jQuery(id).fadeIn("def")
	}else {
		jQuery(id).fadeOut("def")
	}
}

function showHide(id, sinal) {
	if ( jQuery(id).is(":hidden") ) {
		jQuery(id).fadeIn("def")
		jQuery(sinal).html('-')
	} else {
		jQuery(id).fadeOut("def")
		jQuery(sinal).html('+')
	}
}






// Ferramentas / Criado por Cassio

function fonte_f( tamanho )
{
	tamanho = tamanho+"px";
	jQuery("#coluna2_text").css({'font-size': tamanho});
}

function favoritos() {
	var htmlLink = '<a id="add2favorites" href="'+window.location.href+'" title="'+document.title+'"></a>';
	jQuery('#ferramenta4').after(htmlLink);
	jQuery('#add2favorites').jFav();
	jQuery('#add2favorites').click();
	jQuery('#add2favorites').remove();
}


function favoritos_antigo_a() {
    var url      = "http://www.cfo.org.br";
    var title    = "CFO - Conselho Federal de Odontologia";
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}

function favoritos_antigo()
{
	try {
		var title = document.title;
		var url = window.location.href;
		if ( window.sidebar ) 
			window.sidebar.addPanel(title, url, "");
		else if( window.opera && window.print )
		{
			var mbm = document.createElement('a');
			mbm.setAttribute('rel','sidebar');
			mbm.setAttribute('href',url);
			mbm.setAttribute('title',title);
			mbm.click();
		}
		else if( document.all ){
			window.external.AddFavorite(url, title);
		}
	} catch ( ex ) {
		alert(ex.toString());
	}
}

function imprimir( ato_normativo, elemento )
{
	if ( ato_normativo == true )
	{
		var width = 810;
		var height = 500;
		
		var left = ( window.screen.width / 2 ) - ( ( width / 2 ) + 10 );;
		var top = ( window.screen.height / 2 ) - ( ( height / 2 ) + 50 );;
		
		window.open('http://cfo.org.br/ato-normativo-pop.php?id='+elemento,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=yes, fullscreen=no');
	}
	else
	{
		window.print();
	}
}


