// Get the domain - cookie functions will need this variable - mharen 12/26/01
thisdomain = document.location +"";
thisdomain = thisdomain.substring(thisdomain.indexOf('//')+2,thisdomain.length);
thisdomain = thisdomain.substring(0,thisdomain.indexOf('/'));
thisdomain = (navigator.appName != "Netscape")? thisdomain.substring(thisdomain.indexOf('.')+1,thisdomain.length): thisdomain;

//this function is used for email addresses to hide from spambots.
//example usage:
//<!-- Begin foil spambots -->
//<script language="Javascript">
//WriteEa ('car','eer-i','nfo');
//</script>
//<noscript>
//career&#45;info
//&#64;&#32;&#106;&#117;&#110;&#105;&#112;&#101;&#114;&#32;&#46;&#32;&#110;&#101;&#116;
//</noscript>
//<!-- End foil spambots -->
function WriteEa (first, second, third, subject) {
		var display, ema, ea;
		
		//if no subject is present
		if (subject == null){
			ema = first + second + third + '\&\#64\;' + 'juniper' + '\&\#46\;' + 'net';
			display = ema;
		}
		
		else{
			display = first + second + third + '\&\#64\;' + 'juniper' + '\&\#46\;' + 'net' //text to display
			ema = first + second + third + '\&\#64\;' + 'juniper' + '\&\#46\;' + 'net' + '?subject=' + subject //actual go-to link
		}		
		
		ea = '<a href=\"ma' + 'ilto:' + ema + '"' + '>' + display + '</a>' //writes href code and displays
		
		document.write (ea);
}


// This is for re-directing pages from a drop-down list control - mharen 7/13/01

//function redirects to "Main" in body of frames.
function goTherePartner(theform) {
        var URL = theform.url.options[theform.url.selectedIndex].value;
        location.href = URL;
}


function goThere(theform) {
        var URL = theform.url.options[theform.url.selectedIndex].value;
        parent.location.href = URL;
}


// This is for the video pop-up windows - rwc 08/10/01
function video_pop_up(page)
{
OpenWin = this.open(page,"CtrlWindow","toolbar=no,menubar=no,location=no,scrollbars=no,resize=no,status=no,width=340,height=440");
}


// This is for the corporate video pop-up window - rwc 09/17/01
function corp_video_pop_up()
{
OpenWin = this.open("/video/corporate/frameset.html","CorpVidWin","toolbar=no,menubar=no,location=no,scrollbars=no,resize=no,status=no,width=620,height=373");
// setTimeout('CorpVidWin.focus();',250);
}


// This is for opening pop-up windows in a way that addresses usability complaints. Use this instead of target="_blank" 
// It guarentees that pop-up windows will be smaller than the parent window in both dimensions- mharen 7/13/01

// example usage: <a href="javascript:new_window('/video/corporate/','620','420','chrome=yes');">link</a> - with chrome
//                         <a href="javascript:new_window('/video/corporate/','620','420');"> - without chrome
function new_window(page, width, height, chrome)
{
if (chrome == "chrome=yes") {chrome="yes"} else {chrome="no"}
var w = width, h = height, docw = width, doch = height;
if (document.all) {
// the following is only available after onLoad
// get current window size for ie
  docw = document.body.clientWidth;
  doch = document.body.clientHeight;
}
// get window size for Netscape
else if (document.layers) {
   docw = window.innerWidth;
   doch = window.innerHeight;
}
if (docw <= w) {
w = (docw - 40)
}
if (doch <= h) {
h = (doch - 40)
}
var leftPos = (screen.width / 2) - (w / 2);
var topPos = (screen.height / 2) - (h / 2);    
OpenWin = this.open(page,"CtrlWindow","top="+topPos+",screenX="+topPos+", left="+leftPos+", screenY="+leftPos+",width="+w+",height="+h+", toolbar="+chrome+",menubar="+chrome+",location="+chrome+",status="+chrome+",scrollbars=yes,resizable=yes,");
}

// enlarge an image in a new window - mharen 5/25/02
function enlarge_image(image, width, height, chrome, caption)
{
if (chrome == "chrome=yes") {chrome="yes"} else {chrome="no"}
var w = width, h = height, docw = width, doch = height;
if (document.all) {
// the following is only available after onLoad
// get current window size for ie
  docw = document.body.clientWidth;
  doch = document.body.clientHeight;
}
// get window size for Netscape
else if (document.layers) {
   docw = window.innerWidth;
   doch = window.innerHeight;
}
// compensate for the chrome
w = parseInt(w)+40;
h = parseInt(h)+100;
// make the new window smaller than the parent
if (docw <= w) {
w = (docw - 40)
}
if (doch <= h) {
h = (doch - 40)
}
var leftPos = (screen.width / 2) - (w / 2);
var topPos = (screen.height / 2) - (h / 2);    
ImageWin = window.open("","ImgWindow","top="+topPos+",screenX="+topPos+", left="+leftPos+", screenY="+leftPos+",width="+w+",height="+h+", toolbar="+chrome+",menubar="+chrome+",location="+chrome+",status="+chrome+",scrollbars=yes,resizable=yes,");
ImageWin.document.open();
ImageWin.document.write('<a href=\"javascript:window.close();\"><img src=\"/images/close_window.gif\" border=\"0\" height=\"21\" width=\"103\" vspace=\"2\" hspace=\"5\"\/><\/a>');
ImageWin.document.writeln('<a href=\"javascript:window.print();\"><img src=\"/images/button_print.gif\" border=\"0\" height=\"21\" width=\"103\" vspace=\"2\" hspace=\"5\"\/><\/a><br \/><br \/>');
ImageWin.document.writeln('<img src=\"'+image+'\" \/><br \/>');
if (caption) {
ImageWin.document.writeln('<span style=\"font-family:arial,verdana,sans-serif\;font-weight:bold\" \/>'+caption+'<\/span>');
}
ImageWin.document.close();
}

//getCookie -- kevin 02/12/04
function getCookie(Name) {
   var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value
         if (end == -1) 
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      } 
   }
}

// Cookie functions - mharen 12/21/01
function setCookie (name, value, hours, path, domain, secure) {
// This next little bit of code tests whether the user accepts cookies.
var acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'acceptsCookies=yes'; // Try to set a cookie.
    if(document.cookie.indexOf('acceptsCookies=yes') != -1) {
	acceptsCookies = true; 
    }// If it succeeds, set variable
} else { // there was already a cookie
  acceptsCookies = true;
}
    if (acceptsCookies) { // Don't waste your time if the browser doesn't accept cookies.
	var not_NN2 = (navigator && navigator.appName 
		       && (navigator.appName == 'Netscape') 
		       && navigator.appVersion 
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
    }
} // setCookie


//setCookie -- kevin 02/12/04 -- much simpler version
function setCookie2(name, value, expire) {
   document.cookie = name + "=" + escape(value)
   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function readCookie(name) {
    if(document.cookie == '') { // there's no cookie, so go no further
	return false; 
    } else { // there is a cookie
	var firstChar, lastChar;
	var theBigCookie = document.cookie;
	firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
	var NN2Hack = firstChar + name.length;
	if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
	    if(lastChar == -1) lastChar = theBigCookie.length;
	    return unescape(theBigCookie.substring(firstChar, lastChar));
	} else { // If there was no cookie of that name, return false.
	    return false;
	}
  }	
} // readCookie

function killCookie(name, path, domain) {
  var theValue = readCookie(name); // We need the value to kill the cookie
  if(theValue) {
      document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
  }
} // killCookie


// the following two functions cause a page reload when the user changes window size in Netscape 4.x This is a
// workaround for a netscape bug which messes up the page layout on resize - added by mharen 8/14/01
  function WM_netscapeCssFix()
  {
       // This checks to make sure that the window's available size 
      // has actually changed.
      if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth ||
              document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight)
          {
          document.location = document.location;
          }
  }
  function WM_netscapeCssFixCheckIn()
  {
      // This function checks to make sure the version of Netscape 
      // in use contains the bug; if so, it records the window's 
      // width and height and sets all resize events to be handled 
      // by the WM_netscapeCssFix() function.

      if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) ==4))
          {
          if (typeof document.WM == 'undefined')
              {
              document.WM = new Object;
              }

          if (typeof document.WM.WM_scaleFont == 'undefined')
              {
              document.WM.WM_netscapeCssFix = new Object;
              document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
              document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
              }

          window.onresize = WM_netscapeCssFix;
          }
  }
  WM_netscapeCssFixCheckIn()

  
// Launches training videos 7/30/02 - mth
function Launch_training(path) {
  var url = path;
  window.open(url, "pptwindow", "width=790,height=600,innerWidth=790,innerHeight=600,status");
}



// for table striping

// this function is need to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

 function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#f4f9ff";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

	    // avoid rows that have a class attribute
        // or backgroundColor style
	    if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
 
         // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
	        if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
        
		      mytd.style.backgroundColor = even ? evenColor : oddColor;
              
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }
  
  
function checkLogin(n1, n2)
{
	var loggedIn = getCookie("SMSESSION");

	if ((loggedIn ==  "LOGGEDOFF") || (loggedIn == null)) {
		document.getElementById(n1).style.display = "block";
		document.getElementById(n2).style.display = "none";
	}
	else {
		document.getElementById(n1).style.display = "none";
		document.getElementById(n2).style.display = "block";
	} 
}


// switch divs on/off
// modified version of http://www.dustindiaz.com/dhtml-expand-and-collapse-div-menu/ 

function switchMenu() {
// alert(document.location.href);
// alert(document.location.href.lastIndexOf("#"));
// get the base url
// if ((document.location.hash.length == 0)) {
// alert(document.location+'#'+switchMenu.arguments[0]); 
// document.location = document.location+'#'+switchMenu.arguments[0];
// } else {
// alert(document.location.href.substring(0,document.location.href.lastIndexOf("#"))+'#'+switchMenu.arguments[0]);
// document.location = document.location.href.substring(0,document.location.href.lastIndexOf("#"))+'#'+switchMenu.arguments[0];
// }
// alert(switchMenu.arguments[0]+'li')
// var elp = document.getElementById(switchMenu.arguments[0]+'li');
// elp.style.backgroundColor = '#eee';

	for (var i = 0; i < switchMenu.arguments.length; i++) {
		var el = document.getElementById(arguments[i]);
	//	var elp = document.getElementById(arguments[0])+'li';
	//	elp.style.backgroundColor = '#000';
		if ( el.style.display != 'none' ) {
		el.style.display = 'none';
		}
		else {
		el.style.display = '';
		}
	}
}

function collapseAll() {
	for (var i=0; i < collapseAll.arguments.length; i++ ) {
	    var el = document.getElementById(arguments[i]);
		el.style.display = 'none';
		}
}

function highlightitem() {
	for (var i = 0; i < highlightitem.arguments.length; i++) {
		var el = document.getElementById(arguments[i]);
		if ( el.style.fontWeight != 'bold' ) {
		el.style.fontWeight = 'bold';
		}
		else {
				el.style.fontWeight = 'normal';
		}
		
//		if ( el.style.backgroundColor  != '#efefef' ) {
//		el.style.backgroundColor  = '#efefef';
//		}
//		else {
//				el.style.backgroundColor  = '#fff';
//		}
		
		
		
	}
}

function MpageLoad() {
var ancr = document.location.hash.substring(1,document.location.hash.length);
	if (ancr != '') {
	switchMenu (ancr,ancr+'sa',ancr+'sb');
	highlightitem (ancr+'link');
	}
}

function showInline (elName) {
	var theElemenet = document.getElementById(elName);
	if (theElemenet) {
		theElemenet.style.display = "inline";
	}
}
function hideInline (elName) {
	var theElemenet = document.getElementById(elName);
	if (theElemenet) {
		theElemenet.style.display = "none";
	}
}
