// ICCportal.js

document.onload = initCtrls;
document.onload = put_favicon("http://www.igc.cat/web/favicon.ico");

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function tablaautocolor(){
/* nomes per IE, la resta entenen el CSS3... */
if (navigator.appName == 'Microsoft Internet Explorer'){
  var tables = document.getElementsByTagName("tbody");
  for (k=0; k <= tables.length ; k++) {
  if(tables[k].className=='tablaautocolor'){
    var allTRs = tables[k].getElementsByTagName("tr");
    for (i=0; i <= allTRs.length ; i++) {
    if (i % 2 == 0)
    allTRs[i].className = "par";
    }
  }
  }
}
}

// 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();
  
  for (var i = 0; i < aLabels.length ; i++)
  {
  //*
  //d'aquesta forma es canvien tots els links a 'inici'; funciona per portal/index_geo.jsp (ok) i portal/index_c.jsp (error conegut)
    if ((aLinks[i])&&(-1 != aLinks[i].indexOf("/portal\/index"))) aLinks[i]="../index.php";
  //*
    HTML += (aLinks[i]) ?   '<a href="' + aLinks[i] + '">' + aLabels[i] + '</a> &gt; ' : aLabels[i];
  }
  document.write(HTML);
  
  //put_favicon("/web/gcontent/img/favicon.ico");
}

function initCtrls()
{
  if (document.all) // IE
  {
		var tabs = document.getElementById('divTabs'); 
              if (! tabs)
              {
                tabs = document.getElementById('divTabs_en'); 
              }
		//alert("tabs.offsetTop:"+tabs.offsetTop);
		if (tabs && tabs.offsetTop != 88)
		{
			tabs.style.top = "14px";
		}
  }

}

function openmapserver(url){
		window.open(url,"","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,width=800,height=550");
}

function cambiamail (buzon) {
var res = "";
for (var n = 0; n < buzon.length; n++)
res += String.fromCharCode(buzon.charCodeAt(n));
if (res.indexOf('@') < 0)
res = res + '@' + 'igc.cat';
location = "mail" + "to:" + res+"?subject=Contacte Web";
}

//control frames aliens
function blockError()
	{ return true; }
window.onerror = blockError;

function checkframes()
{if (top.location != location) top.location.href = location.href ;}
//{if (window != window.top) window.top.location.href = window.location.href;}
document.onload = checkframes();
//exception temporal:
/*if ((parent.frames.length > 0)&&(-1 == location.href.indexOf("igc_sismologia_mapalocal30"))&&(-1 == location.href.indexOf("igc_sismologia_psis_taula"))){
parent.location.href = location.href;
}*/
//control frames aliens

//control url germana
function checklocation()
{
 //var loc = new String(document.location.href);
 if (location.hostname.indexOf(".igc.") == -1) location.hostname = "www.igc.cat";
}
document.onload = checklocation();
//control url germana

function put_favicon(url_favicon){

  var head=document.documentElement.getElementsByTagName("head")[0];
  
  var link = document.createElement('link');
  link.setAttribute('rel','shortcut icon');
  link.setAttribute('type','image/x-icon');
  link.setAttribute('href',url_favicon);
  
  head.appendChild(link);

}

