function lingua(codigo) {
location.href = '../' + codigo + location.href.substring(location.href.lastIndexOf('/'), location.href.length);
}

//javascript para un menú expandible con una sección abierta como máximo
var prev="null";

window.onload=function(){
if(document.getElementsByTagName && document.getElementById){
    document.getElementById("menu").className="jsenable";
    BuildList();
    setUserOptions();
    }
}

function BuildList(){

var claseactual=document.getElementById("contenido").className;

var hs=document.getElementById("menu").getElementsByTagName("a");
for(var i=0;i<hs.length;i++){
    hs[i].onclick=function(){
        if(this.parentNode.className!="show"){
            this.parentNode.className="show";
            if(prev && prev!=this.parentNode) prev.className="hide";
            prev=this.parentNode;
            }
        else this.parentNode.className="hide";
        }
    }


for(var i=0;i<hs.length;i++){
	if(hs[i].className==claseactual){
		if(hs[i].parentNode.className!="show"){
			hs[i].parentNode.className="show";
			if(prev && prev!=hs[i].parentNode) prev.className="hide";
			prev=hs[i].parentNode;
			}
		else hs[i].parentNode.className="hide";
		}
	}


}

//A partir de aqui, los cambios de estilo
var prefsLoaded = false;
var currentFontSize = 17;
var currentFontType = 1;
var currentStyle = "White";
//var currentWidth = 100%;
function revertStyles(){
	currentFontType = 1;
	setFontFace(1);
	
	currentFontSize = 17;
	changeFontSize(0);
	
	currentStyle = "White";
	setColor("White");
	
	currentWidth = 990;
	setWidth(990);
}
function toggleColors(){
	if(currentStyle == "White"){
		setColor("Black");
	}else{
		setColor("White");
	}
}
function setColor(color){
	d=new Date();
	flash=Math.round(Math.random()*d.getTime());
	if(color != "White"){
		document.body.className = 'Retro';
		currentStyle = "Black";
	}else{
		document.body.className = '';
		currentStyle = "White";
	}
}
function toggleWidth(){
	currentWidth = parseInt(currentWidth);
	var newWidth = 990;
	if(currentWidth == 990){
		newWidth = 1200;
	}
	setWidth(newWidth);
	currentWidth = newWidth;
}
function setWidth(width){
	if(width != 990){
		newWidth = 1200;
		document.body.style.width = '90%';
	}else{
		document.body.style.width = '990px';
	}
}
function changeFontSize(sizeDifference){
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference);

	if(currentFontType == 1){
		if(currentFontSize > 21){
			currentFontSize = 21;
		}else if(currentFontSize < 12){
			currentFontSize = 12;
		}
	}else{
		if(currentFontSize > 22){
			currentFontSize = 22;
		}else if(currentFontSize < 13){
			currentFontSize = 13;
		}
	}
	setFontSize(currentFontSize);
};
function setFontSize(fontSize){
	var stObj = (document.getElementById) ? document.getElementById('contenedor') : document.all('contenedor');
	stObj.style.fontSize = fontSize + 'px';
};
function toggleSerif(){
	currentFontType = parseInt(currentFontType);
	if(currentFontType == 1){
		currentFontType = 2;
	}else{
		currentFontType = 1;
	}
	setFontFace(currentFontType);
};
function setFontFace(fontType){
	var stObj = (document.getElementById) ? document.getElementById('contenedor') : document.all('contenedor');
	if(fontType == 2){
		stObj.style.fontFamily = 'georgia,times,times new roman,serif';
		changeFontSize(1);
	}else{
		stObj.style.fontFamily = 'verdana,geneva,arial,helvetica,sans-serif';
		changeFontSize(-1);
	}
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
};

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
};

//window.onload = setUserOptions;

function setUserOptions(){
	if(!prefsLoaded){
		cookie = readCookie("fontFace");
		currentFontType = cookie ? cookie : 1;
		setFontFace(currentFontType);

		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : 17;
		setFontSize(currentFontSize);
		
		cookie = readCookie("pageWidth");
		currentWidth = cookie ? cookie : 990;
		//setWidth(currentWidth);
		
		cookie = readCookie("pageColor");
		currentStyle = cookie ? cookie : "White";
		setColor(currentStyle);

		prefsLoaded = true;
	}

}

window.onunload = saveSettings;

function saveSettings()
{
  createCookie("fontSize", currentFontSize, 365);
  createCookie("fontFace", currentFontType, 365);
  createCookie("pageWidth", currentWidth, 365);
  createCookie("pageColor", currentStyle, 365);
}


// Universal transparent-PNG enabler for MSIE/Win 5.5+
// http://dsandler.org
// From original code: http://www.youngpup.net/?request=/snippets/sleight.xml
// and background-image code: http://www.allinthehead.com/retro/69
// also:
//  * use sizingMethod=crop to avoid scaling PNGs (who would do such a thing?)
//  * only do this once, to make it compatible with CSS rollovers

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	window.attachEvent("onload", enableAlphaImages);
}

function enableAlphaImages(){
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
	if (itsAllGood) {
		for (var i=0; i<document.all.length; i++){
			var obj = document.all[i];
			var bg = obj.currentStyle.backgroundImage;
			var img = document.images[i];
			if (bg && bg.match(/\.png/i) != null) {
				var img = bg.substring(5,bg.length-2);
				var offset = obj.style["background-position"];
				obj.style.filter =
				"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='crop')";
				obj.style.backgroundImage = "url('../imaxes/spacer.gif')";
				obj.style["background-position"] = offset; // reapply
			} else if (img && img.src.match(/\.png$/i) != null) {
				var src = img.src;
				img.style.width = img.width + "px";
				img.style.height = img.height + "px";
				img.style.filter =
				"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='crop')"
				img.src = "../imaxes/spacer.gif";
			}
		}
	}
}
