
function colorBars() {
	var listItems = document.getElementById("leftbarList").getElementsByTagName("li");
	for (var i = 0;  i < listItems.length;  i++) {
		var thisAnchor = listItems[i].getElementsByTagName("a")[0];
		thisAnchor.className = ((i % 2) == 1) ? "oddItem" : "evenItem";
	}
}

function toggleList(me) {
  var checkDisplay = me.getElementsByTagName("ul")[0].style.display;
  if (checkDisplay != "none") {
	  me.style.backgroundImage = "url('images/plusbullet.gif')";
	  me.getElementsByTagName("ul")[0].style.display = "none";
  }
  else {
	  me.style.backgroundImage = "url('images/minusbullet.gif')";
	  me.getElementsByTagName("ul")[0].style.display = "inline";
  }
}

function new_window(location) {
	window.open(location);
}

function check_email(mailField, msg1) {
				mail_exp = /^[A-z0-9\._-]+@[A-z0-9][A-z0-9-]*(\.[A-z0-9_-]+)*\.([A-z]{2,6})$/;
				entered = document.getElementById(mailField).value;
				if (mail_exp.test(entered)) {  
					return true;  //entered email is ok
				}
				else {
					// bad email
					document.getElementById(msg1).style.display = "";
					document.getElementById(mailField).focus();
					document.getElementById(mailField).select();
					return false;
				}					
			}
			
function replaceMainImage(newImageFile, currentAnchor) {
				if(document.getElementById) {
					document.getElementById('mainImage').src = newImageFile;
					// Clear the id of the previous thumbnail 
					document.getElementById('thumbSelected').id = "";
					// Change the id of the new one to thumbSelected
					currentAnchor.firstChild.id = "thumbSelected";
					//Change the image title
					// Perform the php baseImageName function in JavaScript!
					// Strip the '_D.jpg' from the filename
					var newTitle = newImageFile.split("_D.")[0];
					var startLocation = newTitle.lastIndexOf("/") + 1;
					newTitle = newTitle.slice(startLocation);
					// Replace underscores with blanks
					newTitle = newTitle.replace(/_/g, " ");
					//document.getElementById("imageTitle").firstChild.nodeValue = newTitle;
				}
				else {
					alert('These pages require JavaScript in your browser to display correctly');
					return false;
				}
			}
			
function replaceMainImageAndText(newImageFile, currentAnchor) {
				if(document.getElementById) {
					document.getElementById('mainImage').src = newImageFile;
					// Clear the id of the previous thumbnail 
					document.getElementById('thumbSelected').id = "";
					// Change the id of the new one to thumbSelected
					currentAnchor.firstChild.id = "thumbSelected";
					//Determine the name of the image text file	
					var newFileName = newImageFile.replace("_D.jpg", ".txt");
					ajaxReplaceText(newFileName);
				}
				else {
					alert('These pages require JavaScript in your browser to display correctly');
					return false;
				}
			}
			
			
function ajaxReplaceText(textFile) {
			var ajaxRequest;
			try {
				ajaxRequest = new XMLHttpRequest;  // Real browsers
			} catch (e) {  //IE something or another
				try {
					ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) { // Really old IE
					try { 
						ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {
					// No hope, let's give up
					alert("Get a real browser");
					return false;
					}					
				}
			}
			
			ajaxRequest.onreadystatechange = function() {
				if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
					document.getElementById('imageText').innerHTML = ajaxRequest.responseText;
				}
			}
			
			ajaxRequest.open("POST", "changeText.php", true);
			var param = "filename=" + textFile;
			
			ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			ajaxRequest.setRequestHeader("Content-length", param.length);
			ajaxRequest.setRequestHeader("Connection", "close");
			
			ajaxRequest.send(param);
		}
		
		function nextImage() {
			var currentAnchor = document.getElementById('thumbSelected').parentNode;  // thumbSelected is the image
			var newAnchor = getNextSibling(currentAnchor);
			if(newAnchor != null) {
				var executeString = newAnchor.getAttribute('onclick');
				// remove the "; return false;" from the string
				executeString = executeString.split(";")[0];
				// replace 'this' in the string with the new thumbnail anchor
				executeString = executeString.replace('this', 'newAnchor');
				eval(executeString);
			}
		}
		
		function getNextSibling(thisnode) {  // this is required because FF will return newlines and spaces as nodes
			x=thisnode.nextSibling;
			while ((x != null) && (x.nodeType != 1))  { // element nodes are type 1
			  x=x.nextSibling;
			}
			return x;  // returns null if there is no nextSibling
		}
		
		function write_year() {
				var d = new Date();
				document.write(d.getFullYear());
			}
