var calXmlHttp = false;
var xmlHttp2 = false;
var mousex = 0;
var mousey = 0;

var content = "";

var artID = "";


try {
    calXmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttp2  = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
    try {
        calXmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
        xmlHttp2  = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        calXmlHttp  = false;
    }
}
if (!calXmlHttp  && typeof XMLHttpRequest != 'undefined') {
    calXmlHttp = new XMLHttpRequest();
    xmlHttp2 = new XMLHttpRequest();
}

function loadCalendar(month, year)
{
 if (calXmlHttp) {
     if(artID == "") {
         var attribs = document.getElementById("eventCalendar").attributes;

         for(var idx = 0; idx < attribs.length; idx++) {
             if(attribs[idx].nodeName == "artid") {
                 artID = attribs[idx].nodeValue;
             }
         }
     }
     if(artID != "") {
     calXmlHttp.onreadystatechange = function () {
         if (calXmlHttp.readyState == 4) {
             content = calXmlHttp.responseText;
/*             if(content.indexOf("fopen(")  > -1) {
               xmlHttp2.onreadystatechange = function () {
                 if (xmlHttp2.readyState == 4) {
                   content = xmlHttp2.responseText;
                   document.getElementById("eventCalendar").innerHTML = content;
                  }
               };
              xmlHttp2.open('GET', 'front_content.php?idart='+artID+'&month='+month+'&year='+year, true);
             xmlHttp2.send(null);
          } else { */
             document.getElementById("eventCalendar").innerHTML = content;
          //}
         }
     };
     calXmlHttp.open('GET', 'front_content.php?idart='+artID+'&month='+month+'&year='+year, true);
     calXmlHttp.send(null);
     
   } else {
     document.getElementById("eventCalendar").innerHTML = "Error produced by your browser";
   }
 }
}

function showInformationDiv(id) {

  document.getElementById("eventCalendarDetailsDiv").innerHTML = id;
  document.getElementById("eventContainer").style.visibility = "visible";
}

function hideInformationDiv() {
   document.getElementById("eventContainer").style.visibility = "hidden";
}


function getXY(e) {
//    if (!e) var e = window.event;
//    alert(e.type);

//    var body = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ?
//    window.document.documentElement : window.document.body || null;
    
//    mousey = e.pageY ? e.pageY : e.clientY + body.scrollTop;
//    mousex = e.pageX ? e.pageX : e.clientX + body.scrollLeft;

        var posx = 0;
    var posy = 0;
    if(!e) e = window.event;
    if (e.pageX || e.pageY)     { 
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY)    {
        posx = e.clientX + document.body.scrollLeft
            + document.documentElement.scrollLeft;
        posy = e.clientY + document.body.scrollTop
            + document.documentElement.scrollTop;
    }
  mousey = posy + 15;
  mousex = posx + 15;
  document.getElementById("eventContainer").style.top   = mousey+"px";
  document.getElementById("eventContainer").style.left = mousex+"px";
}  

function registerNewEvents() {

  document.body.onmousemove = function(e) {

      var realTarget = e ? e.target : window.event.srcElement;

      if ( realTarget.nodeName.toLowerCase() === 'td' ) {
          getXY(e);
      }

  };
}





