

function xControlMen(id,idKapa,estilos,tim){
	xCMObj= new xControlMen.create(id,idKapa,estilos,tim);
	eval('xCM'+id+'=xCMObj');
	return xCMObj;
}

xControlMen.create=function(id,idKapa,estilos,tim){
	this.arg=arguments;
	this.tiempo=0;
	this.actvFun=0;
	this.classElement=[];
	this.id='xCM'+id;

	for(var x=0;x<=this.arg[2].length;x++){
		this.classElement[x]=this.arg[2].split("/")[x];
	}
}

xControlMen.create.prototype.actvOpc=function(idTd,idHref,ev){
	var classHref=0;
	//farem un tractament especial per a la primera opcio
	//perque quan no estigui en rollover el text no quedi en gris

	if (((idTd.charAt(3)) == "1")&&(idTd.charCodeAt(4) > 58)){
		classHref=this.classElement[2];
	}
	else
	{
		classHref=this.classElement[3];
	}

	if (document.getElementById) { /* Navegadores con DOM- IE5.5,NS6*/
		if(this.actvFun==1){
			if(ev==0){
				document.getElementById(this.arg[1]).style.visibility='visible';
				document.getElementById(idTd).className=this.classElement[0];
				document.getElementById(idHref).className=this.classElement[2];
				if(this.tiempo!=0){
					clearTimeout(this.tiempo);
				}
			}else if(ev==1){
				document.getElementById(idTd).className=this.classElement[1];
				//document.getElementById(idHref).className=this.classElement[3];
				document.getElementById(idHref).className=classHref;
				this.tiempo=setTimeout(this.id+'.actvOpc("'+idTd+'","'+idHref+'",2)',this.arg[3]);
			}else{
				document.getElementById(this.arg[1]).style.visibility='hidden';
			}
		}else{
			this.actvFun=1;
			document.getElementById(this.arg[1]).style.visibility='visible';
		}
	}else if (document.all ) { /* Navegadores IE*/
		if(this.actvFun==1){
					if(ev==0){
						findObj(this.arg[1]).style.visibility='visible';
						findObj(idTd).className=this.classElement[0];
						findObj(idHref).className=this.classElement[2];
						if(this.tiempo!=0){
							clearTimeout(this.tiempo);
						}
					}else if(ev==1){
						findObj(idTd).className=this.classElement[1];
						//findObj(idHref).className=this.classElement[3];
						findObj(idHref).className=classHref;
						this.tiempo=setTimeout(this.id+'.actvOpc("'+idTd+'","'+idHref+'",2)',this.arg[3]);
					}else{
						findObj(this.arg[1]).style.visibility='hidden';
					}
				}else{
					this.actvFun=1;
					findObj(this.arg[1]).style.visibility='visible';
		}

	}
}


xControlMen.create.prototype.showOpc=function(idTd,idHref,ev){
	if (document.layers) { /* Navegadores NS4.5*/
		if(this.actvFun==1){
			if(ev==0){
				for(i=0;i<document.layers.length;i++) document.layers[i].visibility="hide";
				findObj(this.arg[1]).visibility="show";
				if(this.tiempo!=0){
					clearTimeout(this.tiempo);
				}
			}else if(ev==1){
				this.tiempo=setTimeout(this.id+'.showOpc("'+idTd+'","'+idHref+'",2)',this.arg[3]);
			}else{
				findObj(this.arg[1]).visibility="hide";
			}
		}else{
			this.actvFun=1;
			findObj(this.arg[1]).visibility="show";
		}
	}
}

function findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

//AFEGIT PER POSICIONA ELS LAYERS


var hide  = true;

function showhide(obj)
{
	var x = new getObj('testP');
	hide = !hide;
	x.style.visibility = (hide) ? 'hidden' : 'visible';
	setLyr(obj,'testP');
}

function setLyr(obj,lyr,OffsX,OffsY)
{
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	if(OffsX==null) OffsX=0;
	if(OffsY==null) OffsY=0;
	if (lyr == 'testP') newY -= 50;
	var ObjRetorn = new getObj(lyr);
	ObjRetorn.style.left = newX+OffsX;
	ObjRetorn.style.top = newY+OffsY;
}

function findPosX(obj)
{
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
//	window.status = printstring;
	return curtop;
}


function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else
	   {
	    this.obj = document.layers.testP.layers[name];
	    this.style = document.layers.testP.layers[name];
	   }
 }
}



function opcio(indice,nomCapa,numCapa,stTD,stA,nomOp,url,naveg,iconaextern,idiom) {
 strCod='<tr>';
  
 strCat= '<img src="/ca/inc/img/id_cat.gif" width="27" height="11" border="0" align="absmiddle" alt="Page in catalan">';
 strCas= '<img src="/ca/inc/img/id_e.gif" width="17" height="11" border="0" align="absmiddle" alt="Page in spanish" >';
 
 
 if ((iconaextern=='')||(iconaextern==null))
 {
 	linka='<A'; 	
	strFinal='';
 }
 else
 {
 	linka='<A target="_blank"';
 	strFinal=iconaextern;

 }
 if (idiom==1) {
 //catala
   strFinal+=strCat;
 }
 if (idiom==2) {
 //castella
   strFinal+=strCas;
 }
 if ( document.getElementById || document.all) {
  strCod+='<td height=16 onmouseover=xCMpc'+numCapa+'.actvOpc("opc'+indice+nomCapa+'","opc'+indice+nomCapa+'Enc",0) onmouseout=xCMpc'+numCapa+'.actvOpc("opc'+indice+nomCapa+'","opc'+indice+nomCapa+'Enc",1)';
  if (naveg) {strCod+=' colspan=2';}
  strCod+=' id="opc'+indice+nomCapa+'" class="'+stTD+'"><table width=100% border="0" cellspacing="0" cellpadding="0" class="'+stA+'"><tr><td width="5" nowrap></td><td class="'+stA+'">'+linka+' href="'+url+'" id="opc'+indice+nomCapa+'Enc" class="'+stA+'" >'+unescape(nomOp)+strFinal+'</a></td></tr></table></td>';
  strCod+='</tr>';
  document.write(strCod);
 } else
 if (document.layers) {
  strCod+='<td height=16';
  if (naveg) {strCod+=' colspan=2';}
  strCod+=' id="opc'+indice+nomCapa+'" class="'+stTD+'"><table border="0" cellspacing="0" cellpadding="0" class="'+stA+'"><tr><td width="5" nowrap></td><td class="'+stA+'">'+linka+' href="'+url+'" id="opc'+indice+nomCapa+'Enc" class="'+stA+'" onmouseover=xCMpc'+numCapa+'.showOpc("opc'+indice+nomCapa+'","opc'+indice+nomCapa+'Enc",0) onmouseout=xCMpc'+numCapa+'.showOpc("opc'+indice+nomCapa+'","opc'+indice+nomCapa+'Enc",1)>'+unescape(nomOp)+strFinal+'</a></td></tr></table></td>';
  strCod+='</tr>';
  auxLayer=eval('document.layers.'+nomCapa+'Kapa');
  auxLayer.document.write(strCod);
 }
}


var today = new Date()
var expires = new Date()   
expires.setTime(today.getTime() + 1000*60*60*24*365)

function setCookie(name, value, expire)
{
   document.cookie = name + "=" + escape(value)   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}


function getCookie(Name) {   
var search = Name + "=";  
if (document.cookie.length > 0) 
{ // if there are any cookies
	offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
       offset += search.length 
	// set index of beginning of value
		end = document.cookie.indexOf(";", offset)
	// set index of end of cookie value 
		if (end == -1)
			end = document.cookie.length
			
		return unescape(document.cookie.substring(offset, end))
     }    
 }
}

function FullEstil(nouTamany){
	setCookie("FullEstil", nouTamany, expires);
	window.self.location.reload();

}

function ConsultaEstil(){

	// Comprovem que s'accepten cookies
	setCookie("Existencia", "1", expires);
	
	if (getCookie("Existencia"))
	{
		var fulla = getCookie('FullEstil');
	
		if (fulla==null || fulla == "" || fulla=="undefined"){
			fulla = "tamany11";
			setCookie("FullEstil", fulla, expires);
		}
	
		return fulla;	
	}
	else{
		alert("Has d'activar les cookies del teu navegador per poder canviar la mida del text");
		fulla = "tamany11";
	}
	return fulla;
}
//  End Script -->

// precarga de imágenes:
if (document.images) {

	tamany_11_Off = new Image(17,16); tamany_11_Off.src = "/ca/inc/img/mt11_0.gif";
	tamany_11_On = new Image(17,16); tamany_11_On.src = "/ca/inc/img/mt11_1.gif";
	tamany_14_Off = new Image(17,16); tamany_14_Off.src = "/ca/inc/img/mt14_0.gif";
	tamany_14_On = new Image(17,16); tamany_14_On.src = "/ca/inc/img/mt14_1.gif";
	tamany_17_Off = new Image(17,16); tamany_17_Off.src = "/ca/inc/img/mt17_0.gif";
	tamany_17_On = new Image(17,16); tamany_17_On.src = "/ca/inc/img/mt17_1.gif";

}

function cambiar(imgName,imgObjName) {
if (document.images) {
  document.images[imgName].src = eval(imgObjName + ".src");
}}

var tamanyCSS			=	ConsultaEstil();

if (document.layers) {
	if (tamanyCSS == "tamany11"){
		tamany_11_Off.src = "/ca/inc/img/mt11_1.gif";
		document.write("<link rel=stylesheet href='/ca/inc/css/dma_ns.css'>");
	}
	if (tamanyCSS == "tamany14"){
		tamany_14_Off.src = "/ca/inc/img/mt14_1.gif";			
		document.write("<link rel=stylesheet href='/ca/inc/css/dma_ns_14.css'>");
	}
	if (tamanyCSS == "tamany17"){
		tamany_17_Off.src = "/ca/inc/img/mt17_1.gif";
		document.write("<link rel=stylesheet href='/ca/inc/css/dma_ns_17.css'>");
	}
}
else{
	if (tamanyCSS == "tamany11"){
		tamany_11_Off.src = "/ca/inc/img/mt11_1.gif";
		document.write("<link rel=stylesheet href='/ca/inc/css/dma_ie.css'>");
	}
	if (tamanyCSS == "tamany14"){
		tamany_14_Off.src = "/ca/inc/img/mt14_1.gif";						
		document.write("<link rel=stylesheet href='/ca/inc/css/dma_ie_14.css'>");
	}
	if (tamanyCSS == "tamany17"){
		tamany_17_Off.src = "/ca/inc/img/mt17_1.gif";
		document.write("<link rel=stylesheet href='/ca/inc/css/dma_ie_17.css'>");
	}

}	
//obrir popup amb imatge (mapes territorials)
var finestra;
function obrirMapa(imatge)
{
finestra=window.open('','','resizable=yes,scrollbars=no,menubar=no,directories=no,toolbar=no,location=no,locationbar=no')
finestra.document.write('<html><head><title>Mapa</title></head><body style="overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no"><img src="' + imatge + '" onLoad="opener.redimensionar(this.width, this.height)">')
finestra.document.close()
}
function redimensionar(width, height)
{
finestra.resizeTo(width+11,height+82)
finestra.moveTo((screen.width-width)/2,(screen.height-height)/2)
}