//=====================================
// Main menu click event (non-submenu).
//=====================================
function mMClickNS(command,menu,row) {
   var td2Style = document.getElementById(row + "_td2").style;

   if (td2Style.zIndex != 99) {
      mMOut(menu);
      AutoPullDown = false;

      if (command == "helpIntro") {
         top.data_frame.location.href = "intro.htm";

      } else if (command == "helpWebsiteHelp") {
         top.data_frame.location.href = "help.aspx";

      } else if (command == "helpFaq") {
         top.data_frame.location.href = "faq.aspx";

      } else if (command == "helpAbout") {
         top.data_frame.location.href = "about.aspx";

      } else if (command == "helpContact") {
         top.data_frame.location.href = "contactUs.aspx";

      } else if (command == "helpServices") {
         top.data_frame.location.href = "gisServices.aspx";

      } else if (command == "delete") {
         top.deleteAllElements();

      } else if (command == "find") {
         top.find();

      } else if (command == "findAddress") {
         top.findAddress();

      } else if (command == "comps") {
         top.comps();

      } else if (command == "email") {
         top.email();

      } else if (command == "download") {
         top.download();

      } else if (command == "latLon") {
         top.CoordFeet = !top.CoordFeet;

      } else if (command == "printOpt") {
         top.printOpt();

      } else if (command == "overview") {
         top.overview();
      
      } else if (command == "insertGraphics") {
         top.data_frame.location.href = "insert.aspx";

      } else if (command == "activeLayerMenu") {
         top.activeLayerMenu();

      } else if (command == "selectByAtr") {
         top.selectByAtr();

      } else if (command == "selectByGraphics") {
         top.selectByGraphics();

      } else if (command == "clearSelect") {
         top.clearSelect();

      } else if (command == "zoomToSelect") {
         top.zoomToSelect();

      } else if (command == "openAtrTable") {
         top.openAtrTable();
      }
   }
}
//======================
// Sub menu click event.
//======================
function sMClick(command,menu,subMenu,row) {
   var td2Style = document.getElementById(row + "_td2").style;

   if (td2Style.zIndex != 99) {
      sMOut(menu,subMenu);
      AutoPullDown = false;

      if (command == "zoomPrevious") {
         zoomPrevious();
      } else if (command == "zoomNext") {
         zoomNext();
      } else if (command == "zoomToFullExtent") {
         top.zoomToFullExtent();
      } else if (command == "zoomXY") {
         top.zoomXY();
      } else {
         top.processTool(command);
      }
   }
}
//========================
// Enable selection tools.
//========================
function enableSelectTools() {
  if (top.VmlLayerId == top.ParcelLayerId && top.VmlObjectId != "0") {
     
     enableRow("toolsComps");
   } else {
     disableRow("toolsComps");
   }
}
//===============
// Enable a menu.
//===============
function enableRow(row) {
   var td2Style = document.getElementById(row + "_td2").style;
   var wImg = document.getElementById(row + "_img");

   if (row == "editDelete") {
      wImg.src = "images/delete.gif";
      
   } else if (row == "viewZoomPrevious") {
      wImg.src = "images/zoomLast.gif";
      
   } else if (row == "viewZoomNext") {
      wImg.src = "images/zoomNext.gif";

   } else if (row == "viewZoomSelected") {
      wImg.src = "images/zoomSelected.gif";

   } else if (row == "selectionZoomToSelectedFeatures") {
      wImg.src = "images/zoomSelected.gif";

   } else if (row == "selectionClearSelectedFeatures") {
      wImg.src = "images/clearSelected.gif";

   } else if (row == "selectionOpenTable") {
      wImg.src = "images/openAtrTbl.gif";
   }
   td2Style.color = "black";
   td2Style.zIndex = 5;
}
//================
// Disable a menu.
//================
function disableRow(row) {
   var td2Style = document.getElementById(row + "_td2").style;
   var wImg = document.getElementById(row + "_img");
   
   if (wImg) {
      wImg.src = "images/null.gif";
   }
   td2Style.color = top.DisableGray;
   td2Style.zIndex = 99;
}
//==============================
// Menu heading mouseover event.
//==============================
function mHOver(menu) {
   if (top.PostBackDone) {
      showMenu(menu);
      showMenuHeading(menu,"hover");
   }
}
//=============================
// Menu heading mouseout event.
//=============================
function mHOut(menu) {
   if (top.PostBackDone) {
      hideMenu(menu,10);
      hideMenuHeading(menu);
   }
}
//==========================
// Menu heading click event.
//==========================
function mHClick(menu) {
   if (AutoPullDown) {
      AutoPullDown = false;
      hideMenu(menu,10);
   } else {
      AutoPullDown = true;
      mHOver(menu);
   }
}
//====================================
// Main pulldown menu mouseover event.
//====================================
function mMOver(menu) {
   showMenu(menu);
   showMenuHeading(menu);
}
//===================================
// Main pulldown menu mouseout event.
//===================================
function mMOut(menu) {
   hideMenu(menu,500);
   hideMenuHeading(menu);
}
//==========================
// Sub menu mouseover event.
//==========================
function sMOver(menu,subMenu) {
   showMenu(menu,subMenu);
   showMenuHeading(menu);
   showRow(subMenu);
}
//=========================
// Sub menu mouseout event.
//=========================
function sMOut(menu,subMenu) {
   hideMenu(menu,2000);
   hideMenu(subMenu,2000);
   hideMenuHeading(menu);
   hideRow(subMenu);
}
//=======================
// Main menu click event.
//=======================
function mMClick(command,menu) {
   mMOut(menu);
   AutoPullDown = false;
   top.processTool(command);
}
//=====================================
// Highlight the pull-down menu row(s).
//=====================================
function showRow(row) {
	var bdColor = top.HoverBorderColor;
	var rowStyle;
	var td1Style;
	var td2Style;
	var td3Style;

   rowStyle = document.getElementById(row + "_tr").style;
   td1Style = document.getElementById(row + "_td1").style;
   td2Style = document.getElementById(row + "_td2").style;
   td3Style = document.getElementById(row + "_td3").style;

   if (td2Style.zIndex != 99) {
      rowStyle.backgroundColor = top.HoverBackgroundColor;

      td1Style.borderTop = "1px solid " + bdColor;
      td1Style.borderLeft = "1px solid " + bdColor;
      td1Style.borderBottom = "1px solid " + bdColor;

      td2Style.borderTop = "1px solid " + bdColor;
      td2Style.borderBottom = "1px solid " + bdColor;

      td3Style.borderTop = "1px solid " + bdColor;
      td3Style.borderRight = "1px solid " + bdColor;
      td3Style.borderBottom = "1px solid " + bdColor;

      // Process one additional menu row recursively
      if (arguments.length > 1) {
         row = arguments[1];
         showRow(row);
      }
   }
}
//=======================================
// Unhighlight the pull-down menu row(s).
//=======================================
function hideRow(row) {
	var bgColor = top.PullDownBackgroundColor;
	var rowStyle;
	var td1Style;
	var td2Style;
	var td3Style;

   rowStyle = document.getElementById(row + "_tr").style;
   td1Style = document.getElementById(row + "_td1").style;
   td2Style = document.getElementById(row + "_td2").style;
   td3Style = document.getElementById(row + "_td3").style;

   rowStyle.backgroundColor = bgColor;

   td1Style.borderTop = "1px solid " + bgColor;
   td1Style.borderLeft = "1px solid " + bgColor;
   td1Style.borderBottom = "1px solid " + bgColor;

   td2Style.borderTop = "1px solid " + bgColor;
   td2Style.borderBottom = "1px solid " + bgColor;

   td3Style.borderTop = "1px solid " + bgColor;
   td3Style.borderRight = "1px solid " + bgColor;
   td3Style.borderBottom = "1px solid " + bgColor;

   // Process one additional menu row recursively
   if (arguments.length > 1) {
      row = arguments[1];
      hideRow(row);
   }
}

//=================================================
// Highlight the heading menu item in blue or gray.
//=================================================
function showMenuHeading(menu) {
	var menuHeading;
   var bdColor;
	menuHeading = document.getElementById(menu + "_a");
   bdColor = "1px solid " + top.MenuBorderColor;

   // If called with second argument(color), highlight in hover color.
   if (arguments.length > 1) {
      menuHeading.style.backgroundColor = top.HoverBackgroundColor;
      bdColor = "1px solid " + top.HoverBorderColor;
   }
   menuHeading.style.paddingTop = "3px";
   menuHeading.style.paddingBottom = "3px";
   menuHeading.style.borderLeft = bdColor;
   menuHeading.style.borderRight = bdColor;
   menuHeading.style.borderTop = bdColor;
   menuHeading.style.borderBottom = bdColor;
}
//===================================
// UnHighlight the heading menu item.
//===================================
function hideMenuHeading(menu) {
	var menuHeading;
	menuHeading = document.getElementById(menu + "_a");
   menuHeading.style.backgroundColor = top.MenuBackgroundColor;

   menuHeading.style.borderLeft = "1px solid " + top.MenuBackgroundColor;
   menuHeading.style.borderRight = "1px solid " + top.MenuBackgroundColor;
   menuHeading.style.borderTop = "1px solid " + top.MenuBackgroundColor;
   menuHeading.style.borderBottom = "1px solid " + top.MenuBackgroundColor;
}
//============================
// Show the pull-down menu(s).
//============================
function showMenu(menu) {
	var menuHeading;
	var pullDownMenu;
	var sMenuHeading;    //Sub menu heading
	var sPullDownMenu;   //Sub pulldown menu heading
   var menuHeadingHeight;

   if (!AutoPullDown) {
      return;
   }

	if (document.getElementById("menuHeading_div").currentStyle) {
	   menuHeadingHeight = document.getElementById("menuHeading_div").currentStyle.height;
	} else {
	   var elem = document.getElementById("menuHeading_div");
	   var vw = document.defaultView;
	   var menuHeadingHeight = vw.getComputedStyle(elem, "").height;
      if (top.IsOpera) {
         menuHeadingHeight = "26px";
   	}
	}

	menuHeading = document.getElementById(menu + "_a");
   pullDownMenu = document.getElementById(menu + "_div");

   pullDownMenu.style.top = menuHeadingHeight;
   pullDownMenu.style.left = menuHeading.offsetLeft + "px";
   pullDownMenu.style.visibility = "visible";
   pullDownMenu.inUse = true;

   // Process an additional sub pulldown menu
   if (arguments.length > 1) {
      menu = arguments[1];
	   sMenuHeading = document.getElementById(menu + "_tr");
	   sPullDownMenu = document.getElementById(menu + "_div");

      sPullDownMenu.style.top = parseInt(menuHeadingHeight) + sMenuHeading.offsetTop + "px";
      sPullDownMenu.style.left = menuHeading.offsetLeft + pullDownMenu.clientWidth + "px";
      sPullDownMenu.style.visibility = "visible";
      sPullDownMenu.inUse = true;
   }
}
//============================
// Hide the pull-down menu(s).
//============================
function hideMenu(menu,ms) {
   var pullDownMenu = document.getElementById(menu + "_div");
   pullDownMenu.inUse = false;
   window.setTimeout("nukeMenu('" + menu + "')", ms);
}
//============================
// Nuke the pull-down menu(s).
//============================
function nukeMenu(menu) {
   var pullDownMenu = document.getElementById(menu + "_div");
   if (!pullDownMenu.inUse) {
      pullDownMenu.style.visibility = "hidden";
   }
}
