
function visitas(Descripcio)
{
	var origen = document.referrer;
	document.write("<DIV style='position:absolute;top:1;left:1;width:10;height:10'>");
	document.write("<IMG SRC='/visites.asp?url=-1&web=-2&origen="+ origen.substring(0,100) + "&Pagina="+Descripcio+ "' alt='' title=''>")
	document.write("</DIV>");
}

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
	 //ahora =  eval(aux.substring(7, 10)) + " " + mes +" " + ano2
	 document.write('<FONT SIZE=1 FACE=Verdana>'+ ahora)
	 return ahora
	}

function pie ()
{
	document.write('<HR SIZE=3 COLOR=#CFDBE7 ALIGN=CENTER WIDTH=700 NOSHADE>')
	document.write('<TABLE BORDER=0 WIDTH="700">')
	document.write('<TR>')
	document.write('<TD ALIGN=CENTER CLASS="ptext">Copyright ©&nbsp;');
	document.write('<script>var Hora=new Date();');
  	document.write('document.write(Hora.getUTCFullYear())');
	document.write('</script>');
	document.write('&nbsp;Ajuntament de Sabadell</TD>')
	document.write('</TR>')
	document.write('</TABLE>')
	return false;
}


function displayWindow(theURL,winName,width,height,features)
{ 
	var window_width = width;
    var window_height = height;
    var newfeatures= features;
    var window_top = (screen.height-window_height)/2;
    var window_left = (screen.width-window_width)/2;
    newWindow=window.open(''+ theURL + '',''+ winName + '','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',features=' + newfeatures + '');
    newWindow.focus();
}

function valida (palabra)
{ 
  if (palabra == '')
   {
     alert('Falten paràmetres de cerca.');

   }
  else
     document.fcercador.submit();
}

function validaAvancada(palabra)
{
//	if (document.getElementById("Cercar"))
//		document.getElementById("Cercar").value = "1"
	var servei;
	var Categories;
	servei = document.getElementById("servei").value;

	if (servei != "agenda" && servei!= "tràmits" && servei != "directori" && servei != "notícies")
	{
		if (document.getElementById("Categories"))
		{
			if ((palabra == '') && (document.getElementById("Categories").value==''))
			{
				alert('Falten paràmetres de cerca.');			
				return;
			}
		}
	}
	else
	{
		if (document.getElementById("Cercar"))
			document.getElementById("Cercar").value = "1"
	}



	document.fcercador.submit();
}


function calendario(opcion)
{
	if ((opcion == "AGENDA") || (opcion == "NOTICIA"))
	{
		toggleT('divt2','s');
	}
	else
	{	
		toggleT('divt2','h');
	}
}

var isIE=document.all?true:false;
var isDOM=document.getElementById?true:false;
var isNS4=document.layers?true:false;

/* _w : which ID (1) or (2) */
/* _h : (h)ide or (s)how */
function toggleT(_w,_h) {
  if (isDOM)
  {
    if (_h=='s') document.getElementById(_w).style.visibility='visible';
    if (_h=='h') document.getElementById(_w).style.visibility='hidden';
  }
  else if (isIE) {
    if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
    if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
	
  }
  else if(isNS4)
  {
    if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
    if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
  }
}


function tecla()
{
  s=window.event.keyCode 
  if (s == 13)
  {
	  document.fcercador.submit();
  }

} 


function desplegable(x,y,cadena)
{
	var url = "./funcions/popup.asp?cad="+cadena
	window.open(url,"Formularis","top="+y+", left="+x+", dependent=yes,toolbar=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no width=200,height=200")
}

var zindex=100
var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ie4=document.all
var opr=navigator.userAgent.indexOf("Opera")

function DropMenu(e,menuname,opcions, Path)
{
	var i;
	var opc;
	var NOpcions;
	var sPath = "";
    var curmenuID;
// Agafem les opcions : Les opcions són parells d'elements:
//			opcion link	
// i tots separats per |
	opc = opcions.split(" | ");
	NOpcions = opc.length / 2;
	if (isDOM)
	{
      var menu = document.getElementById(menuname);
    }
	else if (isIE) {
	  var menu = eval("document.all."+menuname);
    }
    else if(isNS4)
    {
      var menu = eval("document.layers['"+menuname+"']");
    }

   	menu.innerHTML = "";


	if (document.all)
	menu.style.padding="4px"
	for (i=0;i<NOpcions*2;i=i+2)
	{
		sLink = Path + opc[i+1];
		menu.innerHTML = menu.innerHTML + "<a href=\""+sLink+"\">"+opc[i]+"</a><BR>";
	}

	if (document.layers)
	{
		document.menu.captureEvents(Event.CLICK)
		document.menu.onclick=hidemenu
	}

	//curmenuID=(ns6)? document.getElementById(menu).id : eval(menu).id;
	curmenuID = menu.id;

	if (window.themenu&&themenu.id!=curmenuID)
		themenuStyle.visibility=ns4?"hide" : "hidden"
    
	//Oscarthemenu=ns6? document.getElementById(menu): eval(menu)
	themenu = eval(menu);
	//OscarthemenuStyle=(ns6||ie4)? themenu.style : themenu
    themenuStyle = themenu.style;
	themenuoffsetX=(ie4&&opr==-1)? document.body.scrollLeft : 0
	themenuoffsetY=(ie4&&opr==-1)? document.body.scrollTop : 0

	themenuStyle.left=ns6||ns4? e.pageX-e.layerX : themenuoffsetX+event.clientX-event.offsetX
	themenuStyle.top=ns6||ns4? e.pageY-e.layerY+19 : themenuoffsetY+event.clientY-event.offsetY+18

	hiddenconst=(ns6||ie4)? "hidden" : "hide"
	if (themenuStyle.visibility==hiddenconst)
	{
		themenuStyle.visibility=(ns6||ie4)? "visible" : "show"
		themenuStyle.zIndex=zindex++
	}
	else
		hidemenu()
	return false
}

function hidemenu()
{
	if ((ie4||ns6)&&window.themenu)
		themenuStyle.visibility="hidden"
	else if (ns4)
		themenu.visibility="hide"
}


function GetFechaPrimerDiaSemana(Fecha)
{

}

function GetFechaUltimDiaSemana(Fecha)
{

}

function ObtenirCodificador(CodSencer)
{
	var Cod;
	var ind = 0;
	var Trobat = false;
	
	Cod = CodSencer;
	do
	{
		if (Cod.substr(ind, 3) == "000")
			Trobat = true;
		else
			ind = ind + 3;
	}
	while ((ind < 24) && (!Trobat));
	
	if (Trobat) 
		Cod = Cod.substr(0, ind);
	return Cod;
}

	

function ObtenirIdioma()
{
 var radio = document.forms["fcercador"].elements["radioIdioma"];
 if (radio)
 {
	 for (var loop=0; loop<radio.length; loop++) 
	 {
	  if (radio[loop].checked)
	  {
		  return(radio[loop].value);
	  }
	  //return 1; //Per defecte IdiomaActual del Cercador
     }
 }  
}

//Funció que retorna el index selected d'un radio button
function showindex(group) {
                eg = document.getElementsByName(group);
                for (i=0; i<eg.length; i++) {
                        if (eg.item(i).checked) {
                                return eg.item(i).value;
                        }
                }       
        }

//Funció que retorna el tipus d'un input
function tellType(ele) {
    var theType ='';
    if (typeof ele.length != 'undefined') {
        theType = ele[0].type;
    } else {
		theType = ele.type;
    } 
	return theType;
}

//'VersioIdiom
//Funció que fa una redirecció a una url al clickar un item del menú.
//Paràmetres d'entrada: url (nova url)
//                      Idioma: Idioma actiu (valor d'el radio button fins el moment)  
/*function MenuClick(url, Idioma) {
	var type = tellType(document.fcercador.Id);
	if (type == "radio")
	{
		//radioindex index del radio buttom selected 
		var radioindex = showindex('Id');
        var eg = document.getElementsByName('Id');
    	var pos = url.indexOf("?");
		if (pos != -1)
    		window.location.replace(url+'&Id='+eg[radioindex].value)
        else
			window.location.replace(url+'?Id='+eg[radioindex].value)
	}
	else //Case type=hidden (per conservar el valor del Idioma en cas d'enviar el formulari)
    {
		var pos = url.indexOf("?");
		if (pos != -1)
				window.location.replace(url+'&Id='+Idioma)
			else
				window.location.replace(url+'?Id='+Idioma)
	}
}*/

