////////////////////////////////////////////////
//  Funcions index.js ----- Versió 30-01-02   //
////////////////////////////////////////////////

// Temps de descàrrega de la pàgina
////////////////////////////////////////////////////////////////////////////////////////
var then,now=new Date();
function temps(s){
then=new Date();
var lang = new String(s);
if (lang == 'cat') window.status= 'Pàgina carregada en '+((then-now)/1000)+' segons.';
if (lang == 'cas') window.status= 'Página cargada en '+((then-now)/1000)+' segundos.';
if (lang == 'ang') window.status= 'This page took '+((then-now)/1000)+' seconds to load.';
}

// Treu la marca del link en IE
////////////////////////////////////////////////////////////////////////////////////////
function ExplorerFix() {
for (a in document.links) document.links[a].onfocus = document.links[a].blur; }
if (document.all) {
document.onmousedown = ExplorerFix; 
}

// Genera la data genèrica
////////////////////////////////////////////////////////////////////////////////////////
	var ara = new Date();
	var mes = ara.getMonth() + 1
	var mes = (mes < 10) ? "0" + mes : mes
	var dia = ara.getDate();
	var any = ara.getYear();
	if (any < 2000) 
	any = any + 1900;

function getWinNm() {
// Genera un nom de finestra per a poder-ne obrir més d'una
////////////////////////////////////////////////////////////////////////////////////////
  var now = new Date();
  var hr = new String(now.getHours());
  var mn = new String(now.getMinutes());
  var sc = new String(now.getSeconds());
  var winNm = hr + mn + sc;
  return winNm;
}
function statusMsg(msg) {
// Sense paràmetre esborra l'status i amb paràmetre mostra el missatge
////////////////////////////////////////////////////////////////////////////////////////
  var nargs = new Number(arguments.length);
  if(nargs<1) var msg = ' ';
  self.status = msg;
}
function mouseOver(msg) {
  self.status = msg;
}

function mouseOut(msg) {
// Sense paràmetre esborra l'status i amb paràmetre mostra el missatge
////////////////////////////////////////////////////////////////////////////////////////
  var nargs = new Number(arguments.length);
  if(nargs<1) msg = ' ';
  self.status = msg
}

function enrera() {
// Substitut history.back. Si té history, fa back; si és finestra nova inicial,la tanca; 
///////////////////////////////////////////////////////////////////////////////////////////////
  var wnom = new String(top.window.name);
  var historial = new Number(history.length);
  if(detectaVis()=='ne') historial = historial-1;
  if(historial>0) history.back();
  else {
    if(wnom!='') top.close();
  }
}

function detectaVis() {
// Funció genèrica que retorna nom de codi del visualitzador. Retorna 'ne' o 'ie'
////////////////////////////////////////////////////////////////////////////////////////
  var s = new String();
  switch(navigator.appName) {
    case 'Netscape':  s = 'ne';
          break;
    case 'Microsoft Internet Explorer': s = 'ie';
          break;
    default: s = 'ie';
          break;
  }
  return s;
}

function obtNumSes() {
  var nom = new String(top.name);
                if ((nom.indexOf('appid'))!='-1'){
                var ns = nom.substring(6,nom.lastIndexOf('sessiovell'));
        }
return ns;
}
function obtOldNumSes() {
 var nom = new String(top.name);
                if ((nom.indexOf('appid'))!='-1'){
                var oldns = nom.substring(nom.lastIndexOf('sessiovell')+10,nom.lastIndexOf('appid'));
        }
return oldns;
}

function doWrite(adr) {
// Obre una finestra amb un missatge preadreçat
////////////////////////////////////////////////////////////////////////////////////////
	var numSes = obtNumSes();
if ((numSes == 'undefined') || (numSes == null) || (numSes == ''))
	{
	location='mailto:biblioteca@uoc.edu?Subject=Consulta Biblioteca (Portal)';
	}
else
	{
	var x = 730;
	var y = 430;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc?s=' + numSes + '&modul=BIBLIOTECA.PARAMETRES/param.inici&codi=' + adr;
	var messWin = window.open(cgi,getWinNm(),'resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width='+x+',height='+y+',left='+posx+',top='+posy+'');
	}
}

function doOBRE(url){
// Funcio de finestra nova amb paràmetres ja definits
////////////////////////////////////////////////////////////////////////////////////////
	var x = 650;
	var y = 450;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var winNm = getWinNm();
	var cgi = url;
	var recurs = window.open(cgi, 
winNm,'resizable=1,toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,width='+x+',height='+y+',left='+posx+',top='+posy+'');
}

function doDINAWEB(lang,adr) {
// Funcio finestra nova recurs DINAWEB (CAT,CAS,ANG)
////////////////////////////////////////////////////////////////////////////////////////
	var x = 740;
	var y = 430;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var numSes = obtNumSes();
	if ((numSes == 'undefined') || (numSes == null) || (numSes == ''))
	{
	var cgi = 'http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.client?ss=0&nova=1&idioma=' + lang + '&pNode=' + adr;
	var recurs = window.open(cgi, 
'nova','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width='+x+',height='+y+',left='+posx+',top='+posy+'');
	}
	else
	{
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.client?ss=' + numSes + '&nova=1' + '&idioma=' + lang + '&pNode=' + adr;
	var recurs = window.open(cgi, 
'nova','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width='+x+',height='+y+',left='+posx+',top='+posy+'');
	}
}

function doTICKER(lang,adr) {
// Funcio recursos actualitat DINAWEB (CAT,CAS,ANG)
////////////////////////////////////////////////////////////////////////////////////////
	var numSes = obtNumSes();
	if ((numSes == 'undefined') || (numSes == null) || (numSes == ''))
	{
	var cgi = 'http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.client?ss=0&idioma=' + lang + '&pNode=' + adr;
	location.href=cgi;
	}
	else
	{
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.client?ss=' + numSes + '&idioma=' + lang + '&pNode=' + adr;
	location.href=cgi;
	}
}

function doNOVETATS(lang) {
// Funcio novetats DINAWEB (CAT,CAS,ANG)
////////////////////////////////////////////////////////////////////////////////////////
	var numSes = obtNumSes();
	if ((numSes == 'undefined') || (numSes == null) || (numSes == ''))
	{
	var cgi = 'http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.novetats?ss=0&idioma=' + lang;
	location.href=cgi;
	}
	else
	{
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.novetats?ss=' + numSes + '&idioma=' + lang;
	location.href=cgi;
	}
}

function doTICPORTAL(lang,adr) {
// Funcio recursos actualitat finestra nova DINAWEB (CAT,CAS,ANG)
////////////////////////////////////////////////////////////////////////////////////////
	var x = 740;
	var y = 430;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var numSes = obtNumSes();
	if ((numSes == 'undefined') || (numSes == null) || (numSes == ''))
	{
	var cgi = 'http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.client?ss=0&nova=1&idioma=' + lang + '&pNode=' + adr;
	var recurs = window.open(cgi, 
'nova','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width='+x+',height='+y+',left='+posx+',top='+posy+'');
	}
	else
	{
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.client?ss=' + numSes + '&nova=1' + '&idioma=' + lang + '&pNode=' + adr;
	var recurs = window.open(cgi, 
'nova','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width='+x+',height='+y+',left='+posx+',top='+posy+'');
	}
}

function doTREN(adr) {
// Funcio doTREN (finestra nova amb scrollbars)
////////////////////////////////////////////////////////////////////////////////////////
	var x = 730;
	var y = 450;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc?s=' + numSes + '&modul=' + adr;
	var messWin = window.open(cgi,getWinNm(),'resizable=0,toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,width='+x+',height='+y+',left='+posx+',top='+posy+'');
}

function doTREN2(adr) {
// Funcio doTREN2 (dins el el marc de la plataforma)
////////////////////////////////////////////////////////////////////////////////////////
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc?s=' + numSes + '&modul=' + adr;
	location.href=cgi; 
}

function doTREN3(adr) {
// Funcio doTREN3 (finestra nova sense scrollbars)
////////////////////////////////////////////////////////////////////////////////////////
	var x = 730;
	var y = 430;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc?s=' + numSes + '&modul=' + adr;
	var messWin = window.open(cgi,getWinNm(),'resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width='+x+',height='+y+',left='+posx+',top='+posy+'');
}


function doVERITY() {
// Funcio relativa a la crida del Dinaweb (dins el el marc de la plataforma)
////////////////////////////////////////////////////////////////////////////////////////
	var numSes = obtNumSes();
	var cgi = 'http://xina.uoc.es/cat/info/verity.html?ss=' + numSes;
	location.href=cgi;
	}


function doTRENDINAWEB(adr) {
// Funcio relativa a la crida del Dinaweb (dins el el marc de la plataforma)
////////////////////////////////////////////////////////////////////////////////////////
	var numSes = obtNumSes();
	if ((numSes == 'undefined') || (numSes == null) || (numSes == ''))
	{
	location.href='http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.client?ss=0&idioma=' + adr + '&pNode=267';
	}
	else
	{
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.client?ss=' + numSes + '&idioma=' + adr + '&pNode=267';
	location.href=cgi;
	}
}

function doTRENDINAURL(lang,adr) {
// Funcio crida recurs del Dinaweb (dins el el marc de la plataforma)
////////////////////////////////////////////////////////////////////////////////////////
	var numSes = obtNumSes();
	if ((numSes == 'undefined') || (numSes == null) || (numSes == ''))
	{
	location.href='http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.client?ss=0&idioma=' + lang + '&pNode=' + adr;
	}
	else
	{
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.client?ss=' + numSes + '&idioma=' + lang + '&pNode=' + adr;
	location.href=cgi;
	}
}

function doDINAURL(lang,adr) {
// Funcio crida recurs del Dinaweb als missatges de novetats
////////////////////////////////////////////////////////////////////////////////////////
	var x = 730;
	var y = 500;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc/web/BIBLIOTECA.CLIENT/dinaweb_client.client?ss=' + numSes + '&idioma=' + lang + '&pNode=' + adr;
	var messWin = window.open(cgi,getWinNm(),'resizable=1,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,width='+x+',height='+y+',left='+posx+',top='+posy+'');
}

function doAUTOANULA() {
// Funcio relativa a prestec: autoanul·lacio
////////////////////////////////////////////////////////////////////////////////////////
//var numSes = obtNumSes();
var OldnumSes = obtOldNumSes();
var URL_OWS='http://trineu.uoc.es/vtls_bib/plsql/vbAutoBib.showAutoReserve?sid='+OldnumSes;
location.href=URL_OWS;
}

function doLOGIN(adr) {
// Funcio doLOGIN (carrega les dades de login)
////////////////////////////////////////////////////////////////////////////////////////
	var numSes = obtNumSes();
	if ((numSes == 'undefined') || (numSes == null) || (numSes == ''))
	{
	var h='<HTML><BODY BGCOLOR="#2E3A6A"></BODY></HTML>';
	(document.all) ? document.write(h):document.write(h);
	}
	else
	{
	var numSes = obtNumSes();
	var cgi = 'http://cv.uoc.es/tren/trenacc?s=' + numSes + '&modul=' + adr;
	location.href=cgi;
	} 
}

function getValsOWS(url_pre) {
//  Funcions especials per al VTLS Gateway   
////////////////////////////////////////////////////////////////////////////////////////
	var nom = new String(top.name);
		if ((nom.indexOf('appid'))!='-1'){
		var numSes = nom.substring(6,nom.lastIndexOf('sessiovell'));
		var oldNumSes = nom.substring(nom.lastIndexOf('sessiovell')+10,nom.lastIndexOf('appid'));
	}
	var URL_OWS='http://trineu.uoc.es/vtls_bib/plsql/vbUser.tryBorrow?' + url_pre  + '&sid=';
	var vURL_OWS = URL_OWS + oldNumSes;
//--	top.document.location = vURL_OWS;
var winNm = getWinNm(); 
var messWin = window.open(vURL_OWS,winNm,'width=600,height=450,toolbar=yes,scrollbars=yes,location=no,status=yes,resizable=yes');
}

function doAVIS(adr){
// Funcio d'avis de la home de la biblio
////////////////////////////////////////////////////////////////////////////////////////
	var x = 600;
	var y = 320;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var numSes = obtNumSes();
	var cgi = 'http://xina.uoc.es/novetats/' + adr + '/divscroll.html';
	var messWin = window.open(cgi,numSes,'resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width='+x+',height='+y+',left='+posx+',top='+posy+'');
}

function doPROJECT(adr){
// Funcio de les finestres dels Projectes Europeus
////////////////////////////////////////////////////////////////////////////////////////
	var x = 600;
	var y = 320;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var cgi = 'http://xina.uoc.es/' + adr;
	var messWin = window.open(cgi,'faq','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width='+x+',height='+y+',left='+posx+',top='+posy+'');
}

function doFAQ(adr) {
// Funcio per obrir les FAQ
////////////////////////////////////////////////////////////////////////////////////////
	var x = 650;
	var y = 470;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var cgi = 'http://xina.uoc.es/' + adr;
	var messWin = window.open(cgi,'faq','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width='+x+',height='+y+',left='+posx+',top='+posy+'');
}

function doBIBLIO5(adr) {
// Funcio de la Biblioteca en 5 minuts
////////////////////////////////////////////////////////////////////////////////////////
	var x = 700;
	var y = 490;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var cgi = 'http://xina.uoc.es/' + adr;
	var messWin = window.open(cgi,'biblio5','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width='+x+',height='+y+',left='+posx+',top='+posy+'');
}

function doHELP(adr) {
// Funcio de la finestra ajuda
////////////////////////////////////////////////////////////////////////////////////////
	var x = 600;
	var y = 410;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var cgi = 'http://xina.uoc.es/' + adr;
	var messWin = window.open(cgi,'help','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width='+x+',height='+y+',left='+posx+',top='+posy+'');
}

function doLEGEND(adr) {
// Funcio de la finestreta de la llegenda
////////////////////////////////////////////////////////////////////////////////////////
	var x = 230;
	var y = 390;
	var posx=(screen.width-x)/2;
	var posy=(screen.height-y)/2;
	var cgi = 'http://xina.uoc.es/' + adr;
	var messWin = window.open(cgi,'legend','resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width='+x+',height='+y+',left='+posx+',top='+posy+'');
}

function doRECURS(adr) {
// Funcio relativa a la crida de recursos dins el el marc de la plataforma)
/////////////////////////////////////////////////////////////////////////////////////////////
if (location.hostname != 'uocadsl.uoc.es' ) { 
    var loc = new String('http://xina.uoc.es/') 
    }
    else {
    var loc = new String('http://bibadsl.uoc.es/')
    }
	var cgi = loc + adr;
	location.href=cgi;
}

////////////////////////////////////////////////////////////////////
// Funcio per obrir menú amb el botó de la dreta del ratolí (IE)  //
////////////////////////////////////////////////////////////////////

var menuskin = "skin0";
var display_url = 0;
function showmenuie5() {
var rightedge = document.body.clientWidth-event.clientX;
var bottomedge = document.body.clientHeight-event.clientY;
if (rightedge < ie5menu.offsetWidth)
ie5menu.style.left = document.body.scrollLeft + event.clientX - ie5menu.offsetWidth;
else
ie5menu.style.left = document.body.scrollLeft + event.clientX;
if (bottomedge < ie5menu.offsetHeight)
ie5menu.style.top = document.body.scrollTop + event.clientY - ie5menu.offsetHeight;
else
ie5menu.style.top = document.body.scrollTop + event.clientY;
ie5menu.style.visibility = "visible";
return false;
}
function hidemenuie5() {
ie5menu.style.visibility = "hidden";
}
function highlightie5() {
if (event.srcElement.className == "menuitems") {
event.srcElement.style.backgroundColor = "highlight";
event.srcElement.style.color = "white";
if (display_url)
window.status = event.srcElement.url;
   }
}
function lowlightie5() {
if (event.srcElement.className == "menuitems") {
event.srcElement.style.backgroundColor = "";
event.srcElement.style.color = "black";
window.status = "";
   }
}
function jumptoie5() {
if (event.srcElement.className == "menuitems") {
if (event.srcElement.getAttribute("target") != null)
window.open(event.srcElement.url, event.srcElement.getAttribute("target"));
else
window.location = event.srcElement.url;
   }
}

//////////////////////////////////////////////
// Funcions de crida al Servei de notícies  //
//////////////////////////////////////////////

function hide(id,nest){
	if(document.layers){
		if(nest) document.layers[nest].document.layers[id].visibility="hidden"
		else document.layers[id].visibility="hidden"
	}else if(document.all) document.all[id].style.visibility="hidden"
}
function show(id,nest){
	if(document.layers){
		if(nest) document.layers[nest].document.layers[id].visibility="visible"
		else document.layers[id].visibility="visible"
	}else if(document.all) document.all[id].style.visibility="visible"
}