ï»¿Graella.prototype.id;
Graella.prototype.l;
Graella.prototype.primer;
Graella.prototype.fx;
	
function Graella(){
	
	var id;
	var list;
	this.primer = true;
	this.fx = true;
	var xmlDoc;
	var id_act;
	var files;

	//funcio que carrega l'XML de les noticies relacionades
	this.loadNoticies = function(l, xml, num)
	{	
		files = num;
		list = l;
		if (document.implementation && document.implementation.createDocument){
			xmlDoc = document.implementation.createDocument("", "", null);
			xmlDoc.onload = this.writeListNoti;
			xmlDoc.load(xml);
		}else if(window.XMLHttpRequest) {
			this.fx = false;
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");  
			xmlDoc.async = false;
			xmlDoc.load(xml);
			this.writeListNoti();
		}else{
			alert("El seu navegador no soporta aquesta web");
			return;
		}
	}
	
	//funcio que carrega l'xml que en sservira per a la graella
	this.loadGraella = function(l, xml, num)
	{
	  files = num;
	  list = l;
	  
	  if (document.implementation && document.implementation.createDocument){
			xmlDoc = document.implementation.createDocument("", "", null);
			xmlDoc.onload = this.writeList;
			xmlDoc.load(xml);
		}else if(window.XMLHttpRequest) {
			this.fx = false;
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");  
			xmlDoc.async = false;
			xmlDoc.load(xml);
			this.writeList();
		}else{
			alert("El seu navegador no soporta aquesta web");
			return;
		}
	}
	
	//Funcio que escriu les noticies
	this.writeListNoti = function()
	{
		
		var labels = xmlDoc.getElementsByTagName("marker");
		
		id = 0;
		
			for (var x=0; x < files; x++){
						
				if (labels[id].getAttribute('tipo') == "noticia_p"){
					//Informacio de noticia
					var li = document.createElement('LI');
					
					//data
					var labelId2 = document.createTextNode(labels[id].getAttribute('hora') + ": ");
					li.appendChild(labelId2);
					
					var labelId = document.createTextNode(labels[id].getAttribute('titol'));
					
					var newlink = document.createElement('a');				
					newlink.setAttribute('href', 'javascript:;');
					if (labels[id].getAttribute('tipo') == "noticia"){
						if (!IE)
							newlink.setAttribute('onclick', "descargar('fila2'); cargar('visor', 'recursos/visor/visor.php?id="+labels[id].getAttribute('id_noti')+"'); cargar('historic', 'historic/relacionats.php?id="+labels[id].getAttribute('id_noti')+"');");
						else
							newlink['onclick']=new Function("descargar('fila2'); cargar('visor', 'recursos/visor/visor.php?id="+labels[id].getAttribute('id_noti')+"'); cargar('historic', 'historic/relacionats.php?id="+labels[id].getAttribute('id_noti')+"');");
					}else{
						if (!IE){
							newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('noticiesh/"+labels[id].getAttribute('id_noti')+"'); return false;");
						}else{
							newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('noticiesh/"+labels[id].getAttribute('id_noti')+"'); return false;");
						}
					}
					if (!IE)
						newlink.setAttribute('class', 'link_b');
					else
						newlink.setAttribute('className', 'link_b');
					newlink.appendChild(labelId);
					li.appendChild(newlink);

					document.getElementById(list).appendChild(li);
					id = labels[id].getAttribute('id');

				}else{
					
					if (labels.length < 3){
						ocultar('ctr_noti_temes');
					}else{
						mostrar('ctr_noti_temes');
					}
				
					//Nova fila
					var li = document.createElement('LI');
					
					var div = document.createElement('div');
					if (!IE)
						div.setAttribute('class', 'linea_grl');
					else
						div.setAttribute('className', 'linea_grl');
					
					var tab = document.createElement('table');
					var tabBody = document.createElement('tbody'); 
					
						var row = document.createElement('tr');
						row.setAttribute('height', '30');
						
						//Columna hora
						var cellh = document.createElement('td');
						cellh.setAttribute('WIDTH', '58');
						cellh.setAttribute('valign', 'top');
						var hora = document.createTextNode(labels[id].getAttribute('id'));
						var h16 = document.createElement('h16');
						h16.appendChild(hora);
						cellh.appendChild(h16);
						
						//Columna titol
						var cellt = document.createElement('td');
						cellt.setAttribute('valign', 'top');
						var titol = document.createTextNode(labels[id].getAttribute('titol'));
						//Programa
						var newlink = document.createElement('a');
						newlink.setAttribute('href', 'javascript:;');
						
						if(!IE){
							newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('noticies/"+labels[id].getAttribute('id_noti')+"'); return false;");
							newlink.setAttribute('class', 'link_b');
						}else{
							newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('noticies/"+labels[id].getAttribute('id_noti')+"'); return false;");
							newlink.setAttribute('className', 'link_b');
						}
							
						newlink.appendChild(titol);
						cellt.appendChild(newlink);
											
						row.appendChild(cellh);
						row.appendChild(cellt);
					
					tabBody.appendChild(row);
					tab.appendChild(tabBody); 
					
					div.appendChild(tab);
					li.appendChild(div);
					
					document.getElementById(list).appendChild(li);
					id = labels[id].getAttribute('id');
				
				
				}
			}
	}

	//funció que escriu les 2 linies de graella que en s interesen
	this.writeList = function()
	{
	
	  var labels = xmlDoc.getElementsByTagName('marker');
		
		//comprovam hora
		var Digital = new Date();
		var hours = Digital.getHours();
		var minutes = Digital.getMinutes();
		var actual = (60 * parseInt(hours)) + parseInt(minutes);
		var dins = true;
		var i = 0;
		
		
	  //examinam xml
	  while (dins && i < labels.length-1)
	  {
	  
		time = labels[i].getAttribute('hora').split(':');
		
		time2 = labels[i+1].getAttribute('hora').split(':');
		
		temps = (60 * parseInt(time[0])) + parseInt(time[1]);
		
		temps2 = (60 * parseInt(time2[0])) + parseInt(time2[1]);
		
		i++;
		if (temps<=actual && temps2>=actual){
			id = i;
			id_act = i;
			dins = false;
		}
	  }
	  
	  if(id > labels.length-files){
		id = labels.length-files;
		id_act = id;
	  }
	  
		for (var x=0; x < files; x++){
			//Nova fila
			var li = document.createElement('LI');
			
			var div = document.createElement('div');
			if (!IE){
				div.setAttribute('class', 'linea_grl');
			}else{
				div.setAttribute('className', 'linea_grl');
			}
			
			var tab = document.createElement('table');
			var tabBody = document.createElement('tbody'); 
			
				var row = document.createElement('tr');
				row.setAttribute('height', '30');
				
				//Columna hora
				var cellh = document.createElement('td');
				cellh.setAttribute('WIDTH', '58');
				cellh.setAttribute('valign', 'top');
				var hora = document.createTextNode(labels[id].getAttribute('hora'));
				var h16 = document.createElement('h16');
				h16.appendChild(hora);
				cellh.appendChild(h16);
				
				//Columna titol
				var cellt = document.createElement('td');
				cellt.setAttribute('valign', 'top');
				var titol = document.createTextNode(labels[id].getAttribute('titol'));
				//Programa
				var newlink = document.createElement('a');
				newlink.setAttribute('href', 'javascript:;');
				if(labels[id].getAttribute('tipo') == "tv"){
					if (!IE)
						newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('tv/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
					else
						newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('tv/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
				}else if (labels[id].getAttribute('tipo') == "radio"){
					if (!IE)
						newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('radio/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
					else
						newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('radio/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
				}
				if (!IE)
					newlink.setAttribute('class', 'link_b');
				else
					newlink.setAttribute('className', 'link_b');
				newlink.appendChild(titol);
				cellt.appendChild(newlink);
				cellt.appendChild(document.createElement("br"));
				var h5 = document.createElement('h5');
				var capitol = document.createTextNode(labels[id].getAttribute('subtitol'));
				h5.appendChild(capitol);
				cellt.appendChild(h5);
				
				row.appendChild(cellh);
				row.appendChild(cellt);
			
			tabBody.appendChild(row);
			tab.appendChild(tabBody); 
			
			div.appendChild(tab);
			li.appendChild(div);
			
			document.getElementById(list).appendChild(li);
			id = labels[id].getAttribute('id');
		}
	}

	//funcio que passa cap avall la graella
	this.mes = function(algo, boton)
	{
		list = algo;
		var labels = xmlDoc.getElementsByTagName('marker');
		
		if (id < labels.length){
			//Cream el nou element
			var li = document.createElement('LI');
			
			//Escriure linies
			var labelId = document.createTextNode(labels[id].getAttribute('titol'));
			if (labels[id].getAttribute('tipo') == "noticia"){
				//Nova fila
				var li = document.createElement('LI');
				
				var div = document.createElement('div');
				if (!IE)
					div.setAttribute('class', 'linea_grl');
				else
					div.setAttribute('className', 'linea_grl');
				
				var tab = document.createElement('table');
				var tabBody = document.createElement('tbody'); 
				
					var row = document.createElement('tr');
					row.setAttribute('height', '30');
					
					//Columna hora
					var cellh = document.createElement('td');
					cellh.setAttribute('WIDTH', '58');
					cellh.setAttribute('valign', 'top');
					var hora = document.createTextNode(labels[id].getAttribute('id'));
					var h16 = document.createElement('h16');
					h16.appendChild(hora);
					cellh.appendChild(h16);
					
					//Columna titol
					var cellt = document.createElement('td');
					cellt.setAttribute('valign', 'top');
					var titol = document.createTextNode(labels[id].getAttribute('titol'));
					//Programa
					var newlink = document.createElement('a');
					newlink.setAttribute('href', 'javascript:;');					
					
					if (!IE){
						newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('noticies/"+labels[id].getAttribute('id_noti')+"'); return false;");
						newlink.setAttribute('class', 'link_b');
					}else{
						newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('noticies/"+labels[id].getAttribute('id_noti')+"'); return false;");
						newlink.setAttribute('className', 'link_b');
					}
					newlink.appendChild(titol);
					cellt.appendChild(newlink);
										
					row.appendChild(cellh);
					row.appendChild(cellt);
				
				tabBody.appendChild(row);
				tab.appendChild(tabBody); 
				
				div.appendChild(tab);
				li.appendChild(div);
				
				document.getElementById(list).appendChild(li);
			}else if (labels[id].getAttribute('tipo') == "noticia_p"){
				//data
				var labelId2 = document.createTextNode(labels[id].getAttribute('hora') + ": ");
				li.appendChild(labelId2);
			
				var newlink = document.createElement('a');
				newlink.setAttribute('href', 'javascript:;');
				if (!IE){
					newlink.setAttribute('class', 'link_b');
					newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('noticiesh/"+labels[id].getAttribute('id_noti')+"'); return false;");
				}else{
					newlink.setAttribute('className', 'link_b');
					newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('noticiesh/"+labels[id].getAttribute('id_noti')+"'); return false;");
				}
				newlink.appendChild(labelId);
				li.appendChild(newlink);
			}else{
				//Nova fila
				var li = document.createElement('LI');
				
				var div = document.createElement('div');
				if (!IE)
					div.setAttribute('class', 'linea_grl');
				else
					div.setAttribute('className', 'linea_grl');
				
				var tab = document.createElement('table');
				var tabBody = document.createElement('tbody'); 
				
					var row = document.createElement('tr');
					row.setAttribute('height', '30');
					
					//Columna hora
					var cellh = document.createElement('td');
					cellh.setAttribute('WIDTH', '58');
					cellh.setAttribute('valign', 'top');
					var hora = document.createTextNode(labels[id].getAttribute('hora'));
					var h16 = document.createElement('h16');
					h16.appendChild(hora);
					cellh.appendChild(h16);
					
					//Columna titol
					var cellt = document.createElement('td');
					cellt.setAttribute('valign', 'top');
					var titol = document.createTextNode(labels[id].getAttribute('titol'));
					//Programa
					var newlink = document.createElement('a');
					newlink.setAttribute('href', 'javascript:;');
					if(labels[id].getAttribute('tipo') == "tv"){
						if (!IE)
							newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('tv/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
						else
							newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('tv/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
					}else if (labels[id].getAttribute('tipo') == "radio"){
						if (!IE)
							newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('radio/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
						else
							newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('radio/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
					}
					if (!IE)
						newlink.setAttribute('class', 'link_b');
					else
						newlink.setAttribute('className', 'link_b');
					newlink.appendChild(titol);
					cellt.appendChild(newlink);
					cellt.appendChild(document.createElement("br"));
					var h5 = document.createElement('h5');
					var capitol = document.createTextNode(labels[id].getAttribute('subtitol'));
					h5.appendChild(capitol);
					cellt.appendChild(h5);
					
					row.appendChild(cellh);
					row.appendChild(cellt);
				
				tabBody.appendChild(row);
				tab.appendChild(tabBody); 
				
				div.appendChild(tab);
				li.appendChild(div);
			}
			document.getElementById(list).appendChild(li);
			id = labels[id].getAttribute('id');
			
			//Eliminam el primer element de la llista
			var list = document.getElementById(list);
			if (list.childNodes.length > 0) {
				if (this.primer && this.fx){
					list.removeChild(list.firstChild);
					list.removeChild(list.firstChild);
					this.primer = false;
				}else{
					list.removeChild(list.firstChild);
				}
			}
		}
	}

	//funcio que passa cap amunt la graella
	this.menos = function(algo, boton)
	{ 
		list = algo;
		//Cream el nou element
		var labels = xmlDoc.getElementsByTagName('marker');
		
		if (id > files){
			id = id-files-1;
			
			for (var x = 0; x < files; x++){
				var li = document.createElement('LI');
				var labelId = document.createTextNode(labels[id].getAttribute('titol'));
				
				//escriure linies
				if (labels[id].getAttribute('tipo') == "noticia"){
					//Nova fila
					var li = document.createElement('LI');
					
					var div = document.createElement('div');
					if (!IE)
						div.setAttribute('class', 'linea_grl');
					else
						div.setAttribute('className', 'linea_grl');
					
					var tab = document.createElement('table');
					var tabBody = document.createElement('tbody'); 
					
						var row = document.createElement('tr');
						row.setAttribute('height', '30');
						
						//Columna hora
						var cellh = document.createElement('td');
						cellh.setAttribute('WIDTH', '58');
						cellh.setAttribute('valign', 'top');
						var hora = document.createTextNode(labels[id].getAttribute('id'));
						var h16 = document.createElement('h16');
						h16.appendChild(hora);
						cellh.appendChild(h16);
						
						//Columna titol
						var cellt = document.createElement('td');
						cellt.setAttribute('valign', 'top');
						var titol = document.createTextNode(labels[id].getAttribute('titol'));
						//Programa
						var newlink = document.createElement('a');
						newlink.setAttribute('href', 'javascript:;');
						
						if (!IE){
							newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('noticies/"+labels[id].getAttribute('id_noti')+"'); return false;");
							newlink.setAttribute('class', 'link_b');
						}else{
							newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('noticies/"+labels[id].getAttribute('id_noti')+"'); return false;");
							newlink.setAttribute('className', 'link_b');
						}
						newlink.appendChild(titol);
						cellt.appendChild(newlink);
											
						row.appendChild(cellh);
						row.appendChild(cellt);
					
					tabBody.appendChild(row);
					tab.appendChild(tabBody); 
					
					div.appendChild(tab);
					li.appendChild(div);
					
					document.getElementById(list).appendChild(li);
				}else if (labels[id].getAttribute('tipo') == "noticia_p"){
					//data
					var labelId2 = document.createTextNode(labels[id].getAttribute('hora') + ": ");
					li.appendChild(labelId2);
				
					var newlink = document.createElement('a');
					newlink.setAttribute('href', 'javascript:;');
					if(!IE){
						newlink.setAttribute('class', 'link_b');
						newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('noticiesh/"+labels[id].getAttribute('id_noti')+"'); return false;");
					}else{
						newlink.setAttribute('className', 'link_b');
						newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('noticiesh/"+labels[id].getAttribute('id_noti')+"'); return false;");
					}
					newlink.appendChild(labelId);
					li.appendChild(newlink);
				}else{
					//Nova fila
					var li = document.createElement('LI');
					
					var div = document.createElement('div');
					if (!IE)
						div.setAttribute('class', 'linea_grl');
					else
						div.setAttribute('className', 'linea_grl');
					
					var tab = document.createElement('table');
					var tabBody = document.createElement('tbody'); 
					
						var row = document.createElement('tr');
						row.setAttribute('height', '30');
						
						//Columna hora
						var cellh = document.createElement('td');
						cellh.setAttribute('WIDTH', '58');
						cellh.setAttribute('valign', 'top');
						var hora = document.createTextNode(labels[id].getAttribute('hora'));
						var h16 = document.createElement('h16');
						h16.appendChild(hora);
						cellh.appendChild(h16);
						
						//Columna titol
						var cellt = document.createElement('td');
						cellt.setAttribute('valign', 'top');
						var titol = document.createTextNode(labels[id].getAttribute('titol'));
						//Programa
						var newlink = document.createElement('a');
						newlink.setAttribute('href', 'javascript:;');
						if(labels[id].getAttribute('tipo') == "tv"){
							if (!IE)
								newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('tv/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
							else
								newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('tv/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
						}else if (labels[id].getAttribute('tipo') == "radio"){
							if (!IE)
								newlink.setAttribute('onclick', "jQuery.noConflict();  jQuery.historyLoad('radio/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
							else
								newlink['onclick']=new Function("jQuery.noConflict();  jQuery.historyLoad('radio/programes/cercap/"+labels[id].getAttribute('id_prog')+"'); return false;");
						}
						if (!IE)
							newlink.setAttribute('class', 'link_b');
						else
							newlink.setAttribute('className', 'link_b');
						newlink.appendChild(titol);
						cellt.appendChild(newlink);
						cellt.appendChild(document.createElement("br"));
						var h5 = document.createElement('h5');
						var capitol = document.createTextNode(labels[id].getAttribute('subtitol'));
						h5.appendChild(capitol);
						cellt.appendChild(h5);
						
						row.appendChild(cellh);
						row.appendChild(cellt);
					
					tabBody.appendChild(row);
					tab.appendChild(tabBody); 
					
					div.appendChild(tab);
					li.appendChild(div);
				}
				document.getElementById(list).appendChild(li);
				id = labels[id].getAttribute('id');
			}
			
			//Eliminam el primer element de la llista
			var list = document.getElementById(list);
			if (list.childNodes.length > 0) {
				if (this.primer && this.fx){
					for (var x = 0; x < files + 1; x++)
						list.removeChild(list.firstChild);
					this.primer = false;
				}else{
					for (var x = 0; x < files; x++)
						list.removeChild(list.firstChild);
				}
			}
		}
	}
	
	//funcio que buida la llista
	this.buida = function(algo){
		list=algo;
		for (var n = 0; n < list.childNodes.length; n++){
			list.removeChild(list.firstChild);
		}
	}
}