addEvent(window,'load',inicializarEventos,false);

function inicializarEventos()
{
  /*var vec=document.getElementsByTagName('div');
  for(f=0;f<vec.length;f++)
  {
    addEvent(vec[f],'mouseover',mostrarToolTip,false);
    addEvent(vec[f],'mouseout',ocultarToolTip,false);
    addEvent(vec[f],'mousemove',actualizarToolTip,false);
  }*/
  var ele=document.createElement('div');
  ele.setAttribute('id','divmensaje');
  //vec=document.getElementsById('centroIzquierda');
  vec=document.getElementsById('body');
  vec[0].appendChild(ele);
  
  var ob;
  for(f=1;f<=8;f++)
  {
    ob=document.getElementById('anuncio'+f);
    //addEvent(ob,'click',presionEnlace,false);
	/****EVENTOS PARA EL DIV DE TOOLTIP******/
	
	addEvent(ob,'mouseover',mostrarToolTip,false);
    addEvent(ob,'mouseout',ocultarToolTip,false);
    addEvent(ob,'mousemove',actualizarToolTip,false);
  }
  
}

function mostrarToolTip(e) 
{
  var d = document.getElementById("divmensaje");
  d.style.visibility = "visible";
  if (window.event) 
    e=window.event;
  d.style.left = e.clientX + document.body.scrollLeft + 15;
  d.style.top = e.clientY + document.body.scrollTop + 15;
  var ref;
  if (window.event)
    ref=window.event.srcElement;
  else
    if (e)
      ref=e.target;
  recuperarServidorTooltip(ref.getAttribute('href'));
}

function actualizarToolTip(e) 
{
  if (window.event) 
    e=window.event;
  var d = document.getElementById("divmensaje");
  d.style.left = e.clientX + document.body.scrollLeft + 15;
  d.style.top = e.clientY + document.body.scrollTop + 15;
}

function ocultarToolTip(e) 
{
  var d = document.getElementById("divmensaje");
  d.style.visibility = "hidden";
}

var conexion1;
function recuperarServidorTooltip(codigo) 
{
  //codigo=codigo.replace("mostrar","mostrarToolTip");
  //alert(codigo);
  conexion1=crearXMLHttpRequest();

  conexion1.onreadystatechange = procesarTooltip;
  conexion1.open('GET',codigo, true);
  conexion1.send(null);
  d.style.visibility = "visible";
}

function procesarTooltip()
{
  var d = document.getElementById("divmensaje");
  d.style.visibility = "visible";
  if(conexion1.readyState == 4)
  {
    d.innerHTML=conexion1.responseText;
  } 
  else 
  {
    d.innerHTML = '<img src="../cargando.gif">' ;
  }
}


//***************************************
//Funciones comunes a todos los problemas
//***************************************
function addEvent(elemento,nomevento,funcion,captura)
{
  if (elemento.attachEvent)
  {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else  
    if (elemento.addEventListener)
    {
      elemento.addEventListener(nomevento,funcion,captura);
      return true;
    }
    else
      return false;
}

function crearXMLHttpRequest() 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}
