
function obrir(pag) {
	w = window.open(pag, 'finestra', 'left=300, top=60, width=640, height=600, scrollbars=1, menubar=0, addressbar=0, resizable=1, statusbar=0');
}

var reqNoticies;
function procesarRequestNoticies() {
    if (reqNoticies && reqNoticies.readyState && reqNoticies.readyState == 4) {
        // 200 es "OK"
        if (reqNoticies.status == 200) {
//		alert(reqNoticies.responseText);
            if (reqNoticies.responseXML) {
 //               respuesta  = reqNoticies.responseXML.documentElement;
                noticies = reqNoticies.responseXML.getElementsByTagName('noticies');
                filas = noticies[0].getElementsByTagName('noticia');
//			alert('length: ' + filas.length);
                if (filas.length > 0) {
				presentarNoticies(filas);
                }
            }
        } else {
            alert("ERROR recibiendo datos:\n" + reqNoticies.statusText);
        }
    }

}
function presentarNoticies(noticies) {
	taulanot = document.getElementById("taulanoticies");
	for (i = 0; i < noticies.length; i++) {
// Fila 1: Data
// dia, mes, nommes, any, titol, primary, resum
		numRows = taulanot.rows.length;
		trnot = taulanot.insertRow(numRows);
		tdnot = document.createElement("td");
		tdnot.innerHTML = '' + noticies[i].getElementsByTagName('diasetmana')[0].firstChild.data +
					', ' + noticies[i].getElementsByTagName('dia')[0].firstChild.data +
					' de ' + noticies[i].getElementsByTagName('nommes')[0].firstChild.data;
		tdnot.className = 'textnormal';
		tdnot.setAttribute('class', 'textnormal');
		trnot.appendChild(tdnot);

// Fila 2: Titol
		numRows = taulanot.rows.length;
		trnot = taulanot.insertRow(numRows);
		tdnot = document.createElement("td");
		tdnot.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + noticies[i].getElementsByTagName('titol')[0].firstChild.data;
		tdnot.className = 'textnormal';
		tdnot.setAttribute('class', 'textnormal');
		trnot.appendChild(tdnot);

// Fila 3: en blanc
		numRows = taulanot.rows.length;
		trnot = taulanot.insertRow(numRows);
		tdnot = document.createElement("td");
		tdnot.innerHTML = '&nbsp;';
		tdnot.className = 'textnormal';
		tdnot.setAttribute('class', 'textnormal');
		trnot.appendChild(tdnot);

	}
}

function carregarNoticies() {
//	url = "presentarxml.php";
//	reqNoticies = crearHttpRequest(url, reqNoticies, procesarRequestNoticies);

}

function crearHttpRequest(url, request, callback) {
    request = null;
    // XMLHttpRequest existe en Mozilla/Firefox
        if (window.XMLHttpRequest) {
            request = new XMLHttpRequest();
        // Si es IE, usar ActiveXObject 
        } else if (window.ActiveXObject) {
            request = new ActiveXObject("Microsoft.XMLHTTP");
        }
    if (request) {
        request.onreadystatechange = callback;
        request.open("GET", url, true);
        request.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
        request.send(null);
    }
    return request;
}



function enviarCorreu() {
	correu = 'laia';
	domini = 'laiacagigal';
	e1 = 'c';
	e2 = 'o';
	e3 = 'm';
	emailE=(correu +  '@' + domini + '.' + e1 +e2 + e3);
	window.location = 'ma' + 'il' + 'to:' + emailE;
}

function presentarPaginaDebug(pag) {
	alert('presentarPagina ' + pag);
}
function presentarPaginaRequadre() {
alert("Hola xxx"); 
}

var idIntervaloIn;
var idIntervaloOut;
var req;
var reqIn;
var reqOut;
var increment;
var opacIn;
var opacOut;
function presentarPagina(pag) {
	window.location.href = pag;
}
// Per IE: afegir el marge del body
var offsetX = 0;
var offsetY = 0;
var margenX = 9;
var margenY = 11;
var panelDesc;
function canviarImatge(pag, x, y, ample, alt, idreq) {
	panelDesc = '';
	if (pag == 'bio' || pag == 'fotos' || pag == 'musica') {
		panelDesc = pag;
	}

	if (panelDesc == 'bio' || panelDesc == 'fotos' || panelDesc == 'musica') {
		visualitzarPanelDescarregues(panelDesc);
	}
	if (document.all) {
		offsetX = margenX;
		offsetY = margenY;
	}
	else {
		offsetX = 0;
		offsetY = 0;
	}
	increment = .20;
	opacIn = 0;
	reqIn = document.getElementById(idreq);
	reqIn.style.opacity = 0;
	reqIn.innerHTML = '<img src="imatges/' + pag + '.jpg" width="' + ample + '" height="' + alt + '" border="0" />';

	if (idIntervaloIn) clearInterval(idIntervaloIn);
	idIntervaloIn = setInterval('fadeIn();', 100);

	imgfons = document.getElementById('opcio');
	temp = imgfons;
	var ot = temp.offsetTop;
      while ((temp = temp.offsetParent) != null)        
      	ot += temp.offsetTop;
	temp = imgfons;
	var ol = temp.offsetLeft;
      while ((temp = temp.offsetParent) != null)        
      	ot += temp.offsetLeft;
	x = x + ol + offsetX;
	y = y + ot - offsetY;
//	alert('presentarDiv ' + x + '; ' + y);
	reqIn.style.left = x;
	reqIn.style.top = y;
	reqIn.style.height = '' + alt + 'px';
	reqIn.style.width = '' + ample + 'px';


}

function ocultarPanelsDescarregues() {
	p = new Array('fotos', 'bio', 'musica');
	for (i = 0; i - p.length; i++) {
		panelDescarregues = document.getElementById('panel_' + p[i]);
		panelDescarregues.style.visibility = 'hidden';
	}
}
function restaurarImatgesDescarregues(pag) {
	p = new Array('fotos', 'bio', 'musica');
	for (i = 0; i - p.length; i++) {
		if (p[i] != pag) {
			requadre = document.getElementById('requadreopcions_' + p[i]);
			requadre.style.visibility = 'hidden';
		}
	}
}

function visualitzarPanelDescarregues(pag) {
	ocultarPanelsDescarregues();
	restaurarImatgesDescarregues(pag);

		panelDescarregues = document.getElementById('panel_' + pag);
		panelDescarregues.style.visibility = 'visible';
		if (document.all) {
			panelDescarregues.style.filter = 'alpha(opacity=80)';
		}
		if (pag == 'bio') {
			panelDescarregues.style.backgroundColor = '#F0F8FF';
		}
		else if (pag == 'fotos') {
			panelDescarregues.style.backgroundColor = '#FFEFD5';
		}
		else if (pag == 'musica') {
			panelDescarregues.style.backgroundColor = '#FFFACD';
		}
	return panelDescarregues;
}

function presentarDiv(pag, x, y, ample, alt, idreq, sufixe) {
	if (document.all) {
		if (window.location.href.indexOf('index.html') >= 0) {
			offsetX = 1;
			offsetY = 1;
		}
		else {
			offsetX = margenX;
			offsetY = margenY;
		}
	}
	else {
		offsetX = 0;
		offsetY = 0;
	}
	increment = .20;
	opacIn = 0;
	reqIn = document.getElementById(idreq);
	reqIn.style.opacity = 0;
	reqIn.style.visible = 'hidden' ;
	reqIn.innerHTML = '<img src="imatges/' + pag + sufixe + '.jpg" width="' + ample + '" height="' + alt + '" border="0">';
	imgfons = document.getElementById('fons');
	temp = imgfons;
	var ot = temp.offsetTop;
      while ((temp = temp.offsetParent) != null)        
      	ot += temp.offsetTop;
	temp = imgfons;
	var ol = temp.offsetLeft;
      while ((temp = temp.offsetParent) != null)        
      	ot += temp.offsetLeft;
	x = x + ol + offsetX;
	y = y + ot - offsetY;
//	alert('presentarDiv ' + x + '; ' + y);
	reqIn.style.left = x;
	reqIn.style.top = y;
	reqIn.style.height = '' + alt + 'px';
	reqIn.style.width = '' + ample + 'px';
	reqIn.onclick=new Function ('presentarPagina("' + pag + '.html");');
	panelDesc = '';
	if (idIntervaloIn) clearInterval(idIntervaloIn);
	idIntervaloIn = setInterval('fadeIn();', 100);
}
var overRequadre = 0;
function onMouseOverRequadre() {
	overRequadre = 1;
}

function fadeIn() {
	if (opacIn > .99) {
		opacIn = 1.0;
		if (idIntervaloIn) clearInterval(idIntervaloIn);
		idIntervaloIn = null;
		if (reqIn) {
			reqIn.style.opacity = 1.0;
			if (document.all) {
				reqIn.style.filter = 'alpha(opacity=100)';
			}
//			if (panelDesc == 'bio' || panelDesc == 'fotos' || panelDesc == 'musica') {
//				visualitzarPanelDescarregues(panelDesc);
//			}
		}
		return opacIn;
	}
	if (reqIn) {
		reqIn.style.visibility = 'visible';	
		reqIn.style.opacity = opacIn;
		if (document.all) {
			reqIn.style.filter = 'alpha(opacity=' + (opacIn * 100) + ')';
		}
	}
	opacIn += increment;
	return opacIn;
}

function fadeOut() {
	opacOut = fadeOutReal(reqOut, opacOut);
}

function fadeOutReal(req, opac) {
//	if (window.location.href.indexOf('index.html') >= 0 && overRequadre) {
	if (overRequadre) {
			return 0;
	}
//	if (req) req.style.visibility = 'visible';	
	if (opac <= .01) {
// Anular el intervalo al llegar a maxContador
		if (idIntervaloOut) clearInterval(idIntervaloOut);
		idIntervaloOut = null;
		if (req) {
			req.style.opacity = 0.0;
			if (document.all) {
				req.style.filter = 'alpha(opacity=0)';
			}
			req.style.visibility = 'hidden';
		}
		return 0;
	}
	if (req) {
		req.style.opacity = opac;
		if (document.all) {
			req.style.filter = 'alpha(opacity=' + (opac * 100) + ')';
		}
	}
	opac -= increment;
	return opac;
}

function ocultarDiv(idreq) {
	overRequadre = 0;
	reqOut = document.getElementById(idreq);
//	alert('presentarDiv ' + id);
	if (idIntervaloOut) {
		clearInterval(idIntervaloOut);
	}
	idIntervaloOut = null;
	if (reqOut) {
		reqOut.onclick = null;
//		reqOut.style.visibility = 'hidden';
	}
	opacOut = 1.0;
	if (idreq == 'requadremenu') {
		if (reqOut) {
			reqOut.style.opacity = 0.0;
			if (document.all) {
				reqOut.style.filter = 'alpha(opacity=0)';
			}
			reqOut.style.visibility = 'hidden';
		}
	}
	else {
		idIntervaloOut = setInterval('fadeOut();', 100);
	}
}

function canviSeleccio(seccio) {
	sel = window.document.formulari.seccio.selectedIndex;
	if (sel != seccio) {
		window.document.formulari.submit();
	}
}

