// -----------------------------------------------------------------------------
//	Copyright © Viatgeaddictes.com
//	All Rights Reserved. We will take legal action against those who 
//	copy our HTML content, CSS style sheets and JavaScript functions.
// -----------------------------------------------------------------------------

// Canvi d'idioma
function canviIdioma (pagina, nouIdioma)
{
  dir = pagina + "?nl=" + nouIdioma;
  window.location.href = dir;
}

// Impressió
function imprimir()
{
  if (window.print)
      window.print()
  else
    alert ("Disculpe, su navegador no soporta esta opción.");
}

// Correu
function correu (nom,domini,stext)
{
  document.write ('<a class="mail" href=\"mailto:'+nom+'@'+domini+'\" target="_self" alt=\"'+nom+'@'+domini+'\" title=\"'+nom+'@'+domini+'\">');
  if (stext)
	 document.write (stext+'</a>');
  else
	 document.write (nom+'@'+domini+'</a>');
}

// Enviar
function enviar()
{
  str = "mailto:?subject= Envío de página de Viatgeaddictes.com";
  str += "&body= Título: " + document.title;
  str += " -- Leer página en: " + location.href; 
  location.href = str;
}

// Caixes amb les cantonades arrodonides
function caixaR (ample,ccap1,ccap2,ecap,tcap,cpeu1,cpeu2,epeu,tpeu,linia)
{
  document.write ('<div style="width:'+ample+'px">');
  document.write ('<div style="height:1px;margin-left:2px;margin-right:2px;border-left:1px solid '+ccap2+'; border-right:1px solid '+ccap2+';background-color:'+ccap2+';"><!-- --></div>');
  document.write ('<div style="height:1px;margin-left:1px;margin-right:1px;border-left:1px solid '+ccap2+'; border-right:1px solid '+ccap2+';background-color:'+ccap1+';"><!-- --></div>');
  document.write ('<div style="border-left:1px solid '+ccap2+'; border-right:1px solid '+ccap2+'; background-color:'+ccap1+'; padding:3px;'+ecap+'">'+tcap+'</div>');

  if (linia) document.write ('<div style="margin:0 0 1px 0;"></div>');

  if (tpeu != '') {
	document.write ('<div style="border-left:1px solid '+cpeu2+'; border-right:1px solid '+cpeu2+'; background-color:'+cpeu1+';'+epeu+';padding:3px;">'+tpeu+'</div>');
  }
  document.write ('<div style="height:1px;margin-left:1px;margin-right:1px;border-left:1px solid '+cpeu2+'; border-right:1px solid '+cpeu2+';background-color:'+cpeu1+';"><!-- --></div>');
  document.write ('<div style="height:1px;margin-left:2px;margin-right:2px;border-left:1px solid '+cpeu2+'; border-right:1px solid '+cpeu2+';background-color:'+cpeu2+';"><!-- --></div>');
  document.write ('</div>');
}


// Estadístiques web
function estadxt()
{
  // Google Analytics
//  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
//  document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
//  var pageTracker = _gat._getTracker("UA-4985390-1");
//  pageTracker._trackPageview();
}


function textVertical (msg)
{
  cont =0;
  while (cont<msg.length)
  {
    letra = msg.substring(cont,cont+1)
    document.write(letra+"<br>")
    cont+=1
  } 
}


// Mostrar un mapa 
function mmapa (nom,desc,x,y,xp,yp,idioma,i1,i2,i3,i4,i5)
{
  document.write ('<a href="JavaScript:' + "mmapa_w ('" + nom + "','"+ desc + "'," + x + "," + y + ",'" + idioma + "'");
  if (i1) document.write (',1'); else document.write (',0');
  if (i2) document.write (',1'); else document.write (',0');
  if (i3) document.write (',1'); else document.write (',0');
  if (i4) document.write (',1'); else document.write (',0');
  if (i5) document.write (',1'); else document.write (',0');
  document.write (")" +'" target="_self">');
  document.write ('<img src="'+nom+'" border=0 width='+xp+' height='+yp+' alt="'+desc+'" title="'+desc+'" class="foto" /></a>');
}


// Mostrar un mapa (subfunció)
function mmapa_w (nom,desc,x,y,idioma,l1,l2,l3,l4,l5)
{
  var y1 = y - (-23);
  msg = 'toolbar=no,location=no,directories=no,scrollbars=no,status=no,resizable=yes,width='+x+',height='+y1+',menubar=no';
  objWin = window.open ('','foto',msg,false);
  estil = "<style>.llegm {font-weight:bold;font-size:7pt;font-family:Tahoma;text-align:center;}</style>";
  msg = '<HEAD><TITLE>' + desc + '</TITLE>' + estil + '</HEAD>';
  objWin.document.write (msg);
  msg = '<BODY topmargin=0 leftmargin=0 marginheight=0 marginwidth=0>';
  objWin.document.write (msg);

  msg = '<table style="background-color:#A4A4A4; width:'+x+'px; font-family: Verdana,Arial,Helvetica; font-size: 7.5pt;border-bottom:1px solid #000000" cellpadding=5 cellspacing=0><tr><td style="background-color:#f5deb3;color:#7A7A7A"><center><b>Mapa ruta</td>'
  if (idioma == "ca") { t1 = 'Avió'; t2 = 'Autobús/Cotxe'; t3 = 'Vaixell'; t5 = 'A peu/Bicicleta'; }
  else { t1 = 'Avión'; t2 = 'Autobús/Coche'; t3 = 'Barco'; t5 = 'A pie/Bicicleta'; }

  if (l1) { msg = msg + '<td><div class="llegm" style="color:#FFFFFF;">__ ' + t1 + '</div></td>'; }
  if (l2) { msg = msg + '<td><div class="llegm" style="color:#FFFF00">__ ' + t2 + '</div></td>'; }
  if (l3) { msg = msg + '<td><div class="llegm" style="color:#00FFFF">__ ' + t3 + '</div></td>'; }
  if (l4) { msg = msg + '<td><div class="llegm" style="color:#FF0000">__ Tren</div></td>'; }
  if (l5) { msg = msg + '<td><div class="llegm" style="color:#00ff00">__ ' + t5 + '</div></td>'; }

  msg = msg + '</tr></table><div><img src=' + nom + ' width=' + x + ' height=' + y +' alt='+desc+' /></div></BODY>'
  objWin.document.write (msg);
  objWin.document.close ();
}

// -------------------------------------------------------------------
// Image Thumbnail Viewer (http://www.dynamicdrive.com)
// -------------------------------------------------------------------

var thumbnailviewer={
enableTitle: true, 
enableAnimation: true,
definefooter: '<div class="footerbar">[x]</div>', 
defineLoading: '<img src="/img/working.gif" />', 
scrollbarwidth: 16,
opacitystring: 'filter:progid:DXImageTransform.Microsoft.alpha(opacity=10); -moz-opacity: 0.1; opacity: 0.1',
targetlinks:[], //Array to hold links with rel="thumbnail"

createthumbBox:function(){
//write out HTML for Image Thumbnail Viewer plus loading div
document.write('<div id="thumbBox" onclick="thumbnailviewer.closeit()"><div id="thumbImage"></div>'+this.definefooter+'</div>')
document.write('<div id="thumbLoading">'+this.defineLoading+'</div>')
this.thumbBox=document.getElementById("thumbBox")
this.thumbImage=document.getElementById("thumbImage") //Reference div that holds the shown image
this.thumbLoading=document.getElementById("thumbLoading") //Reference "loading" div that will be shown while image is fetched
this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
},

centerDiv:function(divobj){ //Centers a div element on the page
var ie=document.all && !window.opera
var dom=document.getElementById
var scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
var scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset
var docwidth=(ie)? this.standardbody.clientWidth : window.innerWidth-this.scrollbarwidth
var docheight=(ie)? this.standardbody.clientHeight: window.innerHeight
var docheightcomplete=(this.standardbody.offsetHeight>this.standardbody.scrollHeight)? this.standardbody.offsetHeight : this.standardbody.scrollHeight //Full scroll height of document
var objwidth=divobj.offsetWidth //width of div element
var objheight=divobj.offsetHeight //height of div element
var topposition=(docheight>objheight)? scroll_top+docheight/2-objheight/2+"px" : scroll_top+10+"px" //Vertical position of div element: Either centered, or if element height larger than viewpoint height, 10px from top of viewpoint
divobj.style.left=docwidth/2-objwidth/2+"px" //Center div element horizontally
divobj.style.top=Math.floor(parseInt(topposition))+"px"
divobj.style.visibility="visible"
},

showthumbBox:function(){ //Show ThumbBox div
this.centerDiv(this.thumbBox)
if (this.enableAnimation){ //If fading animation enabled
this.currentopacity=0.1 //Starting opacity value
this.opacitytimer=setInterval("thumbnailviewer.opacityanimation()", 20)
}},

loadimage:function(link){ //Load image function that gets attached to each link on the page with rel="thumbnail"
if (this.thumbBox.style.visibility=="visible") //if thumbox is visible on the page already
this.closeit() //Hide it first (not doing so causes triggers some positioning bug in Firefox
var imageHTML='<img src="'+link.getAttribute("href")+'" style="'+this.opacitystring+'" />' //Construct HTML for shown image
if (this.enableTitle && link.getAttribute("title")) //Use title attr of the link as description?
imageHTML+='<br /><center><b>'+link.getAttribute("title")+'<b></center>'
this.centerDiv(this.thumbLoading) //Center and display "loading" div while we set up the image to be shown
this.thumbImage.innerHTML=imageHTML //Populate thumbImage div with shown image's HTML (while still hidden)
this.featureImage=this.thumbImage.getElementsByTagName("img")[0] //Reference shown image itself
this.featureImage.onload=function(){ //When target image has completely loaded
thumbnailviewer.thumbLoading.style.visibility="hidden" //Hide "loading" div
thumbnailviewer.showthumbBox() //Display "thumbbox" div to the world!
}
if (document.all && !window.createPopup) //Target IE5.0 browsers only
this.featureImage.src=link.getAttribute("href")
this.featureImage.onerror=function(){ //If an error has occurred while loading the image to show
thumbnailviewer.thumbLoading.style.visibility="hidden" //Hide "loading" div, game over
}},

setimgopacity:function(value){ //Sets the opacity of "thumbimage" div per the passed in value setting (0 to 1 and in between)
var targetobject=this.featureImage
if (targetobject.filters && targetobject.filters[0]){ //IE syntax
if (typeof targetobject.filters[0].opacity=="number") //IE6
targetobject.filters[0].opacity=value*100
else //IE 5.5
targetobject.style.filter="alpha(opacity="+value*100+")"
}
else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
targetobject.style.MozOpacity=value
else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
targetobject.style.opacity=value
else //Non of the above, stop opacity animation
this.stopanimation()
},

opacityanimation:function(){ //Gradually increase opacity function
this.setimgopacity(this.currentopacity)
this.currentopacity+=0.1
if (this.currentopacity>1)
this.stopanimation()
},

stopanimation:function(){
if (typeof this.opacitytimer!="undefined")
clearInterval(this.opacitytimer)
},

closeit:function(){ //Close "thumbbox" div function
this.stopanimation()
this.thumbBox.style.visibility="hidden"
this.thumbImage.innerHTML=""
this.thumbBox.style.left="-2000px"
this.thumbBox.style.top="-2000px"
},

cleanup:function(){ //Clean up routine on page unload
this.thumbLoading=null
if (this.featureImage) this.featureImage.onload=null
this.featureImage=null
this.thumbImage=null
for (var i=0; i<this.targetlinks.length; i++)
this.targetlinks[i].onclick=null
this.thumbBox=null
},

dotask:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
},

init:function(){ //Initialize thumbnail viewer script by scanning page and attaching appropriate function to links with rel="thumbnail"
if (!this.enableAnimation)
this.opacitystring=""
var pagelinks=document.getElementsByTagName("a")
for (var i=0; i<pagelinks.length; i++){ //BEGIN FOR LOOP
if (pagelinks[i].getAttribute("rel") && pagelinks[i].getAttribute("rel")=="thumbnail"){ //Begin if statement
pagelinks[i].onclick=function(){
thumbnailviewer.stopanimation() //Stop any currently running fade animation on "thumbbox" div before proceeding
thumbnailviewer.loadimage(this) //Load image
return false
}
this.targetlinks[this.targetlinks.length]=pagelinks[i] //store reference to target link
} //end if statement
} //END FOR LOOP
//Reposition "thumbbox" div when page is resized
this.dotask(window, function(){if (thumbnailviewer.thumbBox.style.visibility=="visible") thumbnailviewer.centerDiv(thumbnailviewer.thumbBox)}, "resize")
}}

thumbnailviewer.createthumbBox() //Output HTML for the image thumbnail viewer
thumbnailviewer.dotask(window, function(){thumbnailviewer.init()}, "load") //Initialize script on page load
thumbnailviewer.dotask(window, function(){thumbnailviewer.cleanup()}, "unload")


// Finestra per a enviar correu
function newWindow (mypage,myname,w,h,features) 
{
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}


/*
 Automatic, anti-aliased rounded corners.
 By Steven Wittens
 Based on http://pro.html.it/esempio/nifty/
*/
function NiftyCheck() {
  if(!document.getElementById || !document.createElement) {
    return false;
  }
  var b = navigator.userAgent.toLowerCase();
  if (b.indexOf("msie 5") > 0 && b.indexOf("opera") == -1) {
    return false;
  }
  return true;
}

function Rounded(selector, bk, color, sizex, sizey) {
  var i;
  var v = getElementsBySelector(selector);
  var l = v.length;
  for (i = 0; i < l; i++) {
    AddTop(v[i], bk, color, sizex, sizey);
    AddBottom(v[i], bk, color, sizex, sizey);
  }
}

Math.sqr = function (x) {
  return x*x;
};

function Blend(a, b, alpha) {
  var ca = Array(
    parseInt('0x' + a.substring(1, 3)), 
    parseInt('0x' + a.substring(3, 5)), 
    parseInt('0x' + a.substring(5, 7))
  );
  var cb = Array(
    parseInt('0x' + b.substring(1, 3)), 
    parseInt('0x' + b.substring(3, 5)), 
    parseInt('0x' + b.substring(5, 7))
  );
  r = '0' + Math.round(ca[0] + (cb[0] - ca[0])*alpha).toString(16);
  g = '0' + Math.round(ca[1] + (cb[1] - ca[1])*alpha).toString(16);
  b = '0' + Math.round(ca[2] + (cb[2] - ca[2])*alpha).toString(16);
  return '#'
    + r.substring(r.length - 2)
    + g.substring(g.length - 2)
    + b.substring(b.length - 2);
}

function AddTop(el, bk, color, sizex, sizey) {
  var i, j;
  var d = document.createElement("div");
  d.style.backgroundColor = bk;
  d.className = "rounded";
  var lastarc = 0;
  for (i = 1; i <= sizey; i++) {
    var coverage, arc2, arc3;
    // Find intersection of arc with bottom of pixel row
    arc = Math.sqrt(1.0 - Math.sqr(1.0 - i / sizey)) * sizex;
    // Calculate how many pixels are bg, fg and blended.
    var n_bg = sizex - Math.ceil(arc);
    var n_fg = Math.floor(lastarc);
    var n_aa = sizex - n_bg - n_fg;
    // Create pixel row wrapper
    var x = document.createElement("div");
    var y = d;
    x.style.margin = "0px " + n_bg +"px";
    // Make a wrapper per anti-aliased pixel (at least one)
    for (j = 1; j <= n_aa; j++) {
      // Calculate coverage per pixel
      // (approximates circle by a line within the pixel)
      if (j == 1) {
        if (j == n_aa) {
          // Single pixel
          coverage = ((arc + lastarc) * .5) - n_fg;
        }
        else {
          // First in a run
          arc2 = Math.sqrt(1.0 - Math.sqr(1.0 - (n_bg + 1) / sizex)) * sizey;
          coverage = (arc2 - (sizey - i)) * (arc - n_fg - n_aa + 1) * .5;
        }
      }
      else if (j == n_aa) {
        // Last in a run
        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
        coverage = 1.0 - (1.0 - (arc2 - (sizey - i))) * (1.0 - (lastarc - n_fg)) * .5;
      }
      else {
        // Middle of a run
        arc3 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j) / sizex)) * sizey;
        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
        coverage = ((arc2 + arc3) * .5) - (sizey - i);
      }
      
      x.style.backgroundColor = Blend(bk, color, coverage);
      y.appendChild(x);
      y = x;
      var x = document.createElement("div");
      x.style.margin = "0px 1px";
    }
    x.style.backgroundColor = color;
    y.appendChild(x);
    lastarc = arc;
  }
  el.insertBefore(d, el.firstChild);
}

function AddBottom(el, bk, color, sizex, sizey) {
  var i, j;
  var d = document.createElement("div");
  d.className = "rounded";
  d.style.backgroundColor = bk;
  var lastarc = 0;
  for (i = 1; i <= sizey; i++) {
    var coverage, arc2, arc3;
    // Find intersection of arc with bottom of pixel row
    arc = Math.sqrt(1.0 - Math.sqr(1.0 - i / sizey)) * sizex;
    // Calculate how many pixels are bg, fg and blended.
    var n_bg = sizex - Math.ceil(arc);
    var n_fg = Math.floor(lastarc);
    var n_aa = sizex - n_bg - n_fg;
    // Create pixel row wrapper
    var x = document.createElement("div");
    var y = d;
    x.style.margin = "0px " + n_bg + "px";
    // Make a wrapper per anti-aliased pixel (at least one)
    for (j = 1; j <= n_aa; j++) {
      // Calculate coverage per pixel
      // (approximates circle by a line within the pixel)
      if (j == 1) {
        if (j == n_aa) {
          // Single pixel
          coverage = ((arc + lastarc) * .5) - n_fg;
        }
        else {
          // First in a run
          arc2 = Math.sqrt(1.0 - Math.sqr(1.0 - (n_bg + 1) / sizex)) * sizey;
          coverage = (arc2 - (sizey - i)) * (arc - n_fg - n_aa + 1) * .5;
        }
      }
      else if (j == n_aa) {
        // Last in a run
        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
        coverage = 1.0 - (1.0 - (arc2 - (sizey - i))) * (1.0 - (lastarc - n_fg)) * .5;
      }
      else {
        // Middle of a run
        arc3 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j) / sizex)) * sizey;
        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
        coverage = ((arc2 + arc3) * .5) - (sizey - i);
      }
      
      x.style.backgroundColor = Blend(bk, color, coverage);
      y.insertBefore(x, y.firstChild);
      y = x;
      var x = document.createElement("div");
      x.style.margin = "0px 1px";
    }
    x.style.backgroundColor = color;
    y.insertBefore(x, y.firstChild);
    lastarc = arc;
  }
  el.appendChild(d);
}

function getElementsBySelector(selector) {
  var i;
  var s = [];
  var selid = "";
  var selclass = "";
  var tag = selector;
  var objlist = [];
  if (selector.indexOf(" ") > 0) {  //descendant selector like "tag#id tag"
    s = selector.split(" ");
    var fs = s[0].split("#");
    if (fs.length == 1) {
      return objlist;
    }
    return document.getElementById(fs[1]).getElementsByTagName(s[1]);
  }
  if (selector.indexOf("#") > 0) { //id selector like "tag#id"
    s = selector.split("#");
    tag = s[0];
    selid = s[1];
  }
  if (selid != "") {
    objlist.push(document.getElementById(selid));
    return objlist;
  }
  if (selector.indexOf(".") > 0) {  //class selector like "tag.class"
    s = selector.split(".");
    tag = s[0];
    selclass = s[1];
  }
  var v = document.getElementsByTagName(tag);  // tag selector like "tag"
  if (selclass == "") {
    return v;
  }
  for (i = 0; i < v.length; i++) {
    if (v[i].className == selclass) {
      objlist.push(v[i]);
    }
  }
  return objlist;
}


// Codi per a la finestra de popup
var tmr;
var t;
var obj;

function sFa() {
	obj = gObj();
	sLft();
	shw(true);
	t = 0;
	sTmr();
}

function hFa() {
	t = -100;
	sTmr();
	return false;
}

function sTmr() {
	tmr = setInterval("fd()",20);
}

function fd() {
	var amt = Math.abs(t+=10);
	if(amt == 0 || amt == 100) clearInterval(tmr);
	amt = (amt == 100)?99.999:amt;
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
	if(amt == 0) shw(false);
}

function sLft() {
	var w = 100;	// set this to 1/2 the width of the popup div defined in the style sheet 
	var l = (document.body.innerWidth)? document.body.innerWidth / 2:document.body.offsetWidth / 2;
	obj.style.left = (l - w)+"px";
}

function gObj() {
	return document.getElementById("popup");	
}

function shw(b) {
	(b)? obj.className = 'show':obj.className = '';	
}

