// Init Globals

	function init()
	{
		// Add captions
		addCaptionsToImages();

		// Run Tabls Striper
		stripe();
	}

// Global Javascript variables

	// Determine whether or not to remove flash message
	var keepFlashAlive	= false;


// Stripe the tables and make a selector row
	
	var stripe = function() 
	{
		var tables = document.getElementsByTagName("table");	

		for(var x=0;x!=tables.length;x++)
		{
			var table = tables[x];
			if (! table) { return; }

			var tbodies = table.getElementsByTagName("tbody");

			for (var h = 0; h < tbodies.length; h++) 
			{
				var even 	= true;
				var trs 	= tbodies[h].getElementsByTagName("tr");

				for (var i = 0; i < trs.length; i++) 
				{
						trs[i].onmouseover=function()
						{
							this.className += " activerow"; return false
						}
						trs[i].onmouseout=function()
						{
							this.className = this.className.replace("activerow", ""); return false
						}

						if( !even )
						{
							trs[i].className += "odd";
						}
						
						even = !even;
				}
			}
		}
	}

// Add a caption to the image from the alt tag :) oh yeah 

    function addCaptionsToImages() 
    {
        wrapImagesInDiv( 'figure', [], [ 'float' ] );
    }
    
    function wrapImagesInDiv( className, attributes, styles ) 
    {
       	var images = document.getElementsByTagName( 'img' );
    	for ( var i = 0; i < images.length; ++i ) 
    	{
    	  
    		var img = images[i];
    					
    		if ( !img.id && !img.className )
    		{
          		// Lift the image out of the page and insert a div under it.
          		var parent = img.parentNode;
          		var frame = document.createElement('div');
				var br = document.createElement('br');
				br.className = "clear";
          		var txt = document.createTextNode(img.getAttribute('alt'));
          		parent.insertBefore(frame, img);
          		parent.removeChild(img);
          		frame.appendChild(img);
				frame.appendChild(br);
          		frame.appendChild(txt);
          	
    			
          		if ( img.align == 'right' )
    			    {
    				    frame.className = 'figure right';
        		  }
              else if ( img.align == 'left' )      
              {
                frame.className = 'figure left';
              }
    		    	else
    			    {
    				    frame.className = 'figure';
    			    }
    			    
    			    if (img.align == 'middle' )
        		  {
        		    frame.id = 'centered';
        		  }
    			    
    			
    			// These are special cases.  We always copy these from the image to the div.
          		frame.style.width = img.getAttribute('width') + 'px';

      			// Copy specified attributes and style properties from the image to the div.
          		for ( var j = 0; j < attributes.length; ++j ) 
    			{
             		frame.setAttribute(attributes[j],
                    img.getAttribute(attributes[j]));
          		}
          		for ( var j = 0; j < styles.length; ++j ) 
    			{
             		frame.style[styles[j]] = img.style[styles[j]];
          		}
       		}
    	}
    }

function _initSearchForm() {
    if ($("century_from")) {
      $("century_from").observe('focus', function() { $("filtertype_years").checked = true; });
      $("century_to").observe('focus', function() { $("filtertype_years").checked = true; });
      $("countyname").observe('change', function() { $("filtertype_countyname").checked = true; });
      $("peopleinvolvedname").observe('change', function() { $("filtertype_person").checked = true; });
    }
};

Event.observe(window, 'load', _initSearchForm);
