// JavaScript Document
var xmlDocLinksInteres;
var mozilla;
var ie;
var arLinks;
var arSitio;
var arWeb;
mozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined');
ie = (typeof window.ActiveXObject != 'undefined');
function importaXMLLinksInteres(fichero,funcion) {
  if (mozilla) {
    xmlDocLinksInteres = document.implementation.createDocument("", "", null)
    xmlDocLinksInteres.load(fichero);
    xmlDocLinksInteres.onload = function()
    {
      funcion();
    }
  } else if (ie) {
    xmlDocLinksInteres = new ActiveXObject("Microsoft.XMLDOM");
    xmlDocLinksInteres.async = false;
    xmlDocLinksInteres.load(fichero);
    if (xmlDocLinksInteres.readyState == 4) funcion();
  }
  else {
    alert('Tu navegador no puede manejar este script');
    return;
  }
}

function importaLinksInteresXML(fichero) {
  importaXMLLinksInteres(fichero,PaintData);
}
//Pinta los datos del primer disco
function PaintData(){
	try{
		GetInfo();
		PaintDataLinks();
	}catch(err){
		alert(err.message);
	}	
}

//Obtiene Toda la Info de los discos
function GetInfo(){
	try{
		arLinks = new Array();
		arSitio = new Array();
 		arWeb = new Array();
		arLinks = xmlDocLinksInteres.getElementsByTagName("link");
		//Se obtienen los datos del primero para ser pintados
		for(var i=0;i<arLinks.length;i++){
			arSitio.push(arLinks[i].getElementsByTagName("sitio")[0].firstChild.data);
			arWeb.push(arLinks[i].getElementsByTagName("web")[0].firstChild.data);
		}
	}catch(err){
		alert(err.message)
	}
}

//Pinta la tabla y los links
function PaintDataLinks(){
	try{
		var oDiv = document.getElementById("divLinks");
		var oTableMain=document.getElementById("tbLink");
		var oTbodyMain = oTableMain.appendChild(document.createElement("tbody"));
		var oTrMain;
		var oTdMain;
		var sText;
		for(var i=0;i<arWeb.length;i++){
			oTrMain = oTableMain.appendChild(document.createElement("tr"));
			oTdMain = oTrMain.appendChild(document.createElement("td"));
			if (mozilla) {
				oTdMain.setAttribute("class","tdLink");
			} else if (ie) {
				oTdMain.setAttribute("className","tdLink");
			}else {
				alert('Tu navegador no puede manejar este script');
				return;
			}		
			sText= oTdMain.appendChild(document.createTextNode(arSitio[i]));
			oTdMain.appendChild(sText);
			//Se enlazan al imagen al tr el td
			oTrMain.appendChild(oTdMain);
			//Se crea la segunda celda
			oTdMain = oTrMain.appendChild(document.createElement("td"));
			if (mozilla) {
				oTdMain.setAttribute("class","tdHref");
			} else if (ie) {
				oTdMain.setAttribute("className","tdHref");
			}else {
				alert('Tu navegador no puede manejar este script');
				return;
			}				
			oAnchor = oTdMain.appendChild(document.createElement("a"));
			oAnchor.setAttribute("href",arWeb[i]);
			oAnchor.setAttribute("target","_blank");
			sText=oAnchor.appendChild(document.createTextNode(arWeb[i]));
			//Se enlaza el Texto al alink
			oAnchor.appendChild(sText);
			//Se enlazan al imagen al td
			oTdMain.appendChild(oAnchor);
			//Se enlazan al imagen al tr el td
			oTrMain.appendChild(oTdMain);
			oTbodyMain.appendChild(oTrMain);
		}//Fin for
		oTableMain.appendChild(oTbodyMain);
		var docBody = document.getElementsByTagName("body").item(0);
		docBody.appendChild(oTableMain);
	}catch(err){
		alert(err.message)
	}
}
