// buscar des de qualsevol pàgina
//
 
function buscador()
  {
  var t=document.buscar.text.value;
  opcions="";
  if (t.length<=2)
    { alert("Aviso:\n\nDebe indicar un texto de más de 2 caracteres."); }
    else { document.buscar.submit(); }
    }

// gestió de capes/submenús
//
function mostrar(nomcapa) {
    document.getElementById(nomcapa).style.visibility="visible";
    setTimeout("amagar('"+nomcapa+"');",10000);
} 
function amagar(nomcapa)  {
    document.getElementById(nomcapa).style.visibility="hidden";
} 

//
// selecció full d'estils (mida de la font)
//
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

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 = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = 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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
//
//
// imatge en 360º
//
function DoAutorotationStart() { document.vista.startAutoPan( 0.3, 0.0, 1.0 ); }
function DoAutorotationStop() { document.vista.stopAutoPan(); }
function DoZoomIn() { document.vista.startAutoPan( 0.0, 0.0, 1/1.002 ); }
function DoZoomOut() { document.vista.startAutoPan( 0.0, 0.0, 1.002 ); }
function DoShowHideHotspots() {	document.vista.toggleHS(); }
function DoReset() { document.vista.gotoView( -45, -60, 80 ); }
function DisplayPan() {	status = document.vista.pan().toString() ; }
function DisplayTilt() { status = document.vista.tilt().toString() ; }
function DisplayFov() { status = document.vista.fov().toString() ; }
//
function mousehs(n) {
  if ( n== -1 ) document.cn.hsnum.value = "---" ;
    else document.cn.hsnum.value = n ;
}
function getview(p,t,f) {
  document.cn.pan.value = p ;
  document.cn.tilt.value = t ;
  document.cn.fov.value = f ;
}

function NewPano( pano ) {
  document.vista.newPano( pano );
  document.vista.start();
}
//
function passaparam(ii,d,m,a,sel) { //paràmetre cercar activitats agenda
	//ii=mes i any
	//d=dia
	//m=mes
	//a=any
	document.agenda.ii.value=ii;
	document.agenda.d.value=d;
	document.agenda.m.value=m;
	document.agenda.a.value=a;
	document.agenda.sel.value=sel;
	//
	document.agenda.submit();
}
//
function canvititolpagina(nomweb,titolpagina) {
  titolpagina = titolpagina.replace(/<[^>]+>/g,''); // eliminar les etiquetes html (per si n'hi ha)
  document.title = nomweb + ": " + titolpagina;
}
//