// JavaScript Document

// Sort by Office&Name
max=ix;
sx=0;
lx=0;
nx=0;
sortedMembers = new Array();
while(max>0) {
  lx=0;
  for (nx=1;nx<=max;nx++) {
    thisOffName=member[nx].dept+member[nx].name;
    if (lx==0) { lowOffName=thisOffName; lx=nx; }
    if (thisOffName<lowOffName) { lowOffName=thisOffName; lx=nx; }
  }
  sx++;
  sortedMembers[sx]=member[lx];
  member[lx]=member[max];
  max--;
}
member=sortedMembers;


//  Print the Selection Drop-Box
docwrite='<p class="RightMargin20">';
docwrite+='<form name="SelectForm"><center><select name="menu1" onchange="Button2.focus();MM_jumpMenu(\'parent\',this,0)">';
n=1;
prevDept=" ";
repSpace= new RegExp(/\s/g);
repQuote= new RegExp(/[']/g);
while(n<=ix) {
  fullDept=member[n].dept;
  tempDept=fullDept.replace(repQuote, "");
  thisDept=tempDept.replace(repSpace, "");
  if (thisDept!=prevDept) {
    docwrite+='<option value="#'+thisDept.substring(0,12)+'">'+fullDept+'</option>';
    prevDept=thisDept;
  }
  n++;
}
docwrite+='</select>&nbsp;&nbsp;&nbsp;&nbsp;';
docwrite+='<input type="button" name="Button2" value="Go" onclick="MM_jumpMenuGo(\'menu1\',\'parent\',0)" />';
docwrite+='</center></form></p>&nbsp;';
document.write(docwrite);


//  Print the names
n=1;
bg=0;
prevDept=" ";
writeTableStart();
while(n<=ix) {
  fullDept=member[n].dept;
  // added 7 / 25 / 07 by Seth Freeman
  // only display Employees who are assoicated with a 
  // specific Department
  if ( fullDept != "") {
	  tempDept=fullDept.replace(repQuote, "");
	  thisDept=tempDept.replace(repSpace, "");
	  if (thisDept!=prevDept) {
	    if (prevDept!=" ") { writeRowTop(); }
	    writeRowHead();
	    prevDept=thisDept;
	    bg=0;
	  }
	  if (bg==0) {
	    writeRowLight();
	    bg=1;
	  } else {
	    writeRowDark();
	    bg=0;
	  }
  }
  
  n++;
  
}
writeRowTop();
writeTableEnd();


function writeTableStart() {
  docWrite='<table width="95%" class="dirTable">';
  document.write(docWrite);
}

function writeRowHead() {
  docWrite='<tr><th width="65%"><a name="'+thisDept.substring(0,12)+'" id="'+thisDept.substring(0,12)+'"></a>'+fullDept+'</th><th width="20%">Tel.</th><th width="15%">Room</th></tr>';
  document.write(docWrite);
}

function writeRowLight() {
	// UPDATED: 4/5/07    ---- Seth Freeman
	// if the email does not exist, then do not write mailto:
  if (member[n].email == "") {
	  docWrite='<tr><td>'+member[n].name+'<br />&nbsp;&nbsp;&nbsp;&nbsp;'+member[n].title+'</td><td>'+member[n].phone+'</td><td>'+member[n].office+'</td></tr>';
  }
  else {
  docWrite='<tr><td><a href="mailto:'+member[n].email+'">'+member[n].name+'</a><br />&nbsp;&nbsp;&nbsp;&nbsp;'+member[n].title+'</td><td>'+member[n].phone+'</td><td>'+member[n].office+'</td></tr>';
  }
  document.write(docWrite);
} 

function writeRowDark() {
	// UPDATED: 4/5/07    ---- Seth Freeman
	// if the email does not exist, then do not write mailto:
  if (member[n].email == "") {
	  docWrite='<tr bgcolor="#f3f3f3"><td>'+member[n].name+'<br />&nbsp;&nbsp;&nbsp;&nbsp;'+member[n].title+'</td><td>'+member[n].phone+'</td><td>'+member[n].office+'</td></tr>';
  }
  else {
  docWrite='<tr bgcolor="#f3f3f3"><td><a href="mailto:'+member[n].email+'">'+member[n].name+'</a><br />&nbsp;&nbsp;&nbsp;&nbsp;'+member[n].title+'</td><td>'+member[n].phone+'</td><td>'+member[n].office+'</td></tr>';
  }
  document.write(docWrite);
}

function writeRowTop() {
  docWrite='<tr><td colspan="3"><div align="right"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'backToTop\',\'\',\'images/backToTop_f2.gif\',1);"><img src="images/backToTop.gif" alt="" name="backToTop" width="69" height="16" border="0" /></a></div></td></tr>';
  document.write(docWrite);
} 

function writeTableEnd() {
  docWrite='</table><br />&nbsp;';
  document.write(docWrite);
}
