function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function popUp(url) {
   newWin = window.open(url,'_blank','width=420,height=480,menubar=no,scrollbars=no,status=yes,resizable=yes');
   newWin.focus();
}

function loadPage(url) {
	this.location.href=url;
}

function tbLoadPage(url) {
	parent.tb_remove();
	parent.location.href=url;
}

function externalLinks() {
   if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("a");
   for (var i=0; i<anchors.length; i++) {
      var anchor = anchors[i];
      if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
         anchor.target = "_blank";
   }
}

function setupHomeMenu() {
	// setup llibre submenu
	document.getElementById('llibre_pages').style.display='none';
	document.getElementById('llibre_link').onclick = function() {
		if (document.getElementById('llibre_pages').style.display=='block') {
			document.getElementById('llibre_pages').style.display='none';
		} else {
			document.getElementById('lector_pages').style.display='none';
			document.getElementById('llibre_pages').style.display='block';
		}
		return false;
	}
	// setup lector submenu
	document.getElementById('lector_pages').style.display='none';
	document.getElementById('lector_link').onclick = function() {
		if (document.getElementById('lector_pages').style.display=='block') {
			document.getElementById('lector_pages').style.display='none';
		} else {
			document.getElementById('llibre_pages').style.display='none';
			document.getElementById('lector_pages').style.display='block';
		}
		return false;
	}
	// setup trobada
	document.getElementById('trobada_link').onclick = function() {
		document.getElementById('llibre_pages').style.display='none';
		document.getElementById('lector_pages').style.display='none';
	}
}

// define onload events
addLoadEvent(externalLinks);

