    // javascript file menuControl.js
	//
	//   Villa Project: shared file to display active menu element
	//
	//   Version   Date         Author   Desctiption
	//    1.0      05/07/2007   ddsp     Control navigation active menu only
	//    1.1      05/07/2007   ddsp     Change calling parameter to menuBaseName, activeSelection
	//    1.2      05/18/2007   ddsp     Add reloadURL(extraSettings) for lanuage changes
	//    1.3      12/28/2007   ddsp     Add setActiveVillaMenu, newVilla
	//    1.4      06/26/2008   ddsp     Add changeSelection for HTML selections
	//
	//   Requires shared.css for nav menu classes
    function setActiveClass(baseName, activeElement, classActive, classInactive)
    {
      var mIndex = 0;
      var mName = baseName + mIndex;
      //  Allow the list of menu elements to start at either 0 or 1
      if (document.getElementById(mName) == null) {mIndex = 1;}
      var mObject
      do
	  {
         mName = baseName + mIndex;
         mObject = document.getElementById(mName);
         if (mObject != null)
         {
            mObject.className = (mIndex == activeElement) ? classActive : classInactive;
            mIndex = mIndex + 1
         }
      } while (mObject != null);
    }
    
    function setActiveMenu(menuBaseName, activeSelection)
    {
        setActiveClass(menuBaseName, activeSelection, "navlinkselect", "navlink");
    }
    
    function setActiveVillaMenu(menuBaseName, activeSelection)
    {
        setActiveClass(menuBaseName, activeSelection, "navlinkselect", "vnavlink");
    }

    function reloadURL(extraSettings)
    {
      if (extraSettings == null) { extraSettings = ""; }
      document.location.href = window.location.pathname+extraSettings;
    }    

    function newVilla(newVillaCode)
    {
       reloadURL("?villa="+newVillaCode);
    }
    
    //  Villa Selections is a selection object
    //  changeShift = +/-
    //  action: -1: First/Last only, 0=No loop, 1=loop
    //  Returns the new index value
    //  Example:  Get the value of the next option 
    //      this.options[changeSelection(this,+1,1)].value
    function changeSelection(selectionID, changeShift, action) 
    {
    	 var  thisSelection = document.getElementById(selectionID);
    	 var  lastSelection = thisSelection.options.length-1;
    	 var  oldSelection = thisSelection.selectedIndex;
    	 // alert("select "+changeShift+" from "+oldSelection+" with last = "+lastSelection);
    	 if (action == -1) 
    	 {
    	 	  if (changeShift < 0) {newSelection = 0; }
    	 	  else                 {newSelection = lastSelection; }
    	 }
    	 else
    	 {
    	 	  newSelection = oldSelection + changeShift;
    	 	  if (newSelection < 0)
    	 	  {
    	 	  	 if (action == 0) { newSelection = 0; }
    	 	  	 else             { newSelection = lastSelection; }
    	 	  }
    	 	  else if (newSelection > lastSelection)
    	 	  {
    	 	  	if (action == 0) { newSelection = lastSelection; }
    	 	  	else             { newSelection = 0; }
    	 	  }
    	 }
    	 return newSelection;
    }
    
    //  Dummy to make href look good. 
    function changeVilla()
    {
    }
