function setFocus() {
  if ((navigator.userAgent.toLowerCase().indexOf("msie") < 0) || (parseInt(navigator.appVersion) >= 4)) {
    focus();
  }
}
function requireFrames(Url) {
	if (top.frames.length < 1) {
		top.location = Url;
	}
}
function breakFrames() {
  if (top.location != self.location) {
	  top.location = self.location
	}
}
function validateForm(myform) {
<!-- Check for required fields when Enter pressed or Submit clicked -->

<!-- FirstName Field is required -->
  if (myform.FirstName.value=="") {
    alert("Please provide your first name.");
    myform.FirstName.focus();
    return false;
  }

<!-- LastName Field is required -->
  if (myform.LastName.value=="") {
    alert("Please provide your last name.");
    myform.LastName.focus();
    return false;
  }

<!-- Address1 Field is required -->
  if (myform.Address1.value=="") {
    alert("Please provide your street address.");
    myform.Address1.focus();
    return false;
  }

<!-- City Field is required -->
  if (myform.City.value=="") {
    alert("Please provide your city.");
    myform.City.focus();
    return false;
  }

<!-- State Field is required -->
  if (myform.State.value=="") {
    alert("Please provide your state.");
    myform.State.focus();
    return false;
  }

<!-- Zip Code Field is required -->
  if (myform.ZipCode.value=="") {
    alert("Please provide your zip code.");
    myform.ZipCode.focus();
    return false;
  }

<!-- Email Field is required -->
  if (myform.Email.value=="") {
    alert("Please provide your email address.");
    myform.Email.focus();
    return false;
  }

  return true;
}

function setStyle(theCell, newClass){
  cells = theCell.parentNode.cells;
  for (i = 0; i < cells.length; i++) {
    if (newClass){
      cells[i].orgClass = cells[i].className;
      cells[i].className = newClass;
    } else {
      cells[i].className = cells[i].orgClass;
    }
  }
}

function navClick(url) {
	location.href = url;
}

function stopRKey(evt) {
  var evt  = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text")) { return false; }
}
function resetTarget()
{
  aspnetForm.target='_self';
}

function writeMenu(level)
{
  var s1;
  if (level == 0) {
    s1 = "<table cellpadding=\"0\" cellspacing=\"0\" style=\"margin: 0; border: 0; width: 180px; background-image: url('images/middleNav.gif')\">";
    s1 += "<tr><td style=\"background-image: url('images/topNav.gif')\">&nbsp;</td></tr>";
    s1 += "<tr>";
    s1 += "<td class=\"nav\" onclick=\"navClick('index.html');\" onmouseover=\"setStyle(this, 'navOvr')\"";
    s1 += "  onmouseout=\"setStyle(this)\">";
    s1 += "  <a class=\"nav\" href=\"index.html\" target=\"_self\">Home</a></td>";
    s1 += "</tr>";
  }
  else if (level == 1) {
    s1 = "<table cellpadding=\"0\" cellspacing=\"0\" style=\"margin: 0; border: 0; width: 180px; background-image: url('../images/middleNav.gif')\">";
    s1 += "<tr><td style=\"background-image: url('../images/topNav.gif')\">&nbsp;</td></tr>";
    s1 += "<tr>";
    s1 += "<td class=\"nav\" onclick=\"navClick('../index.html');\" onmouseover=\"setStyle(this, 'navOvr')\"";
    s1 += "  onmouseout=\"setStyle(this)\">";
    s1 += "  <a class=\"nav\" href=\"../index.html\" target=\"_self\">Home</a></td>";
    s1 += "</tr>";
  }

  s1 += "<tr>"
  s1 += "<td class=\"nav\" onclick=\"navClick('http://www.mesavarsity.org/calendar/index.html');\" onmouseover=\"setStyle(this, 'navOvr')\"";
  s1 += "      onmouseout=\"setStyle(this)\">";
  s1 += "    <a class=\"nav\" href=\"http://www.mesavarsity.org/calendar/index.html\" target=\"_self\">Calendar</a></td>";
  s1 += "</tr>";
  s1 += "<tr>"
  s1 += "<td class=\"nav\" onclick=\"navClick('http://huddle.mesavarsity.org');\" onmouseover=\"setStyle(this, 'navOvr')\"";
  s1 += "      onmouseout=\"setStyle(this)\">";
  s1 += "    <a class=\"nav\" href=\"http://huddle.mesavarsity.org\" target=\"_self\">Huddle</a></td>";
  s1 += "</tr>";
  s1 += "<tr>"
  s1 += "<td class=\"nav\" onclick=\"navClick('http://training.mesavarsity.org');\" onmouseover=\"setStyle(this, 'navOvr')\"";
  s1 += "      onmouseout=\"setStyle(this)\">";
  s1 += "    <a class=\"nav\" href=\"http://training.mesavarsity.org\" target=\"_self\">Training</a></td>";
  s1 += "</tr>";
  s1 += "<tr>"
  s1 += "<td class=\"nav\" onclick=\"navClick('http://ontarget.mesavarsity.org');\" onmouseover=\"setStyle(this, 'navOvr')\"";
  s1 += "      onmouseout=\"setStyle(this)\">";
  s1 += "    <a class=\"nav\" href=\"http://ontarget.mesavarsity.org\" target=\"_self\">On-Target</a></td>";
  s1 += "</tr>";
  s1 += "<tr>"
  s1 += "<td class=\"nav\" onclick=\"navClick('http://rendezvous.mesavarsity.org');\" onmouseover=\"setStyle(this, 'navOvr')\"";
  s1 += "      onmouseout=\"setStyle(this)\">";
  s1 += "    <a class=\"nav\" href=\"http://rendezvous.mesavarsity.org\" target=\"_self\">Rendezvous</a></td>";
  s1 += "</tr>";

  if (level == 0) {
    s1 += "<tr><td style=\"font-size: 14pt; background-image: url('images/bottomNav.gif')\">&nbsp;</td></tr>";
    s1 += "</table>"
  }
  else if (level == 1) {
    s1 += "<tr><td style=\"font-size: 14pt; background-image: url('../images/bottomNav.gif')\">&nbsp;</td></tr>";
    s1 += "</table>"
  }
  document.write(s1);
}

function writeFooter()
{
  var s1;
  var CurrentYear = new Date();
  CurrentYear = CurrentYear.getFullYear();
  s1 = "<center>";
  s1 += "<font size=\"-1\">For information about this website contact:&nbsp;";
  s1 += "<a href=\"mailto:mikeheaton@cox.net\">webmaster@mesavarsity.org</a><br/>";
  s1 += "&copy;&nbsp;COPYRIGHT 2008-" + CurrentYear.toString() + " by Mesa District Varsity B.S.A. - All Rights Reserved.<br/>";
  s1 += "All other trademarks are property of their respective holders.<br/>";
  s1 += "Not an official site of the Boy Scouts of America<br/>";
  s1 += "</font>";
  s1 += "</center>";
  document.write(s1);
}

function writePageHeader(level)
{
  var s1;
  s1 = "<table style=\"width: 100%; margin: 0; padding: 0\" cellspacing=\"0\" cellpadding=\"0\">";
  s1 += "<tr>";
  s1 += "  <td valign=\"top\" style=\"width: 196px; padding: 8;\">";
  s1 += "    <a href=\"../index.html\"><img alt=\"Mesa Varsity Scouts\" src=\"../images/PageHead2.jpg\" /></a></td>";
  s1 += "  <td style=\"text-align: right; vertical-align: top\">";

  s1 += "    <table align=\"right\" cellpadding=\"10\"><tr><td>";
  s1 += "    <a class=\"navTop\" href=\"http://www.mesavarsity.org\">Mesa&nbsp;Varsity&nbsp;Home</a>&nbsp;|&nbsp;<a class=\"navTop\" href=\"http://www.mesavarsity.org/contact.html\">contact&nbsp;us</a>";
  s1 += "    </td></tr></table>";

  s1 += "  </td>";

  s1 += "</tr>";
  s1 += "</table>";
  document.write(s1);
}

function Highlight(id)
{
  var div = document.getElementById(id);
  //div.style.fontWeight = "bold";
  div.style.color = "black";
  var colors = ["white", "black", "white", "black", "white", "black"];
  var nextColor = 0;
  var intervalId = setInterval(animate, 500);

  function animate() {
    div.style.color = colors[nextColor++%colors.length];
    if (nextColor == colors.length) {
      clearInterval(intervalId);
    }
  }
  return false;
}

function daysBetween(date1, date2) {

    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)

    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY)

}

function writeSideBar()
{
  var s1;
  var target = new Date();
  target.setDate(19);
  target.setMonth(2);  // January = 0
  target.setYear(2009);
  var today = new Date();

  s1 = "<center>";
  s1 += "<table cellpadding=\"10\"><tr><td>";
  s1 += "<div id=\"sidebar\" style=\"text-align: center; font-size: 20px;\">";
  if (target > today) {
    s1 += "<b>The countdown has begun.  Only " + daysBetween(today, target).toString() + " more days until Rendezvous 2009 begins!!!</b>";
  }
  else {
    s1 += "<b>The next rendezvous will be held in 2011.</b>";
  }
  s1 += "</div>";
  s1 += "</td></tr></table>";
  s1 += "</center>";

  document.write(s1);
  Highlight("sidebar");
}

function getX(element)
{
  var x = 0;
  for (var e = element; e; e = e.offsetParent) {
    x += e.offsetLeft;
  }
  for (e = element.parentNode; e && e != document.body; e = e.parentNode) {
    if (e.scrollLeft) {
      x -= e.scrollLeft;                // subtract scrollbar values
    }
  }
  return x;
}

function getY(element)
{
  var y = 0;
  for (var e = element; e; e = e.offsetParent) {
    y += e.offsetTop;
  }
  for (e = element.parentNode; e && e != document.body; e = e.parentNode) {
    if (e.scrollTop) {
      x -= e.scrollTop;                // subtract scrollbar values
    }
  }
  return y;
}

var movePass = 0;

function moveButton(object, event)
{
  var e = event || window.event; // Get event details for IE
  var left = getX(object);
  if (movePass > 2) {
    movePass = 0;
    object.style.position = "static";
    alert("Have you figured it out yet?  You are not going to have much success clicking on the \"Don't Need Training\" button.  And clearly you will be a lot more effective with much less effort if you are properly trained!!!");
    Highlight("sidebar");
    return;
  }
  else {
    var top = getY(object);
    top += ((movePass == 0) || (movePass == 2))? -30 : 30;
    object.style.position = "absolute";
    object.style.top = top + "px";
    object.style.left = left + "px";
  }
  movePass++;
}

function writeAboveTraining()
{
  var s1;
  s1 = "<center>";
  s1 += "<hr>";
  s1 += "<table cellpadding=\"10\"><tr><td>";
  s1 += "<div id=\"sidebarAboveTraining\" style=\"color: black; text-align: center; font-size: 14px; font-weight: bold\">Never been trained<br />and don't believe you<br />need any?<br /><br />Click here:</div>";
  s1 += "<br />";
  s1 += "<button id='move' style='width: 150' onmouseover='moveButton(this, event)'>Don't Need Training</button>";
  s1 += "</td></tr></table>";
  s1 += "</center>";
  s1 += "<hr>";

  document.write(s1);
  Highlight("sidebar");
}
