// JavaScript Document





       // These defaults should be changed the way it best fits your site
       var _POPUP_FEATURES = 'scrollbars=yes,width=600,resizable=yes,menubar=yes,location=yes,status=yes,toolbar=yes';

       function raw_popup(url, target, features) {
           // pops up a window containing url optionally named target, optionally having features
           if (isUndefined(features)) features = _POPUP_FEATURES;
           if (isUndefined(target  )) target   = '_blank';
           var theWindow = window.open(url, target, features);
           theWindow.focus();
           return theWindow;
       }

       function goTo(src, features) {
           // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
           // pops up a window grabbing the url from the event source's href
           return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
       }

       function event_popup(e) {
           // to be passed as an event listener
           // pops up a window grabbing the url from the event source's href
           link_popup(e.currentTarget);
           e.preventDefault();
       }

       function event_popup_features(features) {
           // generates an event listener similar to event_popup, but allowing window features
           return function(e) { link_popup(e.currentTarget, features); e.preventDefault() }
       }





       /*  LIB FUNCTIONS

       This file contains only functions necessary for the article features
       The full library code and enhanced versions of the functions present
       here can be found at http://v2studio.com/k/code/lib/


       ARRAY EXTENSIONS

       push(item [,...,item])
           Mimics standard push for IE5, which doesn't implement it.


       find(value [, start])
           searches array for value starting at start (if start is not provided,
           searches from the beginning). returns value index if found, otherwise
           returns -1;


       has(value)
           returns true if value is found in array, otherwise false;


       FUNCTIONAL

       map(list, func)
           traverses list, applying func to list, returning an array of values returned
           by func

           if func is not provided, the array item is returned itself. this is an easy
           way to transform fake arrays (e.g. the arguments object of a function or
           nodeList objects) into real javascript arrays.

           map also provides a safe way for traversing only an array's indexed items,
           ignoring its other properties. (as opposed to how for-in works)

           this is a simplified version of python's map. parameter order is different,
           only a single list (array) is accepted, and the parameters passed to func
           are different:
           func takes the current item, then, optionally, the current index and a
           reference to the list (so that func can modify list)


       filter(list, func)
           returns an array of values in list for which func is true

           if func is not specified the values are evaluated themselves, that is,
           filter will return an array of the values in list which evaluate to true

           this is a similar to python's filter, but parameter order is inverted


       DOM

       getElem(elem)
           returns an element in document. elem can be the id of such element or the
           element itself (in which case the function does nothing, merely returning
           it)

           this function is useful to enable other functions to take either an    element
           directly or an element id as parameter.

           if elem is string and there's no element with such id, it throws an error.
           if elem is an object but not an Element, it's returned anyway


       hasClass(elem, className)
           Checks the class list of element elem or element of id elem for className,
           if found, returns true, otherwise false.

           The tested element can have multiple space-separated classes. className must
           be a single class (i.e. can't be a list).


       getElementsByClass(className [, tagName [, parentNode]])
           Returns elements having class className, optionally being a tag tagName
           (otherwise any tag), optionally being a descendant of parentNode (otherwise
           the whole document is searched)


       DOM EVENTS

       listen(event,elem,func)
           x-browser function to add event listeners

           listens for event on elem with func
           event is string denoting the event name without the on- prefix. e.g. 'click'
           elem is either the element object or the element's id
           func is the function to call when the event is triggered

           in IE, func is wrapped and this wrapper passes in a W3CDOM_Event (a faux
           simplified Event object)


       mlisten(event, elem_list, func)
           same as listen but takes an element list (a NodeList, Array, etc) instead of
           an element.


       W3CDOM_Event(currentTarget)
           is a faux Event constructor. it should be passed in IE when a function
           expects a real Event object. For now it only implements the currentTarget
           property and the preventDefault method.

           The currentTarget value must be passed as a paremeter at the moment    of
           construction.


       MISC CLEANING-AFTER-MICROSOFT STUFF

       isUndefined(v)
           returns true if [v] is not defined, false otherwise

           IE 5.0 does not support the undefined keyword, so we cannot do a direct
           comparison such as v===undefined.
       */

       // ARRAY EXTENSIONS

       if (!Array.prototype.push) Array.prototype.push = function() {
           for (var i=0; i<arguments.length; i++) this[this.length] = arguments[i];
           return this.length;
       }

       Array.prototype.find = function(value, start) {
           start = start || 0;
           for (var i=start; i<this.length; i++)
               if (this[i]==value)
                   return i;
           return -1;
       }

       Array.prototype.has = function(value) {
           return this.find(value)!==-1;
       }

       // FUNCTIONAL

       function map(list, func) {
           var result = [];
           func = func || function(v) {return v};
           for (var i=0; i < list.length; i++) result.push(func(list[i], i, list));
           return result;
       }

       function filter(list, func) {
           var result = [];
           func = func || function(v) {return v};
           map(list, function(v) { if (func(v)) result.push(v) } );
           return result;
       }


       // DOM

       function getElem(elem) {
           if (document.getElementById) {
               if (typeof elem == "string") {
                   elem = document.getElementById(elem);
                   if (elem===null) throw 'cannot get element: element does not exist';
               } else if (typeof elem != "object") {
                   throw 'cannot get element: invalid datatype';
               }
           } else throw 'cannot get element: unsupported DOM';
           return elem;
       }

       function hasClass(elem, className) {
           return getElem(elem).className.split(' ').has(className);
       }

       function getElementsByClass(className, tagName, parentNode) {
           parentNode = !isUndefined(parentNode)? getElem(parentNode) : document;
           if (isUndefined(tagName)) tagName = '*';
           return filter(parentNode.getElementsByTagName(tagName),
               function(elem) { return hasClass(elem, className) });
       }


       // DOM EVENTS

       function listen(event, elem, func) {
           elem = getElem(elem);
           if (elem.addEventListener)  // W3C DOM
               elem.addEventListener(event,func,false);
           else if (elem.attachEvent)  // IE DOM
               elem.attachEvent('on'+event, function(){ func(new W3CDOM_Event(elem)) } );
               // for IE we use a wrapper function that passes in a simplified faux Event object.
           else throw 'cannot add event listener';
       }

       function mlisten(event, elem_list, func) {
           map(elem_list, function(elem) { listen(event, elem, func) } );
       }

       function W3CDOM_Event(currentTarget) {
           this.currentTarget  = currentTarget;
           this.preventDefault = function() { window.event.returnValue = false }
           return this;
       }


       // MISC CLEANING-AFTER-MICROSOFT STUFF

       function isUndefined(v) {
           var undef;
           return v===undef;
       }



function switchDiv(div_id) {
  var style_sheet = getStyleObject(div_id);
  if (style_sheet) {
    hideAll();
    changeObjectDisplay(div_id, "inline");
  } else {
    alert("sorry, this only works in browsers that do Dynamic HTML");
  }
}

function hideAll() {
   changeObjectDisplay("betweeninfo","none");
   changeObjectDisplay("inyear","none");
}

function changeObjectDisplay(objectId, newDisplay) {
    // first get the object's stylesheet
    var styleObject = getStyleObject(objectId);

    // then if we find a stylesheet, set its display
    // as requested
    //
    if (styleObject) {
        styleObject.display = newDisplay;
        return true;
    } else {
        return false;
    }
}


function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
        return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {
        return document.all(objectId).style;
   }
   else if (document.layers && document.layers[objectId]) {
        return document.layers[objectId];
   } else {
        return false;
   }
}

function getPage() {
	var sPath = window.location.pathname;
	//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	return sPage;
}

   
function doSubNav(hist) {

	var lnkList = new Array(4);
	lnkList[0]  = new Array("HISTORY", "history.jsp"); // Link Text, HREF
	lnkList[1]  = new Array("SEARCH", "index.jsp");
	lnkList[2]  = new Array("PREFERENCES", "preferences.jsp");
	lnkList[3]  = new Array("HELP", "help.jsp");

	var page	= getPage();
	var Div 	= '<div id="SecondaryNav">\n';
	var EndDiv	= '</div>\n';
	var Ul 		= '\t<ul>\n';
	var EndUl 	= '\t</ul>\n';
	var Li 		= '\t\t<li>';
	var LiFirst	= '\t\t<li id="First">';
	var EndLi	= '</li>\n';
	var Href	= '#'
	var EndA	= '</a>';

	if(page=="") page = "index.html";

	source  = Div + Ul;

	for(i=0; i < lnkList.length; i++) {

		var A    = '<a href="'+ lnkList[i][1] +'">';
		var Acur = '<a href="'+ lnkList[i][1] +'" class="current">';
		var Ahid = '<a href="'+ lnkList[i][1] +'" class="hidden">';

		if(i<1) source += LiFirst;
		else    source += Li;
		if(i<1) {
			if(page == lnkList[i][1]) source += Acur;
			else if(hist>0) source += A;
			else source += Ahid;
		} else {
			if(page == lnkList[i][1]) source += Acur;
			else source += A;
		}
		source += lnkList[i][0];
		source += EndA + EndLi;
	}
	source += EndUl + EndDiv;

	document.write(source);
}

function invertAll(theForm, cName)
{
    for (i=0,n=theForm.elements.length;i<n;i++)
    {
        if (theForm.elements[i].className.indexOf(cName) !=-1)
            if (theForm.elements[i].checked == true) {
                theForm.elements[i].checked = false;
            } else {
                theForm.elements[i].checked = true;
            }
    }
}

function uncheckAll(theForm, cName)
{
    for (i=0,n=theForm.elements.length;i<n;i++)
    {
        if (theForm.elements[i].className.indexOf(cName) !=-1)
            theForm.elements[i].checked = false;
    }
}

function checkAll(theForm, cName)
{
    for (i=0,n=theForm.elements.length;i<n;i++)
    {
        if (theForm.elements[i].className.indexOf(cName) !=-1)
            theForm.elements[i].checked = true;
    }
}
function validateNonNumber (field, evt)
{
  var keyCode = evt.which ? evt.which : evt.keyCode;
    if ((keyCode >47 && keyCode <58 )||( keyCode >95 && keyCode <106)||(keyCode==39||keyCode==40||keyCode==46||keyCode==8))
    {
       return true;
    }
    else
    {
    return false;
    }
}

var checkflag = "false";
function check(field) {
//if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
//checkflag = "true";
//return "Uncheck All"; }
//else {
}

function uncheck(field) {
//if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
//checkflag = "true";
//return "Uncheck All"; }
//else {
}

// Returns true if character c is a digit ie:(0 .. 9).
function isDigit (c) {
//        var year = new.getYear();
//        return ((c >= "0") && (c <= year))
}

function checkDateValue(field) {
    //var year = new.getYear();
   // if (!isDigit(field.value)) {
    //            alert("You must enter a year between 1 and " + year + ".");
    //            field.focus();
    //}
    //if ( (field.value.length <= 0) || (parseInt(field.value) > year) ) {
    //            alert("You didn't enter a value less than " + year + ".");
    //            field.focus();      // Force the user back into the field
    //}
}

//disables the right mouse button
function right(e) {
if (navigator.appName == 'Netscape' &&
(e.which == 3 || e.which == 2)) {
alert("Right-clicking has been disabled.");
return false;
}
else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 2 || event.button == 3)) {
alert("Right-clicking has been disabled.");
return false;
}
return true;
}

//document.onmousedown=right;
//if (document.layers) window.captureEvents(Event.MOUSEDOWN);
//window.onmousedown=right;






function YearSearch() {
    disableDateRange();
    enableinYear();
}

function RangeSearch() {
    enableDateRange();
    disableinYear();
}

function AllDateSearch() {
    disableDateRange();
    disableinYear();
}
//Functions
function enableinYear() {
    document.mainsearchform.inyear.disabled="";
    document.mainsearchform.inyear.focus();
}
//Disable InYear Text Box and Clear Value.
function disableinYear() {
    document.mainsearchform.inyear.disabled="disabled";
    document.mainsearchform.inyear.value=""
    document.mainsearchform.inyear.style.background= "#FFFFFF";
}

function enableDateRange() {
    //Enable FromMonth Drop Down
    document.mainsearchform.fromMonth.disabled="";
    //Enable FromDay Drop Down
    document.mainsearchform.fromDay.disabled="";
    //Enable FromYear Text Box
    document.mainsearchform.fromYear.disabled="";
    //Enable ToMonth Drop Down
    document.mainsearchform.toMonth.disabled="";
    //Enable ToDay Drop Down
    document.mainsearchform.toDay.disabled="";
    //Enable ToYear Text Box
    document.mainsearchform.toYear.disabled="";
}

function disableDateRange() {
    //Disable FromMonth Drop Down
    document.mainsearchform.fromMonth.disabled="disabled";
    document.mainsearchform.fromMonth.value="01"
    //Disable FromDay Drop Down
    document.mainsearchform.fromDay.disabled="disabled";
    document.mainsearchform.fromDay.value="01"
    //Disable FromYear Text Box and Clear Value
    document.mainsearchform.fromYear.disabled="disabled";
    document.mainsearchform.fromYear.value=""
    //Disable ToMonth Drop Down
    document.mainsearchform.toMonth.disabled="disabled";
    document.mainsearchform.toMonth.value="12"
    //Disable ToDay Drop Down
    document.mainsearchform.toDay.disabled="disabled";
    document.mainsearchform.toDay.value="31"
    //Disable ToYear Text Box and Clear Value
    document.mainsearchform.toYear.disabled="disabled";
    document.mainsearchform.toYear.value=""
}
//Value Validation
//Rules:
//1) Must be 4 digits long.
//2) Each digit must be 0-9.
function validateYearSearch(Year) {
    //var Year = document.mainsearchform.inyear.value;
    //var message = "";
    var validated = "true";
    //Validate Length. MUST be 4 digits long.
    if (!validateLength(Year)) {
        alert("Years must contain 4 digits!");
        document.mainsearchform.inyear.style.background= "#FFFF00";
        document.mainsearchform.inyear.focus();
        document.mainsearchform.Search.disabled=true;
        validated = "false";
    }
    //Validate digits. Each digit can ONLY be 0-9.
    //if (Year !=  ""){
        if (!validateDigits(Year)) {
            alert("Years must contain only the numbers zero through nine!");
            document.mainsearchform.inyear.style.background= "#FFFF00";
            document.mainsearchform.Search.disabled=true;
            //document.mainsearchform.inyear.focus();
            validated = "false";
        }
        if (validated == "true") {
            document.mainsearchform.inyear.style.background= "#FFFFFF";

        }
    //} else {
    //    validated == "true";
    //}
}

function validateRangeYearBegin(Year) {
    //var Year = document.mainsearchform.inyear.value;
    //var message = "";
    var validated = "true";
    //Validate Length. MUST be 4 digits long.
    if (!validateLength(Year)) {
        alert("Years must contain 4 digits!");
        document.mainsearchform.fromYear.style.background= "#FFFF00";
        document.mainsearchform.fromYear.focus();
        document.mainsearchform.Search.disabled=true;
        validated = "false";
    }
    //Validate digits. Each digit can ONLY be 0-9.
   if (Year !=  ""){
        if (!validateDigits(Year)) {
            alert("Years must contain only the numbers zero through nine!");
            document.mainsearchform.fromYear.style.background= "#FFFF00";
            document.mainsearchform.fromYear.focus();
            document.mainsearchform.Search.disabled=true;
            validated = "false";
        }
        if (validated == "true") {
            document.mainsearchform.fromYear.style.background= "#FFFFFF";
        }
    } else {
        validated == "true";
    }
}

function validateRangeYearEnd(Year) {
    var validated = "true";
    //Validate Length. MUST be 4 digits long.
    if (!validateLength(Year)) {
        alert("Years must contain 4 digits!");
        document.mainsearchform.toYear.style.background= "#FFFF00";
        document.mainsearchform.toYear.focus();
        document.mainsearchform.Search.disabled=true;
        validated = "false";
    }
    //Validate digits. Each digit can ONLY be 0-9.
    if (Year !=  ""){
        if (!validateDigits(Year)) {
            alert("Years must contain only the numbers zero through nine!");
            document.mainsearchform.toYear.style.background= "#FFFF00";
            document.mainsearchform.toYear.focus();
            document.mainsearchform.Search.disabled=true;
            validated = "false";
        }
        if (validated == "true") {
            document.mainsearchform.toYear.style.background= "#FFFFFF";
        }
    } else {
        validated == "true";
    }
}

 function validateRangeRelationship(EndYear) {
        var BeginYear = document.mainsearchform.fromYear.value;
        var BeginMonth = document.mainsearchform.fromMonth.value;
        var BeginDay = document.mainsearchform.fromDay.value;
        var toMonth = document.mainsearchform.fromMonth.value;
        var toDay = document.mainsearchform.fromDay.value;
        var result = compareDates(BeginMonth + "/" + BeginDay + "/" + BeginYear,"M/d/yyyy",toMonth + "/" + toDay + "/" + EndYear,"M/d/yyyy");
        //var result = compareDates("01/01/1999","MM/dd/yyyy","12/31/2003","MM/dd/yyyy");
        //var result = "1";
        return result;

 }
 function validateLength(yearlength) {
    if (yearlength.length < 4 && yearlength.length > 0) {
        return false;
    } else {
        return true;
    }
 }

 function validateDigits(yearvalue) {
    if (yearvalue.substring(0,1) < "0" || yearvalue.substring(0,1) > "9" || yearvalue.substring(1,2) < "0" || yearvalue.substring(1,2) > "9" || yearvalue.substring(2,3) < "0" || yearvalue.substring(2,3) > "9" || yearvalue.substring(3,4) < "0" || yearvalue.substring(3,4) > "9") {
        return false;
    } else {
        return true;
    }
}




// RENDITION SWITCHING //

function selectRendition(num,total) {
    // first reset the renditions
    resetRenditions('medres',total);
    resetRenditions('lowres',total);
    // then highlight one of them
    document.getElementById('medres'+num).className = 'selected';
    document.getElementById('lowres'+num).className = 'selected';
}

function resetRenditions(prefix,total) {
    // loop through all renditions and reset their classes
    for(i=1;i<=total;i++) {
        document.getElementById(prefix+i).className = '';
    }
}