function showMenu(which) {
	var eltclass = document.getElementById(which).getElementsByTagName('ul')[0].className;

    hideMenus();
	
	if (eltclass == "navigation_hide") {
	    document.getElementById(which).getElementsByTagName('ul')[0].className = "navigation_show";
	}
}

function hideMenus() {
	var uls = document.getElementById('navigation').getElementsByTagName('ul');
	for (var i=0; i < uls.length; i++) {
	    uls[i].className = "navigation_hide";	
	}
}

function validateMailingList(fname, lname, email) {
	if (fname.value == "" || fname.value == null || fname.value == "First Name") {
	    alert("Please enter a first name.");
	    return false;
	}
	if (lname.value == "" || lname.value == null || lname.value == "Last Name") {
	    alert("Please enter a last name.");
	    return false;
	}
    return validateEmail(email);
	
	return true;
}

function validateEmail(emailAddr) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAddr.value)) {
        return (true)
    } else {
	    alert("Please enter a valid email address.");
	    return false;
    }
}

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');
		
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2500, function() {
            $active.removeClass('active last-active');
        });
}

function validateBuyBook() {
	if ((document.search.elements[0].value == "") || (document.search.elements[1].value == "") ||
		(document.search.elements[2].value == "") || (document.search.elements[3].value == "") ||
		(document.search.elements[4].value == "") || (document.search.elements[5].value == "") ||
		(document.search.elements[6].value == "") || (document.search.elements[7].value == "") ||
		(document.search.elements[9].value == "")

	) {
		alert("Please fill in all required fields.");
		return false;
	}

	if (document.search.elements[7].value.length < 10) {
		alert("Please enter a valid phone number (including area code).");
		return false;
	}
	
    if (validateEmail(document.search.elements[9])) {
		return true;
	} else {
		return false;
	}
	
	return true;
}

function showDirections(which) {
	if (document.getElementById(which + "_title").className != "contact_us_directions_title_open") {
	    $('#directions_peninsula').hide();
	    $('#directions_bay_bridge').hide();
	    $('#directions_golden_gate_bridge').hide();
	
	    document.getElementById("directions_peninsula_title").className = "contact_us_directions_title";
	    document.getElementById("directions_bay_bridge_title").className = "contact_us_directions_title";
	    document.getElementById("directions_golden_gate_bridge_title").className = "contact_us_directions_title";

        document.getElementById(which + "_title").className = "contact_us_directions_title_open";
	    $('#' + which).fadeIn('slow');
    }
}

var showing = 'home_picture';
function showVideo(which) {
    document.getElementById(showing).style.visibility = "hidden";
    document.getElementById(which).style.visibility = "visible";
	if (showing == 'home_picture') {
        document.getElementById(which).style.display = "block";
	}
    //$('#' + showing).hide();
	//$('#' + which).show();
	showing = which;
}

function validation(emptyCheck,id_string) {
   if (emptyCheck == "") { 
	var el = document.getElementById(id_string);
	if (el.innerHTML.charAt(el.innerHTML.length - 1) != '*') { el.innerHTML = el.innerHTML + "*"; }
	el.style.color = "red";
	return 1;
    } else {
	var el = document.getElementById(id_string);
	if (el.innerHTML.charAt(el.innerHTML.length - 1) == '*') { el.innerHTML = el.innerHTML.substring(0,el.innerHTML.length-1); }
	el.style.color = "black";
	return 0;
    } 
}

function validatewaitlist() {
    var frm = document.getElementById('wlform');
    var errs = 0;
    errs += validation(frm.FirstName.value,'fn_error');
    errs += validation(frm.LastName.value,'ln_error');
    errs += validation(frm.Email.value,'em_error');
    errs += validation(frm.HomePhone.value,'ph_error');

    if (errs > 0) { 
	var mt = document.getElementById('moretext');
	mt.innerHTML = "You must provide data for the required fields below."; 
	mt.style.color = 'red';
    }
    
    return (errs == 0);
}

function getFlashMovieObject(movieName) {
//alert('getting movie: ' + movieName);
  if (window.document[movieName]) {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1) {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  } else { // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    return document.getElementById(movieName);
  }
}

function scrollToAnchor(eltID) {
  var theElt = '#' + eltID;
  var elt = $(theElt);
  var os = elt.offset();
  window.scrollTo(0,os.top - 20);
}

function showJobDescription(which) {
	if ($(which).html() == "Show Description") {
	  $(which).parents('.job').find('.job_description').show();
	  $(which).html('Hide Description');
	} else {
	  $(which).parents('.job').find('.job_description').hide();
	  $(which).html('Show Description');
	}
}
