function horneaCookie (NombreCookie,ValorCookie,FechaExpiracion,Path,Dominio,Seguridad) {
   if (FechaExpiracion != null) {
      var ahora = new Date();
      ahora.setTime(ahora.getTime() + Math.round(86400000*FechaExpiracion));
      FechaExpiracion = ahora.toGMTString();
   }
   FechaExpiracion = (FechaExpiracion != null) ? '; expires='+FechaExpiracion : '';
   Path = (Path != null)?'; path='+Path:'';
   Dominio = (Dominio != null) ? '; domain='+Dominio : '';
   Seguridad = (Seguridad != null) ? '; secure' : '';
   document.cookie = NombreCookie + '=' + escape(ValorCookie) + FechaExpiracion + Path + Dominio + Seguridad;
}

function pruebaCookie (NombreCookie) {
   var cookies = document.cookie;
   if (cookies.indexOf(NombreCookie + '=') == -1) return null;
   var start = cookies.indexOf(NombreCookie + '=') + (NombreCookie.length + 1);
   var finish = cookies.substring(start,cookies.length);
   finish = (finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';');
   return unescape(cookies.substring(start,finish));
}

function elijeEstilo (NombreCookie, ValorCookie) {
   horneaCookie(NombreCookie, ValorCookie, 90, '/');
   if (NombreCookie == 'menu-es') {
      estableceCSSActiva(ValorCookie);
   } else {
      window.location.reload();
   }
}

function estableceCSSActiva(NombreCSS) {
   var indice, enlace;
   for(indice=0; (enlace = document.getElementsByTagName("link")[indice]); indice++) {
      if(enlace.getAttribute("rel").indexOf("style") != -1 && enlace.getAttribute("title")) {
         enlace.disabled = true;
         if(enlace.getAttribute("title") == NombreCSS) enlace.disabled = false;
      }
   }
}

if (document.cookie.indexOf('fuente-es=')!=-1) {
   css = pruebaCookie('fuente-es');
   document.write('<style type="text/css" media="screen">@import "styles/' + css + '.css";</' + 'style>\n');
} else {
   document.write('<style type="text/css" media="screen">@import "styles/AMP-FNor.css";</' + 'style>\n');
}

if (document.cookie.indexOf('menu-es=')!=-1) {
   css = pruebaCookie('menu-es'); estableceCSSActiva(css);
} else {
   estableceCSSActiva("Menú a la izquierda");
}

if (document.cookie.indexOf('color-es=')!=-1) {
   css = pruebaCookie('color-es');
   document.write('<style type="text/css" media="screen">@import "styles/' + css + '.css";</' + 'style>\n');
} else {
   document.write('<style type="text/css" media="screen">@import "styles/AMP-CNormal.css";</' + 'style>\n');
}

