//** Start JavaScript Ltrim, Rtrim, Trim functions - http://www.developingskills.com/ds.php?article=jstrim&page=1
function strltrim() {
   return this.replace(/^\s+/,'');
   }
function strrtrim() {
   return this.replace(/\s+$/,'');
   }
function strtrim() {
   return this.replace(/^\s+/,'').replace(/\s+$/,'');
   }
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

// Examples of use
// sText = sText.ltrim();  - To remove the leading blanks from a string variable sText  -
// sText = sText.rtrim();  - To remove the trailing blanks from a string variable sText
// sText = sText.trim();   - To remove the leading and trailing blanks from a string variable sText
//** End   JavaScript Ltrim, Rtrim, Trim functions


// Change to 1 to have "Next Hit" go to the next document
// after the last hit in the current document
fAutoNextDoc = 0;

nHit = 0;
//maxHits = %%HitCount%%;

var simpleNav = 1;
var browser = navigator.appName;
var version = parseInt(navigator.appVersion);
if ((browser.indexOf("Microsoft") != -1) || (version >= 4))
    simpleNav = 0;

function old_gotoHit(where) {
    alert("NMT_Utilities.js: function old_gotoHit  ---- this function should not be called ---- to be removed!   Please tell Craig")
    window.location.hash = where;
    }

function findLink(links, name) {
    alert("NMT_Utilities.js: function findLink  ---- this function should not be called ---- to be removed!   Please tell Craig")
    if (links.namedItem)
        return links.namedItem(name);
    for (i = 0; i < links.length; ++i) {
        if (links[i]) {
            if (links[i].name == name)
                return links[i];
            }
        }
}

function gotoHit(where) {
    alert("NMT_Utilities.js: function gotoHit  ---- this function should not be called ---- to be removed!   Please tell Craig")
    if (simpleNav) {
        old_gotoHit(where);
        return;
        }

    var a = findLink(document.anchors, where);
    if (a == null) return;
    if (a.length > 1) return;

    if (a.y) {
        // Netscape
        window.scrollTo(0, a.y);
        }
    else {
        // IE
        window.scrollTo(0, a.offsetTop - a.offsetHeight + a.offsetParent.offsetTop);
        }

    var s = document.body.createTextRange();
    if (s != null) {
        s.moveToElementText(a);
        s.moveEnd("word");
        s.select();
        s.scrollIntoView();
        }
}

function gotoNthHit(n) {
    alert("NMT_Utilities.js: function gotoNthHit  ---- this function should not be called ---- to be removed!   Please tell Craig")
    nHit = n;
    if ((n > 1) && (n == maxHits))
        gotoHit('hit_last');
    else if (n == 0)
        old_gotoHit('hit0');
    else
        gotoHit('hit' + n);
 }
function nextHit() {
    alert("NMT_Utilities.js: function nextHit  ---- this function should not be called ---- to be removed!   Please tell Craig")
    if (nHit < maxHits) {
        gotoNthHit(nHit+1);
        }
    else if (fAutoNextDoc && parent && parent.res)
        parent.res.nextDoc();
    }

function prevHit() {
    alert("NMT_Utilities.js: function prevHit  ---- this function should not be called ---- to be removed!   Please tell Craig")
    if (nHit > 0) {
        gotoNthHit(nHit-1);
        }
    }

function Transcript_Search() {
   //*** check if Search All Transcripts or Page Search
   strLocation = document.theForm.SearchLoc.options[document.theForm.SearchLoc.selectedIndex].value
   if (strLocation == "Page") {
      strLocation = "Page"
      document.theForm.Location.value  = "Page"
      document.theForm.ddate.value     = top.Index.transcript_content.strDate
      document.theForm.URL.value       = top.Index.transcript_content.strURL
      document.theForm.Label.value     = top.Index.transcript_content.strLabel
      document.theForm.Speaker.value   = top.Index.transcript_content.strSpeaker
          //*** alert("Transcript_Search: Location="+document.theForm.Location.value+", date="+document.theForm.ddate.value+", URL="+document.theForm.URL.value+", Label="+document.theForm.Label.value+", Speaker="+document.theForm.Speaker.value )
          //*** alert("Location="+document.theForm.Location.value+", ddate="+document.theForm.ddate.value  )
      }
   else {
      document.theForm.Location.value  = document.theForm.SearchLoc.options[document.theForm.SearchLoc.selectedIndex].value
      }

          //***alert("Searching="+document.theForm.SearchLoc.options[document.theForm.SearchLoc.selectedIndex].value+"\n\nDdate="+document.theForm.ddate.value+"\nURL="+document.theForm.URL.value+"\nLabel="+document.theForm.Label.value+"\nSpeaker="+document.theForm.Speaker.value)

   aok = "Y"
   var rrequest = document.theForm.request.value.trim();         //*** trim removes leading and trailing spaces
   var ssearchType = document.theForm.searchType.value

   if (aok=="Y" && (rrequest==''))   { aok="N"; document.theForm.request.focus();  alert("Please type in the search criteria.") }
   if (aok=="Y") {
      //alert("function Transcript_Search, frame="+parent.frames.length)
      if (parent.frames.length == 0) {
         if (window.location.search.length > 10) {        //*** output from search engine
            var UURL =       "AAT_Search.asp?cmd=search&SearchForm=%25%25SearchForm%25%25&request="+rrequest+"&searchType="+ssearchType+"&Location="+strLocation+"&sort="+Date
            window.location = UURL
            }
         else {        //*** from transcript directory
            var UURL = "../AAT_Search.asp?cmd=search&SearchForm=%25%25SearchForm%25%25&request="+rrequest+"&searchType="+ssearchType+"&Location="+strLocation+"&sort="+Date
            window.location = UURL
            }
         }       //*** end of in Full view
      else {             //*** Normal View inside frames
            var UURL =       "AAT_Search.asp?cmd=search&SearchForm=%25%25SearchForm%25%25&request="+rrequest+"&searchType="+ssearchType+"&Location="+strLocation+"&sort=Hits"
         //parent.parent.ABC_Body_Left.transcript_content.window.location = UURL
//***    top.Index.transcript_content.window.location = UURL
     //*** new code to submit
     document.theForm.submit();

         }

      }
 }  // end function


//**** Cookie functions from http://www.quirksmode.org/js/cookies.html - This script was originally written by Scott Andrew - http://www.scottandrew.com/
function createCookie(name,value,days) {
   //alert("Create Cookie, name="+name+", value="+value+", days="+days)
   if (days) {
       var date = new Date();
       date.setTime(date.getTime()+(days*24*60*60*1000));
       var expires = "; expires="+date.toGMTString();
   }
   else var expires = "";
   //cc = name+"="+value+expires+"; path=/";
   cc = name+"="+value+expires;
   document.cookie = cc
}

function readCookie(name) {
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++) {
       var c = ca[i];
       while (c.charAt(0)==' ') c = c.substring(1,c.length);
       if (c.indexOf(nameEQ) == 0) {
          //alert("readCookie: "+name+"="+c.substring(nameEQ.length,c.length) )
          return c.substring(nameEQ.length,c.length);
          }
   }
   return null;
}

function eraseCookie(name) {
   createCookie(name,"",-1);
   initSize = 2;
   size=2;
}

