/* ******************************************* 
Highlighter de elementos
(ese gran desconocido)
******************************************* */

var arrayElementos = [];

function annadirElemento(valor)
{
    arrayElementos[arrayElementos.size()] = valor;
}

function generateArrayExpReg()
{
    var arrayExpReg = [];
    for(i=0;i<arrayElementos.size();i++)
    {
       expstring = "";
       aux = arrayElementos[i];
       arrayaux = aux.split(" ");
            
       for (j = 0;j<arrayaux.size();j++)
       {
          if(j==0) expstring += '(>[^<]*[^\\w<]|>)(';
          else    expstring += '(?:(?:<[^<]+>)*)\\s(?:(?:<[^<]+>)*)'; 			
          var aux_cadena = arrayaux[j];	         
          aux_cadena = aux_cadena.replace("\.","\\.");  
          aux_cadena = aux_cadena.replace(")","\\)"); 
          aux_cadena = aux_cadena.replace("(","\\("); 
          exp_reg = new RegExp("\\?",'ig');
          aux_cadena = aux_cadena.replace(exp_reg,"\\?"); 
          expstring += aux_cadena;			
          if (j == (arrayaux.size() -1)) expstring += ')([^\\w])';			
       }                 
       exp_reg = new RegExp(expstring,'ig');
       arrayExpReg[arrayExpReg.size()] = exp_reg;     
    }       
    return arrayExpReg;
}

function highlightText(id_capa)
{
    objetos = $$(id_capa)
    var arrayExpReg = [];
    arrayExpReg = generateArrayExpReg();
            
    objetos.each(function(nodo)
    {       
        cadena = nodo.innerHTML;
        for(i=0;i<arrayExpReg.size();i++)
        {                  
                            exp_reg = arrayExpReg[i];
                            cadena = cadena.replace(exp_reg, "$1<b>$2</b>$3");                         
        }
                        
        nodo.innerHTML = cadena;
                        
     });

     $$('#listAuthors').each( function(nodo)
     {
       cadena = nodo.innerHTML;
       for(i=0;i<arrayExpReg.size();i++)
       {                  
            exp_reg = arrayExpReg[i]; 
            cadena = cadena.replace(exp_reg, "$1<b>$2</b>$3"); 
        }
        nodo.innerHTML = cadena;
                            
     });
  }
                    
                    
                    
function unhighlightBioentity(biot,clase){

    var currentElement = $$('span.bioentity[biotype^='+ biot +'|]').each( function(node) {                    
        var newClass = clase; //node.readAttribute('biotype').split('|')[0];        
        var currentID =node.readAttribute('bioid').split('|')[0];
        var bio = node.readAttribute('class')
        node.removeClassName( newClass );                       
        node.style.fontWeight = '';

        node.style.cursor = 'default';
        node.stopObserving('click');
        node.stopObserving('mouseover');
        node.stopObserving('mouseout');

    });           

}

function underLineEntity(node)
{    
    node = $(node);
    
     if(node.up('a') != null)
     {

           deUnderLine(node.up('a'), node);
     }
     else
     {

           node.style.textDecoration = 'underline';     
     }

}

function deUnderLineEntity(node)
{
     node = $(node);
     if(node.up('a') != null)
        underLine(node.up('a'),node);
     else
        node.style.textDecoration = 'none';

}

function highlightBioentity(biot,corpus,clase,criterion,showType){

    var currentElement = $$('span.bioentity[biotype^='+ biot +'|]').each( function(node) {                    
        var newClass = clase; //node.readAttribute('biotype').split('|')[0];
        var currentID =node.readAttribute('bioid').split('|')[0];
        var bio = node.readAttribute('class')
        node.addClassName( newClass );                       
        node.style.fontWeight = 'bold';
        node.style.textDecoration = 'none';
        node.style.cursor = 'pointer';
        //node.observe('mouseover', function(){node.style.textDecoration = 'underline';return false;});                                        
        //node.observe('mouseout', function(){node.style.textDecoration = 'none';});  

        node.observe('mouseover', function(){

            if(node.up('a') != null)
                deUnderLine(node.up('a'), node);
            else
                node.style.textDecoration = 'underline';return false;

        });                                        
        node.observe('mouseout', function(){
            if(node.up('a') != null)
                underLine(node.up('a'),node);
            else
                node.style.textDecoration = 'none';

        });        
        
        node.observe('click', function(event){
            
               showTooltipEntity(event,currentID,bio,corpus,criterion,showType)

        });     

        //node.tooltip = new TooltipClick(node,'baiji_tooltip_document',currentID,bio,'',null,corpus);                                         
    });           

}

                    var linkFrase = "";
                    
                    function deUnderLine(selectedElem, inner) {       
                        inner.style.textDecoration =
                        'underline';                               
                        selectedElem.onmouseover=function(){ this.style.textDecoration =
                            'none'};       
                        
                        linkFrase = selectedElem.onclick;
                        selectedElem.onclick = function anonymous(){return false};       
                        
                    }
                    
                    function underLine (selectedElem, inner) {
                        inner.style.textDecoration = 'none';
                        selectedElem.onmouseover=function(){ this.style.textDecoration =
                            'underline' };                       
                        
                        selectedElem.onclick = linkFrase;
                    }
                    
                    
                    
function highlightElements(corpus) {	


     $$("#queryPanel span[entity]").each(function(node){                

                bio = node.attributes[1].nodeValue;
                currentID_aux = node.attributes[0].nodeValue;

                node.style.textDecoration = 'none';
                node.style.cursor = 'pointer';
                node.observe('mouseover', function(){node.style.textDecoration = 'underline';return false;});                                        
                node.observe('mouseout', function(){node.style.textDecoration = 'none';});                                        
                node.tooltip = new TooltipClick(node,'baiji_tooltip_document',currentID_aux,bio,'',null,corpus);               

            }); 

            $$("#filtersPanel span[entity]").each(function(node){                


                bio = node.getAttribute('entity'); //attributes[3].nodeValue;
                currentID_aux = node.getAttribute('entityId')//attributes[2].nodeValue;
                num = node.getAttribute('numdocs')//attributes[1].nodeValue;
                constante  = node.getAttribute('constante')//attributes[0].nodeValue;
                num_aux = calcNumDocsProfile(null,constante,num);

                node.style.textDecoration = 'none';
                node.style.cursor = 'pointer';
                node.observe('mouseover', function(){node.style.textDecoration = 'underline';return false;});                                        
                node.observe('mouseout', function(){node.style.textDecoration = 'none';});                                        

                node.tooltip = new TooltipClick(node,'baiji_tooltip_document',currentID_aux,bio,num_aux,null,corpus); 

            }); 
            
            
    var elementsArray = new Array();            

    elementsArray = ( $('disambiguationHighligh').value + ";" + $('filters').value + $('filterQuery').value ).split(';')  ;


    elementsArray.each(function(node, index){   
        var auxArray = new Array();
        auxArray = node.split(':');
        if (auxArray.length >= 3) {                
            elementsArray[index] = auxArray;
            var currentID       = elementsArray[index][2];                    

            var currentElement = $$('#documentsPanel span.bioentity[bioid^='+ currentID +'|]').each( function(node) {                    
                var newClass = node.readAttribute('biotype').split('|')[0];
                var bio = node.readAttribute('class')
                node.addClassName( newClass );                       
                node.style.fontWeight = 'bold';

                node.style.textDecoration = 'none';
                node.style.cursor = 'pointer';

                node.observe('mouseover', function(){

                    if(node.up('a') != null)
                        deUnderLine(node.up('a'), node);
                    else
                        node.style.textDecoration = 'underline';return false;

                });                                        
                node.observe('mouseout', function(){
                    if(node.up('a') != null)
                        underLine(node.up('a'),node);
                    else
                        node.style.textDecoration = 'none';

                });                                        
                node.tooltip = new TooltipClick(node,'baiji_tooltip_document',currentID,bio,'',null,corpus);                    
            });                    


            var currentElement = $$('a.resultsAuthor').each( function(node) 
                {   
                    var currentIDAuthor = node.readAttribute('entityid');                     
                    if(currentIDAuthor == currentID)
                        {
                            node.style.fontWeight = 'bold';   
                        }
                        node.tooltip = new TooltipClick(node,'baiji_tooltip_document',currentIDAuthor,'author','',null,corpus);                    

                    });   

                } 
            });	
        }
function highlightElementsDetailDoc(corpus) {	

    var elementsArray = new Array();            

    elementsArray = ( $('disambiguationHighligh').value + ";" + $('filters').value + $('filterQuery').value  ).split(';');


    elementsArray.each(function(node, index){   
        var auxArray = new Array();
        auxArray = node.split(':');
        if (auxArray.length >= 3) {                
            elementsArray[index] = auxArray;

            var currentID       = elementsArray[index][2];                    




            var currentElement = $$('#documentsPanel span.bioentity[bioid^='+ currentID +'|]').each( function(node) {                    
                var newClass = node.readAttribute('biotype').split('|')[0];
                var bio = node.readAttribute('class')
                node.addClassName( newClass );                       
                node.style.fontWeight = 'bold';

                node.style.textDecoration = 'none';
                node.style.cursor = 'pointer';
                node.observe('mouseover', function(){node.style.textDecoration = 'underline';return false;});                                        
                node.observe('mouseout', function(){node.style.textDecoration = 'none';});                                        
                node.tooltip = new TooltipClick(node,'baiji_tooltip_document',currentID,bio,'','true',corpus);                    
            });                    


            var currentElement = $$('a.resultsAuthor').each( function(node) 
                {   
                    var currentIDAuthor = node.readAttribute('entityid');                     
                    if(currentIDAuthor == currentID)
                        {
                            node.style.fontWeight = 'bold';   
                        }
                        node.tooltip = new TooltipClick(node,'baiji_tooltip_document',currentIDAuthor,'author','','true',corpus);                    

                    });   

                } 
            });

        }
        
         function highlightBioentityDetailDoc(biot,corpus,clase,criterion,showType){
                        
                        var currentElement = $$('span.bioentity[biotype^='+ biot +'|]').each( function(node) {                    
                            var newClass = clase; // node.readAttribute('biotype').split('|')[0];
                            var currentID =node.readAttribute('bioid').split('|')[0];
                            var bio = node.readAttribute('class')
                            node.addClassName( newClass );                       
                            node.style.fontWeight = 'bold';
                            node.style.textDecoration = 'none';
                            node.style.cursor = 'pointer';
                            //node.observe('mouseover', function(){node.style.textDecoration = 'underline';return false;});                                        
                            //node.observe('mouseout', function(){node.style.textDecoration = 'none';});  
                            
                            node.observe('mouseover', function(){
                                
                                if(node.up('a') != null)
                                    deUnderLine(node.up('a'), node);
                                else
                                    node.style.textDecoration = 'underline';return false;
                                
                            });                                        
                            node.observe('mouseout', function(){
                                if(node.up('a') != null)
                                    underLine(node.up('a'),node);
                                else
                                    node.style.textDecoration = 'none';
                                
                            });        
                            
                             node.observe('click', function(event){                                
                                   showTooltipEntity(event,currentID,bio,corpus,criterion,showType)
                               return false;
                            });     
                            
                           // node.tooltip = new TooltipClick(node,'baiji_tooltip_document',currentID,bio,'','true',corpus);                                         
                        });           
                        
                    }
        
        
        