function MostrarAbas(num){
    if (document.getElementById)    {	    
        document.getElementById('aba1').style.display = 'none';
        document.getElementById('aba2').style.display = 'none';
		document.getElementById('aba3').style.display = 'none';
        document.getElementById('pesquisa').style.display = 'none';
		document.getElementById('pesquisaTexto').style.display = 'none';
		document.getElementById('pesquisaAssunto').style.display = 'none';	
		document.getElementById('resultados').style.display = 'none';
		document.getElementById('radioItensAssunto').style.display = 'none';
		document.getElementById('erro').style.display = 'none';	
		

		if (num == 'assunto') { 
		    document.getElementById('aba1').style.display = 'block';
			document.getElementById('pesquisa').style.display = 'block';
			document.getElementById('pesquisaAssunto').style.display = 'block';
			document.getElementById('radioItensAssunto').style.display = 'block';
			document.getElementById('tipoAba').value = 'assunto';
         } else if(num == 'texto') {
		    document.getElementById('aba2').style.display = 'block';
			document.getElementById('pesquisa').style.display = 'block';
			document.getElementById('pesquisaTexto').style.display = 'block';
			document.getElementById('tipoAba').value = 'texto';
		} else if (num == 'exata') { 
		    document.getElementById('aba3').style.display = 'block';
			document.getElementById('pesquisa').style.display = 'block';
			document.getElementById('tipoAba').value = 'exata';	
		}
    } else {
        alert('Este site requer IE6 ou Firefox');
    }
}

function preencheFontes()
{
		var s = dwr.util.getValue("codFonteCategoria");
		Ajax.obtemListaFontesPorCategoria(s,function(data) {
			var t = eval(data);
			dwr.util.removeAllOptions(document.forms[0].codFontes);
			dwr.util.addOptions(document.forms[0].codFontes,t,"codFonte", "nmeFonte");
			dwr.util.setValue("codFontes",s);			
		  });	
}

function preencheArvore()
{
	var s = dwr.util.getValue("codFonteCategoria");

	if (s=='0')
	{
        document.getElementById('arvore1').style.display = 'block';
        document.getElementById('arvore2').style.display = 'none';
		document.getElementById('arvore3').style.display = 'none';
		dwr.util.setValue("statusArvore1",'block');
		dwr.util.setValue("statusArvore2",'none');
		dwr.util.setValue("statusArvore3",'none');
	}
	if (s=='2')
	{
        document.getElementById('arvore1').style.display = 'none';
        document.getElementById('arvore2').style.display = 'block';
		document.getElementById('arvore3').style.display = 'none';
		dwr.util.setValue("statusArvore1",'none');
		dwr.util.setValue("statusArvore2",'block');
		dwr.util.setValue("statusArvore3",'none');
	}
	if ((s=='1')||(s=='3')||(s=='4'))
	{
        document.getElementById('arvore1').style.display = 'none';
        document.getElementById('arvore2').style.display = 'none';
		document.getElementById('arvore3').style.display = 'block';
		dwr.util.setValue("statusArvore1",'none');
		dwr.util.setValue("statusArvore2",'none');
		dwr.util.setValue("statusArvore3",'block');
	}
	
	for (i=0;i<document.forms[0].radioDominio.length;i++) {
		if (document.forms[0].radioDominio[i].checked == true) {
			document.forms[0].radioDominio[i].checked = false;
		}
	}

}



function limparCampos()
{
	for (i=0;i<document.forms[0].radioPeriodo.length;i++) {
		var radioPeriodo = document.forms[0].radioPeriodo[i].value;
		if (radioPeriodo == 'selecao') {
			document.forms[0].radioPeriodo[i].checked = true;
		}
	}
	for (i=0;i<document.forms[0].radClassificacao.length;i++) {
		var radioClassificacao = document.forms[0].radClassificacao[i].value;
		if (radioClassificacao == '3') {
			document.forms[0].radClassificacao[i].checked = true;
		}
	}

	for (i=0;i<document.forms[0].radioDominio.length;i++) {
		if (document.forms[0].radioDominio[i].checked == true) {
			document.forms[0].radioDominio[i].checked = false;
		}
	}

	document.forms[0].txtAnalise.value='';
	document.forms[0].bolTipoAnalise.checked = false;
	document.forms[0].codFonteCategoria.value=2;
	document.forms[0].periodoA.value='todo o periodo';
	if (document.getElementById('tipoAba').value == 'texto')	
		document.forms[0].txtAnalise.focus();
	preencheFontes();
	preencheArvore();
}


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_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

//-------UTILITARIOS \\

// script para n?o deixar fazer back...
//if(window.history.forward(1) != null)
   //window.history.forward(1);

/**
 * script que impede que outros sites insiram o sistema em frames
 */
if(top.frames.length!=0) {
	top.location=self.document.location;
}

function PopUpCentralizado(mypage, myname, w, h, scroll) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height=' + h + ', width = ' + w + ', top = ' + wint + ', left = ' + winl + ', scrollbars = ' + scroll + ', location=no, status=no';
    win = window.open(mypage, myname, winprops);
    if (parseInt(navigator.appVersion) >= 4) { 
        win.window.focus(); 
    }    
}
      
function checkboxCmpCheckedForm(cmp, booCheck) { 
   if(typeof(cmp.length) == 'undefined')
      cmp.checked = booCheck;
   else   
      for (i=0; i<cmp.length; i++) 
        if (!booCheck) 
          cmp[i].checked = false; 
        else
          cmp[i].checked = true; 
}

/*
 * Voltar para a pagina desejada, fazendo controle de popUp, fechando o mesmo.
 * @param pagina -> pagina em que se deseja voltar
 */
function voltarPop(pagina) { 
   var nmePag = pagina;
   if(opener == null) { // 1? nivel
      document.location.href = nmePag;
   } else {
	if(opener.opener == null) { // 2? nivel
      		opener.document.location.href = nmePag;
   	} else { // 3? nivel
      		opener.opener.document.location.href = nmePag;
      		opener.close();
   	}
	window.close();
   }
}


/*
 * Tira os espa?os antes e depois da string
 * @param inputString
 * @param trimLeft
 * @param trimRight
 */
function trim(inputString,trimLeft,trimRight) { 
  outputString = ''; 
  espacosAntes = 0; 
  espacosDepois = 0; 
  if (trimLeft) { 
    for (i = 0 ; i < inputString.length ; i++) { 
      if  (inputString.charAt(i) == ' ') { 
  		 espacosAntes++; 
      } else { 
  	     break; 
  	  } 
   	} 
  } 
  if (trimRight) { 
    for (i = inputString.length-1 ; i>0 ; i--) { 
   	  if (inputString.charAt(i) == ' ') { 
   		 espacosDepois++; 
      } else { 
         break; 
      } 
    } 
  } 
  outputString = inputString.substr(espacosAntes); 
  outputString = outputString.substr(0,(outputString.length-espacosDepois)); 
  return outputString; 
}


function mascara_data(field, e) { 
        var key;
        if (window.event)
             key = window.event.keyCode;
        else if (e)
             key = e.which;
        else
             return true;

        var ctrlKeyEvent = (key!=8 && key!=9 && key!=37 && key!=39);
        
    if(ctrlKeyEvent && ((key > 47 && key < 58) || (key > 95 && key < 106))) {
       var dt = trim(field.value); 
       var mydata = dt;
       if (mydata.length == 2) {
         mydata = mydata + '/';
         field.value = mydata;
       }
       if (mydata.length == 5) {
         mydata = mydata + '/';
         field.value = mydata;
       }
	 if (dt.length == 10) {
         var mDay = field.value.substr(0,2);
         var mMonth = field.value.substr(3,2);
         var mYear = field.value.substr(6,4)
         field.value = mDay + '/' + mMonth + '/' + mYear;
       }
    } 
  }
  
function mascara_hora(field,e) {

   var key;
   if (window.event)
   		key = window.event.keyCode;
   else if (e)
        key = e.which;
   else
        return true;

   var ctrlKeyEvent = (key!=8 && key!=9 && key!=37 && key!=39);       
   if(ctrlKeyEvent && ((key > 47 && key < 58) || (key > 95 && key < 106))) {

       var hr = trim(field.value); 
       var myhour = hr;
       if (myhour.length == 2) {
         myhour = myhour + ':';
         field.value = myhour;
       }
       if (myhour.length == 5) {
         myhour = myhour + ':';
         field.value = myhour;
       }
    } 
 
}  


//-------UTILITARIOS EDITOR----\\
/**
 * script que impede que outros sites insiram o sistema em frames
 */
if(top.frames.length!=0){
	top.location=self.document.location;
}

/*
 * discheckedRadioForm, desabilita o componente radio do formulario.
 * @param oForm
 */
function discheckedRadioForm(oForm) {
   for (var i=0; i<oForm.elements.length; i++) {
      var objElemet = oForm.elements[i];
      if(objElemet.type == 'radio' && objElemet.checked)   
         objElemet.checked = false;
   }
}

/*
 * discheckedCmpRadioForm, desabilita o componente radio de um campo do formulario.
 * @param oForm
 */
function discheckedCmpRadioForm(cmp) {
   if(typeof(cmp.length) == 'undefined')
      cmp.checked = false;
   else   
      for (i=0; i<cmp.length; i++) 
        if (cmp[i].checked) 
          cmp[i].checked = false; 
}

/*
 * checkboxCmpCheckedForm, o booCheck controla a checagem.
 * @param oForm
 */
function checkboxCmpCheckedForm(cmp, booCheck) { 
   if(typeof(cmp.length) == 'undefined')
      cmp.checked = booCheck;
   else   
      for (i=0; i<cmp.length; i++) 
        if (!booCheck) 
          cmp[i].checked = false; 
        else
          cmp[i].checked = true; 
}

/*
 * addClassTag, adiciona class no tag.
 * @param tag objeto
 * @param strClassName nome da classe a ser atribuida ao objeto.
 */
function addClassTag(tag, strClassName){
   tag.className = strClassName;
}

function mOvr(src,clrOver) {
	    src.style.cursor = 'hand';
		src.style.background = clrOver;
}
function mOut(src,clrIn) {
    	src.style.cursor = 'default';
        src.style.background = clrIn;
}

