YAHOO.util.Event.onContentReady("navigation", function () {
  var oMenuBar = new YAHOO.widget.MenuBar("navigation", {
                        autosubmenudisplay: true,
                        hidedelay: 0,
                        showdelay:0,
                        lazyload: true });
  oMenuBar.render();
});

YAHOO.util.Event.onContentReady("slideHolder", function(ev) {
  var carousel = new YAHOO.widget.Carousel("slideHolder", {
    isCircular: false, numVisible: 1, autoPlayInterval: 8000, animation: { speed: .5 }
  });
  
  carousel.render();
  carousel.show();
  carousel.startAutoPlay();
});

function openLinkInNewWindow(e) {
  //alert("clicked");
  var url = YAHOO.util.Event.getTarget(e);
  e.preventDefault();
  window.open(url);
}

function validateForm(){
  var isValid = true;
  var errorMessage = "";
  var name=document.forms["myForm"]["name"].value;
  var phone=document.forms["myForm"]["phone"].value;
  var email=document.forms["myForm"]["email"].value;
  document.getElementById("name").setAttribute("class", "");
  document.getElementById("phone").setAttribute("class", "");
  document.getElementById("email").setAttribute("class", "");
  
  //check name
  if (name==null || name==""){
    errorMessage += "Please enter your NAME\n";
    document.getElementById("name").setAttribute("class", "invalidFormField");
    document.getElementById("name").focus();
    isValid = false;
  }
  
  // check phone
  if (phone==null || phone==""){
    errorMessage += "Please enter your PHONE NUMBER\n";
    document.getElementById("phone").setAttribute("class", "invalidFormField");
    document.getElementById("phone").focus();
    isValid = false;
  }
  
  // check email
  var atpos=email.indexOf("@");
  var dotpos=email.lastIndexOf(".");
  if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length){
    errorMessage += "Please enter a valid EMAIL ADDRESS\n";
    document.getElementById("email").setAttribute("class", "invalidFormField");
    document.getElementById("email").focus();
    isValid = false;
  }
  
  // if valid form submit, otherwise show error message
  if (isValid){
    return true;
  } else {
    alert(errorMessage);
    return false;
  }
  
}

function clearNonNumericValue(x){
  var currentValue = document.getElementById(x).value;
  if (isNaN(currentValue)){
    document.getElementById(x).value = "";
  } else {
    document.getElementById(x).value = currentValue;
  }
}

function goToPlantPage(plantUrl){
  location.href=plantUrl;
}

