function flash(src,w,h,string_values) {
    if(string_values==undefined)
        document.write('<object type="application/x-shockwave-flash" FlashVars="'+string_values+'" data="'+src+'" width="'+w+'" height="'+h+'" wmode="transparent"><param name="movie" value="'+src+'" /><param name="wmode" value="transparent" /></object>');
    else
        document.write('<object type="application/x-shockwave-flash" data="'+src+'" width="'+w+'" height="'+h+'" wmode="transparent"><param name="movie" value="'+src+'" /><param name="wmode" value="transparent" /><param name="FlashVars" value="'+string_values+'" /></object>');
}

$(document).ready(function() {

   $('.external').click(function() { window.open(this); return false; });

   // Formulários e Validadores
   $('#IntranetCPF').example("Seu CPF");
   $('#IntranetSenha').example("Senha");
   $('#BuscaRapidaPalavraChave').example("Senha");

    $("#FormularioIntranet").RSV({
        onCompleteHandler: function() { $("#FormularioIntranet").attr("lang","valido"); return false; },
        errorFieldClass: "FormErro",
        rules: [
          "required,login,CPF",
          "required,senha,Senha"
        ]
    });
    
    $("#FormularioIntranet").ajaxForm({
 		beforeSubmit: function(){ return ($("#FormularioIntranet").attr("lang")=="valido"); },
		success: function (responseText, statusText) { 
		   eval(responseText); 
		}
	});

    $(".ajaxform").ajaxForm({
		success: function (responseText, statusText) { 
		   eval(responseText); 
		}
	});	
	

    $("#FormularioBuscaRapida").RSV({
        onCompleteHandler: myOnComplete,
        errorFieldClass: "FormErro",
        rules: [
          "required,palavrachave,Palavra-Chave"
        ]
    });

    $('.jumpmenu').change(function () {
      if ($(this).val() == "") {
         return false;
      } else {
         window.open($(this).val(), "_self"); return false;
      }
   });

   $('.menu IMG').mouseover(function(){
      var caminho = $(this).attr('src');
      var caminhoNovo = caminho.replace('off','on');
      $(this).attr('src',caminhoNovo);
   });

   $('.menu IMG').mouseout(function(){
      var caminho = $(this).attr('src');
      var caminhoNovo = caminho.replace('on','off');
      $(this).attr('src',caminhoNovo);
   });
   
   $('.campo-calendario').calendar({
      autoPopUp: 'button',
      speed: 'fast',
      buttonImageOnly : true,
      buttonImage : 'images/ico-calendario.gif'
   });
   
   $('.campo-calendario').mask('99/99/9999', {placeholder:" "});

   $("#galeria").jCarouselLite({btnNext:".bt-proximo", btnPrev:".bt-anterior", visible:1, auto:3000});

   $('.conteudo-aba').hide();
   $('.conteudo-aba:first').show();
   $('.aba').click(function(){
      $('.conteudo-aba').hide();
      $('.listagem-abas2').children('li').removeAttr('class');
      $('.listagem-abas1').children('li').removeAttr('class');
      $(this).parent('li').attr('class', 'ativo');
      $('#conteudo-'+$(this).attr('id')).show();
   });


   $(".popup-padrao").click(function () {
      abrePopup($(this).attr("href"),1024,600,"popup");
      return false;
   });

});

function myOnComplete() { return true; }

function formataData(date, formato) {
   
   var day   = formataDiaMes(date.getDate().toString());
   var month = formataDiaMes((date.getMonth() + 1).toString());
   var year  = date.getFullYear();

   if (formato=="dmy") {
      return day +'/'+ month +'/'+ year;   
   } else {
      return year +'-'+ month +'-'+ day;
   }
}

function formataDiaMes(valor) {
   return valor.length==1 ? '0' + valor : valor;
}

function ultimoDiaMes(mes, ano) { 
   if (mes==2) {
       if  ((ano/4) == parseInt(ano/4)) {
          return 29; 
       } else {
          return 28; 
       }
   } else { 
      if (mes==1 || mes==3 || mes==5 || mes==7 || mes==8 || mes==10 || mes==12) {
          return 31;
      } else {
          return 30;
      }
   }
}

function abrePopup(url,largura,altura, nomePopup){
	w = screen.width;
	h = screen.height;
	meio_w = w/2;
	meio_h = h/2;
	altura2 = altura/2;
	largura2 = largura/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;
	window.open(url,nomePopup,'height=' + altura + ', width=' + largura + ',top='+meio1+', left='+meio2+',status=no,toolbar=no,menubar=no,location=no,scrollbars=yes');
}

function Arredonda( valor , casas ){
	
   var novo = Math.round( valor * Math.pow( 10 , casas ) ) / Math.pow( 10 , casas );

   return( novo );

}