function cogerIdioma (elemento, NameOfTag, NameOfClass)
{
   var d = elemento.getElementsByTagName(NameOfTag);   
   var i = 0;
   var trobat = false;
   while (i<d.length && !trobat)
   {	
		if(d[i].className == NameOfClass)
		{
			 d[i];			
		     trobat = true;
		}
		else
		{
				i++;
		}
   }
   return d[i];
}
function enviarMailContacteHome (Id, SIdioma)
{
	if(SIdioma == "cas")
	{
		lletra = "e";
	}
	else if (SIdioma == "ang")
	{
		lletra = "a";
	}
	else
	{
		lletra = "c";
	}
	if(document.all)
	{
		openCenteredWindow("/Contacte."+lletra+"/contacte.aspx?Id="+Id,300,429);
	}
	else
	{
		openCenteredWindow("/Contacte."+lletra+"/contacte.aspx?Id="+Id,300,429);
	}

}
function calculaHeight()
{
	var myHeight;
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible				
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}
function calculaWidth()
{
	var myWidth;
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myWidth = window.innerWidth;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible				
		myWidth = document.body.clientWidth;
	}	
	return	myWidth;
}
function enviarMailContacte(Id)
{
	var idiomes = document.getElementById('idiomes');
	var idiomaSel = cogerIdioma(idiomes,'li','idiomaActiu').innerHTML;
	
	if(idiomaSel.indexOf("Espa") > -1 )
	{	
		lletra = "e";
	}
	else if(idiomaSel == "English")
	{
		lletra = "a";
	}
	else
	{
		lletra = "c";
	}

	if(document.all)
	{
		openCenteredWindow("/Contacte."+lletra+"/contacte.aspx?Id="+Id,300,429);
	}
	else
	{
		openCenteredWindow("/Contacte."+lletra+"/contacte.aspx?Id="+Id,300,429);
	}
}
function centerTopW(w_alt)
	{
		// Calcula la posició de la finestra centrada a la pantalla pel Top
		var winH;
		ns4=(document.layers)? true:false
		ie4=(document.all)? true:false
			if(ns4){
				winH = window.screen.height
			}
			if (ie4){
				winH = window.screen.height
			}
			winH = (winH - w_alt)/2
		return(winH)
	}
	
function centerLeftW(w_ample)
{
	// calcula la posició de la finestra centrada a la pantalla per l'esquerra
	var winW;
	ns4=(document.layers)? true:false
	ie4=(document.all)? true:false
		if(ns4){
			winW = window.screen.width
		}
		if (ie4){
			winW = window.screen.width
		}
		winW = (winW - w_ample)/2
	return(winW)
}
	
function openCenteredWindow(url, h, w)
{
	str = "'copyhistory=no,toolbar=no,location=no, menubar=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=" + w + ",height=" + h + ",top=" + centerTopW(h) + ",left=" + centerLeftW(w) + "'"
	w = window.open(url, '', str);
}


function openCenteredEndWindow(url, h, w)
{
	str = "'copyhistory=no,toolbar=no,location=no, menubar=no,directories=no,status=no,scrollbars=yes,resizable=no,width=" + w + ",height=" + h + ",top=" + centerTopW(h) + ",left=" + centerLeftW(w) + "'"
	w = window.open(url, '', str);
}

function startList(){
	
	
	/* Colors */
	var groc = "rgb(253,114,22)";
	var itec = "rgb(0,106,180)";
	var vermell = "rgb(251,0,0)";
	var verd = "rgb(0,91,39)";
	///var blau = "rgb(207,0,230)";
	var blau = "rgb(153,102,51)";
	var cursos = "rgb(0,106,180)";

	/*Treiem separadors tema actiu*/

	var div = document.getElementById("temaActiu");
	tema = div.parentNode;
	if (tema.nextSibling != null)
	{
		tema.nextSibling.innerHTML="";
		tema.nextSibling.style.backgroundColor = eval(tema.id.toString());
	}
	if(tema.previousSibling != null)
	{
		tema.previousSibling.innerHTML="";
	}
	
	/*IE*/
	if (document.all&&document.getElementById)
	{
		
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) 
		{
			node = navRoot.childNodes[i];
			/*POSEM ELS HOVER DE LA SELECCIO DE TEMA I AFEGIM LA FUNCIO PER AMAGAR SEPARADORS*/
			if (node.nodeName=="LI" && node.className!="separador") 
			{
				////////////////////////////////////////////////////////////////////////
				// Per amagar la metaBASE i lo dels Col·legiats
				////////////////////////////////////////////////////////////////////////
				LiS = node.getElementsByTagName("LI")
				for(mB = 0; mB < LiS.length; mB++){
					if(LiS[mB].innerHTML.indexOf('metaBase')>0){
						if(LiS[mB].innerHTML.indexOf('de')<0){
							//LiS[mB].style.visibility='hidden';
							node.childNodes[1].removeChild(LiS[mB]);
							
						}
						
					}
					if(LiS[mB].innerHTML.indexOf('primer any')>0){
						node.childNodes[1].removeChild(LiS[mB]);
					}

						
				}
				
				node.onmouseover=function()
				{
					amagaSelects();
					this.className+=" over";					
					this.getElementsByTagName("div").item(0).className+=" ensenya";
					if( this.nextSibling != null)
					{
						//alert(this.id);
						//this.nextSibling.style.visibility ="hidden";					
						//this.previousSibling.className += " acolora" + this.id
						//this.previousSibling.innerHTML = ""
						//this.nextSibling.className += " acolora" + this.id
						//this.nextSibling.innerHTML = ""
						//alert(this.className);
						//this.nextSibling.style.color = "red"
						//alert(eval(this.id.toString()));
						this.nextSibling.innerHTML = "";
						this.nextSibling.style.backgroundColor = eval(this.id.toString());
						
					}
					if(this.previousSibling != null)
					{
						if(this.previousSibling.previousSibling.id != tema.id){
							this.previousSibling.style.visibility ="hidden";
						}
						//this.nextSibling.className += " acolora" + this.id
					}
				}
				node.onmouseout=function() 
				{
					ensenyaSelects();
					this.className=this.className.replace(" over","");
					this.getElementsByTagName("div").item(0).className=this.getElementsByTagName("div").item(0).className.replace(" ensenya","");
					if(this.nextSibling != null)
					{
						/*this.nextSibling.className += "separador";*/
						if(this.nextSibling.nextSibling.getElementsByTagName("div").item(0).className != "ensenya" && this.id != tema.id){
							this.nextSibling.innerHTML = "|";
						}
						
						this.nextSibling.style.visibility ="visible";
						this.nextSibling.style.backgroundColor = "";
						if(this.id == tema.id){
							this.nextSibling.style.backgroundColor = eval(this.id.toString());
						}
					}
					if(this.previousSibling != null && this.previousSibling.id != "separadorBorrat")
					{
						//this.nextSibling.className += "separador"
						//this.nextSibling.innerHTML = "|"

						this.previousSibling.style.visibility ="visible";						
					}
				}
				/*POSEM ELS HOVERS DELS ELEMENTS INTERIORS*/
				lisInteriors=node.getElementsByTagName("LI");					
					for (j=0; j<lisInteriors.length; j++) 
					{
						liInterior = lisInteriors.item(j);
						
						if (lisInteriors.item(j).className!="titular")
						{							
							liInterior.onmouseover=function() 
							{							
								this.className+=" elementllistaover";																
							}
							liInterior.onmouseout=function() 
							{
								this.className=this.className.replace(" elementllistaover","");								
							}
						}
					}
			}
		}
		/*POSEM ELS HOVERS DE LA SELECCIO DE LA SEGONA LLISTA SUB-SUBTEMES I PINTEM SEPARADORS*/
		navRoot = document.getElementById("navlist");
		for (i=0; i<navRoot.childNodes.length; i++) 
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI" && node.className=="element") 
			{	
						
				node.onmouseover=function()
					{
						this.className+=" sobre";
						if(this.nextSibling != null && this.nextSibling.className!="separadorActiu" )
						{
							this.nextSibling.className+="pintat";
						}
						if(this.previousSibling != null && this.previousSibling.className!="separadorActiu")
						{
							this.previousSibling.className+="pintat";											
						}
					}
					node.onmouseout=function() 
					{
						this.className = this.className.replace(" sobre","");
						if(this.nextSibling != null && this.nextSibling.className!="separadorActiu")
						{
							this.nextSibling.className = this.nextSibling.className.replace("pintat","");

						}
						if(this.previousSibling != null && this.previousSibling.className!="separadorActiu")
						{
							this.previousSibling.className = this.previousSibling.className.replace("pintat","");
						}
					}
			}
			else if(node.nodeName=="LI" && node.className=="active2")
			{
				if(node.nextSibling != null)
				{
					node.nextSibling.className = "separadorActiu";
				}
				if(node.previousSibling != null)
				{
					node.previousSibling.className = "separadorActiu";					
				}
			}
		}
	}
	else/*ES FIREFOX*/
	{
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) 
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI"  && node.className!="separador") 
			{			
				//alert(node.childNodes[0].childNodes[0].innerHTML);
				if (node.childNodes[0].childNodes[0].innerHTML=="Bases de Dades" ||node.childNodes[0].childNodes[0].innerHTML=="Bases de Datos")
				{
					amagarMetaBaseFireFox(node);
				}
				node.onmouseover=function()
				{
					if( this.nextSibling != null)
					{
						this.nextSibling.style.visibility ="hidden";						
					}
					if(this.previousSibling != null)
					{
						this.previousSibling.style.visibility ="hidden";						
					}
				}
				node.onmouseout=function() 
				{
					if(this.nextSibling != null)
					{
						this.nextSibling.style.visibility ="visible";
					}
					if(this.previousSibling != null && this.previousSibling.id != "separadorBorrat")
					{
						this.previousSibling.style.visibility ="visible";					
					}
				}
			}
		}
		/*POSEM ELS HOVERS DE LA SELECCIO DE LA SEGONA LLISTA SUB-SUBTEMES I PINTEM SEPARADORS*/
		navRoot = document.getElementById("navlist");
		for (i=0; i<navRoot.childNodes.length; i++) 
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI" && node.className=="element") 
			{			
				node.onmouseover=function()
					{
						if(this.nextSibling != null && this.nextSibling.className!="separadorActiu" )
						{
							this.nextSibling.className+="pintat";
						}
						if(this.previousSibling != null && this.previousSibling.className!="separadorActiu")
						{
							this.previousSibling.className+="pintat";											
						}
					}
					node.onmouseout=function() 
					{
						if(this.nextSibling != null && this.nextSibling.className!="separadorActiu")
						{
							this.nextSibling.className = this.nextSibling.className.replace("pintat","");
						}
						if(this.previousSibling != null && this.previousSibling.previousSibling.className!="separadorActiu")
						{
							this.previousSibling.className = this.previousSibling.className.replace("pintat","");
						}
					}
			}
			else if(node.nodeName=="LI" && node.className=="active2")
			{
				if(node.nextSibling != null)
				{
					
					node.nextSibling.className = "separadorActiu";
				}
				if(node.previousSibling != null)
				{
					node.previousSibling.className = "separadorActiu";
				}
			}
		}
	}
	posiciona();
	
	
	//Cridem a una funcio per posar invisible el primer separador, que queda entre el logo i el primer text
	treurePrimerSeparador();
	
	

}


function posiciona(){
	if(document.all){
		if(document.body.style.overflow == 'hidden'){
			ample = document.body.offsetWidth;
		}else{
			ample = document.body.offsetWidth // + 23;
		}
	}
	else{
		ample=innerWidth;
	}
	document.getElementById("bodyDiv").style.position = "absolute";
	document.getElementById("bodyDiv").style.left = ((ample - 1001)/2) + "px";
	document.getElementById("bodyDiv").style.top = "0px";
	if(document.body.clientWidth < 800){
		document.body.style.overflow = "auto";
		document.getElementById("bodyDiv").style.left = "0px";
	}
	document.getElementById("bodyDiv").style.visibility = "visible";
}

function treurePrimerSeparador()
{
/*Treiem el primer separador*/
	navRoot = document.getElementById("nav");	
	var i2 = 0;
	var canviat = false;	
	while (i2< navRoot.childNodes.length && canviat == false) 
	{
		node = navRoot.childNodes[i2];
		if (node.nodeName =="LI" && node.className == "separador") 
		{			
			canviat = true;			
			node.style.visibility = 'hidden';
			node.style.width = "0px";
			node.id = "separadorBorrat";			
			
		}
		 i2++;
	}
}

function amagaSelects(){
	x = 0;
	selects = document.getElementsByTagName("select")
	
	for(x=0;x<selects.length;x++){
		aquest = selects[x];
		aquest.className = "caixaText amagaSelects";
	}
	
}
function ensenyaSelects(){
	x = 0;
	selects = document.getElementsByTagName("select")
	
	for(x=0;x<selects.length;x++){
		aquest = selects[x];
		aquest.className = "caixaText";
	}
	
}

function canviaTitol(){
	t = document.getElementById("titol").innerHTML;
	
	t = "metaBase - " + t;
	document.getElementById("titol").innerHTML = t;
}

function amagarMetaBaseFireFox(node)
{
	if(!document.all)
	{
		for (i=0; i<node.childNodes[1].childNodes.length; i++) 
		{
			if(node.childNodes[1].childNodes[i].innerHTML=='<a href="/noumetabase2.c/consultes.aspx">metaBase</a>')
			{
				//alert(node.childNodes[1].childNodes[i].innerHTML);
				node.childNodes[1].childNodes[i].style.display='none';
			}
		}
	}
}

function posaTitol(Titol){
	document.getElementById("titol").innerHTML = Titol;
}

function ocultaApartats(){
	document.getElementById("navlist").innerHTML = "";
}


function openRegistre(url) {
    var alt = calculaHeight();
    var ample = calculaWidth();
    
    if(window.screen){ 
        ample = window.screen.availWidth;
        alt = window.screen.availHeight;
    }
    
    str = "top=0, left=0, height=" + alt + ", width=" + ample;
    str += ",toolbar = yes, menubar = yes, scrollbars = yes, resizable = yes, location = yes, status = yes";
    window.open(url, "registre", str);
}
