function dosearch(formid, param, value) {
doParamChangeAndSubmit(formid, param, value);
}

function doParamChangeAndSubmit(formid, param, value)
// used for changing the value of a parameter and resubmitting a form
// for example for pagination and sorting
{
//  alert(formid + " " + param + " " + value);
  var form = document.getElementById(formid);
  if (form) 
   {
        p = form.elements[param];
        if (p) 
          p.value = value;
//        else alert("no " + param);
   }    
//    else alert("no " + formid);

  if (!form.onsubmit || form.onsubmit()) {
    // either there is no onsubmit method,
    // or we call it and it succeeds
    form.submit();
  }
}

function doParamChange(formid, param, value)
// used for changing the value of a parameter and resubmitting a form
// for example for pagination and sorting
{
  var form = document.getElementById(formid);
  if (form) 
   {
        p = form.elements[param];
        if (p) 
          p.value = value;
   }     
}



function doMultiChangeAndSubmit(formid, param, csv_value)
// used for changing the value of an array of parameters to the values in the csv_value
// then submitting the form
{
  //alert("csv: " + csv_value);
  var form = document.getElementById(formid);
  a = form.elements[param];
  //alert("a.length: " + a.length);
  var values = csv_value.split (",");
  //alert("values.length: " + values.length);
  
  var i;
  for (i=0; i<a.length && i<values.length; i++) {
       //alert(i);
       //alert("Setting param." + i + " to " + values[i]);
       a[i].value = values[i];
  }
  for (; i<a.length; i++)
     a[i].value = "";

  if (!form.onsubmit || form.onsubmit()) {
    // either there is no onsubmit method,
    // or we call it and it succeeds
    form.submit();
  }
}

function compare(formid, param, value) {
	return document.getElementById(formid).elements[param].value == value;
}


function init_select (tag, value, form_index)
{
  var elts = document.forms[form_index].elements;
  var options = elts[tag].options;
  var i;
  if (!options) alert ("no form element " + tag + " in form " + form_index);
  for (i=0; i< options.length; i++)
  {
    if (options[i].value == value)
    {
      elts[tag].selectedIndex = i;
      return;
    }
  }
  elts[tag].selectedIndex = 0;
}

function init_select_text (tag, value, form_index)
{
  var elts = document.forms[form_index].elements;
  var options = elts[tag].options;
  var i;
  for (i=0; i< options.length; i++)
  {
    if (options[i].text == value)
    {
      elts[tag].selectedIndex = i;
      return;
    }
  }
  elts[tag].selectedIndex = 0;
}

// multi-select values always stored as bitfields?
// This uses MySQL-style commas-spearated lists.  Woe to you if a value
// has a comma in it.
function init_select_multiple (tag, value, form_index)
{
  var elts = document.forms[form_index].elements;
  var options = elts[tag].options;
  var values = value.split (",");
  var i, j;
  for (i=0; i< options.length; i++)
  {
    options[i].selected = false;
    for (j=0; j< values.length; j++)
    if (options[i].value == values[j])
    {
      options[i].selected = true;
    }
  }
}

function init_radio (tag, value, form_index)
{
  var elts = document.forms[form_index].elements;
  var radios = elts[tag];
  if (!radios) alert ("no such element " + tag + " in form " + form_index);
  var i;
  for (i=0; i< radios.length; i++)
  {
    if (radios[i].value == value)
    {
      radios[i].checked = true;
      return;
    }
  }
}

function init_checkbox (tag, value, form_index)
{
  var elts = document.forms[form_index].elements;
  var boxes = elts[tag];
  var values = value.split (",");
  var i, j;
  for (i=0; i< boxes.length; i++)
  {
    for (j=0; j< values.length; j++)
        if (boxes[i].value == values[j]) {
              boxes[i].checked = true;
        }
        else {
        //    alert (boxes[i].value + " is not " + value);
              boxes[i].checked = false;
        }
  }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function popup(url, w, h)
{
  var l = Math.round((window.screen.width - w)/2);
  var t = Math.round((window.screen.height - h)/2);
  var win = window.open(url, "", "toolbar=0,location=0,status=1,menubar=0,scrollbars=0,resizable=0,width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + "");
  win.focus();
}

// code for expand collapse menus and show more hide content

function switchMenu(obj) {
  var el = document.getElementById(obj);
  if ( el.style.display != 'none' ) {
    el.style.display = 'none';
  }
  else {
    el.style.display = '';
  }
}

function show(id) {
 document.getElementById(id).style.display='block';
 document.getElementById("toolbarWrapperBottom").style.display='none'; 
}

function hide(id) {
 document.getElementById(id).style.display='none';
 document.getElementById("toolbarWrapperBottom").style.display='block'; 
}

function showAag(id) {
 document.getElementById(id).style.display='block';
}

function hideAag(id) {
 document.getElementById(id).style.display='none';
}


function getMenuPeriodState(period)
{
     //   alert(period);
  if (period == null) return;

  if (period.indexOf(",") > 0){
        periods = period.split(",");
          var curPeriod = document.getElementById(periods[0]);
        if (curPeriod) {
          var curMenu = curPeriod.parentNode;	
  	  curMenu.style.display = "block";
	  changeImage(curMenu);
        }
  }
  else {
	var curPeriod = document.getElementById(period);
      if (curPeriod) {
        var curMenu = curPeriod.parentNode;	
  	//alert("menuParent:" + curMenu.id);
	curMenu.style.display = "block";
	changeImage(curMenu);
      }
  }
}

function getCheckboxPeriodState(period)
{
  if (period!=null) {
    var curPeriod = document.getElementById(period);
    if (curPeriod) {
      var curMenu = curPeriod.parentNode;
      //alert("menuParent:" + curMenu.id);
      curMenu.style.display = "block";
      changeImage(curMenu);
      //       var menuParent = curMenu.parentNode;
      //alert("menuParent:" + menuParent.id);
      //        menuParent.style.backgroundImage = "url(/images/plus.gif)";
    }
  }
}

function getMenuCategoryState(category)
{
  if (category==null) return;

  if (category.indexOf(",") > 0) {
	var categories = category.split(",");
        for (i=0; i<categories.length; i++) {
            var curCategory = document.getElementById(categories[i]);
            //alert("x"+categories[i]+"x");

            if (curCategory) {
            //alert(categories[i]);
                var curMenu = curCategory.parentNode;
                var mainMenu1 = curMenu.parentNode.parentNode;
                var mainMenu2 = curMenu.parentNode.parentNode.parentNode.parentNode;
                	//alert("menuCategory:" + curMenu.id);
                if (mainMenu1.id == 'categoriesMenu') {
                        var changeMe1 = document.getElementById(mainMenu1.id);
                        changeMe1.style.display = "block";
                }
               if (mainMenu2.id == "categoriesMenu") {
                        var changeMe1 = document.getElementById(mainMenu1.id);
                        var changeMe2 = document.getElementById(mainMenu2.id);
                        changeMe1.style.display = "block"
                        changeMe2.style.display = "block";
			changeImage(changeMe1);
                }
                curMenu.style.display = "block";
        	changeImage(curMenu);
	}
    }
  } else {
            var curCategory = document.getElementById(category);
            //alert("x"+category+"x");
            if (curCategory) {
                var curMenu = curCategory.parentNode;
                var mainMenu1 = curMenu.parentNode.parentNode;
                var mainMenu2 = curMenu.parentNode.parentNode.parentNode.parentNode;
                //	alert("menuCategory:" + curMenu.id);
                if (mainMenu1.id == 'categoriesMenu') {
                        var changeMe1 = document.getElementById(mainMenu1.id);
                        changeMe1.style.display = "block";
		}
                if (mainMenu2.id == "categoriesMenu") {
                        var changeMe1 = document.getElementById(mainMenu1.id);
                        var changeMe2 = document.getElementById(mainMenu2.id);
                        changeMe1.style.display = "block"
                        changeMe2.style.display = "block";
			changeImage(changeMe1);
                }
                curMenu.style.display = "block";
		changeImage(curMenu);
	    }
  }
}

function changeImage (menu) {
	var menuId = menu.id.split('Menu');
        var imageId = 'img' + menuId[0] + 'Actuator';
	var image = document.getElementById(imageId);
	if (imageId) {
        	if (image.src.indexOf("minus.gif") > 0) {
                	image.setAttribute("src","/images/plus.gif");
                }
                else {
                        image.setAttribute("src","/images/minus.gif");
                }
       }
}

/*
 * menuExpandable3.js - implements an expandable menu based on a HTML list
 * Author: Dave Lindquist (http://www.gazingus.org)
 */

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId) {
    //alert("Xmenu: " + menuId);
    var menu = document.getElementById(menuId);
//    alert("menu: " + menuId);

    var actuator = document.getElementById(actuatorId);
//	alert("actuator: " + actuatorId);

    if (menu == null) {
  //      alert("no: " + menuId);
        return;
    }
    if (actuator == null) {
    //    alert("no: " + actuatorId);
        return;
    }
    
    var image = actuator.childNodes[0];
    //alert(image.id); 
    if (image.id) {image.setAttribute("src","/images/plus.gif");}

    //actuator.style.backgroundImage = "url(/images/plus.gif)";
    actuator.onclick = function() {
	var display = menu.style.display;
	var menuId = menu.id.split('Menu');
	var imageId = 'img' + menuId[0] + 'Actuator';
	var image = document.getElementById(imageId);
	if (imageId) {
		if (image.src.indexOf("minus.gif") > 0) {
			image.setAttribute("src","/images/plus.gif");
		}
		else {
			image.setAttribute("src","/images/minus.gif");
		}
		menu.style.display = (display == "block") ? "none" : "block";
	}
        return false;
    }
}

function setCookie(c_name,value)
{
//alert("cookiename:" + c_name + "\ncookieValue:" + value + "\nexpiredays:" + expiredays);
document.cookie=c_name+ "=" +escape(value);
}

function changeLink(linkID) {
        var link = document.getElementById(linkID);
        var linkStyle = link.style;
        linkStyle.fontWeight = "bold";
	var oldLink=getLink('linkState');
	if (oldLink!=null) {
	    	//alert("linkState:" + link);
    		var oldLink = document.getElementById(oldLink);
    		oldLink.style.fontWeight = "";
  	}
        setCookie('linkState',link.id);
}

function selectSearch() {
	var txt = '';
	var foundIn = '';
	if (window.getSelection)
	{
		txt = window.getSelection();
		foundIn = 'window.getSelection()';
	}
	else if (document.getSelection)
	{
		txt = document.getSelection();
		foundIn = 'document.getSelection()';
	}
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
		foundIn = 'document.selection.createRange()';
	}
	if (txt == '') {
		alert ("Highlight any word or phrase and click the button to begin a new search.");
		return;
	}

	f = document.getElementById("searchFormForm");
	document.getElementById("query_field").value = "\"" + txt + "\"";
	f.submit();
}



function clearSelects(selects) {
  for (x in selects) {
    e = document.getElementById(selects[x]); 
    if (e != null) e.selectedIndex = 0; //else alert("no " + selects[x])
   }
}

function clearTextBoxes(boxes) {
  for (x in boxes) {
    e = document.getElementById(boxes[x]); 
    if (e != null) e.value = ""; //else alert("no " + boxes[x])
   }
}

function clearChecks(checks) {
  for (x in checks) {
    e = document.getElementById(checks[x]); 
    if (e != null) e.checked = false; //else alert("no " + checks[x])
 }
}


function initSelect(name, value) {
  e = document.getElementById(name); 
  if (!e) {
    //alert("no " + name);
    return;
  }  
  if (!e.length) {
    //alert("no length " + name);
    return;
  }
  for (i=0; i<e.length; i++) {
    if (e[i].value == value) 
       e[i].selected = true;
  }
}

function initMultiSelect(name, values) {
  e = document.getElementById(name); 
  if (!e) {
    //alert("no " + name);
    return;
  }  
  if (!e.length) {
    //alert("no length " + name);
    return;
  }
  for (i=0; i<e.length; i++) {
    for (j=0; j<values.length; j++)
      if (e[i].value == values[j])
         e[i].selected = true;
  }
}



function clearEraCatChecks() {
  checks = ["checkera01", "checkera02", "checkera03", "checkera04", "checkera05", "checkera06", "checkera07", 
            "checkera08", "checkera09", "checkera10", "checkera11",
            "checktop0001", "checktop0001", "checktop0002", "checktop0003", "checktop0004", "checktop0005", 
            "checktop0006", "checktop0007", "checktop1001", "checktop1002", "checktop1003", "checktop1004", 
            "checktop1005", "checktop1006", 
            "checktop1007", "checktop1008", "checktop1009", "checktop1010", "checktop1011", "checktop1012", 
            "checktop1013", "checktop1014", 
            "checktop1015", "checktop1016", "checktop1017", "checktop1018", "checktop1019", "checktop1020", 
            "checktop1021", "checktop1022", 
            "checktop1023", "checktop1024", "checktop1025", "checktop1026", "checktop1027", "checktop1028", 
            "checktop2001", "checktop2002", 
            "checktop2003", "checktop2004", "checktop2005", "checktop2006", "checktop2007", "checktop2008", 
            "checktop2009", "checktop2010", 
            "checktop2011", "checktop2012", "checktop2013", "checktop2014", "checktop2015", "checktop2016", 
            "checktop2017", "checktop2018", 
            "checktop2019", "checktop2002", "checktop2021", "checktop2022", "checktop2023", "checktop2024", 
            "checktop2025", "checktop2026", 
            "checktop2027", "checktop2028", "checktop2029", "checktop2030"];
  clearChecks(checks);

}


/* takes a year and pads it with zeros to make it four digits, then saves it in the second field */
function convertYear(name, name2) {
        e = document.getElementById(name);
        e2 = document.getElementById(name2);
        if (!e || !e2) return;
        v = e.value;
        while (v.length < 4)
          v = "0" + v;
        e2.value = v;
}


// replace all commas into ' OR '
function translateFoo(s) {
      s = s.replace(/,/g, " OR ");
      return s;
}


// replace instances of ' OR ' with a comma
function translateBar(s) {
      s = s.replace(/ OR /g, ",");
      return s;
}

