function getX(obj) {
    var x = obj.offsetLeft;
    while (obj = obj.offsetParent) x += obj.offsetLeft;
    return x;
}
function getY(obj) {
    var y = obj.offsetTop;
    while (obj = obj.offsetParent) y += obj.offsetTop;
    return y;
}

function showCal(input, obj){
    getCal('x','x',input);
    document.getElementById('cal').style.display='block';
    document.getElementById('cal').style.top=(getY(obj)+18) + 'px';
    document.getElementById('cal').style.left=(getX(obj)) + 'px';
    
}
function add(idInput, datum){
    document.getElementById(idInput).value=datum;
    document.getElementById('cal').style.display='none';
}

function hideCal(){
    document.getElementById('cal').style.display='none';
}
function nextMonth(month, year, input){
    getCal(month, year, input);
    document.getElementById('cal').style.display='block';
}
function getCal(month, year, input){
    var xmlHttpReq;
    if(typeof XMLHttpRequest != 'undefined')
    {
      try
      {
        xmlHttpReq = new XMLHttpRequest();
      }
      catch(e)
      {
              try {
                xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
              } catch (e) {
              try {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
              } catch (E) {
                xmlHttpReq = false;
              }
             }
      }
    }
    else
    {
      try {
              xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
            try {
              xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
              xmlHttpReq = false;
            }
      }
    }
    xmlHttpReq.open('GET', 'getcal.php?month='+month+'&year='+year+'&input='+input,false);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.send(null);
    document.getElementById('cal').innerHTML=xmlHttpReq.responseText;
}