<!-- Original:  Eddie Traversa (psych3@primus.com.au) -->
<!-- Web Site:  http://nirvana.media3.net -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function verScroll(dir, spd, loop) {
loop = true;
direction = "up";
speed = 1;
scrolltimer = null;
if (document.layers) {
var page = eval(document.contentLayer);
}
else {
if (document.getElementById) {
var page= eval("document.getElementById('contentLayer').style");
}
else {
if (document.all) {
var page = eval(document.all.contentLayer.style);
      }
   }
}
direction = dir;
speed = parseInt(spd);
var y_pos = parseInt(page.top);
if (loop == true) {
if (direction == "dn") {
page.top = (y_pos - (speed));
} else {
if (direction == "up" && y_pos < 10) {
page.top = (y_pos + (speed));
} else {
if (direction == "top") {
page.top = 10;
      }
   }
}
scrolltimer = setTimeout("verScroll(direction,speed)", 50);
   }
}
function stopScroll() {
loop = false;
clearTimeout(scrolltimer);
}
//  End -->

// buscar des de qualsevol pàgina
//
function busca1()
  {
  var t=document.buscador1.text.value;
  opcions="&e=0";
  //
  if (t.length<=2)
    {
    alert("Avís:\n\nHeu d'indicar un text de més de 2 caràcters.")
    }
    else
      {
      var buscar="buscador.asp?text="+t+opcions;
      top.location.href=buscar;
      }
    }

// buscar des del propi buscador
//
function busca()
  {
  var t=document.buscador.text.value;
  opcions="";
  triats=0;
  if (document.buscador.plen.checked) triats++;
  if (document.buscador.inst.checked) triats++;
  if (document.buscador.acti.checked) triats++;
  if (document.buscador.fixe.checked) triats++;
  if (document.buscador.orde.checked) triats++;
  if (document.buscador.esta.checked) triats++;
  if (document.buscador.treb.checked) triats++;
  if (document.buscador.conc.checked) triats++;
  if (document.buscador.dire.checked) triats++;
  //
  if (t.length<=2 && triats==0)
    {
    alert("Avís:\n\nHeu d'indicar un text de més de 2 caràcters\nNo heu indicat per quin criteri volieu fer la cerca")
    }
    else
    {
    if (t.length<=2 && triats>1)
    {
    alert("Avís:\n\nHeu d'indicar un text de més de 2 caràcters\nPodeu deixar el text en blanc si només busqueu per un dels criteris")
    }
    else
      {
      //if (document.buscador.parc.checked) { opcions=opcions+"&parc=1"; }
      if (document.buscador.plen.checked) { opcions=opcions+"&plen=1"; }
      if (document.buscador.inst.checked) { opcions=opcions+"&inst=1"; }
      if (document.buscador.acti.checked) { opcions=opcions+"&acti=1"; }
      if (document.buscador.fixe.checked) { opcions=opcions+"&fixe=1"; }
      if (document.buscador.orde.checked) { opcions=opcions+"&orde=1"; }
      if (document.buscador.esta.checked) { opcions=opcions+"&esta=1"; }
      if (document.buscador.treb.checked) { opcions=opcions+"&treb=1"; }
      if (document.buscador.conc.checked) { opcions=opcions+"&conc=1"; }
      if (document.buscador.dire.checked) { opcions=opcions+"&dire=1"; }
      if (document.buscador.tots.checked) { opcions="&tots=1"; }
      var buscar="buscador.asp?text="+t+opcions;
      //top.location.href=buscar;
      document.buscador.submit();
      }
    }
    }

function buscaagenda()
{
var d =document.agenda.diai.value;
msg=""; errord=0; errorm=0; errora=0;
var t=document.agenda.tipus.options[document.agenda.tipus.selectedIndex].value;
var d =document.agenda.diai.value;
if (d<=0 || d>=32) errord=1;
m =document.agenda.mesi.value;
if (m<=0 || m>=13) errorm=1;
a=document.agenda.anyi.value;
if (a<=2003 || a>=2010) errora=1;

if (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) { if (d<=0 || d>=32) errord=1; }
if (m==4 || m==6 || m==9 || m==11) { if (d<=0 || d>=31) errord=1; }
if (m==2) { if (d<=0 || d>=30) errord=1; }
if (errord==1) msg=msg+"- Dia incorrecte\n";
if (errorm==1) msg=msg+"- Mes incorrecte\n";
if (errora==1) msg=msg+"- Any incorrecte\n";
if (d.length<2)  { d="0"+d }
if (m.length<2)  { m="0"+m }
i=m+"/"+d+"/"+a;
if (msg=="")
  { var buscar="agenda1.asp?t="+t+ "&i="+i ; top.location.href=buscar;
  }
  else { msg="Hi ha un error en la data indicada:\n\n"+msg; alert(msg); }
}

function buscaagenda1()
{
msg=""; errorm=0; errora=0;
var t=document.agenda.tipus.options[document.agenda.tipus.selectedIndex].value;
m =document.agenda.mes1.value;
if (m<=0 || m>=13) errorm=1;
a=document.agenda.any1.value;
if (a<=2004 || a>=2010) errora=1;

if (errorm==1) msg=msg+"- Mes incorrecte\n";
if (errora==1) msg=msg+"- Any incorrecte\n";
if (m.length<2)  { m="0"+m }
i=m+"/"+a;
if (msg=="")
  { var buscar="agenda1.asp?t="+t+ "&ii="+i ; top.location.href=buscar;
  }
  else { msg="Hi ha un error en la data indicada:\n\n"+msg; alert(msg); }
}

//
// 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);