/*script to include content*/

function mapopenit(url,target)
{
var x = window.open(url,target,'width=520,height=350,toolbar=no,scrollbars=yes,status=yes,resizable=yes,menubar=no,top=150,left=150');
x.focus();
return false;

}


function getFile(n,id){
	document.getElementById(id).innerHTML="Loading...";
  var file; // Define variable
  if(n==''||n==self.location)return []; // Don't request self or empty strings (Safety meassure for some IE and pre0.9.9 Moz versions)
  switch(typeof ActiveXObject){
    case 'function': // Chech if ie
      file=new ActiveXObject('Microsoft.XMLHTTP'); // If so use ie XHreq
      break;
    default:
      file=new XMLHttpRequest;  // Otherwise use moz XHreq
      file.overrideMimeType("text/xml"); // And override content-type to avoid breakage
  }
  try{// Error susceptible code (Moz may screw up, especially if you're breaking the security rules)
    file.open('GET',n,false);// Open connection
    file.send('')// Send empty string
  }catch(e){// If error
   // return []// ...return empty null-length array
  }
	document.getElementById(id).innerHTML=file.responseText;
  //return [f.responseText,f.getAllResponseHeaders()]// Otherwise return response and http headers
}


/*end content includer*/


/* Begin section-handling utilities by Larry */

// Nice wrappers to avoid regexing inline to change an element class
// Based on: http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
function editCSS(a ,o , c1, c2) {
  switch (a) {
    case 'swap':
      o.className=!jscss('check', o, c1) ? o.className.replace(c2, c1) : o.className.replace(c1, c2);
      return 1;
    break;
    case 'add':
      if(!editCSS('check', o, c1)) {
        o.className+=o.className?' '+c1:c1;
      }
      return 1;
    break;
    case 'remove':
      var rep=o.className.match(' '+c1) ? ' ' + c1:c1;
      o.className=o.className.replace(rep,'');
      return 1;
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className);
      return 1;
    break;
  }
  return 0;
}

function getElementsByClassName(o, cls, tag) {
	
	if (! tag) tag = '*';
	
	var elements = o.getElementsByTagName(tag);
	var found = new Array();
	
	var numElements = elements.length;
	for (var i=0; i < numElements; i++) {
		if (editCSS('check', elements[i], cls)) {
			found[found.length] = elements[i];
		}
	}
	return found;
}


function openSection(num, aSection, bSection) {
	
	// Open the section itself
	show_section('m_segment_' + num);

	// Toggle the link
	show_section('plus' + num); 
	show_section('minus' + num); 
	
	// if the section is closed, we don't need to do anything but update the anchors
	// and toggle its +/- status
	if ('none' == document.getElementById('m_segment_' + num).style.display) {
		var anchors = {
			o: sections[num],
			a: 0,
			b: 0
		};
		setLocationAnchors(anchors);
		
		return;
	}
	
	// Get the remote file for this section
	
	/*
	This version would allow us to concatenate the normal content and the external_url
	
	var buffer = document.createElement('div');
	buffer.id = 'loading_buffer';
	var body = document.getElementsByTagName('body')[0];
	body.appendChild(buffer);

	var pageName = sections[num];
	getFile(pageName + '/index.html', 'loading_buffer');
	document.getElementById('container_' + num).innerHTML = buffer.innerHTML;

	// If there is an external_url defined, pull that in, too
	if (sectionLinks[num]) {
		getFile(sectionLinks[num],'loading_buffer');
		document.getElementById('container_' + num).innerHTML += buffer.innerHTML;
	}
	
	// Clean up after ourselves
	body.removeChild(buffer);
	*/
	
	// Load in the contents of this bucket, wtih external_urls taking precedence over 
	if (sectionLinks[num]) {
		getFile(sectionLinks[num],'container_' + num);
	}
	else {
		var pageName = sections[num];
		getFile(pageName + '/index.html','container_' + num);
	}
	
	// And hide its A-level and B-level children, except those we're specifically showing
	var toHide = getElementsByClassName(document.getElementById('container_' + num), 'secondary_landing_content');
	for (i=0; i < toHide.length; i++) {
		if (! ((toHide[i].id == 'm_segment_' + aSection) || (toHide[i].id == 'm_segment_' + bSection))) {
			toHide[i].style.display = 'none';
		}
	}
	
	// Now set the open/close links to their closed state, again except those we're specifically showing
	var toToggle = getElementsByClassName(document.getElementById('container_' + num), 'secondary_landing_link');
	if(! aSection) aSection = '';
	if(! bSection) bSection = '';
	var aKey = aSection.substr(4, aSection.length - 1);	// Anchor is SLC, but we need SLO.  Icky. :-(
	var bKey = bSection.substr(4, bSection.length - 1);
	for (var i=0; i < toToggle.length; i++) {
		if (editCSS('check', toToggle[i], 'plus_link')) {
			if (! ((toToggle[i].id == 'SLO_' + aKey + '_plus') || (toToggle[i].id == 'SLO_' + bKey + '_plus'))) {
				toToggle[i].style.display = 'block';
			}
		}
		else if (editCSS('check', toToggle[i], 'minus_link')) {
			if (! ((toToggle[i].id == 'SLO_' + aKey + '_minus') || (toToggle[i].id == 'SLO_' + bKey + '_minus'))) {
				toToggle[i].style.display = 'none';
			}
		}
	}
	
	// Update the location bar as necessary
	var anchors = {
		o: sections[num],
		a: (typeof aSection == 'undefined') ? 0 : aSection,
		b: (typeof bSection == 'undefined') ? 0 : bSection
	};
	setLocationAnchors(anchors);
	
	// And refresh any necessary iframes
	refreshIFrames();
	
}

function refreshIFrames() {
	// Because of a bug in some browsers, we have to force-refresh any iframes in the section.
	// Otherwise they never load for some reason.
	var frames = document.getElementsByTagName('iframe');
	for (i=0; i < frames.length; i++) {
		var srcBak = frames[i].src;
		frames[i].src = '';
		frames[i].src = srcBak;
	}
}

function setLocationAnchors(components) {
	
	if (! window.anchorComponents) {
		window.anchorComponents = {
			o: 0,
			a: 0,
			b: 0
		};
	}

	if (typeof components.o != 'undefined') window.anchorComponents.o = components.o;
	if (typeof components.a != 'undefined') window.anchorComponents.a = components.a;
	if (typeof components.b != 'undefined') window.anchorComponents.b = components.b;
	
	var anchorPieces = new Array();
	if (window.anchorComponents.o) anchorPieces.push(window.anchorComponents.o);
	if (window.anchorComponents.a) anchorPieces.push(window.anchorComponents.a);
	if (window.anchorComponents.b) anchorPieces.push(window.anchorComponents.b);
	
	window.location = document.URL.substring(0, document.URL.indexOf('#')) + "#" + anchorPieces.join('/');
	
	// And now poke the server to say that we've changed our URL.
	clickTracker(window.location);
}

function sectionToId(sect) {
	for(id in sections) {
		if (sect == sections[id]) {
			return id;
		}
	}
	return 0;
}

function jumpToAnchorSection() {
	var anchorIndex = document.URL.indexOf('#');
	if (-1 != anchorIndex) {
		var anchors = document.URL.substr(anchorIndex+1).split('/');
		
		var aSection = anchors[1] ? anchors[1] : '';
		var bSection = anchors[2] ? anchors[2] : '';
		// Open the specified section and subsections
		openSection(sectionToId(anchors[0]), aSection, bSection);
	}
	else {
		clickTracker(window.location);
	}
}

/* End utilities */


/* Click tracker, by Larry Garfield */

function clickTracker(url) {
	
	var submitURL = 'http://www.saic.edu/scripts/clicktracker.php';
	
	var data = {
		url: url
	}
	
	var request = HTTP.newRequest();
	
	try {
		// We don't want a response, so just send the data and drop the response on the floor
		request.open("POST", submitURL);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		request.send(HTTP.encodeFormData(data));
	}
	catch (e) {
		// This only happens, really, if we're on the test server, in which case we don't care
	}
}


// Cross platform XmlHttpRequest initialization, by JS:TDG, 5th Ed
var HTTP = new Object();
HTTP._factories = [
	function() { return new XMLHttpRequest(); },
	function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
	function() { return new ActiveXObject("Microsoft.XMLHTTP") }
]

HTTP._factory = null;
HTTP.newRequest = function() {
	if (HTTP._factory != null) return HTTP._factory();
	for (i=0; i < HTTP._factories.length; i++) {
		try {
			var factory = HTTP._factories[i];
			var request = factory();
			if (request != null) {
				HTTP._factory = factory;
				return request;
			}
		}
		catch (e) {
			continue;
		}
	}
	
	HTTP._factory = function() {
		throw new Error("XMLHttpRequest not supported");
	}
	HTTP._factory();
	return 1;
}

HTTP.post = function(url, values, callback, errorHandler) {
	var request = HTTP.newRequest();
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			if (request.status == 200) {
				callback(HTTP._getResponse(request));
			}
			else {
				if (errorHandler) errorHandler(request.status, request.statusText);
				else callback(null);
			}
		}
	}
	
	// INCOMPLETE, see p. 488
	
}

HTTP.encodeFormData = function(data) {
	var pairs = [];
	var regexp = /%20/g;
	for (var name in data) {
		var value = data[name].toString();
		var pair = encodeURIComponent(name).replace(regexp, "+") + "=" + encodeURIComponent(value).replace(regexp, "+");
		pairs.push(pair);
	}
	return pairs.join('&');
}

function climbDOM(e, target) {
  // Crawl up the DOM tree to the first node with the specified name.
  // Borrowed from DHTML Utopia by SitePoint, page 68

  while (e.nodeName.toLowerCase() != target && e.nodeName.toLowerCase() != 'html') {
    e = e.parentNode;
  }
  return (e.nodeName.toLowerCase() == 'html') ? null : e;
}

function addEvent(elm, evType, fn, useCapture) {
  // cros-browser event handling for IE 5+, NS6+, and Gecko
  // By Scott Andrew
  if (elm.addEventListener) {
    elm.addEventListener(evType, fn, useCapture);
    return true;
  }
  else if (elm.attachEvent) {
    var r = elm.attachEvent('on' + evType, fn);
  }
  else {
    elm['on' + evType] = fn;	// For IE5 Mac
  }
  return 1;
} // addEvent()

//addEvent(window, 'load', clicktracker.init, false);

function debug(message) {
  var div = document.getElementById('debugdiv');

  if (div) {
    var line = document.createElement('div');
    var text = document.createTextNode(message);
    line.appendChild(text);
    div.appendChild(line);
  }
}


/* End click tracker */



/* window opener by jen*/
/*window opener*/
function openit(url,target)
{
var w = window.open(url,target,'width=500,height=350,toolbar=no,scrollbars=no,status=yes,resizable=yes,menubar=no,top=150,left=150');
w.focus();
return false;
}
function openit_variablesize(url,target,width,height)
{
var w = window.open(url,target,'width='+width+',height='+height+',toolbar=no,scrollbars=no,status=yes,resizable=yes,menubar=no,top=150,left=150');
w.focus();
return false;
}

function openit_width(url,target)
{
var w = window.open(url,target,'width=624,toolbar=no,scrollbars=no,status=yes,resizable=yes,menubar=no,top=150,left=150');
w.focus();
return false;
}
function openit_variablesize(url,target,width,height)
{
var w = window.open(url,target,'width='+width+',height='+height+',toolbar=no,scrollbars=no,status=yes,resizable=yes,menubar=no,top=150,left=150');
w.focus();
return false;
}
function weather(url,target)
{
var w = window.open(url,target,'width=320,height=280,toolbar=no,scrollbars=no,status=yes,resizable=yes,menubar=no,top=150,left=150');
w.focus();
return false;
}
function openit_search(url,target)
{
var w = window.open(url,target,'width=624,toolbar=no,scrollbars=yes,status=yes,resizable=yes,menubar=no,location=yes,top=150,left=150');
w.focus();
return false;
}
/*window opener*/


/*end window opener*/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function toggle(id) {
if(document.getElementById(id).style.display == "none") {
document.getElementById(id).style.display = "block";
}
else if(document.getElementById(id).style.display == "block") {
document.getElementById(id).style.display = "none";
}
}












/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2006 Coppermine Dev Team
  v1.1 originally written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  ********************************************
  Coppermine version: 1.4.4
  $Source: /cvsroot/coppermine/stable/scripts.js,v $
  $Revision: 1.5 $
  $Author: gaugau $
  $Date: 2006/02/26 11:24:06 $
  
  $Touched by Danny 03/15/06
**********************************************/



function show_section(e) {
    if (document.getElementById(e).style.display == 'none') {
        document.getElementById(e).style.display = 'block';
    } else {
        document.getElementById(e).style.display = 'none';
    }
}

function anchor_section(e) {
        document.getElementById(e).style.display = 'block';
}


function expand()
{
        var Nodes = document.getElementsByTagName("div")
        var max = Nodes.length
        for(var i = 0;i < max;i++) {
                var nodeObj = Nodes.item(i)
                var str = nodeObj.id
                if (str.match("section")) {
                        nodeObj.style.display = 'block';
                }
        }
		
}

function hideall()
{
        var Nodes = document.getElementsByTagName("div")
        var max = Nodes.length
        for(var i = 0;i < max;i++) {
                var nodeObj = Nodes.item(i)
                var str = nodeObj.id
                if (str.match("m_segment")) {
                        nodeObj.style.display = 'none';
                }
        }
}