function buida(nodo) {
	while(nodo.childNodes.length!=0) {
		nodo.removeChild(nodo.firstChild);
	}
}

function ultimes_noticies() {
	var xmlHttp = createXmlHttpRequestObject();
	try {
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState==4) {
				if (xmlHttp.status==200) {
					inserta_resums(xmlHttp.responseXML);
				}
			}
		}
		xmlHttp.open('POST', '../Scripts/xml/ultimes_noticies.php');
		xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		xmlHttp.send('idioma='+idioma);
	} catch (e) {
		alert('No es pot connectar amb el servidor');
	}
}

function inserta_noticies() {
	var xmlHttp = createXmlHttpRequestObject();
	try {
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState==4) {
				if (xmlHttp.status==200) {
					inserta_news(xmlHttp.responseXML);
				}
			}
		}
		xmlHttp.open('POST', '../Scripts/xml/noticies.php');
		xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		xmlHttp.send('idioma='+idioma);
	} catch (e) {
		alert('No es pot connectar amb el servidor');
	}
}

function inserta_resums(xml) {
	var noticies = xml.getElementsByTagName('noticia');
	var foto_not_01 = document.getElementById('foto_not_01');
	var foto1 = noticies[0].getAttribute('imatge');
	foto_not_01.setAttribute('src', '../images/noticies/'+foto1);
	var titol1 = noticies[0].getAttribute('titol');
	var titol_not_01 = document.getElementById('titol_not_01');
	titol_not_01.appendChild(document.createTextNode(titol1));
	
	var foto_not_02 = document.getElementById('foto_not_02');
	var foto2 = noticies[1].getAttribute('imatge');
	foto_not_02.setAttribute('src', '../images/noticies/'+foto2);
	var titol2 = noticies[1].getAttribute('titol');
	var titol_not_02 = document.getElementById('titol_not_02');
	titol_not_02.appendChild(document.createTextNode(titol2));
}

function inserta_news(xml) {
	var noticies = xml.getElementsByTagName('noticies')[0];
	var contenidor = document.getElementById('cont_noticies');
	for (var i=0; i<noticies.childNodes.length; i++) {
		var noticia = noticies.childNodes[i];
		var div_noticia = document.createElement('div');
		div_noticia.setAttribute('class', 'noticia');
		div_noticia.className = 'noticia';
		var div_titol = document.createElement('div');
		div_titol.setAttribute('class', 'titular01');
		div_titol.className = 'titular01';
		var titol_txt = document.createTextNode(noticia.getAttribute('titol'));
		div_titol.appendChild(titol_txt);
		div_noticia.appendChild(div_titol);
		var div_foto = document.createElement('div');
		div_foto.setAttribute('class', 'foto_Noticies2');
		div_foto.className = 'foto_Noticies2';
		var img = document.createElement('img');
		img.setAttribute('src', '../images/noticies/'+noticia.getAttribute('imatge'));
		div_foto.appendChild(img);
		div_noticia.appendChild(div_foto);
		var div_cos = document.createElement('div');
		div_cos.setAttribute('class', 'contingut_noticia');
		div_cos.className = 'contingut_noticia';
		var cos_txt = noticia.firstChild.firstChild.nodeValue;
		var paragrafs = cos_txt.split('----');
		for(var j=0; j<paragrafs.length; j++) {
			var p = document.createElement('p');
			var p_txt = document.createTextNode(paragrafs[j]);
			p.appendChild(p_txt);
			div_cos.appendChild(p);
		}
		div_noticia.appendChild(div_cos);
		contenidor.appendChild(div_noticia);
	}
	var br_clear = document.createElement('br');
	br_clear.style.clear = 'both';
	contenidor.appendChild(br_clear);
}