/**
 * Funciones
 */

function fitxers(url)
{
	obret(url,750,500,'no','ficheros');
}


function imatges(projecte)
{
	obret(projecte+'backoffice/ficheros/images',750,500,'no','imatges');
}


/**
  * Switch given value of ID's from 1 to 0, or vice versa.
*/
function switchActive(id)
{
	el = document.getElementById(id);
	el.value = (el.value != 1) ? 1 : 0 ;
}
	
	
var allPageTags = new Array(); 
function hideFlash()
{
    var allPageTags=document.getElementsByTagName("div");
 
    for (i=0; i<allPageTags.length; i++)
    {
    	if (allPageTags[i].className=='message' || allPageTags[i].className=='messageOK' || allPageTags[i].className=='messageFALSE')
    	{
    		allPageTags[i].style.display='none'; 
    	}
    }
}

function showFlashRepositori()
{
	var allPageTags=parent.frames['list'].document.getElementsByTagName("div");
    //var allPageTags=document.getElementsByTagName("div");
 
    for (i=0; i<allPageTags.length; i++)
    {
    	if (allPageTags[i].className=='message' || allPageTags[i].className=='messageOK' || allPageTags[i].className=='messageFALSE')
    	{
    		allPageTags[i].style.display=''; 
    	}
    }
}



function obret(pagina,ample,alt,scroll,finestrapagina)
{
	/* <a href="#" onClick="obret('contacte.htm',460,370,'no','contacte');" class="txtPeu">contacte</a> */	
	if (scroll=="si")d=1;
	if (scroll=="no")d=0;
	if (scroll=="")d=0;
	
	LeftPosition = (screen.width) ? (screen.width-ample)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-alt)/2 : 0;

	settings='width='+ample+',height='+alt+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+d+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	win=window.open(pagina,finestrapagina,settings);
	//Focus de la finestra
	win.focus();	
}


function adjunts(pagina,ample,alt,scroll,finestrapagina)
{
	/* <a href="#" onClick="obret('contacte.htm',460,370,'no','contacte');" class="txtPeu">contacte</a> */	
	if (scroll=="si")d=1;
	if (scroll=="no")d=0;
	if (scroll=="")d=0;
	
	LeftPosition = (screen.width) ? (screen.width-ample)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-alt)/2 : 0;

	// Mirem si se li passa el carcter ~ (voldr dir que s un fitxer del backoffice)
	nom_fitxer = pagina.split("~");
	if(nom_fitxer[1]!=null) obre_pagina = nom_fitxer[0];
	else obre_pagina = pagina;
	
	settings='width='+ample+',height='+alt+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+d+',location=yes,directories=no,status=no,menubar=yes,toolbar=no,resizable=yes';
	win=window.open(obre_pagina,finestrapagina,settings);
	//Focus de la finestra
	win.focus();	
}


/**
  * Posar limit als camps textarea
  * Exemple: posar mxim de 255 carcters
  * <TEXTAREA NAME="something" ROWS="10" COLS="50" onkeypress="textCounter(this,this.form.counter,255);"></TEXTAREA>
  * <input type="text" name="counter" maxlength="3"	size="3" value="255" onblur="textCounter(this.form.counter,this,255);">
  * carcters que falten
  *
  * http://inmyexperience.com/archives/000327.shtml
*/
function textCounter( field, countfield, maxlimit ) 
{
	if ( field.value.length > maxlimit )
	{
		field.value = field.value.substring( 0, maxlimit );
		alert( 'Nomès hi pot haver '+maxlimit+' caràcters.' );
		return false;
	}
	else
	{
		countfield.value = maxlimit - field.value.length;
	}
}



// FITXERS LLISTAT ---------------------------------------------------------
function mira_nav()
{
	var Nav=navigator.appName;
	//alert (Nav);
	return Nav;
}

// TEURE FITXERS
function ext_act(camp,camp_preview,preview,ruta)
{
	nav=mira_nav(); //Alert (nav);

	//numact = eval("document.editor."+camp+".options.length");
	numact = camp.length;
	nomcamp = camp;

	//alert (numact);
	//alert (document.editor.grup_activitat.selectedIndex);
	//Si no hi ha cap activitat, no fem res
	if ((numact == 0) || ((numact != 0) && (nomcamp.selectedIndex==-1)))
	{
		document.editor.elimina.disabled;
		return numact;
	}	
	else
	{
		if (nav=="Netscape")
		{
			//document.editor.grup_activitat.options[document.editor.grup_activitat.selectedIndex].value="";
			//document.editor.grup_activitat.options[document.editor.grup_activitat.selectedIndex]=null;
			nomcamp.options[nomcamp.selectedIndex].value="";
			nomcamp.options[nomcamp.selectedIndex]=null;
		}
		else
		{
			//document.editor.grup_activitat.options.remove(document.editor.grup_activitat.selectedIndex);
			nomcamp.options.remove(nomcamp.selectedIndex);
		}	
		
		if(preview==1) document.getElementById(camp_preview).src=ruta+"img/backoffice/preview.gif";
		//if (numact == document.editor.activitat.options.length) numact--;
		return numact;
	}
}

// INSERTAR FITXERS
function insertaFile(camp, name, file, multiple)
{
	//var nomcamp = document.editor.elements['data[Noticia][img]'];
	var nomcamp = document.editor.elements[camp];

	Nav=mira_nav();

	if(nomcamp.type=="text")
	{
		// text

		// Si es per insertar arxius, el primer valor es '/', s'ha de eliminar per redireccionar correctament
		if(file.substr(0,1)=="/") file = file.substr(1);
		
		document.getElementById(camp).value = file;
	}
	else
	{
		// select-multiple
		
		// Eliminem el primer carcter '/'
		file = file.substr(1)
		
		if (Nav=="Netscape")
		{
			var opcion = new Option(name,file,false,false);
			//opcion.setAttribute("ruta", file);
			if(multiple=="multiple") nomcamp.options[nomcamp.options.length]=opcion;
			else {
				nomcamp.options[0]=opcion;
				}
		}
		else
		{			
			var nou_camp=document.createElement("OPTION");
			nou_camp.text=name;
			nou_camp.value=file;
			//nou_camp.setAttribute("ruta", file);
			
			if(multiple=="multiple") nomcamp.options.add(nou_camp);
			else
			{
				nomcamp.remove(0);
				nomcamp.options.add(nou_camp);
			}
		}
		if(multiple!="multiple") {nomcamp.options[0].selected=true;nomcamp.focus();win.focus();}
	}
}

// FITXERS LLISTAT ---------------------------------------------------------


// CONTINGUTS LLISTAT ---------------------------------------------------------
// INSERTAR contiguts
var contenido_id = new Array(); 
function insertaContingut(camp, name, file)
{
	var nomcamp = document.editor.elements[camp];
	Nav=mira_nav();

	if (Nav=="Netscape")
	{
		var opcion = new Option(name,file,false,false);

		for(x=0;x<nomcamp.options.length;x++)
		{
			if (nomcamp.options[x].value==file)
			{
				var existeix=true;
				break;
			}
		}
		
		// No existeix
		if(!existeix) 
		{
			nomcamp.options[nomcamp.options.length]=opcion;
/*
			// Array de categories - noticies
			contenido_id[file]=new Array();
			contenido_id[file][contenido_id[file].length]=file;
*/			
		}
	}
	else
	{	
		var nou_camp=document.createElement("OPTION");
		
		nou_camp.text=name;
		nou_camp.value=file;
		
		for(x=0;x<nomcamp.length;x++)
		{
			if (nomcamp.options[x].value==file)
			{
				var existeix=true;
				break;
			}
		}
		if(!existeix) nomcamp.options.add(nou_camp);
	}
}

function esborra_contingut(camp)
{
	nav=mira_nav(); //Alert (nav);

	//numact = eval("document.editor."+camp+".options.length");
	numact = camp.length;
	nomcamp = camp;

	//alert (numact);
	//alert (document.editor.grup_activitat.selectedIndex);
	//Si no hi ha cap activitat, no fem res
	contenido_id = nomcamp.options[nomcamp.selectedIndex].value;
	
	if ((numact == 0) || ((numact != 0) && (nomcamp.selectedIndex==-1)))
	{
		document.editor.elimina.disabled;
		return numact;
	}	
	else
	{
		if (nav=="Netscape")
		{
			//document.editor.grup_activitat.options[document.editor.grup_activitat.selectedIndex].value="";
			//document.editor.grup_activitat.options[document.editor.grup_activitat.selectedIndex]=null;
			nomcamp.options[nomcamp.selectedIndex].value="";
			nomcamp.options[nomcamp.selectedIndex]=null;
		}
		else
		{
			//document.editor.grup_activitat.options.remove(document.editor.grup_activitat.selectedIndex);
			nomcamp.options.remove(nomcamp.selectedIndex);
		}

		//	alert(document.getElementById('newsletter_categorias').innerHTML);
		for (pp in categoria_contenido)
		{
			for(jj=0;jj<categoria_contenido[pp].length;jj++)
			{
				if(categoria_contenido[pp][jj]==contenido_id)
				{
					categoria_contenido[pp].splice(jj,1);
					if(categoria_contenido[pp].length==0)
					{
						categoria_contenido.splice(pp,1);
						id_opcion=optionId(document.getElementById('newsletter_categorias').options, pp);						
						if (nav=="Netscape")
						{
							//document.editor.grup_activitat.options[document.editor.grup_activitat.selectedIndex].value="";
							//document.editor.grup_activitat.options[document.editor.grup_activitat.selectedIndex]=null;
							document.getElementById('newsletter_categorias').options[id_opcion].value="";
							document.getElementById('newsletter_categorias').options[id_opcion]=null;
						}
						else
						{
							//document.editor.grup_activitat.options.remove(document.editor.grup_activitat.selectedIndex);
							document.getElementById('newsletter_categorias').options.remove(id_opcion);
						}
					}
				}
			}
		}
		
		return numact;
	}
}


// INSERTAR CATEGORIAS LLISTAT
var categoria_contenido = new Array(); 
function insertaCategoria(camp, name, file, noticia_id)
{
	//var nomcamp = document.editor.elements['data[Noticia][img]'];
	var nomcamp = document.editor.elements[camp];

	Nav=mira_nav();

	if (Nav=="Netscape")
	{
		var opcion = new Option(name,file,false,false);

		for(x=0;x<nomcamp.options.length;x++)
		{
			if (nomcamp.options[x].value==file)
			{
				var existeix=true;
				break;
			}
		}
		
		// No existeix la categoria
		if(!existeix) 
		{
			nomcamp.options[nomcamp.options.length]=opcion;
			
			// Array de categories - noticies
			categoria_contenido[file]=new Array();
			categoria_contenido[file][categoria_contenido[file].length]=noticia_id;
		}
		else
		{
			// Afegim un nou camp al array
			categoria_contenido[file][categoria_contenido[file].length]=noticia_id;
		}
	}
	else
	{			
		var nou_camp=document.createElement("OPTION");
		
		nou_camp.text=name;
		nou_camp.value=file;
		
		for(x=0;x<nomcamp.length;x++)
		{
			if (nomcamp.options[x].value==file)
			{
				var existeix=true;
				break;
			}
		}
		if(!existeix)
		{
			nomcamp.options.add(nou_camp);

			// Array de categories - noticies
			categoria_contenido[file]=new Array();
			categoria_contenido[file][categoria_contenido[file].length]=noticia_id;
		}
		else
		{
			// Afegim un nou camp al array
			categoria_contenido[file][categoria_contenido[file].length]=noticia_id;
		}
	}
}

function reset_contingut(contingut)
{
	nav=mira_nav(); //Alert (nav);
	nomcamp = document.getElementById(contingut);
	
	if (nav=="Netscape")
	{
		total = document.getElementById(contingut).length;
		for(var i=0;i<total;i++)
		{
			nomcamp.options[0].value="";
			nomcamp.options[0]=null;
		}
	}
	else
	{
		total = document.getElementById(contingut).length;
		for(var i=0;i<total;i++)
		{
			nomcamp.options.remove(0);
		}
		
	}
}
// CONTINGUTS LLISTAT ---------------------------------------------------------


// Seleccin de los desplegables de imgenes y ficheros, todos los select-multiple
function seleccionaTots()
{
	var flag_corrector=0;
    if(document.getElementById('correccion_ok'))
    {
        if(document.getElementById('correccion_ok').value!='1')
        {
            alert('Abans de desar, has de passar el corrector');
            flag_corrector=1;
        }
    }
    camps = document.editor.length;
	var categoria_ok=1;
	var hay_categoria_obligatoria=0;
	for(var i=0;i<camps;i++)
	{
		if(document.editor[i].type=="select-multiple")
		{
			if(document.editor[i].getAttribute("seleccionaTot"))
			{
				for(var j=0;j<document.editor[i].length;j++)
				{
					nom = document.getElementById(document.editor[i].id);
					nom.options[j].selected=true;
				}
			}
			if(document.editor[i].getAttribute("valida_select")!='null')
			{
				if(document.editor[i].getAttribute("obligatorio"))
				{
					var alguno_disabled=0;
					hay_categoria_obligatoria=1;
					for(var a=0;a<document.editor[i].length;a++)
					{
						if(!document.editor[i].options[a].disabled) alguno_disabled=1;
					}
					if(document.editor[i].selectedIndex==-1 && alguno_disabled)
					{
						categoria_ok=0;
					}
				}
			}
		}
	}
	if(flag_corrector)
    {
        document.editor.onsubmit=function(){return false;}
    }
    else
    {
        if(hay_categoria_obligatoria)
        {
    		if(categoria_ok)
    		{
    			if(validar(document.editor)==true) document.editor.submit();
    		}
    		else
    		{
        		//alert("Seleccioni una categoria");
    			document.editor.onsubmit=function(){return false;}
    		}
        }
    }
}


// Obrir finestra amb la imatge exacte
function PopupPic(sPicURL,path)
{ 
	window.open(path+"popup.htm?"+sPicURL, "", "resizable=1,HEIGHT=200,WIDTH=200");
}


// Obre la Foto al tamany exacte
var titulopordefecto = "Imatge ampliada";
var ventana;
var cont=0;

function ampliaFoto(imatge,titulo)
{
	if(cont==1)
	{
		ventana.close();
		ventana=null;
	}
	
	if(titulo==null) titulo = titulopordefecto;

	ventana=window.open('','ventana','resizable=yes,scrollbars=no')
	ventana.document.write('<html><head><title>' + titulo + '</title></head><body style="overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no" onUnload="opener.cont=0"><a href="#tancar" onClick="window.close();"><img border=0 alt="Tancar finestra" src="' + imatge + '" onLoad="opener.redimensionar(this.width, this.height)"></a>');
	ventana.document.close();
	cont++;
}

function redimensionar(ancho, alto)
{
	ventana.resizeTo(ancho+12,alto+28);
	//centra la ventana. Eliminar si no se quiere centrar el popup
	ventana.moveTo((screen.width-ancho)/2,(screen.height-alto)/2);
}



/*
 *
 * ***********************************************************************************************************************
 * A select box with some options
 * Written by
 * Krijn Hoetmer ~ http://ktk.xs4all.nl/
 * and
 * Paul Gration ~ http://i-labs.co.uk/
 * ***********************************************************************************************************************
 *
 */

function moveUp(element) {
  for(i = 0; i < element.options.length; i++) {
    if(element.options[i].selected == true) {
      if(i != 0) {
        var temp = new Option(element.options[i-1].text,element.options[i-1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i-1] = temp2;
        element.options[i-1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function moveDown(element) {
  for(i = (element.options.length - 1); i >= 0; i--) {
    if(element.options[i].selected == true) {
      if(i != (element.options.length - 1)) {
        var temp = new Option(element.options[i+1].text,element.options[i+1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i+1] = temp2;
        element.options[i+1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function updateList(list, textBox) {
  textBox.value = '';
  for(i = 0; i < list.options.length; i++) {
    if (i == 0) {
      textBox.value += list.options[i].value;
    } else {
      textBox.value += ',' + list.options[i].value;
    }
  }
}
function swap(list) {
  var j = 0;
  for(i = 0; i < list.options.length; i++) {
    if(list.options[i].selected == true) {
      j++;
      switch (j) {
        case 1:
        var i1 = i;
        var temp = new Option(list.options[i].text, list.options[i].value);
        break;
        case 2:
        var i2 = i;
        var temp2 = new Option(list.options[i].text, list.options[i].value);
        break;
      }
    }
  }
  if (j != 2) {
    alert('Noms dos items poden ser intercanviats');
  } else {
    list.options[i1] = temp2;
    list.options[i1].selected = true;
    list.options[i2] = temp;
    list.options[i2].selected = true;
  }
}
/*
 *
 * ***********************************************************************************************************************
 *
 */
 
 
 
 /*
 *
 * Script per moure o seleccionar el newsletter
 * ***********************************************************************************************************************
 *
 */
function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
   }
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
   }
   fbox.focus()
   if(fbox.length>0)fbox.options[0].selected=true
}
/*
 *
 * ***********************************************************************************************************************
 *
 */



/*
 * Script per ficheroseditor.php, editor de fitxers de imatges i documents
 */
function guardatexto(campo)
{
	// Comprovem que el camp dels fitxers estigui seleccionat per posar el text
	campo_seleccionado = document.getElementById(campo).selectedIndex;
	
	// Entra si esta seleccionado, sino campo_sleeccionado=-1
	if(campo_seleccionado>=0)
	{
		campo_selected_value = document.getElementById(campo).options[document.getElementById(campo).selectedIndex].value;
		//alert(campo_selected_value);
	
		text_value = document.getElementById("text_"+campo).value;
		//alert(text_value);
		
		// Mirem si ja te text la imatge (al modificar arxius)
		nom_imatge = campo_selected_value.split("~");
		
		if(nom_imatge[1]!=null)
		{
			// Modifica text
			// Posem el text al final del value del campo_selected_value		
			document.getElementById(campo).options[document.getElementById(campo).selectedIndex].value=nom_imatge[0]+'~'+text_value;
			//document.getElementById("text_"+campo).value = "";
		}
		else
		{
			// Inserta text
			// Posem el text al final del value del campo_selected_value		
			document.getElementById(campo).options[document.getElementById(campo).selectedIndex].value=campo_selected_value+'~'+text_value;
		}
	}
	else
	{
		arxius_insertats = document.getElementById(campo).length;

		if(arxius_insertats==0) alert("Ha d'adjuntar el fitxer per a poder insertar el text");
		else alert("Ha de sel.leccionar el fitxer per a poder insertar el text");
	}
}


function carga_imagen(campo,webroot)
{
	// Comprovem que el camp dels fitxers estigui seleccionat per posar la imatge
	campo_seleccionado = document.getElementById(campo).selectedIndex;

	// Entra si esta seleccionado, sino campo_seleccionado=-1
	if(campo_seleccionado>=0)
	{
		imatge_selected = document.getElementById(campo).options[document.getElementById(campo).selectedIndex].value;
		//alert(imatge_selected);
	
		// Posem la imatge al Preview
		nom_imatge = imatge_selected.split("~");
		
		imatge = nom_imatge[0];
		document.getElementById("PreviewImage_"+campo).src=webroot+imatge;

		if(nom_imatge[1]!=null) document.getElementById("text_"+campo).value=nom_imatge[1];
		else document.getElementById("text_"+campo).value="";
	}
}

function carga_documento(campo)
{
	// Comprovem que el camp dels fitxers estigui seleccionat per posar el text
	campo_seleccionado = document.getElementById(campo).selectedIndex;
	
	// Entra si esta seleccionado, sino campo_seleccionado=-1
	if(campo_seleccionado>=0)
	{
		documento_selected = document.getElementById(campo).options[document.getElementById(campo).selectedIndex].value;
		//alert(documento_selected);
	
		// Posem el text
		nom_text = documento_selected.split("~");
		
		if(nom_text[1]!=null) document.getElementById("text_"+campo).value=nom_text[1];
		else document.getElementById("text_"+campo).value="";
	}
}
/*
 ****************************************************************************************************************** 
 */
function roundNumber(rnum, rlength) {
	if (rnum > 8191 && rnum < 10485) {
		rnum = rnum-5000;
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		newnumber = newnumber+5000;
	} else {
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	}
	return newnumber;
}

function cambia_checkbox(nombre)
{
	if(document.getElementById(nombre).checked) document.getElementById(nombre).checked=false;
	else document.getElementById(nombre).checked=true;
}
function selecciona_tots_checkbox(nombre_form,activar)
{
	var todos;
	var i;
	todos=document.getElementById(nombre_form).elements;
	for(i=0;i<todos.length;i++)
	{
		if(todos[i].getAttribute('type')=='checkbox')
		{
			todos[i].checked=activar;
			el_tr=todos[i].parentNode.parentNode;
			if (activar) seleccionar(el_tr,1);
			else seleccionar(el_tr,2);
		}
	}
}

function get_checkbox_selected_by_name(nombre_form)
{
	var contador=0;
	var objeto;
	objeto=document.getElementById(nombre_form).elements;
	var i;
	for(i=0;i<objeto.length;i++)
	{
		if(objeto[i].getAttribute('type')=='checkbox') if(objeto[i].checked==true || objeto[i].checked=='true') contador++;
	}
	return contador;
}


/*
Funcions per a mostrar/amagar un fieldset amb un checkbox al legend
veure helper: html2->amagaCheckbox
*/

function mostrar_check(elemento,contador,nombre_check)
{
	elemento.style.display='none';
	document.getElementById('field_gran'+contador).style.display='block';
	nombre_check.checked=true;
}

function ocultar_check(elemento,contador,nombre_check,legend)
{
	test_existe=document.getElementById('field_peque'+contador);
	if(!test_existe)
	{
		field_peque=document.createElement('FIELDSET');
		legend_nuevo=document.createElement('LEGEND');
		legend_nuevo.innerHTML='<input class=checkbox type=checkbox contador='+contador+' id='+nombre_check+'_oculto name='+nombre_check+'_oculto onclick=\'mostrar_check(this.parentNode.parentNode,'+contador+','+nombre_check+');this.checked=false;\' ><label for='+nombre_check+'_oculto>'+legend+'</label>';
		field_peque.appendChild(legend_nuevo);
		field_peque.setAttribute('id','field_peque'+contador);
		elemento.parentNode.parentNode.setAttribute('id','field_gran'+contador);
		document.getElementById('field_gran'+contador).style.display='none';
		document.getElementById('field_gran'+contador).parentNode.insertBefore(field_peque,document.getElementById('field_gran'+contador));
	}
	else
	{
		document.getElementById('field_peque'+contador).style.display='block';
		document.getElementById('field_gran'+contador).style.display='none';
		document.getElementById(nombre_check).checked=false;
	}
}


/*
* JavaScript - Display and Visibility
* Ejemplos: visi('number1') o blocking('number1');
* <A CLASS="page" HREF="#" onClick="visi('number1'); return false">Toggle visible/invisible</A>
* <P CLASS="para" ID="number1"> .... </P>
*/
function visi(nr)
{
	if (document.layers)
	{
		vista = (document.layers[nr].visibility == 'hide') ? 'show' : 'hide'
		document.layers[nr].visibility = vista;
	}
	else if (document.all)
	{
		vista = (document.all[nr].style.visibility == 'hidden') ? 'visible'	: 'hidden';
		document.all[nr].style.visibility = vista;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.visibility == 'hidden') ? 'visible' : 'hidden';
		document.getElementById(nr).style.visibility = vista;

	}
}

function blocking(nr)
{
	if (document.layers)
	{
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	}
	else if (document.all)
	{
		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}


// La funcio getElementsByName no funciona per explorer, la definim:
if(typeof(window.external) != 'undefined')
{
	//yes, this is evil browser sniffing, but only IE has this bug
	document.getElementsByName = function(name, tag)
	{
		if(!tag) tag = '*';
		var elems = document.getElementsByTagName(tag);
		var res = []
		for(var i=0;i<elems.length;i++)
		{
			att = elems[i].getAttribute('name');
			if(att == name)
			{
				res.push(elems[i]);
			}
		}
		return res;
	}
}


/* Switch per mostrar/amagar entre ficheroseditor i ficherosexaminar */
function java_switch(identificador_link,id_div_editor,ids_divs_examinar)
{
    var value_flag;
    var value_foo;
    if(document.getElementById('javaswitch_nojava'+identificador_link).style.display=='none')
    {
        // Amagar uploader per java i mostrar examinar
        document.getElementById('javaswitch_nojava'+identificador_link).style.display='inline';
        document.getElementById('javaswitch_sijava'+identificador_link).style.display='none';
        //amagar examinar
        for(a=0;a<=(ids_divs_examinar.length-1);a++)
        {
            document.getElementById('div__'+ids_divs_examinar[a]).style.display='none';
            //intercanviem valors entre els flags i fooflags
            if(document.getElementById('foo_flag_'+ids_divs_examinar[a]))
            {
                value_flag=document.getElementById('flag_'+ids_divs_examinar[a]).value
                value_foo=document.getElementById('foo_flag_'+ids_divs_examinar[a]).value;
                document.getElementById('flag_'+ids_divs_examinar[a]).value=value_foo;
                document.getElementById('foo_flag_'+ids_divs_examinar[a]).value=value_flag;
            }
        }
        //mostrar uploader
        document.getElementById(id_div_editor).style.display='block';

    }
    else
    {
        // Amagar examinar i mostrar uploader per java
        document.getElementById('javaswitch_nojava'+identificador_link).style.display='none';
        document.getElementById('javaswitch_sijava'+identificador_link).style.display='inline';
        // mostrar examinar
        for(a=0;a<=(ids_divs_examinar.length-1);a++)
        {
            document.getElementById('div__'+ids_divs_examinar[a]).style.display='block';
            //intercanviem valors entre els flags i fooflags
            if(document.getElementById('foo_flag_'+ids_divs_examinar[a]))
            {
                value_flag=document.getElementById('flag_'+ids_divs_examinar[a]).value
                value_foo=document.getElementById('foo_flag_'+ids_divs_examinar[a]).value;
                document.getElementById('flag_'+ids_divs_examinar[a]).value=value_foo;
                document.getElementById('foo_flag_'+ids_divs_examinar[a]).value=value_flag;
            }
        }
        //amagar uploader
        document.getElementById(id_div_editor).style.display='none';
    }
}