//Create a boolean variable to check for a valid Internet Explorer instance.
var xmlhttp = false;

//Check if we are using IE.
try {
  //If the Javascript version is greater than 5.
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  //alert ("You are using Microsoft INternet Explorer");
} catch (e) {
  //If not, then use the older active x object.
  try {
    //If we are using Internet Explorer.
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    //alert("You are using Microsoft Internet Explorer");
  } catch (E) {
    //Else we must be using a non-IE browser.
   // alert("You are not using Microsoft Internet Explorer")
    xmlhttp = false;
  }
}

//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined'){
  xmlhttp = new XMLHttpRequest();
  //alert ("You are not using Microsoft Internet Explorer");
}



//A variable used to distinguish whether to open or close the calendar.
var showCalendar = true;

function showHideDG(){

//The location we are loadig the page into.
var objID="ExampleWindow";

//Change the current image of the minus or plus.
if (showCalendar == true){
  //show the calendar.
  document.getElementById("opencloseDGimg").src = "./images/minus.jpg";
  //The page we are loading.
  var serverPage = "showHideDG.php";
  //Set the open close tracker variable.
  showCalendar=false;

  var obj = document.getElementById(objID);
  xmlhttp.open("GET", serverPage);
  xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
      obj.innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.send(null);
} else {
  //Hide the calendar.
  document.getElementById("opencloseDGimg").src="./images/plus.jpg";
  showCalendar = true;

  document.getElementById(objID).innerHTML = "";
}

}



function showHideBugWalk(){

//The location we are loadig the page into.
var objID="ExampleWindow";

//Change the current image of the minus or plus.
if (showCalendar == true){
  //show the calendar.
  document.getElementById("opencloseBWimg").src = "./images/minus.jpg";
  //The page we are loading.
  var serverPage = "showHideBugWalk.php";
  //Set the open close tracker variable.
  showCalendar=false;

  var obj = document.getElementById(objID);
  xmlhttp.open("GET", serverPage);
  xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
      obj.innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.send(null);
} else {
  //Hide the calendar.
  document.getElementById("opencloseBWimg").src="./images/plus.jpg";
  showCalendar = true;

  document.getElementById(objID).innerHTML = "";
}
}

function showHideBallsAndPend(){

//The location we are loadig the page into.
var objID="ExampleWindow";

//Change the current image of the minus or plus.
if (showCalendar == true){
  //show the calendar.
  document.getElementById("opencloseBPimg").src = "./images/minus.jpg";
  //The page we are loading.
  var serverPage = "showHideBP.php";
  //Set the open close tracker variable.
  showCalendar=false;

  var obj = document.getElementById(objID);
  xmlhttp.open("GET", serverPage);
  xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
      obj.innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.send(null);
} else {
  //Hide the calendar.
  document.getElementById("opencloseBPimg").src="./images/plus.jpg";
  showCalendar = true;

  document.getElementById(objID).innerHTML = "";
}
}




//Function to run a word grabber script.
function grabword(theelement){

  //If there is nothing in the box, run Ajax to populate it.
  if(document.getElementById(theelement).innerHTML.length == 0){
      //Change the background color.
      document.getElementById(theelement).style.background = "#CCCCCC";
      serverPage = "wordgrabber.php";
      var obj = document.getElementById(theelement);
      

      xmlhttp.open("POST",serverPage);
      xmlhttp.onreadystatechange = function() {
          if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
              obj.innerHTML = xmlhttp.responseText;
          }
      }
      xmlhttp.send(null);
  } else {
      //Change the background color.
      document.getElementById(theelement).style.background = "#FFFFFF";
      //If the box is already populated, clear it.
      document.getElementById(theelement).innerHTML = "";
  }
}

function createform (e){
  theObject = document.getElementById("createtask");

  theObject.style.visibility = "visible";
  theObject.style.height = "200px";
  theObject.style.width = "200px";

  var posx = 0;
  var posy = 0;

  posx = e.clientX + document.body.scrollLeft;
  posy = e.clientY + document.body.scrollTop;

  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";

  //The location we are loading the page into.
  var objID = "createtask";
  var serverPage = "theform.php";
  var obj = document.getElementById(objID);
  xhlhttp.open("GET",serverPage);
  xmlhttp.onreadystatechange = function() {
      if(xmlhttp.readyState == 4 && xmlhttp.status ==200) {
          obj.innerHTML = xmlhttp.responseText;
      }
  }
  xmlhttp.send(null);
}

function findPosX(obj){
  var curleft = 0;
  if (obj.offsetParent){
      while(obj.offsetParent){
          curleft += obj.offsetLeft
          obj = obj.offsetParent;
      }
  } else if (obj.x){
      curleft += obj.x;
  }
  return curleft;
}

function findPosY(obj){
    var curtop = 0;
    if (obj.offsetParent){
        while(obj.offsetParent){
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    } else if (obj.y){
        curtop += obj.y;
    }
    return curtop;
}

