// START quick links
function doSel(obj) {
     for (i = 1; i < obj.length; i++)
        if (obj[i].selected == true)
           eval(obj[i].value);
}
// END quick links

// START top container minimizer/maximizer
var helper_topimgminimized = false;
function toggletopcontainer() {
	document.getElementById("secondaryTopContainer").style.display = helper_topimgminimized?"block":"none";
	document.getElementById("minimizer").src = helper_topimgminimized?"/global/images/negative.png":"/global/images/positive.png";
	document.getElementById("topcontainerminimizeexplanation").innerHTML = helper_topimgminimized?"":"(Top Container Minimized)";
	helper_topimgminimized = !helper_topimgminimized;
	document.cookie = "topimgminimized=" + helper_topimgminimized.toString();
}

//jquery must have been initialized at this point.
//when the DOM is read, set the top contianer as minimized if the cookie is set to true
$(document).ready(function() {
	if(document.cookie.length > 0) {
		var c_start = document.cookie.indexOf("topimgminimized=");
		if(c_start != -1) {
			c_start = c_start + 16
			var c_end = document.cookie.indexOf(";",c_start);
			if(c_end==-1) c_end = document.cookie.length;
			var c_value = document.cookie.substring(c_start,c_end);
			if(c_value == "true") {
				toggletopcontainer();
			}
		}
	}
});
// END top container minimizer/maximizer

// START flash header
function getFlashHeader() {
	if (AC_FL_RunContent != 0) {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
			'width', '793',
			'height', '158',
			'src', '/flash/header/header',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'center',
			'play', 'true',
			'loop', 'true',
			'scale', 'noscale',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'header',
			'bgcolor', '#ffffff',
			'name', 'header',
			'menu', 'true',
			'allowScriptAccess','sameDomain',
			'movie', '/flash/header/header',
			'salign', 'lt',
            'flashvars', 'configUrl=/flash/header/headerConfig.txt'
			);
	}
}
// END flash header

// START slideshow header
function getSlideshow() {
	if (AC_FL_RunContent != 0) {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
			'width', '169',
			'height', '192',
			'src', '/flash/slideshow/slideshow',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'center',
			'play', 'true',
			'loop', 'true',
			'scale', 'noscale',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'slideshow',
			'bgcolor', '#ffffff',
			'name', 'slideshow',
			'menu', 'true',
			'allowScriptAccess','sameDomain',
			'movie', '/flash/slideshow/slideshow',
			'salign', 'lt',
            'flashvars', 'configUrl=/flash/slideshow/slideshowConfig.txt'
			); //end AC code
	}
}
// END slideshow flash

// START menu hover
function imageChange(id) {
	document.images[id].src = "/images/topNavButtons/" + id + "Hover.gif";
}

function resetChange(id) {
	document.images[id].src = "/images/topNavButtons/" + id + ".gif";
}
// END menu hover

// START quick links hover
sfHover = function() {
	var sfEls = document.getElementById("quickLinksMenu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
//if (window.attachEvent) window.attachEvent("onload", sfHover);
// END quick links hover


// START getPage function. used to embed dynamic php into static shtml
function getPage(url)  {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.open("GET", url, false);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.open("GET", url, false);
            req.send();
        }
    }
    return req;
}
// END getPage function

//START AJAX Create Request Function
var request = null;

function createRequest() {
  try {
    request = new XMLHttpRequest();
  } catch (trymicrosoft) {
    try {
      request = new ActiveXObject("Msxml12.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        request = new ActiveXObject ("Microsoft.XMLHTTP");
      } catch (failed) {
        request = null;
      }
    }
  }
  if (request == nul)
    alert("Error creating request object!");
}
//END AJAX Create Request Function

//START print_with_links function
	var printReferencesCreated = false;
	function print_with_links() {
		// only create the print the print references if they haven't already been created
		// if there is an error while creating the print references, print the page without references
		try {
			if (printReferencesCreated == false) {
				//the location of all of the current links to be referenced
				var div_article = document.getElementById("secondaryContentMainContainer");

				//the location to print all of the references
				var reference_div = document.createElement("div");
				reference_div.setAttribute("id", "print_reference_div");

				//go through each link in the article and print their references
				var allLinks = div_article.getElementsByTagName("a");
				//indicator for current link number
				var curLink = 0;
				for (var i = 0; i < allLinks.length; i++) {
					//do not print references to the current page
					var anchor_url = allLinks[i].href;
					if (anchor_url.indexOf("#") != -1)
						anchor_url = anchor_url.substring(0, anchor_url.indexOf("#"));
					var document_url = document.location.href;
					if (document_url.indexOf("#") != -1)
						document_url = document_url.substring(0, document_url.indexOf("#"));

					//if the reference is not empty and is not to the current page,
					//add the necessary html to the document
					if (anchor_url != "" && anchor_url != document_url) {
						//links will be changed to the following form:
						//<a href="myurl"><sup class="print_link_reference">[#]</sup>mylink</a>
						var newSup = document.createElement("sup");
						newSup.setAttribute("class", "print_link_reference");
						var newSupText = document.createTextNode("[" + curLink + "]");
						newSup.appendChild(newSupText);
						allLinks[i].insertBefore(newSup, allLinks[i].firstChild);

						//references will be added to the reference div in the following form:
						//<p><sup class="print_link_reference">[#]</sup>myurl</p>
						var newReference = document.createElement("p");
						var newReferenceSup = newSup.cloneNode(true);
						newReference.appendChild(newReferenceSup);
						var newAnchorText = document.createTextNode(anchor_url);
						newReference.appendChild(newAnchorText);
						reference_div.appendChild(newReference);

						//increment the current link number
						curLink++;
					}
				}

				//if all of the links were added successfully, add the
				//reference div to the page and make sure it is not added twice
				if(reference_div.hasChildNodes()) {
					var before_reference = document.createElement("div");
					before_reference.setAttribute("id", "print_reference_div-before");
					var before_reference_text = document.createTextNode("References:");
					before_reference.appendChild(before_reference_text);
					reference_div.insertBefore(before_reference, reference_div.firstChild);
					div_article.appendChild(reference_div);
				}
				printReferencesCreated = true;
			}
		}

		//if an error occurred, make sure that the link references do not show
		//(because the reference div would not have been added to the page)
		catch (e) {
			//add a css stylesheet to the head of the document
			var style_node = document.createElement("style");
			style_node.setAttribute("type", "text/css");
			style_node.setAttribute("media", "print");
			if(style_node.styleSheet) { // for internet explorer
				style_node.styleSheet.cssText = ".print_link_reference{display:none !important;}";
			} else { // for other browsers
				var style_text = document.createTextNode(".print_link_reference{display:none !important;}");
				style_node.appendChild(style_text);
			}
			document.getElementsByTagName("head")[0].appendChild(style_node);
		}

		//print the page regardless of whether referencing was successful or not
		finally {
			window.print();
		}
	}
//END print_with_links function