var enmenus = new Array(Array('HOME', 'index.html', 'go back to main page', ''),
                        Array('ABOUT US', '', 'answers to your questions about i-Profile', 'answers to your questions about i-Profile'),
                        Array('company profile', 'company.html', 'who we are', ''),
                        Array('excellence through quality', 'excellence.html', 'excellence throughout design &amp; production', ''),
                        Array('environmental concerns', 'environmental.html', 'environmentally friendly at every step', ''),
                        Array('our associates', 'associates.html', 'the heart of the company', ''),
                        Array('locations', 'locations.html', 'where we are', ''),
                        Array('MARKETS &amp; PRODUCTS', '', 'what we can provide for you', 'what we can provide for you'),
                        Array('custom profiles', 'customprofiles.html', 'profiles to your specification', ''),
                        Array('IC shipping tubes', 'shippingtubes.html', 'packaging tubes for electronic components', ''),
                        Array('POP display profiles', 'displayprofiles.html', '', ''),
                        Array('tubes and hoses (medical &amp; others)', 'tubeshoses.html', 'tubes &amp; hoses for medical &amp; consumer uses', ''),
                        Array('SOLUTIONS', '', 'how we solve your problems', 'how we solve your problems'),
                        Array('design', 'design.html', '', ''),
                        Array('tooling know-how', 'tooling.html', '', ''),
                        Array('manufacturing', 'manufacturing.html', '', ''),
                        Array('finishing services', 'services.html', '', ''),
                        Array('materials', 'materials.html', '', ''),
                        Array('JOBS', 'jobs.html', 'Join our team', ''),
                        Array('CONTACT', 'contact.php', 'how to communicate with i-Profile', ''));

var zhmenus = new Array(Array('&#x4e3b;&nbsp;&#x9875;', 'home.html', 'go back to main page', ''),
                        Array('&#x516c;&nbsp;&#x53f8;&nbsp;&#x7b80;&nbsp;&#x4Ecb;', '', 'answers to your questions about i-Profile', 'answers to your questions about i-Profile'),
                        Array('&#x516c;&nbsp;&#x53f8;&nbsp;&#x7b80;&nbsp;&#x4ecb;', 'company.html', 'who we are', ''),
                        Array('&#x4ee5;&nbsp;&#x8d28;&nbsp;&#x53d6;&nbsp;&#x80dc;', 'excellence.html', 'excellence throughout design &amp; production', ''),
                        Array('&#x73af;&nbsp;&#x5883;&nbsp;&#x610f;&nbsp;&#x8bc6;', 'environmental.html', 'environmentally friendly at every step', ''),
                        Array('&#x4ee5;&nbsp;&#x4eba;&nbsp;&#x4e3a;&nbsp;&#x672c;', 'associates.html', 'the heart of the company', ''),
                        Array('&#x5730;&nbsp;&#x7406;&nbsp;&#x4f4d;&nbsp;&#x7f6e;', 'locations.html', 'where we are', ''),
                        Array('&#x9500;&nbsp;&#x552e;&nbsp;&#x53ca;&nbsp;&#x4ea7;&nbsp;&#x54c1;', '', 'what we can provide for you', 'what we can provide for you'),
                        Array('&#x5404;&nbsp;&#x884c;&nbsp;&#x5404;&nbsp;&#x4e1A;&nbsp;&#x4e2d;&nbsp;&#x7684;&nbsp;&#x578b;&nbsp;&#x6750;', 'customprofiles.html', 'profiles to your specification', ''),
                        Array('IC&nbsp;&#x5305;&nbsp;&#x88c5;&nbsp;&#x7Ba1;', 'shippingtubes.html', 'packaging tubes for electronic components', ''),
                        Array('&#x4e3b;&nbsp;&#x6d41;&nbsp;&#x578b;&nbsp;&#x6750;&nbsp;&#x4ea7;&nbsp;&#x54c1;', 'displayprofiles.html', '', ''),
                        Array('&#x5305;&nbsp;&#x88c5;&nbsp;&#x7ba1;&nbsp;&#x53ca;&nbsp;&#x8f6f;&nbsp;&#x7Ba1;', 'tubeshoses.html', 'tubes &amp; hoses for medical &amp; consumer uses', ''),
                        Array('&#x89E3;&nbsp;&#x51B3;&nbsp;&#x65B9;&nbsp;&#x6848;', '', 'how we solve your problems', 'how we solve your problems'),
                        Array('&#x8bbe;&nbsp;&#x8ba1;', 'design.html', '', ''),
                        Array('&#x6709;&nbsp;&#x5173;&nbsp;&#x6a21;&nbsp;&#x5177;&nbsp;&#x7684;&nbsp;&#x77e5;&nbsp;&#x8bc6;', 'tooling.html', '', ''),
                        Array('&#x751f;&nbsp;&#x4ea7;&nbsp;&#x5236;&nbsp;&#x9020;', 'manufacturing.html', '', ''),
                        Array('&#x5b8c;&nbsp;&#x5de5;&nbsp;&#x670;&nbsp;&#x52a1;', 'services.html', '', ''),
                        Array('&#x6750;&nbsp;&#x6599;', 'materials.html', '', ''),
                        Array('&#x5De5;&nbsp;&#x4f5c;&nbsp;&#x673a;&nbsp;&#x4f1a;', 'jobs.html', 'Join our team', ''),
                        Array('&#x8054;&nbsp;&#x7cfb;&nbsp;&#x6211;&nbsp;&#x4eec;', 'contact.php', 'how to communicate with i-Profile', ''));

String.prototype.trim = function()
{
  return this.replace(/^\s*|\s*$/g, '');
}

function getSubPath(root, subpath, map)
{
  if (map.length > 0)
    return ((root == true) ? map + '/' : ((subpath == true) ? '../' + map + '/' : map + '/'));
  else
    return ((root == true) ? '' : ((subpath == true) ? '../' : ''));
}

function showMenu(language, root, selected)
{
  var html, i, relativepath, subpath;
  var menus;
  switch (language)
  {
    case 'en':
      menus = enmenus;
      relativepath = ((root == true) ? language + '/' : '');
      break;
    case 'zh':
      menus = zhmenus;
      relativepath = '';
      break;
    default:
      menus = enmenus;
      relativepath = '../en/';
  }
  subpath = ((selected == 1) || (selected == 2) || (selected == 3) || (selected == 4));
  html = '<table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"0\">\n';
  html += '  <tr>\n';
  html += '    <td>\n';
  html += '      <a class=\"' + ((selected == 0) ? 'menuselected' : 'menu') + '\" href=\"' + (((root == true) || (menus[0][1] == 'home.html')) ? '' : '../') + ((subpath == true) ? '../' : '') + menus[0][1] + '\" title=\"' + menus[0][2] + '\"' + ((menus[0][3].length > 0) ? ' onmouseover=\"return showStatusText(\'' + menus[0][3] + '\');\" onmouseout=\"return showStatusText(\'\');\"' : '') + '>' + menus[0][0] + '</a>\n';
  html += '    </td>\n';
  html += '    <td>\n';
  html += '      <div id=\"parent1\">\n';
  html += '        <a class=\"' + ((selected == 1) ? 'menuselected' : 'menu') + '\" href=\"' + menus[0][1] + '\" title=\"' + menus[1][2] + '\"' + ((menus[1][3].length > 0) ? ' onmouseover=\"return showStatusText(\'' + menus[1][3] + '\');\" onmouseout=\"return showStatusText(\'\');\"' : '') + '>' + menus[1][0] + '</a>\n';
  html += '      </div>\n';
  html += '      <div id=\"child1\">\n';
  for (i = 2; i < 7; i++)
    html += '        <a class=\"dropdown1\" href=\"' + relativepath + getSubPath(root, subpath, 'aboutus') + menus[i][1] + '\" title=\"' + menus[i][2] + '\"' + ((menus[i][3].length > 0) ? ' onmouseover=\"return showStatusText(\'' + menus[i][3] + '\');\" onmouseout=\"return showStatusText(\'\');\"' : '') + '>' + menus[i][0] + '</a>\n';
  html += '      </div>\n';
  html += '    </td>\n';
  html += '    <td>\n';
  html += '      <div id=\"parent2\">\n';
  html += '        <a class=\"' + ((selected == 2) ? 'menuselected' : 'menu') + '\" href=\"' + menus[7][1] + '\" title=\"' + menus[7][2] + '\"' + ((menus[7][3].length > 0) ? ' onmouseover=\"return showStatusText(\'' + menus[7][3] + '\');\" onmouseout=\"return showStatusText(\'\');\"' : '') + '>' + menus[7][0] + '</a>\n';
  html += '      </div>\n';
  html += '      <div id=\"child2\">\n';
  for (i = 8; i < 12; i++)
    html += '        <a class=\"dropdown2\" href=\"' + relativepath + getSubPath(root, subpath, 'marketsproducts') + menus[i][1] + '\" title=\"' + menus[i][2] + '\"' + ((menus[i][3].length > 0) ? ' onmouseover=\"return showStatusText(\'' + menus[i][3] + '\');\" onmouseout=\"return showStatusText(\'\');\"' : '') + '>' + menus[i][0] + '</a>\n';
  html += '      </div>\n';
  html += '    </td>\n';
  html += '    <td>\n';
  html += '      <div id=\"parent3\">\n';
  html += '        <a class=\"' + ((selected == 3) ? 'menuselected' : 'menu') + '\" href=\"' + menus[12][1] + '\" title=\"' + menus[12][2] + '\"' + ((menus[12][3].length > 0) ? ' onmouseover=\"return showStatusText(\'' + menus[12][3] + '\');\" onmouseout=\"return showStatusText(\'\');\"' : '') + '>' + menus[12][0] + '</a>\n';
  html += '      </div>\n';
  html += '      <div id=\"child3\">\n';
  for (i = 13; i < 18; i++)
    html += '        <a class=\"dropdown3\" href=\"' + relativepath + getSubPath(root, subpath, 'solutions') + menus[i][1] + '\" title=\"' + menus[i][2] + '\"' + ((menus[i][3].length > 0) ? ' onmouseover=\"return showStatusText(\'' + menus[i][3] + '\');\" onmouseout=\"return showStatusText(\'\');\"' : '') + '>' + menus[i][0] + '</a>\n';
  html += '      </div>\n';
  html += '    </td>\n';
  html += '    <td>\n';
  html += '      <a class=\"' + ((selected == 4) ? 'menuselected' : 'menu') + '\" href=\"' + relativepath + getSubPath(root, subpath, 'jobs') + menus[18][1] + '\" title=\"' + menus[18][2] + '\"' + ((menus[18][3].length > 0) ? ' onmouseover=\"return showStatusText(\'' + menus[18][3] + '\');\" onmouseout=\"return showStatusText(\'\');\"' : '') + '>' + menus[18][0] + '</a>\n';
  html += '    </td>\n';
  html += '    <td>\n';
  html += '      <a class=\"' + ((selected == 5) ? 'menuselected' : 'menu') + '\" href=\"' + relativepath + getSubPath(root, subpath, '') + menus[19][1] + '\" title=\"' + menus[19][2] + '\"' + ((menus[19][3].length > 0) ? ' onmouseover=\"return showStatusText(\'' + menus[19][3] + '\');\" onmouseout=\"return showStatusText(\'\');\"' : '') + '>' + menus[19][0] + '</a>\n';
  html += '    </td>\n';
  html += '  </tr>\n';
  html += '</table>\n';
  document.write(html);
  initialize('parent1', 'child1');
  initialize('parent2', 'child2');
  initialize('parent3', 'child3');
}

function showStatusText(text)
{
  window.status = text;
  return true;
}

function click()
{
  var childobj, parentobj;
  parentobj = document.getElementById(this['parent']);
  childobj = document.getElementById(this['child']);
  if (childobj.style.visibility != 'visible')
    show(parentobj, childobj);
  else
    childobj.style.visibility = 'hidden';
  return false;
}

function create()
{
  var childobj, parentobj;
  parentobj = document.getElementById(this['parent']);
  childobj = document.getElementById(this['child']);
  show(parentobj, childobj);
  clearTimeout(childobj['timeout']);
}

function destroy()
{
  var childobj;
  childobj = document.getElementById(this['child']);
  childobj['timeout'] = setTimeout('document.getElementById(\'' + childobj.id + '\').style.visibility = \'hidden\'', 333);
}

function initialize(parent, child)
{
  var childobj, parentobj;
  parentobj = document.getElementById(parent);
  childobj = document.getElementById(child);
  parentobj['parent'] = parentobj.id;
  childobj['parent'] = parentobj.id;
  parentobj['child'] = childobj.id;
  childobj['child'] = childobj.id;
  childobj.style.position = 'absolute';
  childobj.style.visibility = 'hidden';
  parentobj.onclick = click;
  parentobj.onmouseout = destroy;
  childobj.onmouseover = create;
  childobj.onmouseout = destroy;
}

function show(parentobj, childobj)
{
  var left, top;
  left = 0;
  top = parentobj.offsetHeight;
  for (; parentobj; parentobj = parentobj.offsetParent)
  {
    top  += parentobj.offsetTop;
    left += parentobj.offsetLeft;
  }
  childobj.style.position = 'absolute';
  childobj.style.left = left + 'px';
  childobj.style.top = top + 'px';
  childobj.style.visibility = 'visible';
}

function isApplicationComplete(formobj, requiredfields, codetext)
{
  var buffer, focus;
  buffer = requiredfields + '\r\n';
  focus = false;
  if (formobj.Code.value.trim().length != 4)
  {
    buffer += '\r\n- ' + codetext;
    if (focus == false)
    {
      focus = true;
      formobj.Code.focus();
    }
  }
  if (focus == true)
    window.alert(buffer);
  return Boolean(focus ^ true);
}

function isContactComplete(formobj, requiredfields, companytext, emailtext, countrytext, codetext)
{
  var buffer, focus;
  buffer = requiredfields + '\r\n';
  focus = false;
  if (formobj.Company.value.trim().length == 0)
  {
    buffer += '\r\n- ' + companytext;
    if (focus == false)
    {
      focus = true;
      formobj.Company.focus();
    }
  }
  if ((formobj.Email.value.trim().length == 0) || (formobj.Email.value.indexOf('@') == -1))
  {
    buffer += '\r\n- ' + emailtext;
    if (focus == false)
    {
      focus = true;
      formobj.Email.focus();
    }
  }
  if (formobj.Country.value.trim().length == 0)
  {
    buffer += '\r\n- ' + countrytext;
    if (focus == false)
    {
      focus = true;
      formobj.Country.focus();
    }
  }
  if (formobj.Code.value.trim().length != 4)
  {
    buffer += '\r\n- ' + codetext;
    if (focus == false)
    {
      focus = true;
      formobj.Code.focus();
    }
  }
  if (focus == true)
    window.alert(buffer);
  return Boolean(focus ^ true);
}
