<!--
/******************************************************************
* $file: leftLinks.js $
* $Revision: 1.0 $
* $Date: 2007/02/13 $
* @author James Ricks
*****************************************************************/
//setup function for browser support(author Chris Potter)
var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;
if(document.getElementById)
{
   isID = 1;
   isDHTML = 1;
   }
else
{
   if(document.all)
   {
      isAll = 1;
      isDHTML = 1;
   }
   else
   {
      browserVersion = parseInt(navigator.appVersion);
      if((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4))
      {
         isLayers = 1;
         isDHTML = 1;
      }
   }
}

/******************************************************************
*  FIND DOM (author Chris Potter)
*  This function defines which type of document object model is being 
*  used by the browser.
*****************************************************************/
function findDOM(objectID,withStyle)
{
   if(withStyle == 1)
   {
      if(isID)
      {
         return(document.getElementById(objectID).style);
      }
      else
      {
         if(isAll)
         {
            return(document.all[objectID].style);
         }
         else
         {
            if(isLayers)
            {
               return(document.layers[objectID]);
            }
         }
      }
   }
   else
   {
      if(isID)
      {
         return(document.getElementById(objectID));
      }
      else
      {
         if(isAll)
         {
            return(document.all[objectID]);
         }
         else
         {
            if(isLayers)
            {
               return (document.layers[objectID]);
            }
         }
      }
   }
}
  
/******************************************************************
* Function: Parse Expanded
* Parses the cookie to find which links should be expanded. This 
* function also displays the hidden body once the links are 
* correctly displayed, removing the link flitter.
******************************************************************/
function parseExpanded(cookieName)
{
   try
   {
      var previousExpandedLinks = getExpandedLinks(cookieName)
      var currentLink = ""
      var length = previousExpandedLinks.length
      var end = 0
      var start = 0
      var linkNumberIndex
      var linkNumber = 0;
      while (end < length)  
      {
         end = previousExpandedLinks.indexOf(",")
         currentLink = previousExpandedLinks.substring(start, end)
         linkNumberIndex = currentLink.lastIndexOf("t")
         linkNumber = currentLink.substring(linkNumberIndex + 1)
         document.getElementById(currentLink).style.display = "block";
         document.getElementById("image" + linkNumber).alt = "Expand";
         document.getElementById("image" + linkNumber).src = "http://www.byui.edu/css/v1/images/collapse.gif";
         previousExpandedLinks = previousExpandedLinks.substring(end + 1, length)
         length = previousExpandedLinks.length
      }
      document.body.style.visibility = "visible";
   }
   catch(err)
   {
   writeCookie('expandedLinks', "", -1)
   document.body.style.visibility = "visible";
   }
}

/******************************************************************
* Function: Change Link State
* This function expands and collapses the list when it is clicked
* and this fuction is called. It also updates the cookie on whether
* the list should be expanded or collapsed. 
* parameters - image - The id of the image that was clicked
*            - list  - the id of the list that was clicked
******************************************************************/
function changeLinkState(image, list)
{
    var cookieName = 'expandedLinks'
    var before = 0;
    var after = 0;
    //Expand or Collapse the link if clicked
    if (document.getElementById(image).alt == "Expand")
    {
        document.getElementById(image).alt = "Collapse";
        document.getElementById(image).src = "http://www.byui.edu/css/v1/images/expand.gif";
    }
    else
    {
        document.getElementById(image).alt = "Expand";
        document.getElementById(image).src = "http://www.byui.edu/css/v1/images/collapse.gif";
    }
    //Display or hide the link if clicked
    if (document.getElementById(list).style.display == "none") 
    {
       document.getElementById(list).style.display = "block";
       expandMenu(cookieName, list)
       changeSizeRevised();
    }
    else
    {    
       document.getElementById(list).style.display = "none";
       collapseMenu(cookieName, list)
       changeSizeRevised();
    }
}

/******************************************************************
* Function: Expand Menu
* Adds the list name to the cookie so that it will remain expanded.
******************************************************************/
function expandMenu(cookieName, link)
{
   var previousExpandedLinks = getExpandedLinks(cookieName)
   var currentLink = ""
   var length = previousExpandedLinks.length
   var end = 0
   var start = 0
   while (end < length)  
   {
      end = previousExpandedLinks.indexOf(",")
      currentLink = previousExpandedLinks.substring(start, end)
      if (currentLink == link)
      {
         return true
      }
      else
      {
         previousExpandedLinks = previousExpandedLinks.substring(end + 1, length)
         length = previousExpandedLinks.length
      }
   }
   writeCookie(cookieName, (getExpandedLinks(cookieName) + link + ","), 0)
   return false
}

/******************************************************************
* Function: Collapse Menu
* Removes the list name from the cookie so it will not remain expanded. 
******************************************************************/
function collapseMenu(cookieName, link)
{
   var previousExpandedLinks = getExpandedLinks(cookieName)
   var previousExpandedLinksBegin = ""
   var currentLink = ""
   var length = previousExpandedLinks.length
   var end = 0
   var start = 0
   while (end < length)  
   {
      end = previousExpandedLinks.indexOf(",")
      currentLink = previousExpandedLinks.substring(start, end)
      if (currentLink == link)
      {
         previousExpandedLinks = previousExpandedLinksBegin + previousExpandedLinks.substring(end + 1, length)
         writeCookie(cookieName, previousExpandedLinks, 1)
         return true
      }
      else
      {
         previousExpandedLinksBegin = previousExpandedLinksBegin + currentLink + ","
         previousExpandedLinks = previousExpandedLinks.substring(end + 1, length)
         length = previousExpandedLinks.length
      }
   }
   return false
}

/******************************************************************
* Writes the cookie to the browser
* A zero value will cause the cookie to expire at the end of the 
* session, a negative value will delete the cookie
******************************************************************/
function writeCookie(cookieName, values, expireDays)
{
   var exdate=new Date()
   exdate.setDate(exdate.getDate()+ expireDays)
   if (expireDays == 0)
   {
      document.cookie = cookieName + "=" + values + ((expireDays==null) ? "" : ";")
   }
   else
   {
   document.cookie = cookieName + "=" + values + ((expireDays==null) ? "" : ";expires=" + exdate.toGMTString())
   }
}

/******************************************************************
* Function: Get Expanded Links
* Returns a comma delimited list of the id's of the unordered lists
* which are set to remain expanded. 
******************************************************************/
function getExpandedLinks(cookieName)
{
   var expandedLinks = "" 
   if (document.cookie.length > 0)
   { 
      start = document.cookie.indexOf(cookieName + "=")
      if (start != -1)
      { 
         start = start + cookieName.length + 1 
         end = document.cookie.indexOf( ";", start)
         if (end == -1)
         {
            end = document.cookie.length
         }
         expandedLinks = unescape(document.cookie.substring(start,end))
      } 
   }
   else
   {
      expandedLinks = ""
   }
   return expandedLinks
}
-->