/*  ****  SRVGS Publications JavaScript Sheet  ****  */


    addLoadEvent(prepPhoto);


/*  ****************   prepPhoto   ****************  */

function prepPhoto() 
 {
                                              // Compatibility Tests
    if (!document.getElementsByTagName) return false;
    if (!document.createElement) return false;
    if (!document.createTextNode) return false;
                                              // End Compatibility Tests
 document.getElementById("search").focus();

 var photos = document.getElementsByTagName("a");

 for ( var i=0; i < photos.length; i++)
      {
        if (photos[i].firstChild.nodeValue == "photo")
            {
             var this_link = photos[i];
             photos[i].onmouseover = function()
                                         {
                                           return buildDisplay(this);
                                         }
             photos[i].onmouseout = function()
                                         {
                                           return hidePhoto(this.nextSibling);
                                         }
            }
      }
  }

/*  ************************************************  */


/*  ***************   buildDisplay   ***************  */

 function buildDisplay(this_one)
       {
             var span2 = document.createElement("span");
             span2.setAttribute("id", "photo1");
             var img2 = document.createElement("img");
             img2.setAttribute("src", this_one.getAttribute('href'));
             span2.appendChild(img2);
             if (this_one == this_one.parentNode.lastChild)
                   {
                      this_one.parentNode.appendChild(span2);
                   } else {
                      insertAfter(span2,this_one);
                   }
             span2.setAttribute ("id", "show");

             return false;
       }       

/*  ************************************************  */


/*  *****************   hidePhoto   ****************  */

 function hidePhoto(this_span)
     {        
       this_span.setAttribute("id", "photo1");
     }

/*  ************************************************  */


/*  *****************   noClick   ****************  */

 function noClick()
     {        
       return false;
     }

/*  ************************************************  */


/*  *****************   findWord   ****************  */

 function findWord(text)
     { 
                                                // Preliminary set up
        clearHl();
        if (document.getElementById("results"))
             {
                document.getElementById("results").setAttribute("id", "no_results");
             } else {   
                      if (document.getElementById("neg_results"))
                          {       
                            document.getElementById("neg_results").setAttribute("id", "no_results");
                          }
                    }
        var white_space = /\s/;
        if (text == "" || white_space.test(text))
            {
                     document.getElementById("search").focus();
                     document.getElementById('search').value = "";
                     return false;
            }

        var lower = text.toLowerCase();
        var text_len = text.length;
        var data_set = document.getElementsByTagName("td");
        var row = document.getElementsByTagName("tr");
        var row_num = -1;

     for ( var k= 1; k < row.length; k++)
        {
        var this_row = row[k].getElementsByTagName("td");
        for ( var i = 0; i < this_row.length; i++)
            {
              this_check = this_row[i];
                                              // check for children
              if (this_check.hasChildNodes)
                 { node_list = this_check.childNodes;
                   for ( var j = 0; j < node_list.length; j++)
                       { if (node_list[j].nodeValue)
                            { 
                              if (node_list[j].nodeType == 3)
                                 { var this_text = node_list[j].nodeValue;
                                   var test = this_text.toLowerCase();
                                   var result = test.indexOf(lower);
                                   if (result >= 0)
                                      { if( row_num == -1) row_num = k;
                                        var found_it = true;
                                        node_list[j].parentNode.setAttribute("id","found");  
                                        result = 0;
                                      }
                                 }
                            }
                       }
                 }
            }
        }
        var ans_line = document.getElementById("no_results");
        var ans_text = ans_line.firstChild;
        if (found_it)
            { 
               ans_text.nodeValue = "You search for   \'"+text+"\'   has been found and highlighted.  Scroll down to see the results.";
               ans_line.setAttribute("id", "results");

            }  else  {
               ans_text.nodeValue =" \'"+text+ "\'    was not found on this page.";
               ans_line.setAttribute("id", "neg_results");
            }

     return false;

     }


/*  ************************************************  */


/*  *****************   clearHl   ****************  */

 function clearHl()
    {    
       var data_set = document.getElementsByTagName("td");
       for ( var i = 8; i < data_set.length; i++)
             { 
               if (data_set[i].getAttribute("id")=="found")
                  { data_set[i].setAttribute("id","");
                  }  
              }
       if(document.getElementById("neg_results")) document.getElementById("neg_results").setAttribute("id","no_results");
       if(document.getElementById("results")) document.getElementById("results").setAttribute("id","no_results");
    }

/*  ************************************************  */

/*  *****************   reset   ****************  */

 function clearIt()
    {    
       clearHl();
       document.getElementById("search").focus();
    }
 
/*  ************************************************  */



