
/***********************/
/* Funciones Generales */
/***********************/


function toggle(id) 
{
  var obj= document.getElementById(id);
  if(obj.style.display != 'none' ) 
    obj.style.display = 'none';
  else
    obj.style.display = '';
}


function tag(tipo, atributos, texto)
{
  var etiqueta=document.createElement(tipo);
  if(atributos)
  {
    var arrayAttr=atributos.split(' ');
    for(i in arrayAttr)
    {
      atrib=arrayAttr[i].split(':');
      etiqueta.setAttribute(atrib[0], atrib[1]);
    }
  }
  if(texto)
  {
    etiqueta.appendChild(document.createTextNode(texto));
  }
  
  return etiqueta;
}


function isArray(obj) 
{
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}


function entidadesHtml(texto)
{

  var entidades=[['á', '\00e1'], ['é', '\00e9'], ['í', '\00ed'], ['ó', '\00f3'], ['ú', '\00fa'], ['Á', '\00c1'], ['É', '\00c9'], ['Í', '\00cd'], ['Ó', '\00d3'], ['Ú', '\00da'], ['ñ', '\00f1'], ['Ñ', '\00d1']];
  
  var ent;
  for(idEnt in entidades)
  {
    ent=entidades[idEnt];
    texto.replace(ent[0], ent[1]);
  }
  return texto;
}


/***************/
/* Formularios */
/***************/

function toggle_pass(id)
{
  var input=document.getElementById(id);
  var toggleInput=document.getElementById('toggle_' + id);
  if(input.type=='text')
  {
    input.type='password';
    toggleInput.removeChild(toggleInput.firstChild);
    toggleInput.appendChild(document.createTextNode('Ver Password'));
  }
  else if(input.type=='password')
  {
    input.type='text';
    toggleInput.removeChild(toggleInput.firstChild);
    toggleInput.appendChild(document.createTextNode('Ocultar Password'));
  }
}


/*************/
/* animación */
/*************/


function load_anim(id)
{
  var destino=document.getElementById(id);

  for(var i=0; i<=frames; i++)
  {
    anim[i]=new Image();
    anim[i].src=url[0] + i + url[1];
  }

  destino.setAttribute('onmouseover', 'clearTimeout(idAnim);fwAnim("f");');
  destino.setAttribute('onmouseout', 'clearTimeout(idAnim);fwAnim("r");');

  destino.style.backgroundImage='url(' + anim[pos].src + ')';
  destino.style.backgroundRepeat='no-repeat';
  destino.style.backgroundPosition='50%';
}

function fwAnim(dir)
{
  var destino=document.getElementById(id);

  var go=(dir=='f')?(pos<frames):(pos>0);
  if(go)
  {
    (dir=='f')?pos++:pos--;
    destino.style.backgroundImage='url(' + anim[pos].src + ')';
    idAnim=setTimeout('fwAnim("' + dir + '")', timer);
  }
  else
   clearTimeout(idAnim);
}


