//functions.js
//Create a boolean variable to check for a valid IE instance.
var xmlhttp = false;
var serverPageLoc="";
var showmore=0;
var tbheight =180;
var tbwidth =400;
//Check if we are using IE.
try {
  //If the javascript version is greater than 5.
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  //If not, then use the older active x object.
  try {
    //If we are using IE.
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
    //Else we must be using a non-IE browser.
    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();
}
//A variable used to distinguish whether to open or close the calendar.
var showEmailAFriend = true;
function showHideEmailAFriend() {
  //The location we are loading the page into.
  var objID = "HideEmailAFriend";
  theObject = document.getElementById("HideEmailAFriend");
  theObjectImage = document.getElementById("nextimg");

  //Change the current image of the minus or plus.
  if (showEmailAFriend == true){
  theObject.style.visibility = "visible";
  theObject.style.height = "350px";
  theObject.style.width = "200px";
  theObjectImage.style.height = "96px";
  theObjectImage.style.width = "128px";
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  //document.body.scrollLeft="0px"
  //document.body.scrollTop="-100px"
  window.scroll(0,200)

  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
    //Show the calendar.
 
    //The page we are loading.
    var serverPage = "/common/emailafrienddisplay.php";
    //Set the open close tracker variable.
    showEmailAFriend = 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 {
  theObject.style.visibility = "visible";
  theObject.style.height = "0px";
  theObject.style.width = "0px";
  theObjectImage.style.height = "317px";
  theObjectImage.style.width = "423px";
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
  //Hide the calendar.
 
  showEmailAFriend = true;
  document.getElementById(objID).innerHTML = "";
}
}
var getCalendar=true;

function getCalendarClick() {
  //The location we are loading the page into.
  var objID = "CalendarTextBox";
  theObject = document.getElementById("CalendarTextBox");
  //Change the current image of the minus or plus.
  if (getCalendar == true){
  theObject.style.visibility = "visible";
  var posx = 0;
  var posy = 0;
    //Show the calendar.
 
    //The page we are loading.
    //var serverPage = "/common/emailafrienddisplay.php";
    //Set the open close tracker variable.
    var obj = document.getElementById(objID);
    xmlhttp.open("GET", serverPageLoc);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      obj.innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.send(null);
}
}
var ShowTextBox = true;
function showTextBox() {
  //The location we are loading the page into.
  var objID = "BottomTextBox";
  theObject = document.getElementById("BottomTextBox");

  //Change the current image of the minus or plus.
  if (ShowTextBox == true){
  theObject.style.visibility = "visible";
	if (showmore==0){
		var serverPage = "text.php";
		theObject.style.height = "auto";
		theObject.style.width = "400px";
	}
	else
	{
		showmore=0
		theObject.style.height ="auto";
		theObject.style.width = tbwidth+"px";
		var serverPage= "text.php?disp=full";
	}

  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
    //Show the calendar.

    //Set the open close tracker variable.
    ShowTextBoxDivesites = true;
    ShowTextBoxWeather = true;
    ShowTextBoxProperty = true;
    ShowTextBox = false;
    ShowTextBoxThings = true;
    ShowTextBoxHowTo = true;
    ShowTextBoxWTD == true;
 
    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 {
  theObject.style.visibility = "visible";
  theObject.style.height = "auto";
  theObject.style.width = "0px";
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
  //Hide the calendar.
  ShowTextBox = true;
  document.getElementById(objID).innerHTML = "";
}
}
var ShowTextBoxThings = true;
function showTextBoxThings() {
  //The location we are loading the page into.
  var objID = "BottomTextBox";
  theObject = document.getElementById("BottomTextBox");

  //Change the current image of the minus or plus.
  if (ShowTextBoxThings == true){
  theObject.style.visibility = "visible";
//	if (showmore==0){
//		var serverPage = "thingstodo.php";
//		theObject.style.height = "auto";
//		theObject.style.width = "400px";
//	}
//	else
//	{
		showmore=0
		theObject.style.height = "auto";
		theObject.style.width = tbwidth+"px";
		var serverPage= "thingstodo.php?disp=full";
//	}
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
    //Show the calendar.

    //Set the open close tracker variable.
    ShowTextBoxDivesites = true;
    ShowTextBoxWeather = true;
    ShowTextBoxProperty = true;
    ShowTextBoxThings = false;
    ShowTextBoxHowTo = true;
    ShowTextBoxMap = true;
    ShowTextBox = true;
    ShowTextBoxWTD == true;
    
    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 {
  theObject.style.visibility = "visible";
  theObject.style.height ="auto";
  theObject.style.width = "0px";
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
  //Hide the calendar.
  ShowTextBoxThings = true;
  document.getElementById(objID).innerHTML = "";
  showTextBox()
}
}

////////////////////////////////////////
////////////////////////////////////////
var ShowTextBoxProperty = true;
function showTextBoxProperty() {
  //The location we are loading the page into.
  var objID = "BottomTextBox";
  theObject = document.getElementById("BottomTextBox");

  //Change the current image of the minus or plus.
  if (ShowTextBoxProperty == true){
  theObject.style.visibility = "visible";
	if (showmore==0){
		var serverPage = "property.php";
		theObject.style.height = "auto";
		theObject.style.width = "400px";
	}
	else
	{
		theObject.style.height = "auto";
		theObject.style.width = tbwidth+"px";
		var serverPage= "property.php?next="+showmore ;
	}
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
    //Show the calendar.

    //Set the open close tracker variable.
    ShowTextBoxDivesites = true;
    ShowTextBoxWeather = true;
    ShowTextBoxProperty = false;
    ShowTextBoxThings = true;
    ShowTextBoxHowTo = true;
    ShowTextBoxMap = true;
    ShowTextBox = true;
    ShowTextBoxWTD == true;
    
    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 {
  theObject.style.visibility = "visible";
  theObject.style.height = "auto";
  theObject.style.width = "0px";
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
  //Hide the calendar.
  ShowTextBoxProperty = true;
  document.getElementById(objID).innerHTML = "";
  showTextBox()
}
}



var ShowTextBoxDivesites = true;
function showTextBoxDivesites() {
  //The location we are loading the page into.
  var objID = "BottomTextBox";
  theObject = document.getElementById("BottomTextBox");

  //Change the current image of the minus or plus.
  if (ShowTextBoxDivesites == true){
  theObject.style.visibility = "visible";
	if (showmore==0){
		var serverPage = "divesites.php";
		theObject.style.height = "auto";
		theObject.style.width = "400px";
	}
	else
	{
		theObject.style.height = "auto";
		theObject.style.width = tbwidth+"px";
		var serverPage= "divesites.php?next="+showmore ;
	}
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
    //Show the calendar.

    //Set the open close tracker variable.
    ShowTextBoxDivesites = false;
    ShowTextBoxWeather = true;
    ShowTextBoxProperty = false;
    ShowTextBoxThings = true;
    ShowTextBoxHowTo = true;
    ShowTextBoxMap = true;
    ShowTextBox = true;
    ShowTextBoxWTD == true;
    
    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 {
  theObject.style.visibility = "visible";
  theObject.style.height = "auto";
  theObject.style.width = "0px";
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
  //Hide the calendar.
  ShowTextBoxDivesites = true;
  document.getElementById(objID).innerHTML = "";
  showTextBox()
}
}






var ShowTextBoxHowTo = true;
function showTextBoxHowTo() {
  //The location we are loading the page into.
  var objID = "BottomTextBox";
  theObject = document.getElementById("BottomTextBox");

  //Change the current image of the minus or plus.
  if (ShowTextBoxHowTo == true){
  theObject.style.visibility = "visible";
	if (showmore==0){
		var serverPage = "howtogetthere.php";
		theObject.style.height = "auto";
		theObject.style.width = "400px";
	}
	else
	{
		showmore=0
		theObject.style.height = "auto";
		theObject.style.width = tbwidth+"px";
		var serverPage= "howtogetthere.php?disp=full";
	}
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
    //Show the calendar.
    
    //Set the open close tracker variable.
    ShowTextBoxDivesites = true;
    ShowTextBoxWeather = true;
    ShowTextBoxProperty = true;
    ShowTextBoxHowTo = false;
    ShowTextBox = true;
    ShowTextBoxThings= true;
    ShowTextBoxMap = true;
    ShowTextBoxWTD == true;
    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 {
  theObject.style.visibility = "visible";
  theObject.style.height = "auto";
  theObject.style.width = "0px";
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
  //Hide the calendar.
  ShowTextBoxHowTo = true;
  document.getElementById(objID).innerHTML = "";
  showTextBox()
}
}
var ShowTextBoxWTD = true;
function     showTextBoxWTD() {
  //The location we are loading the page into.
  var objID = "BottomTextBox";
  theObject = document.getElementById("BottomTextBox");

  //Change the current image of the minus or plus.
  if (ShowTextBoxWTD == true){
  theObject.style.visibility = "visible";
	if (showmore==0){
		var serverPage = "wheretodine.php";
		theObject.style.height = "auto";
		theObject.style.width = "400px";
	}
	else
	{
		
		theObject.style.height = "auto";
		theObject.style.width = tbwidth+"px";
		var serverPage= "wheretodine.php?disp=full&next="+showmore ;
	}
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
    //Show the calendar.
    
    //Set the open close tracker variable.
    ShowTextBoxDivesites = true;
    ShowTextBoxWeather = true;
    ShowTextBoxProperty = true;
    ShowTextBoxHowTo = true;
    ShowTextBoxMap = true;
    ShowTextBox = true;
    ShowTextBoxThings= true;
    ShowTextBoxWTD= 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 {
  theObject.style.visibility = "visible";
  theObject.style.height = "auto";
  theObject.style.width = "0px";
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
  //Hide the calendar.
  ShowTextBoxWTD= true;
  document.getElementById(objID).innerHTML = "";
  showTextBox()
}
}
var ShowTextBoxWeather = true;
function showTextBoxWeather() {
  //The location we are loading the page into.
  var objID = "BottomTextBox";
  theObject = document.getElementById("BottomTextBox");

  //Change the current image of the minus or plus.
  if (ShowTextBoxHowTo == true){
  theObject.style.visibility = "visible";
	if (showmore==0){
		var serverPage = "weather.php";
		theObject.style.height = "auto";
		theObject.style.width = "400px";
	}
	else
	{
		showmore=0
		theObject.style.height = "auto";
		theObject.style.width = tbwidth+"px";
		var serverPage= "weather.php?disp=full";
	}
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
    //Show the calendar.
    
    //Set the open close tracker variable.
    ShowTextBoxDivesites = true;
    ShowTextBoxWeather = false;
    ShowTextBoxMap = true;
    ShowTextBoxProperty = true;
    ShowTextBoxHowTo = true;
    ShowTextBox = true;
    ShowTextBoxThings= true;
    ShowTextBoxWTD == true;
    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 {
  theObject.style.visibility = "visible";
  theObject.style.height = "auto";
  theObject.style.width = "0px";
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
  //Hide the calendar.
  ShowTextBoxWeather = true;
  document.getElementById(objID).innerHTML = "";
  showTextBox()
}
}

var ShowTextBoxMap = true;
function showTextBoxMap() {
  //The location we are loading the page into.
  var objID = "BottomTextBox";
  theObject = document.getElementById("BottomTextBox");

  //Change the current image of the minus or plus.
  if (ShowTextBoxMap == true){
  theObject.style.visibility = "visible";
	if (showmore==0){
		var serverPage = "map.php";
		theObject.style.height = "auto";
		theObject.style.width = "400px";
	}
	else
	{
		showmore=0
		theObject.style.height = "auto";
		theObject.style.width = tbwidth+"px";
		var serverPage= "map.php?disp=full";
	}
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
    //Show the calendar.
    
    //Set the open close tracker variable.
    ShowTextBoxDivesites = true;
    ShowTextBoxMap = false;
    ShowTextBoxWeather = true;
    ShowTextBoxProperty = true;
    ShowTextBoxHowTo = true;
    ShowTextBox = true;
    ShowTextBoxThings= true;
    ShowTextBoxWTD == true;
    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 {
  theObject.style.visibility = "visible";
  theObject.style.height = "auto";
  theObject.style.width = "0px";
  var posx = 0;
  var posy = 0;
  //posx = e.clientX + document.body.scrollLeft;
  //posy = e.clientY + document.body.scrollTop;
  posx = document.body.scrollLeft;
  posy = document.body.scrollTop;
  
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
  //Hide the calendar.
  ShowTextBoxMap = true;
  document.getElementById(objID).innerHTML = "";
  showTextBox()
}
}

// END BASE BUTTON FUNCTIONS



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);
  xmlhttp.open("GET", serverPage);
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      obj.innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.send(null);
}
function closetask (){
  theObject = document.getElementById("createtask");
  theObject.style.visibility = "hidden";
  theObject.style.height = "0px";
  theObject.style.width = "0px";
  acObject = document.getElementById("autocompletediv");
  acObject.style.visibility = "hidden";
  acObject.style.height = "0px";
  acObject.style.width = "0px";
}
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;
}
function autocomplete (thevalue, e){
  theObject = document.getElementById("autocompletediv");
  theObject.style.visibility = "visible";
  theObject.style.width = "152px";
  var posx = 0;
  var posy = 0;
  posx = (findPosX (document.getElementById("yourname")) + 1);
  posy = (findPosY (document.getElementById("yourname")) + 23);
  theObject.style.left = posx + "px";
  theObject.style.top = posy + "px";
  var theextrachar = e.which;
  if (theextrachar == undefined){
    theextrachar = e.keyCode;
  }
  //The location we are loading the page into.
  var objID = "autocompletediv";
    //Take into account the backspace.
    if (theextrachar == 8){
      if (thevalue.length == 1){
        var serverPage = "autocomp.php";
      } else {
        var serverPage = "autocomp.php" + "?sstring=" + thevalue.substr (0, (thevalue.length -1));
      }
    } else {
      var serverPage = "autocomp.php" + "?sstring=" + thevalue + String.fromCharCode (theextrachar);
    }
    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);
  }
  function setvalue (thevalue){
    acObject = document.getElementById("autocompletediv");
    acObject.style.visibility = "hidden";
    acObject.style.height = "0px";
    acObject.style.width = "0px";
    document.getElementById("yourname").value = thevalue;
  }
