
// Original javascript menu

activateMenu = function(nav) {
  /* currentStyle restricts the Javascript to IE only */

	if (document.all && document.getElementById(nav).currentStyle) {
    var navroot = document.getElementById(nav);
		/* Get all the list items within the menu */

		var lis=navroot.getElementsByTagName("LI");

      for (i=0; i<lis.length; i++) {
        /* If the LI has another menu level */
        if(lis[i].lastChild.tagName=="UL"){
        /* assign the function to the LI */
         	lis[i].onmouseover=function() {
          /* display the inner menu */
            this.lastChild.style.display="block";
          }
          lis[i].onmouseout=function() {

          this.lastChild.style.display="none";

        }
      }
    }
  }
}

window.onload= function(){
  /* pass the function the id of the top level UL */
  /* remove one, when only using one menu */
 if (document.getElementById('nav')) {
   activateMenu('nav');
 }
 if (document.getElementById('nav2')) {
   activateMenu('nav2');
 }
 if (document.getElementById('nav3')) {
   activateMenu('nav3');
 }
 initLightbox();
}

// End original javascript menu

  // Validate the optional email contact form for pages and
  // sub-pages

function validateEmail(){

  if (document.getElementById('name').value == '') {
    document.getElementById('name').focus();
    alert('The name field is required\n');
    return false;
  }
  if (document.getElementById('email').value == '') {
    document.getElementById('email').focus();
    alert('The email field is required\n');
    return false;
  }
  if (document.getElementById('comments').value == "") {
    document.getElementById('comments').focus();
    alert('The comments field is required\n');
    return false;
  }
  return true;
}

  // Validate the optional email contact form for pages and
  // sub-pages

function validateGuestbook(){

  if (document.getElementById('name').value == '') {
    document.getElementById('name').focus();
    alert('The name field is required\n');
    return false;
  }
  if (document.getElementById('email').value == '') {
    document.getElementById('email').focus();
    alert('The email field is required\n');
    return false;
  }
  if (document.getElementById('comment').value == "") {
    document.getElementById('comment').focus();
    alert('The comment field is required\n');
    return false;
  }
  return true;
}

// Shows all hidden images from a gallery or hides all images
// if they are shown.  Takes two parameters, gallery and number.
// The gallery value is for the gallery to show/hide, whereas
// number is the number of images in the gallery

function showall(gallery, number){

  if (document.getElementById(gallery + '2').style.display == 'none') {
    for (i = 2;i <= number;i++){
      var showname = '' + gallery + i;
      document.getElementById(showname).style.display = 'inline';
    }
  } else {
    for (i = 2;i <= number;i++){
      var showname = '' + gallery + i;
      document.getElementById(showname).style.display = 'none';
    }
  }
}

// Shows a related faq answer to a faq question.

function showfaq(faqnumber){

  if (document.getElementById(faqnumber).style.display == 'none') {
    document.getElementById(faqnumber).style.display = 'inline';
  } else {
    document.getElementById(faqnumber).style.display = 'none';
  }
}

// Makes an seo friendly filename

function makeSeo(title) {

  var title = title;
  //document.getElementById('title').value;
  var replaces = ["#", " ", "$", '[', ']'];
  var repwiths = ["-", "-", "-", "-", "-"];

  for (var i = 0;i < replaces.length;i++) {
    var index = title.indexOf(replaces[i]);
    while (index != -1) {
      title = title.replace(replaces[i], repwiths[i]);
      index = title.indexOf(replaces[i]);
    }
  }
  document.getElementById('filename').value = title.toLowerCase();
}
