var menuColor = "#000000";
var submenuColor = "#444444";
var submenuBorderColor = "#000000";

var menuTop = 0;
var menuLeft = 0;

if (document.layers) {
  visible = 'show';
  hidden = 'hide';
} else if (document.all) {
  visible = 'visible';
  hidden = 'hidden';
}

function getItem(id) {
  if(document.layers) {
    return document.layers[id];
  } else if (document.all) {
    return document.all(id).style;
  }
}

function moveItemBy(id, x, y) {
  getItem(id).left = parseInt(getItem(id).left) + x;
  getItem(id).top = parseInt(getItem(id).top) + y;
}

function getWidth() {
  if(document.layers) {
    return window.innerWidth - 20;
  } else if(document.all) {
    return document.body.offsetWidth - 20;
  }
}

function AlignLayers() {
  var x = parseInt(getWidth() / 2 - 375 - menuLeft);
  if(menuLeft + x < 0)
	x = -menuLeft;
  var y = 75 - menuTop;
  y = 0;

  menuLeft += x;
  menuTop += y;

  moveItemBy("menubar", x, y);
  moveItemBy("loginMenu", x, y);
  moveItemBy("productsMenu", x, y);
  moveItemBy("productsSubMenu", x, y);
  moveItemBy("currentProjectsMenu", x, y);
  moveItemBy("currentProjectsSubMenu", x, y);
  moveItemBy("supportMenu", x, y);
  moveItemBy("supportSubMenu", x, y);
  moveItemBy("downloadsMenu", x, y);
  moveItemBy("siteTitle", x, y);
  moveItemBy("mainBody", x, y);
}

function showMenu(menu, show) {
  sub = menu + "SubMenu";
  getItem(sub).visibility = show;
}

function IsFormComplete(FormName)
{
var x       = 0
var FormOk  = true

while ((x < document.forms[FormName].elements.length) && (FormOk))
   {
     if (document.forms[FormName].elements[x].value == '')
     { 
        FormOk = false 
     }
     x ++
   }
return FormOk
}

function IsEmailValid(FormName,ElemName)
{
var EmailOk  = true
var Temp     = document.forms[FormName].elements[ElemName]
var AtSym    = Temp.value.indexOf('@')
var Period   = Temp.value.lastIndexOf('.')
var Space    = Temp.value.indexOf(' ')
var Length   = Temp.value.length - 1   // Array is from 0 to length-1

if ((AtSym < 1) ||                     // '@' cannot be in first position
    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    (Period == Length ) ||             // Must be atleast one valid char after '.'
    (Space  != -1))                    // No empty spaces permitted
   {  
      EmailOk = false
   }
return EmailOk
}

function checkPass(FormName, Email) {
  var f = document.forms[FormName];

  if(IsFormComplete(FormName) && IsEmailValid(FormName, Email)
	&& f.password.value.length > 5 && f.password.value == f.confirm.value) {
    f.submit();
  } else if(!IsFormComplete(FormName)) {
    alert("Please complete the entire form");
  } else if(!IsEmailValid(FormName, Email)) {
    alert("Please enter a valid email address");
    document.forms[FormName].elements[Email].focus();
  } else if(f.password.value.length < 6) {
    f.password.value = "";
    f.confirm.value = "";
    alert("Password must be between 6 and 15 characters");
    f.password.focus();
  } else {
    f.password.value = "";
    f.confirm.value = "";
    alert("Passwords do not match, please enter them again");
    f.password.focus();
  }
}