// JavaScript Document
function cambioImagenes (id,img){
	window.document[id].src = img ;
}

// Leer XML desde AJAX
   var http_request = false;
   var xmlTexto     = "imagenes/datos.xml";
   
   function makeRequest(url) {
      http_request = false;
	  
      // Detectar navegador
	  if (navigator.appName.indexOf("Explorer") != -1) {
	  
	   try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         	//alert("Objeto creado Explorer");
		 } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
	  
	  
	  } else {
	  // Mozilla, Safari, ......
	  	
		http_request = new XMLHttpRequest();
         //alert("Objeto creado Mozilla");
		 
		 if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }

	  }
	  
      if (!http_request) {
         alert('No se puede crear XMLHTTP instancia use Internet Explorer, Firefoz, Mozilla, Safari.');
         return false;
      }
	  
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url , true);
      http_request.send(null);
   }

   function alertContents() {
   
   
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {

            var xmldoc = http_request.responseXML;
            var root = xmldoc.getElementsByTagName('root').item(0);
            
			 // Nodo DATA para cargar el contenido de Atributos.
			 /*
			if (navigator.appName == "Microsoft Internet Explorer") {
			 	textoDominio("dominio",root.childNodes[0].getAttribute("dominio"))
				textoNombre("nombre",root.childNodes[0].getAttribute("nombre"))
				document.title = root.childNodes[0].getAttribute("titulo");
				}else{
				textoDominio("dominio",root.childNodes[1].getAttribute("dominio"))
				textoNombre("nombre",root.childNodes[1].getAttribute("nombre"))
				document.title = root.childNodes[1].getAttribute("titulo");
				}
			  	*/
			  //
			
			
			// Nodo principal
            for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
               
			 
			 
			  
			   var node = root.childNodes.item(iNode);
			   
			   // Nodo secundario 
               for (i = 0; i < node.childNodes.length; i++) {
			   
			   //alert("Nodo secundario:" + node.childNodes[i].nodeName);
			   
			   // Saber que nodo 
			   var tipo = node.childNodes[i].nodeName;
			   // Saber que nodo
			   
                  var sibl = node.childNodes.item(i);
                  var len = parseInt(sibl.childNodes.length / 2);
                  var arr = new Array(len);
                  var cnt = 0;
                  for (x = 0; x < sibl.childNodes.length; x++) {
                     var sibl2 = sibl.childNodes.item(x);
                     var sibl3;
                     if (sibl2.childNodes.length > 0) {
                        sibl3 = sibl2.childNodes.item(0);
                        arr[cnt] = sibl3.data;   
                        cnt++;
                     }
                  }
				// Rellenar contenidos
					verificarTipos(tipo,arr);
                  //addrow("mytable", arr);
				  
				 // Fin de rellenar contenidos
               
			   }
			   // Fin nodo secundario
            }
			// Fin nodo principal
			
			
         } else {
            alert('Hay un problema con la respuesta. / There was a problem with the request.');
         }
      }
   }
   
   // Genera la respuesta desde el servidor
   function do_xml() {
	   makeRequest(xmlTexto);
   }
   
   // Aņade datos a una tabla
   function addrow(tablename, arr) {
   var tbl = document.getElementById(tablename);
   var lastRow = tbl.rows.length;
   var row = tbl.insertRow(lastRow);
      for (r = 0; r < arr.length; r++) {   
         var cell = row.insertCell(r);
         cell.innerHTML = arr[r];
		 textoDiv('titulo',arr[r]);
		 
      }
   }
   
   // Aņade texto a un DIV
   function textoDiv1(id,texto){
   
   var objeto = document.getElementById(id);
   objeto.innerHTML = texto;
   
   }
   
   function textoDominio(id,datos){
	publidos = "| <a href='#' onclick='abrirVentana(1);' class='blanco'><b>Privacidad</b></a>";
	publi = " | <a href='publicidad.html' class='blanco'><b>Anuncios</b></a> | &copy;2006 ";
   texto = '';
   var objeto = document.getElementById(id);
   texto = "<a href='http://"+ datos +"'>" + datos + "</a>";
   objeto.innerHTML = publidos + publi + texto;
   
   }
   
   function textoNombre(id,datos){
   texto = '';
   var objeto = document.getElementById(id);
   texto = "<h2>"+ datos + "</h2>";
   objeto.innerHTML = texto;
   
   }
   
   // Aņade texto a un DIV
   function textoDiv(id,datos){
   var objeto = document.getElementById(id);
    texto = '';
	for (r = 0; r < datos.length; r++) {
		if (texto == "") {
				texto = datos[r];
			} else {
				texto = texto + '<br><br>' +datos[r];
			}
	  }
	texto = "<h3>"+ id + "</h3>" + "<blockquote>" + texto + "</blockquote>";
   objeto.innerHTML = texto;
   
   }
   
    // Vericar el tipo de nodo
   // ***********************
   // ***********************
   // ***********************
   /*
   function verificarTipos(tipo,datos){
		
		switch (tipo) { 
		case 'presentacion': 
		    textoDiv('ofertas',datos);
		   break ;
		case 'fotos': 
		    textoDiv('fotos',datos); 
		   break; 
		case 'caracteristicas': 
		    textoDiv('caracteristicas',datos);
		   break ;
		case 'servicios': 
		   textoDiv('servicios',datos);
		   break ;
		case 'contacto': 
		   textoDiv('contacto',datos); 
		   break ;
		case 'tarifas': 
		    textoDiv('tarifas',datos);
		   break ;
		} 
		
	}
	*/
// Fin funciones de AJAX