//*******************************************************************
//***** DiXiMenú creat per Xindes, www.DIXIBIT.com
//*******************************************************************

// **** RECERQUES
function crear_recerques() {
		document.write("<div class=\""+recerques[1]+"\" id=\"cerca_0\"><h2 onmousedown=\"dragStart(event, 'cerca_0')\"><a href=\"javascript:onoff('c',0)\" class=\"boto\" title=\"mostrar/ocultar\"><img src=\"imgs/ico_minimaxi.gif\" width=12 height=14 border=0></a>"+recerques[0]+"</h2>");
		document.write('<form name="frmRecerca" onsubmit="fer_recerca(0);return false;" action=""><input type="text" size="30" name="ftext" /><input type="checkbox" name="chkFora" title="recerca a nova finestra" /></form>');
		document.write('<div id="cerca_0_int">');
		document.write("<ul>");
		for (var j=0; j < recerques[2].length; j++) {
		  if (recerques[2][j][0]=="") document.write("</ul><ul>");
		  else {
			if (recerques[2][j][2]=="") 
			  document.write('<li><a href="javascript:fer_recerca('+j+')">'+recerques[2][j][0]+'</a></li>');
			else
			  document.write('<li><a href="javascript:fer_recerca('+j+')" title="'+recerques[2][j][0]+'"><img src="'+recerques[2][j][2]+'" border=0></a></li>');
		  }	  
		}
		document.write("</ul></div></div>");
}
function fer_recerca(numportal) {
  if (document.frmRecerca.chkFora.checked) window.open(recerques[2][numportal][1] + document.frmRecerca.ftext.value);
  else location.href = recerques[2][numportal][1] + document.frmRecerca.ftext.value;
}

// **** FUNCIONS
function onoff(tip,num) {
	if (tip=='b') var nomid = 'bloc_'+num+'_int';
	else if (tip=='n') var nomid = 'nota_'+num+'_int';
	else if (tip=='c') var nomid = 'cerca_'+num+'_int';
  if (document.getElementById(nomid).style.display != '') { marcaC1='';} else { marcaC1='none';}    
  document.getElementById(nomid).style.display = marcaC1;
}

function canvi_estil(num) {
	if (document.getElementById('bloc_'+num).className == 'bloc1') nova = 'bloc2'; else nova = 'bloc1';
	document.getElementById('bloc_'+num).className = nova;
	document.getElementById('bloc_'+num+'_int').style.display = '';
  	if ((nova=='bloc1')&&(browser.isNS)) {  //bug firefox? per provocar ajustar mida!
  	  document.getElementById('bloc_'+num).style.zIndex = ++dragObj.zIndex;
	}
}

function fer_nl2br(txt) {
	var salts = new Array('%0D%0A', '%0A', '%0D');
	txt = escape(txt);
	for (var sa=0; sa<salts.length; sa++) {
		while (txt.indexOf(salts[sa]) > -1) { txt=txt.replace(salts[sa],"<br />"); }
	}
	var s = new String(unescape(txt));
	txt = s.replace(/(http:\/\/[A-Z0-9._%-\/]+)/gi, "<a href=\"$1\">$1</a>");
	return txt;
}

function OnOff_nota(num) {
  if (document.getElementById('dnota_'+num).style.display != '') { marcaC1='';} else { marcaC1='none';}    
  document.getElementById('dnota_'+num).style.display = marcaC1;
  
  if (marcaC1=='none') {
  	eval('document.getElementById(\'pnota_'+num+'\').innerHTML = fer_nl2br(document.fnota_'+num+'.tnota_'+num+'.value)');
  	document.getElementById('pnota_'+num).style.display = '';
  	document.getElementById('bnota_'+num).innerHTML = '[ editar ]';
  	if (browser.isNS) {  //bug firefox? per provocar ajustar mida!
  	  document.getElementById('nota_'+num).style.zIndex = ++dragObj.zIndex;
	}
  } else {
  	eval('document.fnota_'+num+'.tnota_'+num+'.focus()');
  	document.getElementById('pnota_'+num).style.display = 'none';
  	document.getElementById('bnota_'+num).innerHTML = '[ tancar ]';
  	document.getElementById('nota_'+num).style.zIndex = ++dragObj.zIndex;
  }
}

function i_llista(llista, valor) {
	for (var i=0; i < llista.length; i++) {
		if (llista.options[i].value==valor) return i;
	}
	return -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 = prefixCk+name+"="+value+expires+"; path=/";
}
function readCookie(name) {
  var nameEQ = prefixCk+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;
}

// **** NOTES
function editar_nota(num) {
	  if ((num == -1)&&(num_cks >= MAX_CKS)) {
	  	alert('No pots tenir més de '+MAX_CKS+' cookies!');
	  	return;
	  }
	document.getElementById('ed_li').style.display='none';
	document.getElementById('ed_bl').style.display='none';
	document.getElementById('ed_no').style.display='block';
	document.getElementById('ed_no').style.zIndex = ++dragObj.zIndex;
	if (num == -1) {  //afegir
		document.getElementById('ed_no_tit').innerHTML='afegir nova nota';
		document.frmEdit_no.fboto.value = 'Afegir nota';
		document.frmEdit_no.fedit.value = -1;
		document.frmEdit_no.ftit.value = '';
		document.frmEdit_no.fx.value = 50;
		document.frmEdit_no.fy.value = 20;
		document.getElementById('ed_no_elim').style.display='none';
	} else {  //modificar
		document.getElementById('ed_no_tit').innerHTML='modificar nota '+num;
		document.frmEdit_no.fboto.value = 'Modificar nota';
		document.frmEdit_no.fedit.value = num;
		document.frmEdit_no.ftit.value = document.getElementById('nota_'+num+'_tit').innerHTML;
		document.frmEdit_no.fx.value = document.getElementById('tnota_'+num).getAttribute('cols');
		document.frmEdit_no.fy.value = document.getElementById('tnota_'+num).getAttribute('rows');
		document.frmEdit_no.fest.options[i_llista(document.frmEdit_no.fest,document.getElementById('pnota_'+num).className)].selected = true;
		document.getElementById('ed_no_elim').style.display='';
	}
	document.frmEdit_no.ftit.focus();
	document.frmEdit_no.ftit.select();
}
function cancelar_nota() {
	document.getElementById('ed_no').style.display='none';
}
function eliminar_nota() {
	var i=parseInt(document.frmEdit_no.fedit.value);
	document.getElementById('cos').removeChild(document.getElementById('nota_'+i));
	document.getElementById('ed_no').style.display='none';
	num_cks--;
}
function accio_editar_nota() {
	if (document.frmEdit_no.fedit.value == -1) {
		var ftit = document.frmEdit_no.ftit.value;
		var fest = document.frmEdit_no.fest.value;
		var fx = document.frmEdit_no.fx.value;
		var fy = document.frmEdit_no.fy.value;
		crear_nota(ftit,'nota1',fest,fx,fy,50,50,0,'nota buida');
	} else modif_nota();
	document.getElementById('ed_no').style.display='none';
}

function crear_nota(ftit,fest1,fest,fx,fy,posx,posy,esoff,conti) {
	if (ftit == "") ftit = "&nbsp;";
	
	var i=num_notes; num_notes++;
	var el1 = document.createElement("div");
	el1.setAttribute('id', 'nota_'+i);
	el1.className = fest1;
	el1.style.left = posx+'px';
	el1.style.top = posy+'px';

	var el11 = document.createElement("h2");
	if (browser.isIE) el11.onmousedown = function() { dragStart(event, 'nota_'+i); };
	else el11.setAttribute('onmousedown', "dragStart(event, 'nota_"+i+"')");  //ie no ho pilla!!!!
	el11.innerHTML = "<a href=\"javascript:onoff('n',"+i+")\" class=\"boto\" title=\"mostrar/ocultar nota\"><img src=\"imgs/ico_minimaxi.gif\" width=12 height=14 border=0></a>"
	+"<span id=\"nota_"+i+"_tit\">"+unescape(ftit)+"</span>"
	+"&nbsp;<a href=\"javascript:editar_nota("+i+")\" title=\"modificar/eliminar nota\"><img src=\"imgs/ico_config.gif\" width=12 height=14 border=0></a>";
	el1.appendChild(el11);
	
	var el12 = document.createElement("div");
	el12.setAttribute('id', 'nota_'+i+'_int');
	if (esoff==1) el12.style.display='none';

	var el121 = document.createElement("p");
	el121.setAttribute('id', 'pnota_'+i);
	el121.className = fest;
	el121.innerHTML = fer_nl2br(unescape(conti));
	el12.appendChild(el121);

	var el122 = document.createElement("div");
	el122.setAttribute('id', 'dnota_'+i);
	el122.style.display = 'none';
	el122.innerHTML = '<form name="fnota_'+i+'"><textarea id="tnota_'+i+'" name="tnota_'+i+'" cols="'+fx+'" rows="'+fy+'">'+unescape(conti)+'</textarea></form>';
	el12.appendChild(el122);

	var el123 = document.createElement("p");
	el123.setAttribute('id', 'bnota_'+i);
	el123.className = fest;
	
	if (browser.isIE) el123.onmousedown = function() { OnOff_nota(i); };
	else el123.setAttribute('onmousedown', "OnOff_nota("+i+")");  //ie no ho pilla!!!!
	//el123.setAttribute('style', 'text-align:center; font-size:0.8em; cursor:pointer;'); //ie no ho pilla!!!!
	el123.style.textAlign = 'center';
	el123.style.fontSize = '0.8em';
	el123.style.cursor = 'pointer';
	el123.innerHTML = "[ editar ]";
	el12.appendChild(el123);

	el1.appendChild(el12);

	document.getElementById('cos').appendChild(el1);
	num_cks++;
}
function modif_nota() {
	var i=parseInt(document.frmEdit_no.fedit.value);
	//if (document.frmEdit_no.ftit.value == "") return;
	if (document.frmEdit_no.ftit.value == "") document.frmEdit_no.ftit.value = "&nbsp;";
	
	document.getElementById('nota_'+i+'_tit').innerHTML=document.frmEdit_no.ftit.value;
	document.getElementById('pnota_'+i).className = document.frmEdit_no.fest.value;
	document.getElementById('bnota_'+i).className = document.frmEdit_no.fest.value;
	document.getElementById('tnota_'+i).setAttribute('cols', document.frmEdit_no.fx.value);
	document.getElementById('tnota_'+i).setAttribute('rows', document.frmEdit_no.fy.value);
}

function desar_cookie_notes() {
	var a,i,aju;
	var ajuck = new Array();
	for(i=0; i < num_notes; i++) {
	  if (a=document.getElementById('nota_'+i)) {
	    if (desades < MAX_CKS) {
	  	ajuck[0]=escape(document.getElementById('nota_'+i+'_tit').innerHTML);
	  	ajuck[1]=document.getElementById('nota_'+i).className;
	  	ajuck[2]=document.getElementById('pnota_'+i).className;
	  	ajuck[3]=document.getElementById('tnota_'+i).getAttribute('cols');
	  	ajuck[4]=document.getElementById('tnota_'+i).getAttribute('rows');
	  	ajuck[5]=parseInt(document.getElementById('nota_'+i).style.left);
	  	ajuck[6]=parseInt(document.getElementById('nota_'+i).style.top);
	        if (document.getElementById('nota_'+i+'_int').style.display != "") aju=1; else aju=0;
	        ajuck[7]=aju;
	  	eval('ajuck[8] = escape(document.fnota_'+i+'.tnota_'+i+'.value)');
	  	aju = ajuck.join(separCk);
	  	createCookie('nota_'+i, aju, diesCk);
	  	desades++;
	    }
	  } else {
	  	createCookie('nota_'+i, '', 0); //eliminar cookie !?
	  }
	}
}
function llegir_cookie_nota(valor) {
	var ajuck = valor.split(separCk);
	crear_nota(ajuck[0],ajuck[1],ajuck[2],ajuck[3],ajuck[4],ajuck[5],ajuck[6],ajuck[7],ajuck[8]);
}

// **** BLOCS
function editar_bloc(num) {
	  if ((num == -1)&&(num_cks >= MAX_CKS)) {
	  	alert('No pots tenir més de '+MAX_CKS+' cookies!');
	  	return;
	  }
	document.getElementById('ed_no').style.display='none';
	document.getElementById('ed_li').style.display='none';
	document.getElementById('ed_bl').style.display='block';
	document.getElementById('ed_bl').style.zIndex = ++dragObj.zIndex;
	if (num == -1) {  //afegir
		document.getElementById('ed_bl_tit').innerHTML='afegir nou bloc';
		document.frmEdit_bl.fboto.value = 'Afegir bloc';
		document.frmEdit_bl.fedit.value = -1;
		document.frmEdit_bl.ftit.value = '';
		document.getElementById('ed_bl_elim').style.display='none';
	} else {  //modificar
		document.getElementById('ed_bl_tit').innerHTML='modificar bloc '+num;
		document.frmEdit_bl.fboto.value = 'Modificar bloc';
		document.frmEdit_bl.fedit.value = num;
		document.frmEdit_bl.ftit.value = document.getElementById('bloc_'+num+'_tit').innerHTML;
		document.frmEdit_bl.fest.options[i_llista(document.frmEdit_bl.fest,document.getElementById('bloc_'+num+'_int').className)].selected = true;
		document.getElementById('ed_bl_elim').style.display='';
	}
	document.frmEdit_bl.ftit.focus();
	document.frmEdit_bl.ftit.select();
}
function cancelar_bloc() {
	document.getElementById('ed_bl').style.display='none';
}
function eliminar_bloc() {
	var i=parseInt(document.frmEdit_bl.fedit.value);
	document.getElementById('cos').removeChild(document.getElementById('bloc_'+i));
	document.getElementById('ed_bl').style.display='none';
	document.getElementById('ed_li_gru').options[i_llista(document.getElementById('ed_li_gru'),i)] = null;
	num_cks--;
}
function accio_editar_bloc() {
	if (document.frmEdit_bl.fedit.value == -1) {
		var ftit = document.frmEdit_bl.ftit.value;
		var fest = document.frmEdit_bl.fest.value;
		crear_bloc(ftit,'bloc1',fest,300,100,0);
	} else modif_bloc();
	document.getElementById('ed_bl').style.display='none';
}

function modif_bloc() {
	var i=parseInt(document.frmEdit_bl.fedit.value);
	//if (document.frmEdit_bl.ftit.value == "") return;
	if (document.frmEdit_bl.ftit.value == "") document.frmEdit_bl.ftit.value = "&nbsp;";
	
	document.getElementById('bloc_'+i+'_tit').innerHTML=document.frmEdit_bl.ftit.value;
	document.getElementById('bloc_'+i+'_int').className = document.frmEdit_bl.fest.value;
	document.getElementById('ed_li_gru').options[i_llista(document.getElementById('ed_li_gru'),i)].text = document.frmEdit_bl.ftit.value;
}

function crear_bloc(ftit,fest1,fest,posx,posy,esoff) {
	if (ftit == "") ftit = "&nbsp;";
	
	var i=num_blocs; num_blocs++;
	var el1 = document.createElement("div");
	el1.setAttribute('id', 'bloc_'+i);
	el1.className = fest1;
	el1.style.left = posx+'px';
	el1.style.top = posy+'px';

	var el11 = document.createElement("h2");
	if (browser.isIE) el11.onmousedown = function() { dragStart(event, 'bloc_'+i); };
	else el11.setAttribute('onmousedown', "dragStart(event, 'bloc_"+i+"')");  //ie no ho pilla!!!!
	el11.innerHTML = "<a href=\"javascript:onoff('b',"+i+")\" class=\"boto\" title=\"mostrar/ocultar bloc\"><img src=\"imgs/ico_minimaxi.gif\" width=12 height=14 border=0></a>"
	+"<span id=\"bloc_"+i+"_tit\">"+unescape(ftit)+"</span>"
	+"&nbsp;<a href=\"javascript:editar_bloc("+i+")\" title=\"modificar/eliminar bloc\"><img src=\"imgs/ico_config.gif\" width=12 height=14 border=0></a>"
	+"&nbsp;<a href=\"javascript:canvi_estil("+i+")\" title=\"canviar estil\"><img src=\"imgs/ico_fletxes.gif\" width=12 height=14 border=0></a>";
	el1.appendChild(el11);
	
	var el12 = document.createElement("ul");
	el12.setAttribute('id', 'bloc_'+i+'_int');
	el12.className = fest;
	if (esoff==1) el12.style.display='none';

	el1.appendChild(el12);

	document.getElementById('cos').appendChild(el1);
	document.getElementById('ed_li_gru').options[document.getElementById('ed_li_gru').options.length] = new Option(unescape(ftit), i);
	num_cks++;
}

function desar_cookie_blocs() {
	var a,i,aju;
	var ajuck = new Array();
	for(i=0; i < num_blocs; i++) {
	  if (a=document.getElementById('bloc_'+i)) {
	    if (desades < MAX_CKS) {
	  	ajuck[0]=escape(document.getElementById('bloc_'+i+'_tit').innerHTML);
	  	ajuck[1]=document.getElementById('bloc_'+i).className;
	  	ajuck[2]=document.getElementById('bloc_'+i+'_int').className;
	  	ajuck[3]=parseInt(document.getElementById('bloc_'+i).style.left);
	  	ajuck[4]=parseInt(document.getElementById('bloc_'+i).style.top);
	        if (document.getElementById('bloc_'+i+'_int').style.display != "") aju=1; else aju=0;
	        ajuck[5]=aju;
	        ajuck[6]=desar_cookie_links(i);
	  	aju = ajuck.join(separCk);
	  	createCookie('bloc_'+i, aju, diesCk);
	  	desades++;
	    }
	  } else {
	  	createCookie('bloc_'+i, '', 0); //eliminar cookie !?
	  }
	}
}
function llegir_cookie_bloc(valor) {
	var ajuck = valor.split(separCk);
	crear_bloc(ajuck[0],ajuck[1],ajuck[2],ajuck[3],ajuck[4],ajuck[5]);
	if (ajuck[6]!="") llegir_cookie_links(num_blocs-1, ajuck[6]);
}

function desar_cookie_links(grup) {
	var ajuck = new Array(); var ii=0;
	var el1 = document.getElementById('bloc_'+grup+'_int');
	for (var i=0; i < el1.childNodes.length; i++) {
		ajuck[ii] = el1.childNodes[i].firstChild.innerHTML;
		ii++;
		ajuck[ii] = el1.childNodes[i].firstChild.href;
		ii++;		
	}
	return escape(ajuck.join(separCk));
}
function llegir_cookie_links(grup,valor) {
	valor = unescape(valor);
	var ajuck = valor.split(separCk);
	var i=0;
	while (i < ajuck.length) {
		var ftit = ajuck[i];
		var furl = ajuck[i+1];
		crear_link(ftit,furl,grup);
		i+=2;
	}
}

// **** LINKS
function linkar(num,fgru) {
	if (document.frmBotons.chkModif.checked==true) {editar_link(num,fgru); return false; }
	else if (document.frmBotons.chkFora.checked==true) {window.open(document.getElementById('link_'+num).firstChild.href); return false; }
	else return true;
}

function editar_link(num,fgru) {
	document.getElementById('ed_no').style.display='none';
	document.getElementById('ed_bl').style.display='none';
	document.getElementById('ed_li').style.display='block';
	document.getElementById('ed_li').style.zIndex = ++dragObj.zIndex;
	document.frmEdit_li.fantgru.value = fgru;
	if (num == -1) {  //afegir
		document.getElementById('ed_li_tit').innerHTML='afegir nou link';
		document.frmEdit_li.fboto.value = 'Afegir link';
		document.frmEdit_li.fedit.value = -1;
		document.frmEdit_li.ftit.value = '';
		document.frmEdit_li.furl.value = 'http://';
		document.getElementById('ed_li_elim').style.display='none';
		document.getElementById('mou0').style.display='none';
		document.getElementById('mou1').style.display='none';
	} else {  //modificar
		document.getElementById('ed_li_tit').innerHTML='modificar link '+num;
		document.frmEdit_li.fboto.value = 'Modificar link';
		document.frmEdit_li.fedit.value = num;
		document.frmEdit_li.ftit.value = document.getElementById('link_'+num).firstChild.innerHTML;
		document.frmEdit_li.furl.value = document.getElementById('link_'+num).firstChild.href;
		document.frmEdit_li.fgru.options[i_llista(document.frmEdit_li.fgru, fgru)].selected = true;
		document.getElementById('ed_li_elim').style.display='';
		document.getElementById('mou0').style.display='';
		document.getElementById('mou1').style.display='';
	}
	document.frmEdit_li.ftit.focus();
	document.frmEdit_li.ftit.select();
}
function cancelar_link() {
	document.getElementById('ed_li').style.display='none';
}
function eliminar_link() {
	var i=parseInt(document.frmEdit_li.fedit.value);
	var fgru = document.frmEdit_li.fgru.value;
	document.getElementById('bloc_'+fgru+'_int').removeChild(document.getElementById('link_'+i));
	document.getElementById('ed_li').style.display='none';
}
function moure_link(direc) {
	var i=parseInt(document.frmEdit_li.fedit.value);
	var fgru = document.frmEdit_li.fgru.value;	
	var ajuant = document.getElementById('link_'+i);
	if (direc==0) var ajunou = document.getElementById('link_'+i).nextSibling;
	else var ajunou = document.getElementById('link_'+i).previousSibling;
	if (ajunou != null) {
	  var ant = document.getElementById('bloc_'+fgru+'_int').replaceChild(ajunou, ajuant);
	  if (direc==0) document.getElementById('bloc_'+fgru+'_int').insertBefore(ant, ajunou.nextSibling);
	  else document.getElementById('bloc_'+fgru+'_int').insertBefore(ant, ajunou);
	}
}
function accio_editar_link() {
	if (document.frmEdit_li.fedit.value == -1) {
		var ftit = document.frmEdit_li.ftit.value;
		var furl = document.frmEdit_li.furl.value;
		var fgru = document.frmEdit_li.fgru.value;
		crear_link(ftit,furl,fgru);
	} else modif_link();
	document.getElementById('ed_li').style.display='none';
}
function crear_link(ftit,furl,fgru) {
	if (ftit == "") ftit = "&nbsp;";
	
	var i=num_links; num_links++;
	var el1 = document.createElement("li");
	el1.setAttribute('id', 'link_'+i);
	
	var el11 = document.createElement("a");
	el11.setAttribute('href', unescape(furl));
	el11.innerHTML = unescape(ftit);
	if (browser.isIE) el11.onclick = function() { return linkar(i,fgru); };
	else el11.setAttribute('onClick', "return linkar("+i+","+fgru+")");  //ie no ho pilla!!!!
	el1.appendChild(el11);

	document.getElementById('bloc_'+fgru+'_int').appendChild(el1);
}
function modif_link() {
	var i=parseInt(document.frmEdit_li.fedit.value);
	//if (document.frmEdit_li.ftit.value == "") return;
	if (document.frmEdit_li.ftit.value == "") document.frmEdit_li.ftit.value = "&nbsp;";
		
	//Si canvi de grup, eliminar de ul i afegir a nova ul
	if (document.frmEdit_li.fgru.value != document.frmEdit_li.fantgru.value) {
		document.getElementById('bloc_'+document.frmEdit_li.fantgru.value+'_int').removeChild(document.getElementById('link_'+i));
		var ftit = document.frmEdit_li.ftit.value;
		var furl = document.frmEdit_li.furl.value;
		var fgru = document.frmEdit_li.fgru.value;
		crear_link(ftit,furl,fgru);
	} else {
	  document.getElementById('link_'+i).firstChild.innerHTML=document.frmEdit_li.ftit.value;
	  document.getElementById('link_'+i).firstChild.href = document.frmEdit_li.furl.value;
	}
}

// **** CONFIG
function desar_cookie_config() {
    if (desades < MAX_CKS) {
	var ajuck = new Array(); var aju;
  	ajuck[0]=parseInt(document.getElementById('cerca_0').style.left);
  	ajuck[1]=parseInt(document.getElementById('cerca_0').style.top);
        if (document.getElementById('cerca_0_int').style.display != "") aju=1; else aju=0;
        ajuck[2]=aju;
        if (document.frmRecerca.chkFora.checked==true) aju=1; else aju=0;
        ajuck[3]=aju;
        if (document.frmBotons.chkFora.checked==true) aju=1; else aju=0;
        ajuck[4]=aju;
  	aju = ajuck.join(separCk);
  	createCookie('config', aju, diesCk);
	desades++;
    }
}
function llegir_cookie_config(valor) {
	var ajuck = valor.split(separCk);
	document.getElementById('cerca_0').style.left = ajuck[0] + 'px';
	document.getElementById('cerca_0').style.top = ajuck[1] + 'px';
	if (ajuck[2]==1) document.getElementById('cerca_0_int').style.display = 'none';
	else document.getElementById('cerca_0_int').style.display = '';
	document.frmRecerca.chkFora.checked = (ajuck[3]==1);
	document.frmBotons.chkFora.checked = (ajuck[4]==1);
}


// **** GENERAL
function llegir_cookies() {
	var nomsck = Array('config', 'bloc_', 'nota_');

  var ca = document.cookie.split(';'); var teconfig=0;
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.substring(0,prefixCk.length)==prefixCk) {
	var clau = c.substring(prefixCk.length, c.indexOf('='));
	var valor = c.substring(c.indexOf('=')+1);
	if (clau==nomsck[0]) { 
		if (valor != "") { llegir_cookie_config(valor); teconfig=1; }
	} else if (clau.indexOf(nomsck[1])==0) {
		if (valor != "") llegir_cookie_bloc(valor);
	} else if (clau.indexOf(nomsck[2])==0) {
		if (valor != "") llegir_cookie_nota(valor);
	}
    }
  }
  if ((num_blocs==0)&&(num_notes==0)) {
	crear_defecte_blocs();
	crear_defecte_notes();
  }
  if (teconfig==0) crear_defecte_config();
}

function preferencies() {
	document.getElementById('bt_tit').innerHTML = botonera_titol;
	document.getElementById('bt_ema').href = botonera_email_link;
	document.getElementById('bt_ema').title = botonera_email_titol;
	document.getElementById('bt_ema').innerHTML = botonera_email_text;

	var i=0;
	while (i < estil_notes.length) {
		document.getElementById('ed_no_est').options[document.getElementById('ed_no_est').options.length] = new Option( estil_notes[i+1], estil_notes[i]);
		i+=2;
	}

	var i=0;
	while (i < estil_blocs.length) {
		document.getElementById('ed_bl_est').options[document.getElementById('ed_bl_est').options.length] = new Option( estil_blocs[i+1], estil_blocs[i]);
		i+=2;
	}
}


// **** MAIN
var num_blocs=0, num_notes=0, num_links=0;
var num_cks=1, desades=0; //1 del config


window.onload = function(e) {
  preferencies();
  llegir_cookies();
}

window.onunload = function(e) {
  desar_cookie_config();
  desar_cookie_notes();
  desar_cookie_blocs();
}

//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",	dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",	dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,	true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}