/* **** Javier Blasco ***** */

function ini(gru) {
  // activa hoja de estilo
  galleta = leerCookie('style');
  titulo = galleta ? galleta : buscarPreferida();
  cambiarEstilo(titulo);
}

function final() {
  titulo = buscarActiva();
  crearCookie('style',titulo,365);
}

/* ver ejemplo */
function verEjemplo(obj,an,al,es) { // an=ancho, al=alto , es=scroll
  iz = (screen.width-an) / 2;
  ar = (screen.height-al) / 2;
  carac = 'left=' + iz + ', top=' + ar + ', width=' + an + ', height=' + al +',scrollbars=' + es;
  ventana = window.open(obj,'ventana',carac);
}

/**** Funciones para hojas de estilo alternativas ****/

/* cambiar hoja de estilo */
function cambiarEstilo(titulo) {
  for (i=0; lin=document.getElementsByTagName('link')[i]; i++) {
    if (lin.getAttribute('rel').indexOf('style') != -1 && lin.getAttribute('title')) {
      lin.disabled = true;
      if (lin.getAttribute('title') == titulo) 
        lin.disabled = false;
    }
  }
}

/* buscar hoja de estilo activa */
function buscarActiva() {
  for (i=0; lin=document.getElementsByTagName('link')[i]; i++) {
    //alert(i+'-'+lin.getAttribute('title')+'-'+lin.disabled);
    if (lin.getAttribute('rel').indexOf('style')!=-1 && lin.getAttribute('title') && !lin.disabled) 
      return lin.getAttribute('title');
  }
   return null;
}

/* crear cookie */
function crearCookie(nombre,valor,dias) {
  if (dias) {
    var fecha = new Date();
    fecha.setTime(fecha.getTime() + (dias*24*60*60*1000));
    var espira = '; expires=' + fecha.toGMTString();
  }
  else espira = '';
  document.cookie = nombre + '=' + valor + espira + ';path=/';
}

/* leer cookie */
function leerCookie(nombre) {
  var nombreC = nombre + '=';
  var ca = document.cookie.split(';');
  for (i=0; i<ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') c = c.substring(1,c.length);
    if (c.indexOf(nombreC)==0) return c.substring(nombreC.length, c.length);
  }
  return null;
}

/* buscar hoja de estilo preferida */
function buscarPreferida() {
  for (i=0; lin = document.getElementsByTagName('link')[i]; i++) {
    if (lin.getAttribute('rel').indexOf('style')!=-1 && lin.getAttribute('rel').indexOf('alt')==-1 && lin.getAttribute('title'))
      return lin.getAttribute('title');
  }
  return null;
}
/****       ****/

/**** función para cambiar el tamaño del texto ****/

function cambiarTamano(tam) {
  if (document.all)
    miRegla = document.styleSheets[0].rules;
  else
    miRegla = document.styleSheets[0].cssRules;
  // código extra para que funcione en la página editar tabla.html
  if (miRegla[1].selectorText.toLowerCase()=='#tabla')
    if (document.all)
      miRegla = document.styleSheets[1].rules;
    else
      miRegla = document.styleSheets[1].cssRules;
  //  
  for (i=0; reg=miRegla[i]; i++) {
    size = reg.style.fontSize;
    if (size!='') {
      size=parseFloat(size)+tam+'em';
      reg.style.fontSize=size;
    }
  }
}

/**** función para manejar el teclado ****/
function pulsar(e,obj) {
  tecla = (document.all) ? e.keyCode : e.which;
  if (tecla==13 || tecla==32) obj.onclick;
}