﻿var activeDropdown;
var activeMenuItem;
var stillActive;
function ShowDropdown(dropdownID, menuItemID) {
  if (!document.getElementById) return false;
  var dropdown = document.getElementById(dropdownID);
  var menuItem = document.getElementById(menuItemID);
  if (dropdown) {
    if (menuItem) {
      dropdown.style.left = findPosX(menuItem) - 15 + "px";
      dropdown.style.top = findPosY(menuItem) + 25 + "px";
      dropdown.firstChild.style.width = menuItem.offsetWidth - 2 + "px";
    }
    HideDropdown();
    activeDropdown = dropdown;
    activeMenuItem = menuItem;
    stillActive = true;
    dropdown.style.display = 'block';
    menuItem.className = "tabBorder";
    setTimeout("HideDropdown();", 500);
  }
}
function HideDropdown() {
  if (!stillActive) {
    if (activeDropdown) {
      activeDropdown.style.display = 'none';
      activeMenuItem.className = "noBorder";
    }
  }
  else {
    setTimeout("HideDropdown();", 500);
  }
}

function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (1) {
      curleft += obj.offsetLeft;
      if (!obj.offsetParent) break;
      obj = obj.offsetParent;
    }
  }
  else if (obj.x) {
    curleft += obj.x;
  }
  return curleft;
}

function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    while (1) {
      curtop += obj.offsetTop;
      if (!obj.offsetParent) break;
      obj = obj.offsetParent;
    }
  }
  else if (obj.y) {
    curtop += obj.y;
  }
  return curtop;
}

function setActiveState() {
  URL = location.href.toString();
  if (URL.indexOf('business-needs') != -1) {
    document.getElementById('item_2').className = "selected";
  } else if (URL.indexOf('products') != -1) {
    document.getElementById('item_3').className = "selected";
  } else if (URL.indexOf('try') != -1) {
    document.getElementById('item_4').className = "selected";
  } else if (URL.indexOf('how-to-buy') != -1) {
    document.getElementById('item_5').className = "selected";
  } else if (URL.indexOf('contact') != -1) {
    document.getElementById('item_6').className = "selected";
  } else {
    document.getElementById('item_1').className = "selected";
  }
}