// FUNCIONES GENERICAS

// TiraWebTitulo(titulo, color)
// PieDePagina(fecha, visitas) 
// sobre(src,Color) 
// fuera(src,Color2) 
// pulsar(src)
// BeginMenu(ancho, color_borde) 
// ItemMenu(nombre, url, target, img_url, img_width, img_height, label, color_celda, color_link, fuente, tamany, color_letra)
// EndMenu()
// BeginBarra(titulo, color_borde, color_tabla) 
// ItemBarra(nombre, url, target, anchocelda, img_url, img_width, img_height, label, color_celda, color_link, fuente, tamany, color_letra)
// EndBarra()
// Item()
// Fecha() 
// IrBuscador()
// Telefons()
// Trim(texto)

function TiraWebTitulo(titulo, color) 
	{
	 document.write('<TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 cellpadding=0 bgcolor="#' + color + '">');
	 document.write('<TR><TD ALIGN="RIGHT"><B>' + titulo + '&nbsp;</B></TD></TR>');
	 document.write('</TABLE>');
	}

function PieDePagina(fecha, visitas) 
	{
	 document.write('<TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 cellpadding=0 bgcolor="#810043">');
	 document.write('<TR>');
	 document.write('<TD CLASS="fuente">&nbsp;&copy; 2002 Ajuntament de Sabadell</TD>');
	 document.write('<TD CLASS="fecha">Actualització: ' + fecha + '&nbsp;&nbsp; Visites: ' + visitas + '</TD>');
	 document.write('</TR>');
	 document.write('</TABLE>');
	}

function sobre(src, Color) 
	{
	  if (!src.contains(event.fromElement)) 
		  {
			  src.style.cursor = 'hand';
			  src.bgColor = Color;
		  }
	}

function fuera(src, Color2) 
	{
	  if (!src.contains(event.toElement)) 
		  {
			src.style.cursor = 'default';
			src.bgColor = Color2;
		   }
	}

function pulsar(src) 
	{
      if(event.srcElement.tagName=='TD')
		  {
			src.children.tags('A')[0].click();
		   }
	}

function BeginMenu(ancho, color_borde) 
	{
		document.write('<TABLE WIDTH="' + ancho + '" CELLPADDING="1" BGCOLOR="#' + color_borde + '" CLASS="BeginMenu">');
	}

function ItemMenu(nombre, url, target, img_url, img_width, img_height, label, color_celda, color_link, fuente, tamany, color_letra, estilo)
	{
	 if (estilo == 0) { document.write('<TR CLASS="ItemMenuTR"><TD onClick="pulsar(this)" onMouseOut="fuera(this,') }
	  else { document.write('<TR CLASS="ItemMenuTR"><TD CLASS="ItemMenu" onClick="pulsar(this)" onMouseOut="fuera(this,') }
	 document.write("'#");
	 document.write(color_celda);
	 document.write("'");
	 document.write(');" onMouseOver="sobre(this,');
	 document.write("'#");
	 document.write(color_link);
	 document.write("'");
	 document.write(');" BGCOLOR="#' + color_celda + '"><A CLASS="menu" HREF="');
	 document.write(url+'"');
	 if (target == "_blank") { document.write('TARGET="' + target + '"'); }
	 document.write('><FONT FACE="' + fuente + '" SIZE="' + tamany + '" COLOR="#' + color_letra + '">');
	 if (label != "") { document.write('<ACRONYM TITLE="' + label + '">'); }
	 if (img_url != "") { document.write('<IMG SRC="' + img_url + '" WIDTH="' + img_width + '" HEIGHT="' + img_height + '" BORDER="0">'); }
	 document.write(' ' + nombre);
	 if (label != "") { document.write('</ACRONYM>'); }
	 document.write('</FONT></A></TD></TR>');
   }

function EndMenu()
	{
		document.write('</TABLE>');
	}

function BeginBarra(ancho, titulo, color_borde, color_tabla) 
	{
	  if (! titulo) {titulo = '';}
	  document.write('<TABLE WIDTH="100%" BGCOLOR="#' + color_borde + '" CLASS="BeginBarra"><TR>');
	  document.write('<TD WIDTH="' + ancho + '" VALIGN="bottom" BGCOLOR="#' + color_tabla + '">' + titulo + '</TD>');
	}

function ItemBarra(nombre, url, target, anchocelda, img_url, img_width, img_height, label, color_celda, color_link, fuente, tamany, color_letra, estilo)
	{
	 if (estilo == 0) {document.write('<TD onClick="pulsar(this)" onMouseOut="fuera(this,') }
	   else {document.write('<TD CLASS="ItemBarra" onClick="pulsar(this)" onMouseOut="fuera(this,') }	
	 document.write("'#");
	 document.write(color_celda);
	 document.write("'");
	 document.write(');" onMouseOver="sobre(this,');
	 document.write("'#");
	 document.write(color_link);
	 document.write("'");
	 document.write(');" BGCOLOR="#' + color_celda + '" WIDTH="' + anchocelda + '"><DIV ALIGN="center"><A CLASS="menu" HREF="');
	 document.write(url+'"');
	 if (target == "_blank") { document.write('target="' + target + '"'); }
	 document.write('><FONT FACE="' + fuente + '" SIZE="' + tamany + '" COLOR="#' + color_letra + '">');
	 if (label != "") { document.write('<ACRONYM TITLE="' + label + '">'); }
	 if (img_url != "") { document.write('<IMG SRC="' + img_url + '" WIDTH="' + img_width + '" HEIGHT="' + img_height + '" BORDER="0">'); }
	 document.write(' ' + nombre);
	 if (label != "") { document.write('</ACRONYM>'); }
	 document.write('</FONT></A></DIV></TD>');
	}

function EndBarra()
	{
	 document.write('</TR></TABLE>');
	}

function Item()
	{
		this.length = Item.arguments.length 
		for (var i = 0; i < this.length; i++)
		  this[i] = Item.arguments[i]
	}

function Fecha() 
	{
	 var ndia = new Item('diumenge','dilluns','dimarts','dimecres','dijous','divendres','dissabte');
	 var nmes = new Item('de gener','de febrer','de març','d´abril','de maig','de juny','de juliol','d´agost','de setembre','d´octubre','de novembre','de desembre')
	 var ahora
	 var fecha = new Date()
	 var ano = fecha.getYear()
	 var mes = fecha.getMonth()
	 var dia = fecha.getDay()
	 var aux = "" + fecha

	 if (ano<10) { ano2 = "200" + eval(ano) }
	 else if (ano<80) // ano tiene 2 dígitos 19xx (más de 80)
			{
			  ano2 = "20" + ano
			} 
		  else if (ano<=99) // ano tiene 2 dígitos 20xx (menor de 80)
					{
					 ano2 = "19" + ano
					}
				else if (ano<1000) // ano tiene 3 dígitos (100 es 2000)
						{
						 ano2 = eval(ano) + eval(1900)
						}
					  else // ano tiene 4 dígitos 
						  {
					 		ano2 = ano
						  }
	 ahora = ndia[dia] + ", " + eval(aux.substring(7, 10)) + " " + nmes[mes] + " del " + ano2
	 return ahora
	}

function IrBuscador()
	{
	  var comprovar = paso.value;	
	  if (comprovar.length >= 3) 
		  {
			document.fDatos.palabra.value = paso.value;
			document.fDatos.submit();
		  }
	  else if (comprovar.length == 0) 
				{
				window.location.href='http://laintranet/intranetajsab/buscador/cerca_avanzada.htm';
				}
			else { alert ("La paraula ha de ser com a mínim de 3 caràters.") }
	}

function Telefons()
	{
	  var comprovar = paso.value;	
	  if (comprovar.length >= 3) {
		window.location.href='http://laintranet/intranetajsab/scripts/telefons_ado.exe/pernom?cognom1='+paso.value+'&cognom2=&B1=Cerca';
	  }
	  else { alert ("La paraula ha de ser com a mínim de 3 caràters.") }
	}

function Trim(texto)
	{
     var newtext = String(texto);
     var letra;    

     // por la derecha
     letra = newtext.substring(newtext.length - 1, newtext.length);
     while(letra == ' ' && newtext.length > 0)
	 {
  		 newtext = newtext.substring(0, newtext.length - 1); 
		 letra = newtext.substring(newtext.length - 1, newtext.length);
	 }

    // por la izda
    letra = newtext.substring(0, 1);
    while(letra == ' ' && newtext.length > 0)
	{
		newtext = newtext.substring(1, newtext.length);
		letra = newtext.substring(0, 1)
	} 
    return newtext;
  }

function PosarTitol(titol, adreca)
	{
	  if (Trim(titol) == "") { document.write("<H2>&nbsp;</H2>") }
		else { document.write('<H2><SPAN CLASS="onepix">&nbsp;&nbsp;' + titol + '</SPAN></H2>') }
	}
