// Default javascript file for the APS website
// 11/25/2008
// Jonas Downey (jbd@anl.gov)

/* ANL TEMPLATE FUNCTIONS (from anlmain.js) */

// Code for swapping stylesheets
// Load the alternate stylesheet based on platform
var p = navigator.platform;
if (p.substring(0,3) == 'Mac' && (navigator.appName == "Microsoft Internet Explorer"))
	{
	// do nothing - the default is fine
	}
else
	{
		// load some additional style sheet items
		document.write('<link rel="stylesheet" href="/anl_templates/stylesheets/anl_default.css" type="text/css">');
	}

// FUNCTION: anlBreadCrumbs(string baseURL)

// Last Modified: 08/17/2004
// Modified by: D. M. Stasiak (CIS)
//
// Public function for creating breadcrumbs, all defaults for delimiter and styles
// are set in this function.  End-users only need to specify the base URL for their
// site, without the trailing slash (/)
//function anlBreadCrumbs(baseURL){
//	breadCrumbs(baseURL,">","",null,null,null,"0");
//}
//Overwrite breadcrumbs function
//removed "" from function call
//to allow for non-.html index pages
function anlBreadCrumbs(baseURL){
	breadCrumbs(baseURL,">");
}

//function simplified by Jonas Downey
//initial improvements: march 14 2008
//revised with absolute linking: sep 11 2008
function breadCrumbs(base,delStr) {
	//grab current URL
	loc=window.location.toString();
	//split into array
	subs = loc.split("/");
	//print the crumbs
	//note: the first four entries in the subs array are contents pulled from 'http://www.domain.com',
	//so we start with i=3. the last entry is 'filename.html' and should not be printed, 
	//so we opt for subs.length-1.
	var path='';
	for (i=3;i<(subs.length-1);i++) 
	{
		//build up the path variable for each successive folder
		path=path+'/'+subs[i];
		subs[i]=makeCaps(unescape(subs[i]));
		
		//create absolute links using base path
		document.write('<a href="'+base+path+'">'+subs[i]+'</a>  '+delStr+' ');

		//relative link option
		//document.write('<a href="'+getLoc(subs.length-i-2)+'">'+subs[i]+'</a>  '+delStr+' ');
	}
}
function makeCaps(a) {
  g=a.split(' ');for (l=0;l<g.length;l++) g[l]=g[l].toUpperCase().slice(0,1)+g[l].slice(1);
  return g.join(" ");
}
function getLoc(c) {
  var d="";if (c>0) for (k=0;k<c;k++) d=d+"../";else d="./"; return d;
}

// Search functions
function checkSearchForm(f)
{
		// Check to see if a restriction is applied to the search
		if(f.q.value == "" || f.q.value == "Search APS ...")
		{
				alert("Please enter your search terms.");
				f.q.focus();
				return false;
		}
		return true;
}


<!--
//
// format date as dd-mmm-yy
// example: 12-Jan-99
//
function date_ddmmmyy(date)
{
  var d = date.getDate();
  var m = date.getMonth() + 1;
  var y = date.getYear();

  // handle different year values 
  // returned by IE and NS in 
  // the year 2000.
  if(y >= 2000)
  {
    y -= 2000;
  }
  if(y >= 100)
  {
    y -= 100;
  }

  // could use splitString() here 
  // but the following method is 
  // more compatible
  var mmm = 
    ( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar':
    ( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun':
    ( 7==m)?'Jul':( 8==m)?'Aug':(9==m)?'Sep':
    (10==m)?'Oct':(11==m)?'Nov':'Dec';

  return "" +
    mmm + "-" + (d<10?"0"+d:d) + "-20" + (y<10?"0"+y:y);
}

//show or hide a layer
function toggleLayer(whichLayer){
	if (document.getElementById){
	// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all){
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers){
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}


// get last modified date of the 
// current document.
function date_lastmodified()
{
  var lmd = document.lastModified;
  var s   = "Unknown";
  var d1;

  // check if we have a valid date
  // before proceeding
  if(0 != (d1=Date.parse(lmd)))
  {
    s = "" + date_ddmmmyy(new Date(d1));
  }
  return s;
}
// -->

//function to remove mailto links from documents
//helps avoid spamming
function noSpam(to, cc, domain, subj)
{
 flag=false;
 loc = "mailto:" + to + "@" + domain;
 if(cc != ""){loc += "?cc=" + cc + "@" + domain;flag=true;}
 if(subj != ""){
	 if(flag){loc += "&";}
	 else{loc += "?";}
	 loc += "&subject=" + subj;
}
 window.location = loc;
}

//functions for image rollovers
function findimg()
{
 var imgs,i;
// loop through all images of the document
 imgs=document.getElementsByTagName('img');
 for(i=0;i<imgs.length;i++)
 {
// test if the class 'roll' exists
  if(/roll/.test(imgs[i].className))
  {
// add the function roll to the image onmouseover and onmouseout and send
// the image itself as an object
   imgs[i].onmouseover=function(){roll(this);};
   imgs[i].onmouseout=function(){roll(this);};
  }
 }
}
function roll(o)
{
 var src,ftype,newsrc;
// get the src of the image, and find out the file extension
 src = o.src;
 ftype = src.substring(src.lastIndexOf('.'), src.length);
// check if the src already has an _on and delete it, if that is the case 
 if(/_on/.test(src))
 {
  newsrc = src.replace('_on','');
 }else{
// else, add the _on to the src 
  newsrc = src.replace(ftype, '_on'+ftype);
 }
 o.src=newsrc;
}
//IP-based search
//if you are outside, you will get the external public Argonne appliance
//if you are inside, you will get the internal APS appliance
function getIP(){
	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") {
	  http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	  http = new XMLHttpRequest();
	}
	http.open("GET", "/Library/ipcheck/verify.php");
	http.onreadystatechange=function() {
	  if(http.readyState == 4) {
		 searchmod(http.responseText);
	  }
	}
	http.send(null);
}
function searchmod(ip)
{
    if (ip == 1 && document.search.site) {
			document.search.site.value = 'default_collection'
			document.search.client.value = 'default_frontend'
			document.search.proxystylesheet.value = 'default_frontend'
			document.search.action = 'http://google.aps.anl.gov/search'
    } 
}

/* 
  ------------------------------------
  PVII Menu CSS Express Drop-Down Menu
  by Project Seven Development
  www.projectseven.com
  ------------------------------------
*/
function P7_ExpMenu(){ //v1.1.0.2 by PVII-www.projectseven.com
 if(navigator.appVersion.indexOf("MSIE")==-1){return;}
 var i,k,g,lg,r=/\s*p7hvr/,nn='',c,cs='p7hvr',bv='p7menubar';
 for(i=0;i<10;i++){g=document.getElementById(bv+nn);if(g){
 lg=g.getElementsByTagName("LI");if(lg){for(k=0;k<lg.length;k++){
 lg[k].onmouseover=function(){c=this.className;cl=(c)?c+' '+cs:cs;
 this.className=cl;};lg[k].onmouseout=function(){c=this.className;
 this.className=(c)?c.replace(r,''):'';};}}}nn=i+1;}
}
window.onload=function(){P7_ExpMenu();findimg();getIP();}
