//<![CDATA[

// added by Chris for fadeIn() feature of menu items
var fadeInDefault = 50;
// use this to hold select groups that we hide because of conflict with dropdown menus
var hiddenElemsArray = new Array();
//var selList = getAllDocElementsByTagName("Select");

// new for v1.3
var navOff = ((location.href).indexOf("&nav=0") > 1 || (location.href).indexOf("&nav=off") > 1);

function underConstructionMsg(){
	alert('This feature has not been implemented yet. \n\nComing Soon!');
}	

function isUndefined(item) {
	item += "";
	//alert(item);
	if(item == "undefined" || item == "" || item == "null") {
		return true;
	}
	return false;
}

//----------------------------------------------------------------------------
// Code to determine the browser and version.
//----------------------------------------------------------------------------

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------

function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

// code for hiding select groups that conflict with menus *************

function getAllDocElementsByTagName(tag) {
	var e = document.getElementsByTagName(tag);
	//alert("There are " + a.length + " " + tag + " elements in this document!");	
	return e;
	
}

///********** OTHER FUNCTIONS ********************************
//   for navigation and view handling and general site navigation 
//*******************************************************************/

function manageNavDisplay(pageKey) {

    var sectId;
    if(isUndefined(pageKey)) {
        alert("pageKey is empty");
        return;
    }
    pageKey = pageKey.toLowerCase();
    //alert(pageKey);
    try {
        // set sidebar links and expand sections
        
        switch (pageKey) {
        case "areas":
            sectId = "sideAreas";
            showHideSideSect(sectId, true, false);
            highlightSideSect(sectId);
            break;
        case "subjects":
            sectId = "sideSubjects";
            showHideSideSect(sectId, true, false);
            highlightSideSect(sectId);
            break;
        case "rgl":
            sectId = "sideRGL";   
            highlightSideSect(sectId);
            break;    
        case "ecfr":
            sectId = "sideECFR";   
            highlightSideSect(sectId);
            break;    
        case "relatedinfo":
            sectId = "sideRInfo";
            showHideSideSect(sectId, true, false);
            highlightSideSect(sectId);
            break;
        case "publications":
            sectId = "sidePubs";   
            highlightSideSect(sectId);
            break;    
        case "index":
            sectId = "sideIndex";   
            highlightSideSect(sectId);
            break;    
        //case "search":
        //    //sectId = "sideSearch"; 
        //    sectId = "ctl00_subNavLink_Search";  
        //    highlightSideSect(sectId);
        //    break;   
        case "help":
            sectId = "sideHelp";   
            highlightSideSect(sectId);
            break;    
        case "crossref":
            sectId = "sideCrossRef";   
            highlightSideSect(sectId);
            //showHideSideSect(sectId, true, false);
            break;    
        case "contents":
            sectId = "sideContents";               
            highlightSideSect(sectId);
            break; 
        default:
            sectId = null;
            break;
        }
        // expand the matching sidebar section
//        if(sectId != null) {
//            showHideSideSect(sectId, true, false);
//            highlightSideSect(sectId);
//        }
        
    } catch(e) {
        // problem setting page element attributes
        alert(e.toString() + " - " + e.message);
    }
}

function showHideSideSect(sectContentHolderId, autoExp, autoColl) {
    var obj;
    var obj2;
    var expandIt; // default to collapse
    try {
    
	    if(autoExp == null) {
	        autoExp = false;
	    }
	    if(autoColl == null) {
	        
	        //autoExp = false;
	        autoColl = false;
	    }
	    
	    obj = document.getElementById(sectContentHolderId + "_Holder");
	    //obj2 = document.getElementById(sectContentHolderId + "_Filler");
	    
	    if(autoColl) {
            expandIt = false;
	    } else if(autoExp || obj.style.display + '' == 'none') {
            expandIt = true;
	    }
	    
	    
	    // otherwise toggle
	    if(expandIt) {
	        //alert("expand: " + sectContentHolderId);
	        obj.style.display = '';	        
	        //obj2.style.display = 'none';
	        // if expanding, collapse the others
	        switch (sectContentHolderId) {
                case "sideAreas":
                    showHideSideSect("sideRInfo", false, true);
                    showHideSideSect("sideSubjects", false, true);
                    //showHideSideSect("sideCrossRef", false, true);
                    break;
                case "sideSubjects":
                    showHideSideSect("sideRInfo", false, true);
                    showHideSideSect("sideAreas", false, true);
                    //showHideSideSect("sideCrossRef", false, true);
                    break;
                case "sideRInfo":
                    showHideSideSect("sideAreas", false, true);
                    showHideSideSect("sideSubjects", false, true);
                    //showHideSideSect("sideCrossRef", false, true);
                    break;
                case "sideCrossRef":
                    //showHideSideSect("sideAreas", false, true);
                    //showHideSideSect("sideSubjects", false, true);
                    //showHideSideSect("sideRInfo", false, true);
                    break;
                case "sidePubs":
                    break;     
                default:
                    //sectContentHolderId = null;
                    break;
            }
	        
	    } else {
	        //alert("collapse: " + sectContentHolderId);
	        obj.style.display = 'none';	        
	        //obj2.style.display = '';
	    }
	    return;
	} catch (e) {
	    alert(e.toString() + " - " + e.message);
	}
}	  

function highlightSideSect(sectId) {
    var obj;
    var anchorObj;
    if(sectId != null) {
        try {
            //alert("highlight: " + sectId);
            if(sectId.indexOf("side") == 0) {
                sectId += "_Head_List";
            }
	        obj = document.getElementById(sectId);
	        anchorObj = obj.getElementsByTagName("A")[0];
	        //alert(obj.className);
	        strClass = anchorObj.className;
	        if(strClass.search("On") == -1) {	
	            strClass += "On";
	        }    
	        anchorObj.className = strClass;
	        //alert(obj.className);
	        return;
	    } catch (e) {
	        alert(e.toString() + " - " + e.message);
	    }
	}
}	  

function openDocViewer(docId, pixelsWide, pixelsHigh) {
//    // open pic display page with passed in UNID from Notes
//    pixelsWide = '780';
//    pixelsHigh = '585';
    url = "PICDetail.aspx?docId="+docId;
//    tempwin=window.open(url,'FSIMS_Document_Viewer', 'alwaysRaised=yes, height='+ parseInt(pixelsHigh) +',width='+ parseInt(pixelsWide) +',screenX=150,screenY=50,left=150,top=50,scrollbars=yes,resizable=no');
//	tempwin.focus();
//	return;
	
		//alert(url);
	
	var prefs = new String("height=" + pixelsHigh + ",width=" + pixelsWide + ",left=40,top=40");
	if (url.toLowerCase().indexOf("http") == 0) {
		prefs += ",resizable=1,scrollbars=1";
	}
     else {
     		prefs += ",resizable=0,scrollbars=0";
     }
     tempwin = window.open(url,"FSIMS_Document_Viewer",prefs);					
     try {
        tempwin.focus();
     } catch(err) {
        // just attempting to focus - if disallowed no error
     }
	
	return;
	
}

function extDocWinPopup( url, title, pixelsWide, pixelsHigh ) {
    if( pixelsWide == null ) { pixelsWide = '700' };
	if( pixelsHigh == null ) { pixelsHigh = '600' };
	if( title == null ) { title = '' };
	tempwin=window.open(url, title, 'alwaysRaised=yes,height='+ parseInt(pixelsHigh) +',width='+ parseInt(pixelsWide) +',screenX=40,screenY=40,left=40,top=40,scrollbars=yes,resizable=yes,status=no');
	try {
        tempwin.focus();
     } catch(err) {
        // just attempting to focus - if disallowed no error
     }
}

function winPopup( url, pixelsWide, pixelsHigh ) {
	if( pixelsWide == null ) { pixelsWide = '700' };
	if( pixelsHigh == null ) { pixelsHigh = '600' };
	tempwin=window.open(url,'tempwin', 'alwaysRaised=yes,height='+ parseInt(pixelsHigh) +',width='+ parseInt(pixelsWide) +',screenX=150,screenY=50,left=150,top=50,scrollbars=yes,resizable=no,status=no');
	try {
        tempwin.focus();
     } catch(err) {
        // just attempting to focus - if disallowed no error
     }
}

function docWinPopup( url, title, pixelsWide, pixelsHigh ) {
    if( pixelsWide == null ) { pixelsWide = '700' };
	if( pixelsHigh == null ) { pixelsHigh = '600' };
	if( title == null ) { title = '' };
	var menubar = ',menubar=no';
	if (url.toLowerCase().indexOf(".xml") > 0 || url.toLowerCase().indexOf(".doc") > 0 || url.toLowerCase().indexOf(".pdf") > 0) {
	    menubar = ',menubar=yes';
	}
	//else if (url.toLowerCase().indexOf(".doc") > 0) {
	//    menubar = ',menubar=yes';
    //}
	
	tempwin=window.open(url, title, 'alwaysraise=yes,height='+ parseInt(pixelsHigh) +',width='+ parseInt(pixelsWide) +',screenX=150,screenY=50,left=150,top=50,scrollbars=yes,resizable=yes,statusbar=no'+menubar);
	try {
        tempwin.focus();
     } catch(err) {
        // just attempting to focus - if disallowed no error
     }
}

function GetWinPopup( url, pixelsWide, pixelsHigh ) {
	if( pixelsWide == null ) { pixelsWide = '700' };
	if( pixelsHigh == null ) { pixelsHigh = '600' };
	tempwin=window.open(url,'tempwin', 'alwaysRaised=yes,height='+ parseInt(pixelsHigh) +',width='+ parseInt(pixelsWide) +',screenX=150,screenY=50,left=150,top=50,scrollbars=yes,resizable=no,status=no');
	return tempwin;
}
//]]>