// ----------------------------------------------------------------------------------------------------
/*
   Program: a1villa_menus.js

   Author:  James Whitfield
   Date:    9 June 2004

   Description:
   Creates the drop-down menu constructs - highlighting etc...

   Amendments:

   15/01/05  JJW  Replaces a1villa_dropdown.js
   17/04/05  JJW  Included 'kissimmee.htm'
   19/11/05  JJW  Included 'carhire.htm'
   21/01/06  JJW  Moved 'golf.htm' to Kissimmee menu.
   10/04/06  JJW  Amended widths to accommodate new font.
   22/10/06  JJW  Added in 'SelectQuickLink'.
   26/11/06  JJW  Added in 'Booking Summary'.
   16/12/06  JJW  Include <DIV> tag for drop-down menus.
   04/03/07  JJW  Included 'eating_out.htm'
   24/03/07  JJW  'Site Map' included in Bookings drop-down.
   16/12/07  JJW  Revamped for 2008
   26/08/08  JJW  Included 'hover' for buttons.
   25/02/09  JJW  Revamped for 2009.
   07/07/09  JJW  Replaced 'parentElement' with 'parentNode' for Firefox compatibility.
   22/01/10  JJW  Web 8.1 improvements
   14/05/10  JJW  Integration with MyA1villa.com

*/
// ----------------------------------------------------------------------------------------------------

var menu_visible= false; 
var last_menu_id_shown= 0;

// ----------------------------------------------------------------------------------------------------

function chr(ascii) { return String.fromCharCode(ascii) };

// ----------------------------------------------------------------------------------------------------

function PopulateTabMenus(thismenu) {
// Create the individual drop-down menus with related items and associated URL or javascript code.
// Builds up the HTML code directly.

   var tabs_main = ["welcome","elegant","lakeside","location","florida","bookings"];

   var tabmenu_captions = 
     ["Home|villa: Elegant|villa: Lakeside|Indian Wells|Availabilty & Rates|World Cup 2010|FAQs|Copyright",
      "Villa Overview|Living & Dining|Bedrooms|Private Pool & Deck|Floorplan",
      "Villa Overview|Living & Dining|Bedrooms|Private Pool & Deck|Floorplan",
      "Location, Map & Community|Shopping, Dining & Medical|Golf Courses",
      "Parks & Attractions|Sunshine State|Rental Car Hire|Useful Information",
      "Availability & Rates|Terms & Conditions|Frequently Asked Questions|Check My Booking"];

   var tabmenu_urls = 
     ["home.htm|elegant_quicktour.htm|lakeside_quicktour.htm|indianwells.htm|availabilityrates.htm|indianwells_shops.htm#indianwells_bars|faqs.htm|copyright.htm",
      "elegant_quicktour.htm|elegant_livingdining.htm|elegant_bedrooms.htm|elegant_pool.htm|elegant_floorplan.htm",
      "lakeside_quicktour.htm|lakeside_livingdining.htm|lakeside_bedrooms.htm|lakeside_pool.htm|lakeside_floorplan.htm",
      "indianwells.htm|indianwells_shops.htm|golf.htm",
      "parksandattractions.htm|florida.htm|carhire.htm|florida_faqs.htm",
      "availabilityrates.htm|terms.htm|faqs.htm|bookingsummary.htm"];

   var tabselected = document.getElementById("tab_" + thismenu);
   var tabmenu     = document.getElementById("tab_menu");
   var mnidx;
   var itemidx;

// Get the name of the current document/page

   var thisurl     = document.location.href;
   var thisurlpage = thisurl.split("/");
   var thispage    = thisurlpage[thisurlpage.length -1];

   for (midx = 0; midx < tabs_main.length; midx++) {
        if (tabs_main[midx] == thismenu) { mnidx = midx };
        tabid= document.getElementById("tab_" + tabs_main[midx]);
        if (tabid.className == "menu_tabselected") {
           tabid.className = "menu_tab";
           tabid.innerHTML = "<a href=\"javascript: PopulateTabMenus('"+ tabs_main[midx] + "');\" class=\"h100tab\" " +
                             "onMouseOver=\"HLTabOn(this);\" onMouseOut=\"HLTabOff(this);\">" + tabid.innerHTML + "</a>";
         };
   }; //for

// Set the selected tab to just the anchor text
   tabselected.className = "menu_tabselected";
   tabselected.innerHTML = tabselected.innerHTML.split(">")[1].split("<")[0];
   tabmenu_caption = tabmenu_captions[mnidx].split("|");
   tabmenu_url  = tabmenu_urls[mnidx].split("|");

   for (itemidx in tabmenu.rows[0].cells) { 
       tabmenu.rows[0].cells[itemidx].innerHTML = "";
       tabmenu.rows[0].cells[itemidx].className = "";
     }; //for

//   tabmenu.rows[0].cells[0].innerHTML = tabs_main[mnidx] + ": ";
//   tabmenu.rows[0].cells[0].className = "menu_item";

   for (itemidx=0;itemidx<=tabmenu_caption.length -1;itemidx++) {

       if ((tabmenu_url[itemidx] == thispage) || 
         (((thispage == "index.html") || (thispage == "")) && (tabmenu_url[itemidx] == "home.htm"))) {

          tabmenu.rows[0].cells[(itemidx *2) +1].innerHTML = 
               "<td><a class=\"menu_item_selected\">" + tabmenu_caption[itemidx] + "</a></td>\n";
//          HLOn(itemidx *2 +1);
        } else {
          tabmenu.rows[0].cells[(itemidx *2) +1].innerHTML = 
               "<td><a href=\"" + tabmenu_url[itemidx] + "\" " +
               "onMouseOver=\"HLOn(" + ((itemidx *2) +1) + ");\" " +
               "onMouseOut=\"HLOff(" + ((itemidx *2) +1) + ");\" " +
               "class=\"menu_item\">" + tabmenu_caption[itemidx] + "</a></td>\n";
       }; //if

       if (itemidx != tabmenu_caption.length -1) { 
          tabmenu.rows[0].cells[itemidx *2 +2].innerHTML = "|";
          tabmenu.rows[0].cells[itemidx *2 +2].className = "menu_item_divide"
       }; //if

   } // for
}


// ----------------------------------------------------------------------------------------------------

function HLTabOn(tabid) {
  if (tabid.parentNode) { tabid.parentNode.className="menu_tab_over" };
}

// ----------------------------------------------------------------------------------------------------

function HLTabOff(tabid) {
   if (tabid.parentNode) { tabid.parentNode.className="menu_tab" };
}

// ----------------------------------------------------------------------------------------------------

function HLOn(seqno) {
   if (!document.getElementById) return;
   obj=document.getElementById("tab_menu");
   obj.rows[0].cells[seqno].className = "menu_item_background";
}

// ----------------------------------------------------------------------------------------------------

function HLOff(seqno) {
   if (!document.getElementById) return;
   obj=document.getElementById("tab_menu");
   obj.rows[0].cells[seqno].className = "";
}
// ----------------------------------------------------------------------------------------------------

function HideDropDownMenu(menu_to_hide) {

   if (!document.getElementById) return;

   menu_id= menu_to_hide.substring(5,99);
   if (menu_visible && last_menu_id_shown == menu_id) return;

   menulist= document.getElementById(menu_id);
   menulist.style.visibility= "hidden";

//   a1menuitem= document.getElementById(menu_id_to_hide);
//   srcjpg= a1menuitem.src;
//   if (srcjpg.charAt(srcjpg.length -5) == "2") {
//      a1menuitem.src = srcjpg.substring(0,srcjpg.length -5) + "0.gif";
//   }
}


// ----------------------------------------------------------------------------------------------------

function SlowTimeoutMenu(current) {
   menu_visible= false;
   window.setTimeout("HideDropDownMenu('menu-" + current + "');",500);
}

// ----------------------------------------------------------------------------------------------------

function TimeoutMenu(menu_to_hide) {
   menu_visible= false;
   window.setTimeout("HideDropDownMenu('" + menu_to_hide + "');",10);
}

// ----------------------------------------------------------------------------------------------------

function ShowDropDownMenu(menu_to_show) {

   if (!document.getElementById) return;

// Reset previously selected menu
   prev_menu_id_shown= last_menu_id_shown;

// Quick disappear
//   if (prev_menu_id_shown) HideDropDownMenu(prev_menu_id_shown);

   last_menu_id_shown= menu_to_show.substring(5,99);
   menu_visible= true;

   a1pageid =  document.getElementById("a1page");
   a1menu_id = document.getElementById("a1menu");
   a1menuitem= document.getElementById(menu_to_show);
   menulist=   document.getElementById(last_menu_id_shown);

//   srcjpg = a1menuitem.src;
//   if (srcjpg.charAt(srcjpg.length -5) == "0") {
//      a1menuitem.src = srcjpg.substring(0,srcjpg.length -5) + "2.gif";
//   }

   switch(menu_to_show) {
     case "menu-welcome" :
       menuwidth= 90;
       offset=0;
       break;
     case "menu-elegant" : 
       menuwidth= 130;
       offset=110;
       break;
     case "menu-lakeside" : 
       menuwidth= 130;
       offset=220;
       break;
     case "menu-location" : 
       menuwidth= 150;
       offset=330;
       break;
     case "menu-florida" : 
       menuwidth= 130;
       offset=110;
       break;
     case "menu-bookings" : 
       menuwidth= 180;
   }
   if (menuwidth != 0) {
      menulist.style.left=  a1menuitem.offsetLeft + a1menu_id.offsetLeft + a1pageid.offsetLeft;
      menulist.style.top=   a1menuitem.offsetTop + a1menuitem.offsetHeight + a1menu_id.offsetTop + a1pageid.offsetTop +0;
      menulist.style.width= menuwidth + 'px';
      menulist.style.border= 1;
      menulist.style.visibility= "visible";
   }
}



// ----------------------------------------------------------------------------------------------------

function ShowCarHireWindow() { 
  window.open('carhire.htm','','top=50,left=50,width=640,height=485');
}

// ----------------------------------------------------------------------------------------------------

function ShowHotelRoomWindow() { 
  window.open('hotelroom.htm','','top=50,left=50,width=500,height=420');
}

// ----------------------------------------------------------------------------------------------------

function ShowPromotionsWindow() { 
  window.open('promotions.htm','','top=50,left=50,width=690,height=385');
}

// ----------------------------------------------------------------------------------------------------

function ShowCopyrightWindow() { 
  window.open('copyright.htm','','top=100,left=200,width=660,height=310');
}

// ----------------------------------------------------------------------------------------------------

function ShowRates2006Window() { 
  window.open('rates2006.htm','','top=100,left=200,width=800,height=590');
}
// ----------------------------------------------------------------------------------------------------

function BookmarkSite(){

var bookmarkurl="http://www.a1villa.com"
var bookmarktitle="a1villa.com - Fantastic Villas in Indian Wells"

if (document.all)
   window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

// ----------------------------------------------------------------------------------------------------

function SelectQuickLink(thisform) {
// Move to the page as defined through the 'Tip & Quick Links'.

   var strURL = thisform.options(thisform.selectedIndex).value;

   if ( strURL.substring(0,4) == "http" ) {
      window.open(strURL);
    } else 
    if ( strURL != "null") {
       location= strURL;
    }
}

// ----------------------------------------------------------------------------------------------------


function HoverOn(id) {
  if (id) { id.className= id.className + "hover"; };
}

// ====================================================================================================

function HoverOff(id) {
  if (id) { id.className= id.className.replace("hover","") };
}

// ----------------------------------------------------------------------------------------------------



