/*
   Heman Lee November 2011 CISW400

   Function List:


   addEvent(object, evName, fnName, cap)
      Adds an event hander to object where evName is the name of the event,
      fnName is the function assigned to the event, and cap indicates whether
      event handler occurs during the capture phase (true) or bubbling
      phase (false)

   stringReverse
      Used to reverse the order of characters in a text string

   showSubmenu()
      Show submenu when click on UL with ID submenu.

   expandCollapse()
      Expands and collapse the content of menu in the Nav div.

   isHidden(object)
      Returns a Boolean value indicating whether object is hidden (true) or
      not hidden (false) on the Web page by examining the display style for object
      and all its parent nodes up to the body element

*/

// window.onload = showSubmenu;
addEvent(window, "load", showSubmenu, false);

function showSubmenu() {

    var menu = document.getElementById("topmenu");
    addEvent(menu,"click", expandCollapse, false);
         
}


function expandCollapse(e) {
     // var subMenu = e.target || event.srcElement;
     var subMenu = document.getElementById("submenu");

     // toggle the display style of the nested list
     if (subMenu.style.display == "list-item") 
        subMenu.style.display = "none"
     else 
        subMenu.style.display = "list-item";    
}    


function addEvent(object, evName, fnName, cap) {
   if (object.attachEvent)
       object.attachEvent("on" + evName, fnName);  // IE before v8
   else if (object.addEventListener)
       object.addEventListener(evName, fnName, cap);
}


function setOpacity(object, value) {  
   // Apply the opacity value for IE and non-IE browsers
   object.style.filter = "alpha(opacity = " + value + ")";
   object.style.opacity = value/100;
}


function stringReverse(textString) {
   if (!textString) return '';
   var revString='';
   for (i = textString.length-1; i>=0; i--)
       revString+=textString.charAt(i)
   return revString;
}

function showEMT(userName,emServer,emTitle) {
  var emLink=userName+"&#64;"+emServer;
  document.write("<a href='mailto:" + emLink + "' title='" + emTitle+ "'>");
  document.write (emLink);
  document.write ("</a>");
}

function showEM(userName, emServer) {
  /* 
  The showEM() function displays a link to the user's email address.
  The text of the user and e-mail server names are entered in 
  reverse order to thwart e-mail harvesters.
  */
	 
  userName = stringReverse(userName);  // reverse the text of the userName parameter
  emServer = stringReverse(emServer);  // reverse the text of the emServer paramenter
	 
  var emLink = userName + "@" + emServer;  // combine the text of UserName and emServer

  document.write("<a href='mailto:" + emLink + "'>");	   
  document.write(emLink);	   
  document.write("</a>");

}


function isHidden(object) {
    for (var n = object; n.nodeName != "BODY"; n = n.parentNode) {
        if (n.style.display == "none") return true;
    }
    return false;
}


function popWin(url) {
   pop = window.open(url,"pop","width=640,height=520,scrollbars=yes");
   
   testpop = (pop == null || typeof(pop) == "undefined") ? true: false;
   return testpop;
}

function openNewWindow(domain) {
 popupWin = window.open(domain, "PopUp", "menubar, toolbar, scrollbars, resizable, width=800, height=600, left=0, top=0")
}
