var isIE = false;
var req;

function loadXMLDoc(url) {
    if (window.XMLHttpRequest) {
        req = newXMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function newXMLHttpRequest() {
  var xmlreq = false;
  if (window.XMLHttpRequest) {
    xmlreq = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
      try {
        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
      }
    }
  }
  return xmlreq;
}


function processReqChange() {
    if (req.readyState == 4) {
        if (req.status == 200) {
            handleResult();
        } else {
            alert("Error de transmisión:\n" + req.statusText);
        }
    }
}


function handleResult() {
	var elementos = req.responseXML.getElementsByTagName("elementos");
	if(elementos.length > 0) {
		document.getElementById("lugarcomentarios").innerHTML = elementos[0].firstChild.data;

	ajaxtooltip.iebody=(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	var tooltips=[] //array to contain references to all tooltip DIVs on the page
	$('*[@muestra^="ficha:"]').each(function(index){ //find all links with "muestra=ficha:" declaration
		this.titleurl='/shared/info2.php?id='+jQuery.trim(this.getAttribute('muestra').split(':')[1]) //get URL of external file
		this.titleposition=index+' pos' //remember this tooltip DIV's position relative to its peers
		tooltips.push($('<div id="fichita'+jQuery.trim(this.getAttribute('muestra').split(':')[1])+'" class="ajaxtooltip"></div>').appendTo('body'))
		var $target=$(this)
		$target.removeAttr('muestra')
		$target.hover(
			function(e){ //onMouseover element
				var $tooltip=tooltips[parseInt(this.titleposition)]
				if (!$tooltip.get(0).loadsuccess){ //first time fetching Ajax content for this tooltip?
//					$tooltip.html(ajaxtooltip.loadingHTML).show()
					$tooltip.load(this.titleurl, '', function(){
						ajaxtooltip.positiontip($tooltip, e)
//						ajaxtooltip.showtip($tooltip, e)
						$tooltip.get(0).loadsuccess=true
					})

				}
				else{
					ajaxtooltip.positiontip($tooltip, e)
					ajaxtooltip.showtip($tooltip, e)
				}
			},
			function(e){ //onMouseout element
				var $tooltip=tooltips[parseInt(this.titleposition)]
				ajaxtooltip.hidetip($tooltip, e)		
			}
		)
		$target.bind("mousemove", function(e){
			var $tooltip=tooltips[parseInt(this.titleposition)]
			ajaxtooltip.positiontip($tooltip, e)
		})
	})



	}
}


