// ICCportal.js

// Switch the current page language
function switchCurrLang(pLang)
{
  var loc      = new String(document.location.href);
	if (-1 != loc.indexOf("/ca/"))
	{	
		re = new RegExp("/ca/")
	} 
	else if (-1 != loc.indexOf("/es/"))
	{	
		re = new RegExp("/es/")
	} 
	else
	{
		re = new RegExp("/en/")
	}
	loc = loc.replace(re, "/" + pLang + "/" );
  document.location.replace(loc);
}

/*function writeBreadCrumbs(pLabels,pLinks)
{
  var aLabels = pLabels.split(",");
  var aLinks  = pLinks.split(",");
  var HTML = new String();
  var tLabel = ""; 
  for (var i = 0; i < aLabels.length ; i++)
  {   
      tLabel = aLabels[i].toLowerCase();
      HTML += (aLinks[i]) ?   '<a href="' + aLinks[i] + '">' + aLabels[i] + '</a> &gt; ' : aLabels[i];  
  }
  document.write(HTML);
}*/
function writeBreadCrumbs(pLabels,pLinks) {
var aLabels = pLabels.split(",");
var aLinks = pLinks.split(",");
var HTML = new String();
var tLabel = "";
var strHomepage = "/web/content";
//ruta homepage
var loc = new String(document.location.href);
if (-1 != loc.indexOf("/ca/")) {
  strHomepage += "/ca/index.html";
} else if (-1 != loc.indexOf("/es/")) {
  strHomepage += "/es/index.html";
} else {
  strHomepage += "/en/index.html";
}

for (var i = 0; i < aLabels.length ; i++) {
  tLabel = aLabels[i].toLowerCase();
  
  if ((aLinks[i])&&(-1 != aLinks[i].indexOf("/portal\/index"))) aLinks[i]=strHomepage;
  if ((aLinks[i])&&(-1 != aLinks[i].indexOf("/portal\/"))) aLinks[i]=strHomepage;

  HTML += (aLinks[i]) ? '<a href="' + aLinks[i] + '">' + aLabels[i] + '</a> &gt; ' : aLabels[i];
}
document.write(HTML);
}

onload=initCtrls;

function initCtrls()
{
  var tDiv=null;
  if (document.all) // IE
  {
		var tabs = document.getElementById('divTabsCiutada');
		if (! tabs)
		{ tabs = document.getElementById('divTabs'); }
		if (tabs && tabs.offsetTop != 87)
		{
			tabs.style.top = "11px";
		}
  }
}
//ojdinteractiva
function ojdWrite(IVW) {
document.write( "<IMG SRC=\""+IVW+"?r="+escape(document.referrer)+"&d="+(Math.random()*100000)+"\" WIDTH=\"1\" HEIGHT=\"1\" />");
}

// Obrir pdf s en finestra nova amb control ojd
function sR(target) {
        pixel = new Image();
        window.open(target);
        pixel.src = "http://icc.ojdinteractiva.com/cgi-bin/ivw/CP/catala;pdf";
}
//Enviar email a través d'un link
function canviamail (bustia, subj) {
var res = "";
for (var n = 0; n < bustia.length; n++) res += String.fromCharCode(bustia.charCodeAt(n));
if (res.indexOf('@') < 0) res = res + '@' + 'icc.cat';
location = "mail" + "to:" + res+"?subject=" + subj;
}

function wopen(url, w, h)
{
// Fudge factors for window decoration space.
// In my tests these work well on all platforms & browsers.
w += 32;
h += 96;
var win = window.open(url,'popup', 'width=' + w + ', height=' + h + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no');
}
//funcio per Cartoteca. Series cartografiques del mon
function obrirSeriesMon(theURL) {

var win =window.open(theURL,"","scrollbars=yes,resizable=yes");

}

//funcio per poder cridar 2 funcions diferents durant el window onload
function makeDoubleDelegate(function1, function2) {
    return function() {
        if (function1)
            function1();
        if (function2)
            function2();
    }
}
