function getStyleClass (className) {
  if (document.styleSheets.length < 1) {
    return null;
  }
  if (document.styleSheets[0].cssRules) {
    var cssRules = 'cssRules';
  } else {
    var cssRules = 'rules';
  }
  for (var s = 0; s < document.styleSheets.length; s++) {
    for (var r = 0; r < document.styleSheets[s][cssRules].length; r++) {
      if (document.styleSheets[s][cssRules][r].selectorText == '.' + className) {
        return document.styleSheets[s][cssRules][r];
      }
    }
  }
  return null;
}
function url_amigable(url)
{
	var rst = url
		.toLowerCase() // change everything to lowercase
		.replace(/^\s+|\s+$/g, "") // trim leading and trailing spaces		
		.replace(/[_|\s]+/g, "-") // change all spaces and underscores to a hyphen
		.replace(/[^a-z0-9-]+/g, "") // remove all non-alphanumeric characters except the hyphen
		.replace(/[-]+/g, "-") // replace multiple instances of the hyphen with a single instance
		.replace(/^-+|-+$/g, "") // trim leading and trailing hyphens				
		; 
  return rst;
}
function increaseFontSize() {
 var max=160;
 if (getStyleClass('resizeable').style.fontSize){
   var s = parseInt(getStyleClass('resizeable').style.fontSize.replace('%',''));
 } else {
   var s = 120;
 }
 if(s!=max) {
   s += 10;
 }
 getStyleClass('resizeable').style.fontSize = s+'%';
}
function limitText(limitField,update,limit) {
  if (limitField.value.length > limit) {
    limitField.value = limitField.value.substring(0, limit);
  } else {
    $(update).innerHTML = limit - limitField.value.length + ' caracteres disponibles';
  }
}
function decreaseFontSize() {
 var min=90;
 if (getStyleClass('resizeable').style.fontSize){
   var s = parseInt(getStyleClass('resizeable').style.fontSize.replace('%',''));
 } else {
   var s = 120;
 }
 if(s!=min) {
   s -= 10;
 }
 getStyleClass('resizeable').style.fontSize = s+'%';
}
function showhide(objs) {
  var obj = $('txt_'+objs);
  obj.toggle();
  if (obj.visible()){
    $('img_'+objs).src = '/img/navigator/menos.gif';
    $('img_'+objs).alt = '-';
    $('img_'+objs).title = '-';
  } else {
    $('img_'+objs).src = '/img/navigator/mas.gif';
    $('img_'+objs).alt = '+';
    $('img_'+objs).title = '+';
  }
 return false;
}
function desactive_tab(obj) {
  $('li_'+obj).className='';
  $('tab_'+obj).hide();
}
function active_tab(obj,grp) {
  switch(grp){
    case 'ficha':
      if ($('li_sinopsis')) desactive_tab('sinopsis');
      if ($('li_contratapa')) desactive_tab('contratapa');
      if ($('li_ficha')) desactive_tab('ficha');
      if ($('li_comentarios')) desactive_tab('comentarios');
      if ($('li_noticias')) desactive_tab('noticias');
      if ($('li_extras')) desactive_tab('extras');
      if ($('li_concursos')) desactive_tab('concursos');
      break;
    case 'micuenta':
      if ($('li_micuenta')) desactive_tab('micuenta');
      if ($('li_misnewsletters')) desactive_tab('misnewsletters');
      if ($('li_misautores')) desactive_tab('misautores');
      if ($('li_misconcursos')) desactive_tab('misconcursos');
      if ($('li_tuproyecto')) desactive_tab('tuproyecto');
      break;
    case 'autor':
      if ($('li_libros')) desactive_tab('libros');
      if ($('li_biografia')) desactive_tab('biografia');
      if ($('li_noticias')) desactive_tab('noticias');
      if ($('li_extras')) desactive_tab('extras');
      if ($('li_concursos')) desactive_tab('concursos');
      break;
    case 'los5mas':
      if ($('li_vendidos')) desactive_tab('vendidos');
      if ($('li_vistos')) desactive_tab('vistos');
      if ($('li_valorados')) desactive_tab('valorados');
      break;
  }
 $('li_'+obj).className='selected';
 $('tab_'+obj).show();
 return false;
}

