function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function esqueciMinhaSenha()
{
  document.frmLogin.action = 'EsqueciMinhaSenhaRh.jsp';
  document.frmLogin.Login.value = 'E';
  document.frmLogin.submit();
}

function excluiBloco(p_bloco)
{
  document.frmConteudo.AcaoPersonaliza.value='B';
  document.frmConteudo.Bloco.value=p_bloco;
  document.frmConteudo.action='IndexRh.jsp';
  document.frmConteudo.submit();
}

function Votar()
{
    erro = 1;
    for (var i=0;i<document.frmPesquisa.Alternativa.length;i++)
       if (document.frmPesquisa.Alternativa[i].checked)
          erro = 0;             
              
    if (erro == 0){
      // vai();
       document.frmPesquisa.submit();
    } else {
       alert("Marque uma opção.");
    }
}

function stateChecker(pForm)
{   var checkedButton = ""
    for (var i=0;i<pForm.Alternativa.length;i++)
    {      if (pForm.Alternativa[i].checked=="1")
            {
               return pForm.Alternativa[i].value
            }
    }
    return ""
}

function alertMsg(p_msg)
{
  if ((p_msg != "") && (p_msg != "null"))
    alert("Login Erro: \n "+p_msg);
}

function redireciona(p_link, p_cate, p_menu, p_area )
{
  if (p_link.indexOf("/") != -1)
    p_link = p_link.substring(p_link.lastIndexOf("/")+1);

  //alert(p_link);  
  document.frmConteudo.CdCategoria.value=p_cate;
  document.frmConteudo.CdMenu.value=p_menu;
  document.frmConteudo.CdArea.value=p_area;
  document.frmConteudo.action=p_link;
  document.frmConteudo.submit();
}

function redirecionaCal(p_link, p_mes , p_datames , p_dia , p_mesano )
{
  document.frmConteudo.Mes.value=p_mes;
  document.frmConteudo.DataMes.value=p_datames;
  document.frmConteudo.Dia.value=p_dia;
  document.frmConteudo.MesAno.value=p_mesano;
  redireciona(p_link,document.frmConteudo.CdCategoria.value,document.frmConteudo.CdMenu.value,document.frmConteudo.CdArea.value);
  
}

ns4 = document.layers
ie4 = document.all 
nn6 = document.getElementById && !document.all 

function hideAviso() {
   if (ns4) {
      document.aviso.visibility = "hide";
   }
   else if (ie4) {
      document.all['aviso'].style.visibility = "hidden";
   }
   else if (nn6) {
      document.getElementById('aviso').style.visibility = "hidden";
   }
   else {
      document.getElementById('aviso').style.visibility = "hidden";
   }
}

// Show/Hide functions for pointer objects
function showAviso() {
   if (ns4) {
      document.aviso.visibility = "show";
      document.aviso.left =( screen.width-332)/2;
   }
   else if (ie4) {
      document.all['aviso'].style.visibility = "visible";
      document.all['aviso'].style.left =( screen.width-332)/2;
   }
   else if (nn6) {
      document.getElementById('aviso').style.visibility = "visible";
      document.getElementById('aviso').style.left =( screen.width-332)/2;
   }
   else {
      document.getElementById('aviso').style.visibility = "visible";
      document.getElementById('aviso').style.left =( screen.width-332)/2;
   }
}

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_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 MM_openBrWindow(theURL,winName,features) { //v2.0
  janelaNova=window.open(theURL,winName,features);
}
function abreJanela(caminho,janela,parametros){
	MM_openBrWindow(caminho,janela,parametros);
	janelaNova.focus();
}
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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function selecionarCSS(){
	estiloCerto=(document.getElementById)?'ie.css':((document.all)?'ie.css':'ns.css');
	document.write('<link rel="stylesheet" href="styles/'+estiloCerto+'" type="text/css">')
}

// Autor:          Desconhecido
// Modificado por: Robert W. Husted
// Empresa:        Netscape Communications

// Retona o número de dias no mes
function getDaysInMonth(month,year)  {
    var days;
    if (month==1 || month==3 || month==5 || month==7 || month==8 ||
        month==10 || month==12)  days=31;
    else if (month==4 || month==6 || month==9 || month==11) days=30;
    else if (month==2)  {
        if (isLeapYear(year)) {
            days=29;
        }
        else {
            days=28;
        }
    }
    return (days);
}

// Verifica se é ano bisexto
function isLeapYear (Year) {
    if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
        return (true);
    }
    else {
        return (false);
    }
}

// 
function intMask() {
    var i = window.event.keyCode;
    var bOK = false;
    if ( i == 9 ||                  // TAB key
            i == 8 ||               // Backspace key
            i == 36 ||              // Home key
            i == 35 ||              // End key
            i == 39 ||              // Right Arrow
            i == 37 ||              // Left Arrow
            i == 46 ||              // Delete Key
			i == 47 ||              // '/' Key
            (i >= 48 && i <= 57)    // Top row 0 to 9
            //(i >= 96 && i <= 105)   // Number pad 0 to 9
            ) {
        bOK = true; 
    }
    if (!bOK) {
        window.event.returnValue = false;
    }
  }

  function Numericos() {
    var i = window.event.keyCode;
    var bOK = false;
    if (i >= 48 && i <= 57){
        bOK = true; 
    }
    if (!bOK) {
        window.event.returnValue = false;
    }
  }

function FormataData(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = Campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			Campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			Campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}

///////////////////////////////////////////////////////////////////////////////////////////////
// Método ........: ValidaData(data,mascara,nome) ** DEPRECATED **  USE A FUNÇÃO dateValidation
// Funcionalidade.: Função para verificação de data.
//////////////////////////////////////////////////////////////////////////////////////////////

function ValidaDataN(data,mascara,nome) {
    // Esta função retorna true se a data está no formato (dd/mm/aaaa),
	var inDate = data;
	posFimAno = mascara.lastIndexOf('y');//se for 9 tem quatro dígitos
	//se for 7 tem dois dígitos
	posDia = mascara.indexOf('dd'); //se for 0 dia vem antes do mês

	limite = 0;
	if (posFimAno==6)
	limite=7;
	if (posFimAno==7)
	limite=8;
	if (posFimAno==9)
	limite=10;

	if ( (inDate.length != limite) && (inDate.indexOf("/") ) )
	{
    	alert(nome+": Formato incorreto");
        return false;
	}
	else
	{
        // Transforma valor de inData nas variáveis: inDay, inMonth, inYear
    	if (inDate.indexOf("/"))
	{

	if (posDia != -1){
	if (posDia == 0)
    	inDay = inDate.substring(0,inDate.indexOf("/"));
	else
    	inDay = inDate.substring(inDate.indexOf("/") + 1,inDate.lastIndexOf("/"));

	if (inDay.substring(0,1) == "0" && inDay.length > 1)
	inDay = inDay.substring(1,inDay.length);
	inDay = parseInt(inDay);


	if (posDia == 0)
    	inMonth = inDate.substring(inDate.indexOf("/") + 1, inDate.lastIndexOf("/"));
	else
        inMonth = inDate.substring(0,inDate.indexOf("/"));

	if (inMonth.substring(0,1) == "0" && inMonth.length > 1)
    	inMonth = inMonth.substring(1,inMonth.length);
    	inMonth = parseInt(inMonth);
	} else {
    	inMonth = inDate.substring(0,inDate.indexOf("/"));
    	inDay = 1;
	}

	//alert(''dia=''+inDay+'' mes=''+inMonth);
	var inYear = parseInt(inDate.substring(inDate.lastIndexOf("/") + 1, inDate.length));
	if (inYear == 0)
	{
	alert(nome+": Data inválida");
	return false;
	}
	// Verifica se os dados são numéricos
	//alert(isNaN (inDay+inMonth+inYear) + " " + inDay + inMonth + inYear);
	if (isNaN (inDay+inMonth+inYear))
	{
		  alert (nome+": Data inválida");
		  return false;
		 } else {
		  // Verifica se mês informado está entre 1 e 12
		  if ((inMonth < 1) || (inMonth > 12))
		  {
		  alert(nome+": Data inválida");
		  return false;
		  } else {

	if (posDia != -1){
	// Verifica se o Dia informado não é maior do que o número máximo de dias para o mês informado
		  if ( (getDaysInMonth(inMonth,inYear) < inDay) || (inDay < 1) )
		  {
	alert(nome+": Data inválida.");
			   return false;
		  }
	}
		  }
		 }
	} else {
	alert(nome+": Data inválida.");
	return false;
	}
	}
	return true;
}


///////////////////////////////////////////////////////////////////////////////////////////////
// Método ........: dateValidationEvent(element, event)
// Parâmetros ....: element - Indica o caractere do evento, event - event do JavaScript
// Funcionalidade.: Usado em conjunto com o evento onKeyPress não permite que o usuário 
// ...............: digite caracteres inválidos no campo data, essa função também acrescenta
// ...............: os caracteres "/" no devido lugar.
// Uso ...........: <input type="text" name="x" onKeyPress="return dateValidationEvent(this, event)">
//////////////////////////////////////////////////////////////////////////////////////////////

function dateValidationEvent(element, Event){
    var tecla = Event.keyCode;
	
    var BACKSPACE = 8;
    if (tecla != BACKSPACE){
    	if (element.value.length == 2)
            element.value = element.value+"/"
    	else if(element.value.length == 5)
   		   	element.value = element.value+"/"
	}
	if (tecla < 48 || tecla > 57){
		return false;
	}else{
		return true
	}
}

function Letra(){
	var Tecla = window.event.keyCode;
	event.cancelBubble = true;
	//alert(Tecla);
	if((Tecla > 47 && Tecla < 91) || (Tecla > 95 && Tecla < 122) || (Tecla >191 && Tecla < 246) || (Tecla == 32))
		event.returnValue 
	else
	event.returnValue = false; 
}

//
function ValidaPeriodoMarc(dataIni,dataFim) {
   var anoIni  = parseInt(dataIni.substring(dataIni.lastIndexOf("/") + 1));
   var anoFim  = parseInt(dataFim.substring(dataFim.lastIndexOf("/") + 1));

   var mesIni  = dataIni.substring(0, dataIni.indexOf("/"));
   var mesFim  = dataFim.substring(0, dataFim.indexOf("/"));
   
   var diaIni  = dataIni.substr(0,2);
   var diaFim  = dataFim.substr(0,2);
   

   if((dataIni != "") && (dataFim != ""))
   {
	 if (anoIni <= anoFim) {
		  if ((anoIni == anoFim && mesIni <= mesFim && diaIni <= diaFim) ||
			  (anoIni < anoFim))
		  {
			msg = "";
			return msg;
		  }
		  else  if ((anoIni == anoFim && mesIni <= mesFim && diaIni >= diaFim) ||
			  (anoIni < anoFim) && (mesIni < mesFim))
		  {
			msg = "";
			return msg;
		  }
		  else {
			//window.alert("' || w_label_valida_periodo || '");
			msg = "<%=sArrayTraducao[27] %>";
			return msg;
		  }
		}
		//window.alert("' || w_label_valida_periodo || '");
		msg = "<%=sArrayTraducao[27] %>";
		return msg;
	}
	else
	{
		msg = "";
		return msg;
	}
}

function Letra(){
	var Tecla = window.event.keyCode;
	event.cancelBubble = true;
	//alert(Tecla);
	if((Tecla > 47 && Tecla < 91) || (Tecla > 95 && Tecla < 122) || (Tecla >191 && Tecla < 246) || (Tecla == 32))
		event.returnValue 
	else
	event.returnValue = false; 
}

		function ValidaPeriodoMM(dataIni,dataFim) {
           var anoIni  = parseInt(dataIni.substring(dataIni.lastIndexOf("/") + 1));
           var anoFim  = parseInt(dataFim.substring(dataFim.lastIndexOf("/") + 1));
  
           var mesIni  = dataIni.substring(0, dataIni.indexOf("/"));
           var mesFim  = dataFim.substring(0, dataFim.indexOf("/"));
           
           var diaIni  = dataIni.substr(0,2);
           var diaFim  = dataFim.substr(0,2);
           

           if((dataIni != "") && (dataFim != ""))
           {
             if (anoIni <= anoFim) {
                  if ((mesIni <= mesFim && diaIni <= diaFim) ||
                      (anoIni < anoFim))
                  {
					msg = "";
                    return msg;
                  }
                  else  if ((mesIni <= mesFim && diaIni >= diaFim))
                  {
                    msg = "";
                    return msg;
                  }
                  else {
                    //window.alert("' || w_label_valida_periodo || '");
                    msg = "Data Inicial maior do que data final";
                    return msg;
                  }
                }
                //window.alert("' || w_label_valida_periodo || '");
                msg = "Data Inicial maior do que data final";
                return msg;
            }
            else
            {
                msg = "";
                return msg;
            }
        }
selecionarCSS();
