// JavaScript Document
function fcn_acessa_aplicacao( p_cod_projeto, p_cod_aplicacao )
{
 with( document.form_aplicacao )
 {
   cod_projeto.value   = p_cod_projeto;
   cod_aplicacao.value = p_cod_aplicacao;
	
   action  		= 'aplicacoes/' + cod_aplicacao.value.toLowerCase() + '/index.cfm';
   method 	    = 'post';
   
	submit();
  
 }
}

/**
 * @descritivo	: fnc_preview_pdf
 * @parametro	: p_arquivo : String ( Requerido )
 * @retorno		: void
 * @autor       : Jefferson Petilo ( jefferson@netdom.com.br )
 * @versão		: 1, 29 de Dezembro de  2004
*/					

function fnc_preview_pdf( p_arquivo )
{
  w = window.open( 'about:blank' ,'_blank','toolbar=0, location=0,directories=0,menuBar=0,status=0');
  w.window.moveTo(0,0);
  
  if( document.all )
  {
    w.window.resizeTo( screen.availWidth, screen.availHeight );
  } else if ( document.layers||document.getElementById ) {
	if ( w.window.outerHeight < screen.availHeight || w.window.outerWidth < screen.availWidth )
    {
		w.window.outerHeight = screen.availHeight;
		w.window.outerWidth = screen.availWidth;
     }
  }

 if( w.location.href.length == 11 )
   tempo =  setInterval( function() { clearInterval( tempo );  w.location.href = p_arquivo; } , 1000 );
}


/**
 * @objetivo	: Consulta a prefeitura ou câmara
 * @parametro	: Sem parâmetros
 * @retorno		: void
 * @autor      	: Jefferson Petilo( jefferson@netdom.com.br) 
 * @versão		: 2, 13 de Dezembro de  2004
 */					
function fnc_consulta_entidade( p_operacao )
{
 var form = document.getElementById('form');

    
	 form.method	     = 'post';
     form.action 	     = '/_config/aplicacoes/consultas.cfm';
     form.target	     = 'resultado';
     form.operacao.value = p_operacao;	
   
       if( getCurrentPage() == 'publicacao_dados.cfm') form.submit();
     else 
		if( fnc_verifica_form( form ) ) form.submit();
}
/**
 * @descritivo	: Limpa Formulário
 * @parametro	: sem parâmetros
 * @retorno		: void
 * @autor       : Jefferson Petilo( jefferson@kmm.com.br ) 
 * @versão		: 1, 10  de Novembro de 2003
 */					
function fnc_limpa_formulario()
{
 var form    = document.getElementById('form');
 var cookies = 'editor,palavra_chave,data_inicio,data_fim,publicacao_tipo_id,modalidade_id,municipio_id';
 var vars 	 = cookies.split(','); 
	
 for ( var i = 0; i <= vars.length; i++ ) if( getCookie(  vars[ i ] ) ) setCookie( vars[ i ] , '' );  
   
 form.reset();
 
}	

/**
 * @objetivo	: Remove linha na tbody
 * @parametro	: p_cod_elemento  : string ( Requerido )
 				  p_idx			  : string ( Requerido )
				  p_count		  : string ( Requerido )
				  p_linha		  : string ( Requerido )
 * @retorno		: void
 * @autor      	: Jefferson Petilo( jefferson@netdom.com.br) 
 * @versão		: 2, 07 de Dezembro de  2004
 */					
function fnc_remove_entidade( p_cod_elemento, p_idx , p_count, p_linha )
{
  corpo   =  document.getElementById( p_cod_elemento ).getElementsByTagName('TBODY')[ 0 ];
  linha   = document.getElementById( p_linha ).rowIndex;		

    corpo.deleteRow( linha );
	v_entidades[ p_count ] = null ;
		
	fnc_cor_tablesort( p_cod_elemento ); 	// alterna linhas da tabela 

}						


/**
 * @objetivo	: Remove todas as linhas da tabela dinâmica.
 * @parametro	: p_cod_elemento   : string. ( Requerido )
 * @retorno		: void
 * @autor       : Jefferson Petilo( jefferson@netdom.com.br) 
 * @versão		: 2, 18  de Fevereiro 2004
 */					
function f_deleta_linhas( p_cod_elemento )
{
  corpo =  document.getElementById( p_cod_elemento ).getElementsByTagName('TBODY')[ 0 ];

	while ( corpo.rows.length > 2 ) { corpo.deleteRow( 2 );	}
    for( i=0; i < v_entidades.length ; i++) v_entidades[ i ] = null;
}

/**
 * @objetivo	: Consulta itens publicados
 * @parametro	: Sem parâmetros
 * @retorno		: void
 * @autor      	: Jefferson Petilo( jefferson@netdom.com.br) 
 * @versão		: 2, 13 de Dezembro de  2004
 */					
function fnc_consulta_publicacao()
{
 var form = document.getElementById('form');
	 form.method	     = 'post';
     form.action 	     = '';
     form.target	     = '_self';
     form.operacao.value = 1;	

   if( ( !form.editor  ) ||  ( form.editor.value || form.palavra_chave.value || form.municipio_id.value ) )
   {
       form.data_inicio.obrigatorio = 0;
       form.data_fim.obrigatorio    = 0;

   } else {

       form.data_inicio.obrigatorio = 1;
       form.data_fim.obrigatorio    = 1;

   }

  for( var i = 0 ; i < form.length; i++ )
  {
    switch( form.elements[ i ].type )
    {
	 case 'select-one':
	 case 'text':
			 setCookie( form.elements[ i ].name , form.elements[ i ].value );
	 break;
	 case 'radio' :
			 setCookie( form.elements[ i ].name , getRadioSelecionadoValor( form.elements[ i ] ) );
	 break;
	 case 'checkbox' :
			 setCookie( form.elements[ i ].name , form.elements[ i ].value );
     break;
    }
  }

	if( fnc_verifica_form(  form ) ) 
        form.submit();
}

/**
 * @objetivo	: Consulta itens publicados
 * @parametro	: Sem parâmetros
 * @retorno		: void
 * @autor      	: Jefferson Petilo( jefferson@netdom.com.br) 
 * @versão		: 2, 13 de Dezembro de  2004
 */					
function fnc_exportar_excel()
{
 var form = document.getElementById('form');
	 form.method	     = 'post';
     form.action 	     = 'publicacao_gerar_excel.cfm';
     form.target	     = '_excel';
     form.operacao.value = 1;	

   if( ( !form.editor  ) ||  ( form.editor.value || form.palavra_chave.value || form.municipio_id.value ) )
   {
       form.data_inicio.obrigatorio = 0;
       form.data_fim.obrigatorio    = 0;

   } else {

       form.data_inicio.obrigatorio = 1;
       form.data_fim.obrigatorio    = 1;

   }

  for( var i = 0 ; i < form.length; i++ )
  {
    switch( form.elements[ i ].type )
    {
	 case 'select-one':
	 case 'text':
			 setCookie( form.elements[ i ].name , form.elements[ i ].value );
	 break;
	 case 'radio' :
			 setCookie( form.elements[ i ].name , getRadioSelecionadoValor( form.elements[ i ] ) );
	 break;
	 case 'checkbox' :
			 setCookie( form.elements[ i ].name , form.elements[ i ].value );
     break;
    }

 }
  
	if( fnc_verifica_form(  form ) ) 
    {
	  w = window.open( '' , form.target ,'toolbar=0, location=0,directories=0,menuBar=0,status=0');
	  w.window.moveTo(0,0);
  
	  if( document.all )
	  {
		w.window.resizeTo( screen.availWidth, screen.availHeight );
	  } else if ( document.layers||document.getElementById ) {
		if ( w.window.outerHeight < screen.availHeight || w.window.outerWidth < screen.availWidth )
		{
			w.window.outerHeight = screen.availHeight;
			w.window.outerWidth = screen.availWidth;
		 }
	  }

	 if( w.location.href.length == 11 )
	   tempo =  setInterval( function() { clearInterval( tempo );  w.location.href = form.action; form.submit(); } , 1000 );
       
   }
}

/**
 * @objetivo	: Modificar painel em tempo de execuçaõ de acordo com o tipo da publicação( Geral | Individual )
 * @parametro	: p_publicacao_tipo_id : numérico ( Requerido )
 * @retorno		: void
 * @autor       : Jefferson Petilo ( jefferson@netdom.com.br )
 * @versão		: 1, 10 de Fevereiro de  2005
 */					
function fnc_mostrar_painel_entidade_publica( )
{
  if( document.getElementById('publicacao_tipo_id').type == 'checkbox' && document.getElementById('publicacao_tipo_id').checked )
  {
	  
	  document.getElementById('cabecalho_entidade_publica').style.display = '';
	  document.getElementById('corpo_entidade_publica').style.display     = '';
	  document.getElementById('rodape_entidade_publica').style.display    = ''; 
	  document.getElementById('espaco_entidade_publica').style.display    = '';
	  
   } else {
	   
      document.getElementById('municipio_id').options[ 0 ].selected       = true;
	  document.getElementById('espaco_entidade_publica').style.display    = 'none';
	  document.getElementById('rodape_entidade_publica').style.display    = 'none'; 
	  document.getElementById('corpo_entidade_publica').style.display     = 'none';
	  document.getElementById('cabecalho_entidade_publica').style.display = 'none';
  }
}
/**
 * @objetivo	: Visualiza documento do Word no browser
 * @parametro	: p_arquivo : string ( Requerido )
 * @retorno		: void
 * @autor       : Jefferson Petilo ( jefferson@netdom.com.br )
 * @versão		: 1, 23 de Agosto de  2005
 */		
function fnc_visualiza_word( p_arquivo )
{
  var largura  = eval( screen.width  * 0.75 );
  var altura   = eval( screen.height * 0.85 )
  var esquerda = ( screen.width  ) ? ( screen.width  - parseInt( largura )  ) / 2 : 0;
  var topo	   = ( screen.height ) ? ( screen.height - parseInt( altura )   ) / 2 : 0; 
  
  win 	       = window.open( '', 'word' ,'height='+ altura +', width='+ largura +', left='+ esquerda + ', top=' + topo + ', toolbar=0, location=0,directories=0,status=0,menuBar=1,scrollBars=1,resizable=1');

   if( win.location.href.length == 11 )
       tempo   =  setInterval( function() { clearInterval( tempo );  win.location.href = p_arquivo; } , 1000 );
   
  win.focus(); 
}


function fnc_publicar_jornal(){
	
	
	var tal = form.arquivo.value;
	var tal2 = tal.substring(tal.length-3, tal.length);
	if (!(tal2 == 'pdf' || tal2 == 'PDF')){
		alert('Requerido arquivo no formato PDF no campo > Arquivo <');
		return false;
	}

	var tal = form.thumbnail.value;
	var tal2 = tal.substring(tal.length-3, tal.length);
	if (!(tal2 == 'jpg' || tal2 == 'JPG')){
		alert('Requerido arquivo no formato JPG no campo > Miniatura <');
		return false;
	}

	document.form_publicar_capa.submit();
}


function fnc_publicar_capa(){
	
	
	var tal = form.arquivo.value;
	var tal2 = tal.substring(tal.length-3, tal.length);
	if (!(tal2 == 'pdf' || tal2 == 'PDF')){
		alert('Requerido arquivo no formato PDF no campo > Capa <');
		return false;
	}

	var tal = form.thumbnail.value;
	var tal2 = tal.substring(tal.length-3, tal.length);
	if (!(tal2 == 'jpg' || tal2 == 'JPG')){
		alert('Requerido arquivo no formato JPG no campo > Miniatura do Arquivo <');
		return false;
	}

	document.form_publicar_capa.submit();
}

function fnc_limpar_capa(){
	document.form_publicar_capa.reset();
}


function fnc_criar_site(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form(  form ) ) {
			return;
		}
		
		if(!validaCNPJ()){
			return;	
		}
		
		limpaCEP(document.getElementById('cep').value)
		
		

		form.acao.value = "gravar"
		form.submit();

}

function fnc_grava_edital(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form( form ) ) {
			return;
		}
		
/*
		if(form.data.value == ''){
			alert('Formato de Data incorreto!'); 
			form.data.focus();
			return( false ); 			
		}
*/
		if (!ehHoraValida(form.credenciamento)){form.credenciamento.focus(); return false;}
		if (!ehHoraValida(form.inicio_sessao)){form.inicio_sessao.focus(); return false;}
		
		var tal = form.arquivo.value;
		var tal2 = tal.substring(tal.length-3, tal.length);
		if (!(tal2 == 'pdf' || tal2 == 'PDF')){
			alert('Requerido arquivo no formato PDF no campo > Arquivo <');
			form.arquivo.focus();
			return( false ); 			
		}		
		
		form.acao.value = "gravar"
		//alert('vai');
		form.submit();

}


function fnc_grava_licitacao(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form( form ) ) {
			return;
		}
		
		var tal = document.getElementById('arquivo').value;
		if ( tal != '' ){
			var tal2 = tal.substring(tal.length-3, tal.length);
			if (!( tal2 == 'pdf' || tal2 == 'PDF')){
			   alert('Requerido arquivo no formato PDF no campo > Arquivo <');
			   document.getElementById('arquivo').focus();
			   return( false );    
			} 
		}
		
		
		form.acao.value = "gravar"
		//alert('vai');
		form.submit();

}

function fnc_grava_ao(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form( form ) ) {
			return;
		}
		
		form.acao.value = "gravar"
		//alert('vai');
		form.submit();

}

function fnc_edita_ao(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form( form ) ) {
			return;
		}
		
		form.acao.value = "editar"
		//alert('vai');
		form.submit();

}


function fnc_edita_licitacao(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form( form ) ) {
			return;
		}
		
		form.acao.value = "editar"
		//alert('vai');
		form.submit();

}


function fnc_atualiza_edital(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form( form ) ) {
			return;
		}
		
/*
		if(form.data.value == ''){
			alert('Formato de Data incorreto!'); 
			form.data.focus();
			return( false ); 			
		}
*/
		if (!ehHoraValida(form.credenciamento)){form.credenciamento.focus(); return false;}
		if (!ehHoraValida(form.inicio_sessao)){form.inicio_sessao.focus(); return false;}
		
		var tal = form.arquivo.value;
		if ( tal != ''){
			var tal2 = tal.substring(tal.length-3, tal.length);
			if (!(tal2 == 'pdf' || tal2 == 'PDF')){
				alert('Requerido arquivo no formato PDF no campo > Arquivo <');
				form.arquivo.focus();
				return( false ); 			
			}		
		}
		
		
		form.acao.value = "gravar"
		//alert('vai');
		form.submit();

}

function fnc_listar_licitacoes(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form( form ) ) {
			return;
		}
		

//		if (!ehHoraValida(form.credenciamento)){form.credenciamento.focus(); return false;}
//		if (!ehHoraValida(form.inicio_sessao)){form.inicio_sessao.focus(); return false;}

/*
		var tal = form.arquivo.value;
		var tal2 = tal.substring(tal.length-3, tal.length);
		if (!(tal2 == 'pdf' || tal2 == 'PDF')){
			alert('Requerido arquivo no formato PDF no campo > Arquivo <');
			form.arquivo.focus();
			return( false ); 			
		}		
*/		
		form.acao.value = "buscar"
		form.action = "iframe_listar_licitacoes.cfm";
		//alert('vai');
		form.submit();
		form.action = "";
}

function fnc_listar_ao(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form( form ) ) {
			return;
		}
		
		form.acao.value = "buscar"
		form.action = "iframe_listar_ao.cfm";
		form.submit();
		form.action = "";
}

function fnc_listar_cp(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form( form ) ) {
			return;
		}
		
		form.acao.value = "buscar"
		form.action = "iframe_listar_cp.cfm";
		form.submit();
		form.action = "";
}

function fnc_listar_igf(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form( form ) ) {
			return;
		}
		
		form.acao.value = "buscar"
		form.action = "iframe_listar_igf.cfm";
		form.submit();
		form.action = "";
}


function fnc_listar_editais(){

		var form = document.getElementById('form');
		if( !fnc_verifica_form( form ) ) {
			return;
		}
		

//		if (!ehHoraValida(form.credenciamento)){form.credenciamento.focus(); return false;}
//		if (!ehHoraValida(form.inicio_sessao)){form.inicio_sessao.focus(); return false;}

/*
		var tal = form.arquivo.value;
		var tal2 = tal.substring(tal.length-3, tal.length);
		if (!(tal2 == 'pdf' || tal2 == 'PDF')){
			alert('Requerido arquivo no formato PDF no campo > Arquivo <');
			form.arquivo.focus();
			return( false ); 			
		}		
*/		
		form.acao.value = "buscar"
		form.action = "iframe_listar_editais.cfm";
		//alert('vai');
		form.submit();
		form.action = "";
}




function limpaCEP(CEP){
		CEP = CEP.replace(".","");
		CEP = CEP.replace("-","");
		document.getElementById('cep').value = CEP;
}	

function limpamunicipios(){
	document.getElementById("regiao_id").value = 0;
	selectElemRef = document.getElementById('municipio_id');	
	while (selectElemRef.length> 0) {
		selectElemRef.remove(0);
	} 
	var newElem		= document.createElement("option");
	newElem.text	= "Selecione o Estado";
	newElem.value	= "";
	document.getElementById('municipio_id').add(newElem);	
}

function fnc_limpar_site(){
	var form = document.getElementById('form')
	limpamunicipios()
	form.reset();

}

