/*

  DOM.js
  Copyright (c) 2007 - Formauri, S.L. - Todos los derechos reservados/All rights reserved
  <http://www.formauri.es/>

*/
/* Functions that haven't been created by Formauri will be clearly detailed */



function MostrarCapa(idCapa)
{
  document.getElementById(idCapa).style.display = 'block';
}

function OcultarCapa(idCapa)
{
  document.getElementById(idCapa).style.display = 'none';
}

function MostrarUOcultarCapa(idCapa)
{
  if (document.getElementById(idCapa).style.display == 'block')
  {
    document.getElementById(idCapa).style.display = 'none';
  }
  else
  {
    document.getElementById(idCapa).style.display = 'block';
  }
}


function MostrarInline(idInline)
{
  document.getElementById(idInline).style.display = 'inline';
}

function OcultarInline(idInline)
{
  document.getElementById(idInline).style.display = 'none';
}

function MostrarOcultarInlines(idInlineMostrar, idInlineOcultar)
{
  MostrarInline(idInlineMostrar);
  OcultarInline(idInlineOcultar);
}



function OcultarDiv(queDiv, siNo)
{
  if( document.getElementById(queDiv) )
  {
    document.getElementById(queDiv).style.display = siNo ? 'none' : 'block';
  }
}











/*--------------------------------------------------------------------------*/

// http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
function getElementsByClassName(oElm, strTagName, strClassName)
{
  var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
  var arrReturnElements = new Array();
  strClassName = strClassName.replace(/\-/g, "\\-");
  var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
  var oElement;
  for(var i=0; i<arrElements.length; i++)
  {
    oElement = arrElements[i];    
    if(oRegExp.test(oElement.className))
    {
      arrReturnElements.push(oElement);
    }
  }
  return (arrReturnElements)
}

// http://www.bigbold.com/snippets/posts/show/2630
function addClassName(objElement, strClass, blnMayAlreadyExist)
{
  if ( objElement.className )
  {
    var arrList = objElement.className.split(' ');
    if ( blnMayAlreadyExist )
    {
      var strClassUpper = strClass.toUpperCase();
      for ( var i = 0; i < arrList.length; i++ )
      {
        if ( arrList[i].toUpperCase() == strClassUpper )
        {
          arrList.splice(i, 1);
          i--;
        }
      }
    }
    arrList[arrList.length] = strClass;
    objElement.className = arrList.join(' ');
  }
  else
  {
    objElement.className = strClass;
  }
}

// http://www.bigbold.com/snippets/posts/show/2630
function removeClassName(objElement, strClass)
{
  if ( objElement.className )
  {
    var arrList = objElement.className.split(' ');
    var strClassUpper = strClass.toUpperCase();
    for ( var i = 0; i < arrList.length; i++ )
    {
      if ( arrList[i].toUpperCase() == strClassUpper )
      {
        arrList.splice(i, 1);
        i--;
      }
    }
    objElement.className = arrList.join(' ');
  }
}

// http://ejohn.org/projects/flexible-javascript-events/
function addEvent( obj, type, fn )
{
  if ( obj.attachEvent )
  {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() { obj["e"+type+fn]( window.event ) };
    obj.attachEvent( "on"+type, obj[type+fn] );
  } 
  else
  {
    obj.addEventListener( type, fn, false );
  }
}
