//////////////////////////////////////////////////////////////////////

document.write('<script language=JavaScript src=/web/funciones/servidor.js><' + '/script' + '>');

var idioma = obtener_parametro('i'); if (idioma != 0 && idioma != 1) idioma = 2;
idioma = eval(idioma);

escuela = new Array(
'School of Architecture of Barcelona',
'Escuela Técnica Superior de Arquitectura de Barcelona',
'Escola Tècnica Superior d\'Arquitectura de Barcelona');

lang = new Array('en','es','ca');
tidioma = new Array('english','español','català');

var IE = new Boolean(); IE = false;
var KO = new Boolean(); KO = false;
var MO = new Boolean(); MO = false;
if (navigator.appName.indexOf("Konqueror") >= 0)  KO = true;
else if (navigator.appName.indexOf("Internet Explorer") >= 0) IE = true;
else if (navigator.appName.indexOf("Netscape") >= 0) MO = true;

llave = '<span><img border=0 title="intranet" src="/web/imagenes/llave.gif"></span>';
arroba = '<span><img border=0 align="absmiddle" src="/web/imagenes/am.gif" /></span>';
info = '<span><img border=0 align="absmiddle" src="/web/imagenes/info.gif" /></span>';
flecha_d = '<span><img border=0 height="20" align="absmiddle" src="/web/imagenes/flecha_d.gif" /></span>';
 
logo_mac = '<span><img border=0 height="20"  title="Mac OS" src="/web/imagenes/logos/apple_64.jpg" /></span>';
logo_linux = '<span><img border=0 height="20" title="GNU Linux" src="/web/imagenes/logos/linux_64.jpg" /></span>';
logo_win = '<span><img border=0 height="20" title="Windows" src="/web/imagenes/logos/windows_64.jpg" /></span>';

//////////////////////////////////////////////////////////////////////

function contador(campo, cuentacampo, limite) {
	
if (campo.value.length > limite) campo.value = campo.value.substring(0, limite);
else cuentacampo.value = limite - campo.value.length;
}

function maxtxt(campo, idtxt, limite) {

if (campo.value.length > limite) campo.value = campo.value.substring(0, limite);
document.getElementById(idtxt).innerHTML = "[" + campo.value.length + "/" + eval(limite - campo.value.length) + " " + limite + "]";
}

function soloNumeros() {
	
if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
}

//////////////////////////////////////////////////////////////////////

var to;
var to2;
var stop = 0;
var paraFlash = "";

function showNext(i,j) {
clearTimeout(to);
if (j == 0) {
	if (i == items.length) i = 0;
	news.innerHTML = '<p class=ciego>' + items[i] + '</p>';
	to = setTimeout('showNext(' + i + ',1)', 250);
}
else {
	if (i == items.length) i = 0;
	news.innerHTML = '<p class=aviso>' + items[i] + '</p>';
	to = setTimeout('showNext(' + ++i + ',0)', 1000);
}
}

function avisos(lar,pos,area,texto) {

var aviso = new Array('Notice','Avisos','Avisos');
items = new Array();
if (typeof texto == 'undefined') items[0] = aviso[idioma]; else items[0] = texto;
var ali = 'left';
if (pos == 'c') ali = 'center'; else if (pos == 'd') ali = 'right';
document.write('<div align=' + ali + '>');
document.write('<table width='+ lar +'% cellspacing=0 cellpadding=7 border=0><tr><td>');
document.write('<a href="/web/general/noticias/avisos.jsp?i=' + idioma + '&a=' + area + '&t=v,b&f=3" class=enlace><span id=news><p class=aviso>' + items[0] + '</p></span></a>');
document.write('</td></tr></table></div>');
//to = setTimeout('showNext(0,0)', 1000);
}

//////////////////////////////////////////////////////////////////////

function flash(et,txt1,txt2,i) {

//	if (document.getElementById(et).innerHTML == 'STOP') document.getElementById(et).innerHTML = txt2;

	if (typeof i == 'undefined') {
		document.getElementById(et).innerHTML = txt2;
		if (stop == 0 && paraFlash.indexOf(et) < 0)  setTimeout('flash("' + et + '","' + txt1 + '","' + txt2 + '",1)', 180);
	}
	else {
		document.getElementById(et).innerHTML = txt1;
		setTimeout('flash("' + et + '","' + txt1 + '","' + txt2 + '")', 180);
	}

}

function carrusel(i,nseg) {
	clearTimeout(to);
	if (i == items.length) i = 0;
	plus = (items[i].length * 60) + 120;
	if (typeof nseg == 'undefined') {
		et.innerHTML = items[i];
		to = setTimeout('carrusel(' + ++i + ')', plus);
	}
	else {
		et.innerHTML = items[i] + ' ' + ++nseg + '';
		to = setTimeout('carrusel(' + ++i + ',' + nseg + ')', plus);
	}
}

function sindatos(modo) {
	document.write('<table width=100% height=100% cellspacing=0 cellpadding=2 border=0>');
	document.write('<tr><td><p class=gc id=et>&nbsp;</p></td></tr></table>');
	items = new Array();
	if (typeof modo == 'undefined') {
		items[0]='[ Data not found ]';
		items[1]='[ No hay datos ]';	
		items[2]='[ No hi ha dades ]';
		carrusel(2);
	}
	else if (modo==1){
		items[0]='Loading...';
		items[1]='Cargando...';
		items[2]='Carregant...';
		carrusel(2,0);
		document.location.href = document.location.href + "&bucle=1";
	}
	else if (modo==2){
		items[0]='&nbsp;<br>..Out of order...';
		items[1]='Páginas no disponibles<br>Disculpen las molestias';
		items[2]='Pàgines no disponibles<br>Disculpeu les molèsties';
		carrusel(2);

	}
}

//////////////////////////////////////////////////////////////////////

function resizeImg(cualImg,ancho,alto) {
	var imagen = document.getElementById(cualImg);
	if ((imagen.width > ancho) || (imagen.height > alto)) {
		var escala = Math.min((ancho/imagen.width),(alto/imagen.height), 1);
		var new_width = Math.floor(escala*imagen.width);
		var new_height = Math.floor(escala*imagen.height);
		imagen.width = new_width;
		imagen.height = new_height;
	}
}
//////////////////////////////////////////////////////////////////////

function proporcionimagen(cualImg) { 
	var imagen = document.getElementById(cualImg);
	var proporcionimagen = "";
	if (imagen.width > imagen.height) proporcionimagen = "H";
	else if (imagen.width < imagen.height) proporcionimagen = "V";
	else if (imagen.width == imagen.height) proporcionimagen = "C";
return(proporcionimagen);
}
//////////////////////////////////////////////////////////////////////

function into(objeto,color) {objeto.bgColor = color;}

//////////////////////////////////////////////////////////////////////

function cargar(direccio,nomframe) {nomframe.location.href = direccio;}

//////////////////////////////////////////////////////////////////////

function indice(a,v) {
	var puntero = 0;
	for (var i=1; i < v.length; i=i+v[0]) {
		if (a == v[i]) puntero = i;
	}
return(puntero);
}

function texto(a,v,idio){
	var palabra = "";
	for (var i=1; i < v.length; i=i+v[0]) {
		if (a == v[i]) palabra = v[i + idio + 1];
	}
return(palabra);
}

//////////////////////////////////////////////////////////////////////

function filtrar_parametro(variable) {

var result = "";
if (variable != 'undefined') {
	result = variable.replace('%','');
	result = result.replace('\'','´');
	result = result.replace('\"','`');
	result = result.replace('/','');
	result = result.replace('\\','');
	result = result.replace('+','');
	//result = result.replace('-','');
	result = result.replace('<','');
	result = result.replace('>','');
}
return result;
}

//////////////////////////////////////////////////////////////////////

function obtener_parametro(variable) { 

var url = window.location.href;
url = unescape(url);
url = url.replace(/\+/gi," ");
url_min = url.toLowerCase();

var variable_min = variable.toLowerCase();
var variable_pos = url_min.indexOf(variable_min+"=");
var aux=false;

if (variable_pos > 0)
	aux=(url_min.charAt(variable_pos-1)=="&" || url_min.charAt(variable_pos-1)=="?");

if (variable_pos != -1 && aux) {
	var pos_separador = url.indexOf("&", variable_pos);
	if (pos_separador != -1) var pos_final = pos_separador;
	else var pos_final = url.length;
	var valor_parametro = url.substring(variable_pos + variable_min.length + 1, pos_final);
	while (valor_parametro.indexOf("|") != -1) {
		valor_parametro = valor_parametro.replace("|","&");
	}
}
else var valor_parametro = "KO";
var parametro = filtrar_parametro(valor_parametro);
return parametro;
}

//////////////////////////////////////////////////////////////////////

function TamVentana() { 
 
var Tamanyo = [0, 0];  
if (typeof window.innerWidth != 'undefined') Tamanyo = [window.innerWidth,window.innerHeight];   
else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){ 
	Tamanyo = [document.documentElement.clientWidth,document.documentElement.clientHeight];
} 
else{ 
	Tamanyo = [document.getElementsByTagName('body')[0].clientWidth,document.getElementsByTagName('body')[0].clientHeight];
}

return Tamanyo;
}

function ventana(pag,x,y,activarScroll,maximizable,nombre) {
	
var posx = 0;
var posy = 0;
var tamx = 0;
var	tamy = 0;
if (typeof nombre == 'undefined') nombre ='winpdf';
if (posicionPDF = pag.lastIndexOf(".pdf") > 0){
	tamx = screen.availWidth; 
	tamy = screen.availHeight;
	if(tamx > 1280) tamx = 1200 * 0.95;
	if(tamy > 768) tamy = tamy * 0.97 * 0.95;
	}
else {
	tamx = x;
	tamy = y;
	}
	posx = (screen.availWidth - tamx) / 2;
	posy = (screen.availHeight - tamy) / 3;
	defWindows = window.open(pag,nombre,
	"toolbar=0,location=0,directories=0,status=0,menubar=0" +
	",scrollbars=" + activarScroll + ",resizable=" + maximizable + ",dependent=1" +
	",width=" + tamx + ",height=" + tamy + ",left=" + posx + ",top=" + posy);
	
	window.defWindows.moveTo(posx,posy);
	
return (defWindows);
}

function ventanaxy(x,y,v) {
	if (x == 0) x = screen.availWidth;
	if (y == 0) y = screen.availHeight;
	px = (screen.availWidth - x)/2;
	py = (screen.availHeight - y)/2;
	if ( v == 0) {
		moveTo(0,0);
		resizeTo(x,y);
		moveTo(px,py);
	}
	else {
		window.top.moveTo(0,0);
		window.top.resizeTo(x,y);
		window.top.moveTo(px,py);
	}
}

function cerrar(v) {
	if (v == 0)	{
		window.opener='x';
		close();
	}
	else {
		window.top.opener='x';
		window.top.close();
	}
}

function ventanaorigen(url) {
		window.opener.top.location = url;
		cerrar(0);
}

function redimensionarVentana(alto,ancho){
	posx=(screen.availWidth-ancho)/2;
	posy=(screen.availHeight-alto)/3;
	self.moveTo(posx,posy);
	self.resizeTo(ancho,alto);
}

function ventanax100(xx,xy){
	var  cx = xx / 100;
	var  cy = xy / 100;
	if(cx < 0.1) cx = 0.1; if(cx > 1) cx = 1;
	if(cy < 0.1) cy = 0.1; if(cy > 1) cy = 1;
	cx = screen.availWidth * cx;
	cy = screen.availHeight * cy;
	self.moveTo(0,0);
	self.resizeTo(cx,cy);
	self.moveTo((screen.availWidth - cx)/2,(screen.availHeight - cy)/2);

}

//////////////////////////////////////////////////////////////////////

function fecha_modificacion() {

var LastModDate = new Date(document.lastModified);
dia = LastModDate.getDate();
mes = LastModDate.getMonth()+1;

var ano = LastModDate.getYear();
if (ano < 2000) ano = ano + 1900;

if (dia < 10) dia = "0" + dia;
if (mes < 10) mes = "0" + mes;
document.write(dia + "-" + mes + "-" + ano);
}

//////////////////////////////////////////////////////////////////////

sistemas = new Array('Information systems Web','Sistemas de Información Web','Sistemes d\'Informació Web');
cerrar = new Array('Close','Cerrar','Tancar');

infocab = new Array('<span class=n>' + escuela[idioma] + '</span><br>' + sistemas[idioma] + '',
98,'&nbsp;' + cerrar[idioma] + '&nbsp;','javascript:void(0); onclick=window.close();',
99,'','');

function cabecera(botones){

var texto = '<table width=100% cellspacing=0 cellpadding=1 border=0>' +
'<tr><td width=60px style="border-bottom: solid #000000; border-bottom-width: 2px;">' +
'<img src="/web/imagenes/logo2.gif" border=0>' +
'</td><td valign="bottom" style="border-bottom: solid #000000; border-bottom-width: 2px;">';
document.write(texto);

if (infocab.length < 1) {
	document.write('&nbsp;</td>');
}
else {
	document.write('<p class=g>'+infocab[0]+'</p></td>');
	var trobat=false; 
	document.write('<td valign=bottom style="border-bottom: solid #000000; border-bottom-width: 2px;"><p class=md>&nbsp;');
	for (var i=0; i < botones.length; i++){   
		trobat=false;
		for (var j=1; ((j< infocab.length) && !trobat); j=j+3){
 			if (infocab[j]==botones[i]){
				if (infocab[j+1] != '') 
					document.write('&nbsp;&nbsp;&nbsp;<a href=' + infocab[j+2] + ' class=enlace0>' + infocab[j+1] + '</a>');
	 			trobat=true;
			}
		}
	}
	document.write('</p></td>');
}
document.write('</tr></table>');
}

//////////////////////////////////////////////////////////////////////

function color(pos){
	var bgcolor="#f9f9f9";
	if (pos%2==0) bgcolor="#eeeeee";
return (bgcolor);
}

//////////////////////////////////////////////////////////////////////

function cabeza(op,fmenu,submenu,cuerpo,i2) {

document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');
document.write('<html dir="ltr>"');
document.write('<head lang="' + lang[idioma] + '">');
document.write('<title>UPC - ETS Arquitectura Barcelona</title>');
document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
document.write('<style type="text/css">@import url(/web/funciones/estilo.css);</style>');
document.write('</head>');
document.write('<body ' + op + '>');

var color = new Array('enlace3','enlace4');
var boton = 0;
var enlace = '';
if (i2 >= 0) {
	document.write('<table width=100% cellspacing=0 cellpadding=0 border=0><tr><td><p class=md>');
	for (var i=2; i >= 0 ; i--) {
		if (i == i2) boton = 1; else boton = 0;
		enlace = montalink(fmenu,submenu,cuerpo,i);
		document.write('&nbsp;&nbsp;<a href="' + enlace + '" class=' + color[boton] + ' target=_top>' + tidioma[i] + '</a>');
	}
	document.write('&nbsp;</p></td></tr></table>');
}
}

//////////////////////////////////////////////////////////////////////

function pie(fmenu,submenu,cuerpo,i2,sifecha) {

//sifecha = 0 no pone fecha
//sifecha "cualquier otro valor" pone la de modificación
var volver = new Array("Back","Volver","Tornar");
var color = new Array('enlace3','enlace4');
var boton = 0;
var enlace = '';

document.write('<br class=br>');
document.write('<table width=100% cellspacing=0 cellpadding=0 border=0>');
document.write('<tr><td>');
if (i2 >= 0) {
	document.write('<p class=md>');
	for (var i=2; i >= 0 ; i--) {
		if (i == i2) boton = 1; else boton = 0;
		enlace = montalink(fmenu,submenu,cuerpo,i);
		document.write('&nbsp;&nbsp;<a href="' + enlace + '" target=_top class=' + color[boton] + '>' + tidioma[i] + '</a>');
	}
	document.write('&nbsp;</p>');
}
else if (i2 == -1){
//	enlace = top.location.href;
	enlace = "javascript:history.go(-1);";
	document.write('<p class=nd><a href="' + enlace + '" target=_top class=rojo><b>' + volver[idioma] + '</b></a>&nbsp;</p><br class=br>');
}
document.write('</td></tr>');
document.write('<tr><td style="color:#777777; border-top: solid #bbbbbb; border-width: 1px;"><p class=m>© ETS Arquitectura Barcelona');
if (sifecha == 1) document.write(', <script>fecha_modificacion();</script>'); //fecha modificación
document.write('&nbsp;</p></td></tr>');
document.write('</table>');
}

//////////////////////////////////////////////////////////////////////

function leermenu(f) {
if (f != 'KO') document.write('<script language=JavaScript src=/web/menu/' + f + '.js>' + '<' + '/script' + '>');
}

//////////////////////////////////////////////////////////////////////

function montalink(fmenu,submenu,cuerpo,idioma){

var linea = '/web/frame.htm?i=' + idioma;
if (fmenu != '' && fmenu != 'KO') linea = linea + '&m=' + fmenu;
if (submenu != '' && submenu != 'KO') linea = linea + '&s=' + submenu;
if (cuerpo != '' && cuerpo != 'KO') linea = linea + '&c=' + cuerpo;

return (linea);
}

//////////////////////////////////////////////////////////////////////

function montacuerpo(i) {

var cuerpo = menu[i+1];
if (menu[i+2] != '') cuerpo = cuerpo + idioma + menu[i+2];
if (cuerpo == '') cuerpo = "/web/clases/error.jsp?ce=1";
cuerpo = cuerpo.replace(' ','');

return (cuerpo);
}

//////////////////////////////////////////////////////////////////////


function fechaPeriodo (anoini,mesini,diaini,anofin,mesfin,diafin){

/*  Se le pasa año,mes,dia de la fecha inicio y fin, en ese orden 
	Devuelve cierto si la fecha de hoy está comprendida en el rango de fecha inicio y fin pasado,
	incluyendo la fecha de inicio y fin en el periodo.
*/

	var res = false;
	var fini = new Date(anoini,mesini-1,diaini);
	var ffin = new Date(anofin,mesfin-1,diafin);
	var fhoyaux = new Date();
	var fhoy = new Date(fhoyaux.getFullYear(),fhoyaux.getMonth(),fhoyaux.getDate());
	
	if (fini <= fhoy && fhoy <= ffin ) res = true;
	/*alert(fini.toString());
	alert(ffin.toString());
	alert(fhoy.toString())*/
	return res;
}


//////////////////////////////////////////////////////////////////////

