var ns4=false; var ie4=false; var standard=false;

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}
 
function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}
 
function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}
 
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;
}
 
function leerEstilo() {
  var cookie = readCookie("style");
  if(cookie == null){
  	title = "dia";
	//alert ("no hi ha cookie!");
  } else {
  	title = cookie ? cookie : getPreferredStyleSheet();
  }
  setActiveStyleSheet(title);
  
  
if (location.hash !='' ) {
	if (location.hash.substring(0,1)=='#') {
		var n = (location.hash.substring(1,location.hash.length));
		if (n>0 && n<10) {
			salta('1',n);
		}
	}
}

}
var title = '';
function ponerEstilo(idioma) {
  var cookie = readCookie("style");
  if(cookie == null){
  	title = "dia";
	//alert ("no hi ha cookie!");
  } else {
  	title = cookie ? cookie : getPreferredStyleSheet();
	//alert(title);
}
if (title=='nit') {
	document.write('<link rel="stylesheet" type="text/css" href="css/'+idioma+'_nit.css" title="nit" />');
	document.write('<link rel="alternate stylesheet" type="text/css" href="css/'+idioma+'_dia.css" title="dia" />');
} else {
	document.write('<link rel="stylesheet" type="text/css" href="css/'+idioma+'_dia.css" title="dia" />');
	document.write('<link rel="alternate stylesheet" type="text/css" href="css/'+idioma+'_nit.css" title="nit" />');
}
//setActiveStyleSheet(title);
  
  
if (location.hash !='' ) {
	if (location.hash.substring(0,1)=='#') {
		var n = (location.hash.substring(1,location.hash.length));
		if (n>0 && n<10) {
			salta('1',n);
		}
	}
}

}


function guardarEstilo() {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

///////////////////////////////////////////////////////////////

function canviaLlum() {
	if (title == "dia") { 
		title = "nit"; 
		document.getElementById('titol').style.visibility = 'visible';
		fosa('titol',100,0,-5);
	} else { 
		title = "dia"; 
	}
	//document.getElementById('dinamic').src='captallum.php?llum='+title;
	setActiveStyleSheet(title, 1);
}
function fosa (nomCapa,alfa,final,increment) {
	var alfa=alfa + increment;
	opacitat (nomCapa, alfa);
	if (alfa != final) {
		setTimeout('fosa("'+nomCapa+'",'+alfa+','+final+','+increment+')', 50);
	} else {
		document.getElementById(nomCapa).style.visibility = 'hidden';
	}
}

function opacitat (nomCapa,alfa) {
	if (document.all) {
		document.getElementById(nomCapa).style.filter = 'alpha(opacity='+alfa+')';
	} else {
		document.getElementById(nomCapa).style.MozOpacity = alfa/100;
	}
}

function salta ( amagar, veure ) {
	document.getElementById('prod' + amagar).style.visibility = 'hidden';
	document.getElementById('prod' + veure).style.visibility = 'visible';
}

