
	var xmlDoc;
	var root;
	var idImage;
	var prev;
	function loadXML(idImage)
	{
	// code for IE
	this.idImage=idImage;
	if (window.ActiveXObject)
	  {
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async=false;
	  xmlDoc.load("/xml/programaciontv.xml");
	  searchImage();
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation &&
	document.implementation.createDocument)
	  {
	  xmlDoc=document.implementation.createDocument("","",null);
	  xmlDoc.load("/xml/programaciontv.xml");
        xmlDoc.onload=searchImage;
	  }			
	}
	
	function getHora(){
		return (new Date()).getHours();
	}
	
	function getMinuto(){
		return (new Date()).getMinutes();
	}

	
	function getDia(){
		return (new Date()).getDay();
	}

	function searchImage(){
		var img;	
		var prgDefault;
		var minute=0;
		prev=false;
		img=0;
		root=xmlDoc.getElementsByTagName("programacion")[0];
		var hora=getHourToUse(root,getHora());
		for(i=0;i<root.childNodes.length;i++){
			child=root.childNodes[i];
			if(child.tagName!=null){
				if(child.getAttribute("nombre")=="default"){
					prgDefault=child.getAttribute("imagen");
				}else if(child.getAttribute("estado")!="I" && hora==child.getAttribute("hora") && child.getAttribute("dia")==getDia()){
					if(child.getAttribute("minuto")<=getMinuto() && getMinuto()>minute){
						img=child.getAttribute("imagen");
						minute=child.getAttribute("minuto");
					}else if(prev==true && child.getAttribute("minuto")>minute){
						img=child.getAttribute("imagen");
						minute=child.getAttribute("minuto");
					}
				}
			}
			
		}
		img=(img==0)?prgDefault:img;
		document.getElementById(idImage).src=img;
	}

	function getHourToUse(root,hora){
		var cnt=0;
		for(i=0;i<root.childNodes.length;i++){
			child=root.childNodes[i];
			if(child.tagName!=null && child.getAttribute("nombre")!="default" 
					&& child.getAttribute("estado")!="I" && hora==child.getAttribute("hora") 
					&& child.getAttribute("dia")==getDia() && child.getAttribute("minuto")<=getMinuto()){
				cnt=cnt+1;
			}
		}
		if(cnt!=0){
			return hora;
		}else{
			if(hora>0){
				prev=true;
				return getHourToUse(root,(hora  - 1));
			}else return 0;
		}
	}	

