var maxWidth = 50;
/* maximum width of the submenus (in 'em' units) */

var borderBox  = false;
var horizontal = new Array();
var menuTop    = new Array();
var menuHeight = new Array();
var menuLeft   = new Array();
var menuWidth  = new Array();

window.onload = function() { loadMenu(); }

function loadMenu() {
  if (!document.getElementById) return;
  var i = 0, j, root, submenus, node, li, link, division;
  while (true) {
    root = document.getElementById("menuList" + (i + 1));
    if (root == null)
      break;
    submenus = root.getElementsByTagName("ul");
    division = root.parentNode;

    if (document.createElement) {
      /* Win/IE5-6 trick: makes the whole width of the submenus clickable
       */
      for (j = 0; j < submenus.length; j++) {
        node = submenus.item(j);
        if (node.className == "menu" && node.getElementsByTagName("ul").length == 0) {
          li = document.createElement("li");
          node.appendChild(li);
          li.style.position = "absolute";
          li.style.visibility = "hidden";
        }
      }
      /* checks whether the 'width' property applies to the border box or
       * the content box of an element
       */
      if (i == 0) {
        li.style.display = "block";
        li.style.padding = "0";
        li.style.width   = "2px";
        li.style.border  = "1px solid";
        if (li.offsetWidth == 2)
          borderBox = true;
      }
    }

    initializeMenu(root, division, i);

    for (j = 0; j < submenus.length; j++) {
      node = submenus.item(j);
      if (node.className == "menu") {
        link = node.previousSibling;
        while (link != null) {
          if (link.className == "actuator") {
            initializeSubmenu(node, link, root, division);
            node.set();
            break;
          }
          link = link.previousSibling;
        }
      }
    }
    i++;
  }
}

function initializeMenu(root, div, index) {

  horizontal[index] = menuIsHorizontal(root);
  menuTop[index]    = div.offsetTop;
  menuHeight[index] = div.offsetHeight;
  menuLeft[index]   = div.offsetLeft;
  menuWidth[index]  = div.offsetWidth;

  div.horizontal = function() {
    return horizontal[index];
  }

  div.checkMove = function() {
    if (this.hasMoved()) this.resetMenu();
  }

  div.hasMoved = function() {
    if (menuTop[index]    == this.offsetTop    &&
        menuHeight[index] == this.offsetHeight &&
        menuLeft[index]   == this.offsetLeft   &&
        menuWidth[index]  == this.offsetWidth)
      return false;
    return true;
  }

  div.resetMenu = function() {
    horizontal[index] = menuIsHorizontal(root);
    menuTop[index]    = this.offsetTop;
    menuHeight[index] = this.offsetHeight;
    menuLeft[index]   = this.offsetLeft;
    menuWidth[index]  = this.offsetWidth;

    var submenus = root.getElementsByTagName("ul");
    for (var j = 0; j < submenus.length; j++) {
      var node = submenus.item(j);
      if (node.className == "menu") {
        node.style.right = "";
        node.style.left  = "";
        if (!window.opera)
          node.style.width = "";
        node.set();
      }
    }
  }
}

function menuIsHorizontal(root) {
  var first = firstElement(root, "LI");
  if (first != null) {
    var second = first.nextSibling;
    while (second != null) {
      if (second.tagName == "LI") {
        first  = firstElement(first,  "A");
        second = firstElement(second, "A");
        if (first != null && second != null)
          if (first.offsetLeft == second.offsetLeft)
            return false;
        return true;
      }
      second = second.nextSibling;
    }
  }
  return true;
}

function initializeSubmenu(menu, actuator, root, div) {

  var parent = menu.parentNode;

  parent.onmouseover = function() {
    div.checkMove();
    menu.style.visibility = "visible";
  }

  actuator.onfocus = function() {
    div.checkMove();
    menu.style.visibility = "visible";
  }

  parent.onmouseout = function() {
    menu.style.visibility = "";
  }

  var tags = menu.getElementsByTagName("a");
  var link = tags.item(tags.length - 1);
  if (!link.onblur)
    link.onblur = function() {
      var node = link.parentNode.parentNode;
      while (node != menu) {
        node.style.visibility = "";
        node = node.parentNode.parentNode;
      }
      menu.style.visibility = "";
    }

  if (parent.parentNode == root) {
    menu.set = function() {
      setLocation1(this, actuator, root, div);
    }
  } else {
    menu.set = function() {
      setLocation2(this, actuator, div);
    }
  }
}

function setLocation1(menu, actuator, root, div) {
  var first = firstElement(menu, "LI");
  if (first != null)
    if (first.offsetParent == menu)
      setWidth(menu);
  if (div.horizontal()) {
    if (actuator.offsetParent == menu.offsetParent) {
      menu.style.left = actuator.offsetLeft + "px";
      menu.style.top  = actuator.offsetTop  + actuator.offsetHeight + "px";
    } else {
      /* happens in Win/IE5-6 when some ancestors are 'static' and have their
       * 'width' or 'height' different than 'auto' */
      var parent = actuator.offsetParent;
      var top  = 0;
      var left = 0;
      while (parent != menu.offsetParent && parent != null) {
        top  = top  + parent.offsetTop;
        left = left + parent.offsetLeft;
        parent = parent.offsetParent;
      }
      menu.style.left = left + actuator.offsetLeft + "px";
      menu.style.top  = top  + actuator.offsetTop  + actuator.offsetHeight + "px";
    }
  } else {
    menu.style.top = actuator.offsetTop + "px";
    menu.style.left = (div.offsetWidth + actuator.offsetWidth) / 2 + "px";
  }
}

function setLocation2(menu, actuator, div) {
  if (menu.offsetParent != document.body)
    setWidth(menu);
  menu.style.top = actuator.offsetTop + "px";
  menu.style.left = actuator.offsetWidth + "px";
}

function setWidth(menu) {
  menu.style.right = - maxWidth + "em";
  var width  = 0;
  var height = 0;
  var items = menu.getElementsByTagName("a");
  for (var i = 0; i < items.length; i++) {
    var link = items.item(i);
    if (link.parentNode.parentNode == menu) {
      height = height + link.offsetHeight;
      if (link.offsetWidth > width)
        width = link.offsetWidth;
    }
  }
  if (borderBox)
    width = width + (menu.offsetHeight - height);
  menu.style.width = width + "px";
}

function firstElement(node, name) {
  var first = node.firstChild;
  while (first != null) {
    if (first.tagName == name)
      return first;
    first = first.nextSibling;
  }
  return null;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// Anti-Spam Email Displayer- By JavaScriptKit.com
// Visit JavaScript Kit (http://javascriptkit.com) for this script and more.
// This notice must stay intact for use

var contacts=new Array()
//Specify text and corresponding email address.
//Use [at] and [dot] in place of "@" and "." for anti spam purpose:
contacts[0]=["Contact Us", "office[at]laurenceschool[dot]com"]
contacts[1]=["alum@laurenceschool.com", "alum[at]laurenceschool[dot]com"]
contacts[2]=["development@laurenceschool.com", "development[at]laurenceschool[dot]com"]
contacts[3]=["businessoffice@laurenceschool.com", "businessoffice[at]laurenceschool[dot]com"]
contacts[4]=["Marvin Jacobson", "mjacobson[at]laurenceschool[dot]com"]
contacts[5]=["Laurie Wolke", "lwolke[at]laurenceschool[dot]com"]
contacts[6]=["Gary Stern", "gstern[at]laurenceschool[dot]com"]
contacts[7]=["Shawn Shahmiri", "sshahmiri[at]laurenceschool[dot]com"]
contacts[8]=["Karen Beskid", "kbeskid[at]laurenceschool[dot]com"]
contacts[9]=["Melanie Sherwood", "msherwood[at]laurenceschool[dot]com"]
contacts[10]=["Lynn Jacobson", "ljacobson[at]laurenceschool[dot]com"]
contacts[11]=["Wendy Wolin", "wwolin[at]laurenceschool[dot]com"]
contacts[12]=["Jeffrey Tremblay", "jtremblay[at]laurenceschool[dot]com"]
contacts[13]=["Sondra Simolo", "ssimolo[at]laurenceschool[dot]com"]
contacts[14]=["Lonnie Ngo", "lngo[at]laurenceschool[dot]com"]
contacts[15]=["Melissa Kaplan", "mkaplan[at]laurenceschool[dot]com"]
contacts[16]=["Sharon Green", "sgreen[at]laurenceschool[dot]com"]
contacts[17]=["Joyce Prescott", "jprescott[at]laurenceschool[dot]com"]
contacts[18]=["Fran Goodsite", "fgoodsite[at]laurenceschool[dot]com"]
contacts[19]=["Gina Miller", "gmiller[at]laurenceschool[dot]com"]
contacts[20]=["Judy Braun", "jbraun[at]laurenceschool[dot]com"]

contacts[21]=["Rochelle Robinson", "rrobinson[at]laurenceschool[dot]com"]
contacts[22]=["Jerry Manise", "art[at]laurenceschool[dot]com"]
contacts[23]=["Warren Stewart", "wstewart[at]laurenceschool[dot]com"]
contacts[24]=["Bernard Redmond", "bredmond[at]laurenceschool[dot]com"]

contacts[26]=["Dan Wexler", "dwexler[at]laurenceschool[dot]com"]
contacts[28]=["Sue Arul", "science[at]laurenceschool[dot]com"]
contacts[29]=["Sylvia Ossorio", "sossorio[at]laurenceschool[dot]com"]
contacts[30]=["Janice Ross", "jross[at]laurenceschool[dot]com"]
contacts[31]=["Melissa Curtin", "mcurtin[at]laurenceschool[dot]com"]
contacts[32]=["Merrie Libicki", "mlibicki[at]laurenceschool[dot]com"]
contacts[33]=["Kelley Isinger", "kisinger[at]laurenceschool[dot]com"]
contacts[34]=["Shana Ellis", "sellis[at]laurenceschool[dot]com"]
contacts[35]=["Jeannine Brager", "jbrager[at]laurenceschool[dot]com"]

contacts[37]=["Aimee Manalastas", "amanalastas[at]laurenceschool[dot]com"]
contacts[38]=["Sarah Curry", "scurry[at]laurenceschool[dot]com"]
contacts[39]=["Xylene Garcia", "xniega[at]laurenceschool[dot]com"]

contacts[40]=["sdrob@rfam5.com", "sdrob[at]rfam5[dot]com"]

contacts[41]=["Susan Lee", "slee[at]laurenceschool[dot]com"]


contacts[42]=["Mary Chen", "mchen[at]laurenceschool[dot]com"]

contacts[43]=["auction@laurenceschool.com", "auction[at]laurenceschool[dot]com"]

contacts[44]=["Priscilla Traylor", "ptraylor[at]laurenceschool[dot]com"]

contacts[45]=["admissions@laurenceschool.com", "admissions[at]laurenceschool[dot]com"]
contacts[46]=["pa@laurenceschool.com", "pa[at]laurenceschool[dot]com"]
contacts[47]=["Chiho Nakashima", "cnakashima[at]laurenceschool[dot]com"]
contacts[48]=["Whitney Stange", "wstange[at]laurenceschool[dot]com"]
contacts[49]=["Kimberly Milman", "kmilman[at]laurenceschool[dot]com"]
contacts[50]=["Eddie Wiernik", "ewiernik[at]laurenceschool[dot]com"]
contacts[51]=["Ivy Dennis", "idennis[at]laurenceschool[dot]com"]
contacts[52]=["Roya Falahi", "rfalahi[at]laurenceschool[dot]com"]

contacts[53]=["Christy Medley", "cmedley[at]laurenceschool[dot]com"]
contacts[54]=["Susie Heckendorn", "sheckendorn[at]laurenceschool[dot]com"]
contacts[55]=["Kelly Spinks", "kspinks[at]laurenceschool[dot]com"]

contacts[56]=["Christina Chiu", "cchiu[at]laurenceschool[dot]com"]
contacts[57]=["Lauren Aronson", "laronson[at]laurenceschool[dot]com"]
contacts[58]=["Jennifer Kovacs", "jkovacs[at]laurenceschool[dot]com"]
contacts[59]=["Tanika Schliebe", "tschliebe[at]laurenceschool[dot]com"]

//Specify caption text to display within SELECT menu. Only applicable if you're using the form option:
var dropmenucaption="CONTACT US FORM "

function displaycontact(emailarray, cssclass, displaymethod, extrainfo){
if (displaymethod=="text"){
document.write('<span class="' + cssclass + '">\n')
if (typeof emailarray[0]=="object"){ //if array passed consists of multiple elements
for (i=0; i<emailarray.length; i++){
var seperator=(i<emailarray.length-1)? extrainfo : ""
document.write('<a href="mailto:' + modifyemail(emailarray[i][1])+ '">'+ emailarray[i][0] + '</a>' + seperator)
}
}
else //else if it is a single array element
document.write('<a href="mailto:' + modifyemail(emailarray[1])+ '">'+ emailarray[0] + '</a>')
document.write('</span>')
}
else if (displaymethod=="form"){
document.write('<form>\n')
document.write('<select size="' + extrainfo + '" onChange="jumptooption(this)" class="' + cssclass + '">\n')
document.write('<option value="caption">' + dropmenucaption + '</option>\n')
for (i=0; i<emailarray.length; i++)
document.write('<option value="mailto:' + modifyemail(emailarray[i][1]) +'">' + emailarray[i][0] + ' </option>\n')
document.write('</select></form>\n')
}
}

function modifyemail(emailitem){
var modified=emailitem.replace(/\[at]/gi, "@")
modified=modified.replace(/\[dot]/gi, ".")
return modified
}

function jumptooption(themenu){
if (themenu.options[themenu.selectedIndex].value !="caption")
location=themenu.options[themenu.selectedIndex].value
}

//USAGE INSTRUCTION. displaycontact(1st paramter, "2nd paramter", "3rd paramter", "4th paramter")
//1st parameter: Input the name of the array containing the list of email addresses. To display one single email, input the corresponding array element. 
//2nd parameter: Input the CSS Classname that is to be applied. Enter arbitrary name for none.
//3rd parameter: Input either "form" or "text." Former will display email in drop down menu. Later in plain text. Only "text" mode supports displaying of single email address!
//4th parameter: If in "form" mode, enter an integer to control the height of the <SELECT> tag. If "text" mode, enter any string to act as a divider between each email text. For example "|", "<br>" etc.

//SAMPLE USAGES (uncomment below to see)
//displaycontact(contacts, "textstyle", "text", " | ")

//displaycontact(contacts, "formstyle", "form", "1")

//displaycontact(contacts[2], "textstyle", "text", "")

//Email validateForm
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

