/***************************
*   INICIALIZACAO
****************************/
// <![CDATA[
			
function init()
{
  // caso o título esteja definido, então preencha como padrão na barra de status 
  if( document.title ) window.defaultStatus = document.title;
  // restringe controle 
  if( window.fnc_seguranca ) fnc_seguranca(); 
  // ativa as tooltips
  // ativa rotina de validacao
  if( window.fnc_controla_campos ) fnc_controla_campos(); 
  // centraliza formulario
 
  switch( getCurrentPage() )
  {
	case 'assinatura_digital.cfm' : 
	 	 if( window.fnc_config_valida_asssinatura_digital ) fnc_config_valida_asssinatura_digital();  
	break;
	
	case 'act_imprime_assinatura_digital.cfm' : 
		window.focus(); 
		window.print(); 
	break;
	
	case '%6d%61%69%6e%2e%63%66%6d':
	case 'main.cfm':
	/*case 'main_alteracoes.cfm':*/
	case 'prova_banner.cfm':
		 // modifica header da página
		 fnc_modifica_header();
		 // mostra banner
		 fnc_mostra_banner();
		 // oculta após 20 segundos
		 setTimeout( function(){ fnc_oculta_banner();} , 50000);
		 // realiza a substituição do header do diário
		 tempo = setInterval( function() { clearInterval( tempo ); fnc_modifica_header() } , 3000 ); 			
	 break;
	 
	 case 'extrato_publicacao.cfm': 
		if( getCookie('criterio_chave') ) 
			setFormVariavel('form_extrato_publicacao','criterio_chave', getCookie('criterio_chave'));
		if( getCookie('periodo') )
		{
			setFormVariavel('form_extrato_publicacao','periodo', getCookie('periodo'));
			fnc_mostra_periodo( getCookie('periodo') );
			if(	document.getElementById('Mensal')        && getCookie('Mensal') )               setFormVariavel('form_extrato_publicacao','Mensal', getCookie('Mensal'));
			if(	document.getElementById('Bimestral')     && getCookie('Bimestral'))             setFormVariavel('form_extrato_publicacao','Bimestral', getCookie('Bimestral'));
			if(	document.getElementById('Trimestral')    && getCookie('Trimestral'))            setFormVariavel('form_extrato_publicacao','Trimestral', getCookie('Trimestral'));
			if(	document.getElementById('Quadrimestral') && getCookie('Quadrimestral'))         setFormVariavel('form_extrato_publicacao','Quadrimestral', getCookie('Quadrimestral'));
			if(	document.getElementById('Semestral')     && getCookie('Semestral'))             setFormVariavel('form_extrato_publicacao','Semestral', getCookie('Semestral'));
		}
			if(	document.getElementById('Anual')         && getCookie('Anual'))                 setFormVariavel('form_extrato_publicacao','Anual', getCookie('Anual'));
	
	 break;
	
	/* alterado por Bruno Soares em 27/11/2006 para fazer funcionar a pagina de contatos !
	case 'contato.cfm':
		 fnc_escolhe_cidade( document.getElementById('estado_id').value )
	break;	
	*/
	
  } 
}

/***************************
*   GERAL
****************************/
function fnc_modifica_header(){
 var dominio     		 = window.location.href.replace('http://','');
 var subdominio  		 = ( dominio.split('.')[ 1 ] == 'diariooficialdosmunicipios')?'ba':( dominio.split('.')[ 0 ] == 'www' )?dominio.split('.')[ 1 ]:dominio.split('.')[ 0 ];
 var tipo_site   		 = ( dominio.split('\/')[1] == 'prefeitura' || dominio.split('\/')[1] == 'camara')?'individual':'geral';
 var contador    		 = eval( Math.round(  new Date().getMinutes() ) );	
 var tipo_header 		 = ( contador % 2 == 0 )?'header_principal':'header_secundario';
 var header_path 		 = '/_modelos/' + subdominio + '/headers/' + tipo_site + '/' + tipo_header;
 var div  				 = document.createElement('div'); 
	 div.id 			 = 'hd_diario';
	 div.style.width	 = '127px';
	 div.style.height    = '109px';
	 div.style.position  = 'absolute';
	 div.style.top		 = '86px';
	 div.style.left		 = '0px';
	 div.style.zIndex    = '1';

	 document.body.appendChild( div );
	
	/* matando a animação flash da imagem do header!!!
   // se existir o SWF Object
   if( window.SWFObject ) {
	// criando os filme
	var  hd_diario = new SWFObject( header_path + '.swf' , "topo","770","117","8.0.23", "", true);
		 hd_diario.addParam("scale", "noscale");
		 hd_diario.addParam("quality", "high");
		 hd_diario.addParam("wmode", "transparent");
		 hd_diario.addParam("menu", "false");
		 hd_diario.addVariable("novar", ""); 
		 hd_diario.write("hd_diario"); 
   }
   
   // modifica o plano de fund oda tabela
   fnc_referencia_div('bg_diario').style.backgroundImage    = 'url( ' + header_path + '.jpg' + ')';
   */
}

function fnc_mostra_banner() {
  //não faz nada se não existir o banner
 if( !banner_altura && !banner_largura && !banner_arquivo ) return;

 var resolucao 			 = screen.width  + 'x' + screen.height;
 var div  				 = document.createElement('div'); 
     div.id 			 = 'banner_suspenso';
 	 div.style.width	 = banner_largura;
	 div.style.height    = banner_altura;
 	 div.style.position  = 'absolute';
 	 div.style.float	 = 'left';
	 div.style.top		 = ( resolucao == '800x600' || resolucao == '1024x768')?220:( resolucao == '1152x864' )?220:220;
/*	 div.style.top		 = ( resolucao == '800x600' || resolucao == '1024x768')?350:( resolucao == '1152x864' )?400:380;
*/ 	 div.style.zIndex    = '550';
	 document.body.appendChild( div );
 
 // se existir o SWFOBject, então mostra o banner
 if( window.SWFObject ) {
	var  banner_suspenso = new SWFObject( banner_arquivo , "topo", banner_largura , banner_altura ,"8.0.23", "", true);
		 banner_suspenso.addParam("scale", "noscale");
		 banner_suspenso.addParam("quality", "high");
		 banner_suspenso.addParam("wmode", "transparent");
		 banner_suspenso.addParam("menu", "false");
		 banner_suspenso.addVariable("novar", Math.floor(Math.random()*5) ); 
		 banner_suspenso.write("banner_suspenso");
  }
	
 // mostra o banner flutuante
 
}

function fnc_oculta_banner() {
 if( fnc_referencia_div('banner_suspenso') ) fnc_referencia_div('banner_suspenso').style.visibility = 'hidden';
}	

function fnc_escolhe_cidade( p_estado_id ) {
	
 with( document.form_contato ) {
   action 		   = '/_actions/act_selecionar_cidades.cfm';
   method 		   = 'post';
   target 		   = 'resultado';
   estado_id.value = p_estado_id;
   operacao.value  = 2;
  
    submit();	
 }
 
}

function fnc_acessar_site_entidade() {

 var root  = window.location.host;
 var win   = window.open( '' ,'_blank','');
 
 // se o bloqueador de popups estiver ativo
  if (!win) {
	alert("Bloqueador de pop-ups detectado! Por favor adicione perrmissão que as popups dejam abertas para esse site.!");
	return; 
  }

 with( document.form_painel_entidade ) {
	 
  var modalidade = ( parseInt( getRadioSelecionadoValor( modalidade_id )  ) ) == 1?'prefeitura':'camara';


  win.window.moveTo(0,0);
  
  // maximiza a tela 
  if( document.all ) {
	win.window.resizeTo( screen.availWidth, screen.availHeight );
  } else if ( document.layers||document.getElementById ) {
	if ( win.window.outerHeight < screen.availHeight || win.window.outerWidth < screen.availWidth ) {
		win.window.outerHeight = screen.availHeight;
		win.window.outerWidth = screen.availWidth;
	}
  }

 // redireciona para o site escolhido após 1 segundo
 if( win.location.href.length == 11 )
	 tempo =  setInterval( function() { clearInterval( tempo );  win.location.href = 'http://' + root + '/' +  modalidade + '/' +  municipio_id[ municipio_id.options.selectedIndex ].value + '/'; } , 500 );	 
 }
}


function fnc_enviar_mensagem_contato() {
 with( document.form_contato )
 {
   action 		     = '/_actions/act_form_contato.cfm';
   method 		     = 'post';
   target 		     = 'resultado';
   operacao.value    = 1;
   /*localizacao.value = estado_id[ estado_id.options.selectedIndex ].text + ' \\ ' + municipio_id[ municipio_id.options.selectedIndex ].text;*/

	if( fnc_verifica_form( document.form_contato ) ) 
	{
        enviar_contato.disabled = true;   
		submit();
		reset();
	}
 }
}


// ]]>
