function writeDate() {
	var today = new Date();
	if (today.getFullYear) {
		var year = today.getFullYear();
	} else {
		var year = today.getYear();
	}
	var month = today.getMonth();
	var mArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var date = today.getDate();
	var theDate = date + " " + mArray[month] + " " + year + ".";				
	return theDate;
}
function openWin(url){
	aWindow = window.open(url,"external","left=10,top=10,location,toolbar=yes,width=600,height=300,status=yes,scrollbars=yes,resizable=yes,menubar=no");
	aWindow.focus();
}
function openRelated(url) {
	theWindow = window.open(url,"win","left=10,top=10,location=no,toolbar=no,width=500,height=450,status=no,scrollbars=yes,resizable=yes,menubar=no");
	theWindow.focus();
}
function openATA(url) {
	theWindow = window.open(url,"win","left=10,top=10,location=no,toolbar=no,width=550,height=200,status=no,scrollbars=yes,resizable=yes,menubar=no");
	theWindow.focus();
}
function openEmail(url) {
	theWindow = window.open(url,"win","left=10,top=10,location=no,toolbar=no,width=700,height=500,status=no,scrollbars=yes,resizable=yes,menubar=no");
	theWindow.focus();
}
function backToBook(loc) {
	window.opener.document.location = loc;
	window.close();
	window.opener.focus();
}
function thumb(url) {
	/*Tests for and closes previously opened window. If test is not performed, 
	  new images will open in the same window on top of the previous coding.*/		
	if (window.thumbWindow && !window.thumbWindow.closed) {
		thumbWindow.close()
	}	
	thumbWindow = window.open(url, 'thumbWinWide', 'left=10,top=10,width=450,height=400,location=no,toolbar=no,status=no,scrollbars=yes,resizable=no,menubar=no')
	thumbWindow.focus()
}	
function openNote(url){
	aWindow = window.open(url,'window_note','location=no,toolbar=no,left=80,top=80,width=400,height=200,status=no,scrollbars=yes,resizable=yes,menubar=no');
	aWindow.focus();
}
function openMap(url){
	aWindow = window.open(url,'map','location=no,toolbar=no,width=695,height=500,status=no,scrollbars=yes,resizable=yes,menubar=no');
	aWindow.focus();
}
function openChron(url){
	aWindow = window.open(url,'chronology','location=no,toolbar=no,width=525,height=500,status=no,scrollbars=yes,resizable=yes,menubar=no');
	aWindow.focus();
}
function openSidebar(url){
	aWindow = window.open(url,'sidebar','left=25,top=25,location=no,toolbar=no,width=500,height=300,status=no,scrollbars=yes,resizable=yes,menubar=no');
	aWindow.focus();
}
function openImage(url){
	aWindow = window.open(url,'map','location=no,toolbar=no,left=10,top=10,width=630,height=410,status=no,scrollbars=yes,resizable=yes,menubar=no');
	aWindow.focus();
}
function openEditor(url){
	aWindow = window.open(url,"editor",'location=no,toolbar=no,left=10,top=10,width=475,height=300,status=no,scrollbars=yes,resizable=yes,menubar=no');
	aWindow.focus();
}
function openPopup(url){
	aWindow = window.open(url,"advisoryboard","left=10,top=10,location,width=540,height=500,toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
	aWindow.focus();
}
function openFactbook(url){
	aWindow = window.open(url,"factbook","left=10,top=10,location,width=570,height=500,toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
	aWindow.focus();
}
function openTour(url){
	aWindow = window.open(url,"tour","left=10,top=10,location=no,width=705,height=500,toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
	aWindow.focus();
}
function openResources(theURL,winName,features) { 
	if (window.rWindow && !window.rWindow.closed) {
		rWindow.close()
	}	
	rWindow = window.open(theURL,winName,features);
	rWindow.focus();
}
function reFocus(theObject) {
	//alert(theObject.name);
	var objName = theObject.name;
	if(objName == "qB1") {
		document.advsearch.qt[1].checked = true;
	} else {
		document.advsearch.qt[0].checked = true;
	}
}
function checkBoxes(theForm) {
	if(theForm == document.advsearch) {
		var radioButton = theForm.qt
		for (var i=0; i < radioButton.length; i++) {
			if (radioButton[i].checked) {
				radioText = radioButton[i].value;
			}
		}
		if(radioText == 2) {
			radioText = "Keyword";
		} else if(radioText == 1) {
			radioText = "Boolean";
		}				
		if((theForm.qK1.value != "" || theForm.qK2.value != "" || theForm.qK3.value != "" || theForm.qK4.value != "") && theForm.qB1.value != "") {
			return confirm("You have entered text in both the Keyword and Boolean search boxes,\nbut the " + 
			                radioText + " button is selected.  Only the " + radioText + " values will be used.\n" + 
			                "Click \"OK\" to continue or \"Cancel\" to make changes.");
		}
		// A nice idea, but prevents use of checkboxes as only search items
		//if((theForm.qK1.value == "" && theForm.qK2.value == "" && theForm.qK3.value == "" && theForm.qK4.value == "") && radioText == "Keyword") {
		//	alert("Keyword Search is selected, but no text\nwas found in any of the text boxes.");
		//	return false;			
		//}
	} else if(theForm == document.quicksearch) {
		if(theForm.qK1.value == "") {
			alert("You did not enter any search terms.");
			return false;
		}		
	} 
}
function insertOperator(formValue) {	
	// Get the value of the radio button selected
	var radioText = "";
	var radioButton = document.advsearch.qt;
	for (var i = 0; i < radioButton.length; i++) {
		if (radioButton[i].checked) {
			radioText = radioButton[i].value;
		}
	}
	var advSearchJspTab = document.getElementById("qTab").value;
	if(radioText == 1 || advSearchJspTab == "bool") {	// The Boolean search radio button is selected
		var opValue = formValue[formValue.selectedIndex].value; // operator value
		var qValue = document.advsearch.qB1.value; // text in the query box
		
		if(qValue != "") {
			if(opValue != "*" & opValue != "?") { // add space if not a wildcard character
				opValue = " " + opValue + " ";
			}		
			if(opValue != "") {
				document.advsearch.qB1.value = qValue + opValue;				
				document.advsearch.qB1.focus();
			} 
		} else {
			alert("Your query really shouldn't begin with a Boolean term.");
		}
	} else {
		alert("Change the search type to Boolean phrase\nsearch to use Boolean operators");		
	}
	document.advsearch.operators.selectedIndex = 0;
}
function insertOperatorJsp(formValue) {	
	var advSearchJspTab = document.getElementById("qTab").value;
	if(advSearchJspTab == "1") {	// The Boolean search tab is selected
		var opValue = formValue[formValue.selectedIndex].value; // operator value
		var qValue = document.advsearch.qB1.value; // text in the query box
		
		if(qValue != "") {
			if(opValue != "*" & opValue != "?") { // add space if not a wildcard character
				opValue = " " + opValue + " ";
			}		
			if(opValue != "") {
				document.advsearch.qB1.value = qValue + opValue;				
				document.advsearch.qB1.focus();
			} 
		} else {
			alert("Your query really shouldn't begin with a Boolean term.");
		}
	} 
	document.advsearch.operators.selectedIndex = 0;
}
function submitSort() {
	//document.resort.submit();
	sortValue = document.resort.sort[document.resort.sort.selectedIndex].value;
	if(sortValue != "") {
		document.resort.submit();
	} else {
		document.resort.sort.selectedIndex = 0;
	}
}
function adv_focus() {
	document.advsearch.qK1.focus();
}
function year() {
	var today = new Date();
	if (today.getFullYear) {
		var year = today.getFullYear();
	} else {
		var year = today.getYear();
	}
	document.write(year);
}
function elimBreaks(theString) {
	theString = theString.replace(/\r|\n/g, " ");
	return (theString);
}
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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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 MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false) {
      eval("obj."+theProp+"="+theValue);
  	} else {
  	  eval("obj."+theProp+"='"+theValue+"'");
  	}
  }
}

// See http://www.communitymx.com/content/article.cfm?cid=651FF
// Comma separated list of images to rotate
var imgs = new Array('/images/home/1_MesaVerde2.jpg','/images/home/2_Chicago2.jpg','/images/home/3_IceSkaters2.jpg','/images/home/4_Skateboarders2.jpg','/images/home/5_WagonWheel2.jpg','/images/home/6_FerrisWheel2.jpg',
                     '/images/home/1_MesaVerde2.jpg','/images/home/2_Chicago2.jpg','/images/home/3_IceSkaters2.jpg','/images/home/4_Skateboarders2.jpg','/images/home/5_WagonWheel2.jpg','/images/home/6_FerrisWheel2.jpg',
                     '/images/home/1_MesaVerde2.jpg','/images/home/2_Chicago2.jpg','/images/home/3_IceSkaters2.jpg','/images/home/4_Skateboarders2.jpg','/images/home/5_WagonWheel2.jpg','/images/home/6_FerrisWheel2.jpg',
                     '/images/home/1_MesaVerde2.jpg','/images/home/2_Chicago2.jpg','/images/home/3_IceSkaters2.jpg','/images/home/4_Skateboarders2.jpg','/images/home/5_WagonWheel2.jpg','/images/home/6_FerrisWheel2.jpg',
                     '/images/home/1_MesaVerde2.jpg','/images/home/2_Chicago2.jpg','/images/home/3_IceSkaters2.jpg','/images/home/4_Skateboarders2.jpg','/images/home/5_WagonWheel2.jpg','/images/home/6_FerrisWheel2.jpg',
                     '/images/home/end_ComboCities2.jpg');
// delay in milliseconds between image swaps 1000 = 1 second
var delay = 3000;
var counter = 0;

function preloadImgs(){
  for(var i=0;i<imgs.length;i++){
    MM_preloadImages(imgs[i]);    
  }
}

function randomImages(){
  // Uncomment for endless loop
  /*if(counter == (imgs.length)){
    counter = 0;
  }*/
  if(counter < imgs.length){
  	MM_swapImage('rotator', '', imgs[counter++]);
  	setTimeout('randomImages()', delay);
  }
}

// Used in advanced search JSP version
//======
// Show a given tab and the associated box contents.
//======
function tabshow(baseid) {
  if (document.getElementById('tab'+baseid)) {
    document.getElementById('tab'+baseid).className = "relatedtabShow";
    //Switches the hidden form value so we know which tab is active and which
    //search the user is going to do when they submit the form.
    if(baseid == "bool") {
    	document.getElementById("qTab").value = 1;
    } else if(baseid == "key") {
    	document.getElementById("qTab").value = 3;
    } else {
    	document.getElementById("qTab").value = 3;
   }
  }
  if (document.getElementById('box'+baseid)) {
    document.getElementById('box'+baseid).className = "searchboxShow";
  }  
}
	
//======
// Hide a given tab and the associated box contents.
//======
function tabhide(baseid) {
  if (document.getElementById('tab'+baseid)) {
    document.getElementById('tab'+baseid).className = "relatedtabHide";
  }
  if (document.getElementById('box'+baseid)) {
    document.getElementById('box'+baseid).className = "searchboxHide";
  }
}

function formHandler(form){
	var URL = document.stateForm.stateList.options[document.stateForm.stateList.selectedIndex].value;
	window.location.href = URL;
}

function checkMoreAboutBoxes()
{            
   var Inputs = document.getElementsByTagName("input");     
   for(var n = 0; n < Inputs.length; ++n)
      if(Inputs[n].type == 'checkbox' && Inputs[n].checked)
         return true;        
            
   alert('Please select a topic.');
   return false;

}