﻿<!--
// JScript File


//Image variables used for the user interface
var WorldCat = new Image(); WorldCat.src = 'images/searchworldcat.gif';
var Union = new Image(); Union.src = 'images/searchunion.gif';
var CSUF = new Image(); CSUF.src = 'images/searchfullerton.gif';
var CloseHoverOn = new Image(); CloseHoverOn.src = 'images/close_small_hover.gif';
var CloseHoverOff = new Image(); CloseHoverOff.src = 'images/close_small.gif';
  
function SetCheck(check)
  {
    if(check==1)
    {
        //check fullerton
        if(document.getElementById('chkFullerton').checked == true)
        {
            document.getElementById('imgChkFullerton').src = "images/check_off.jpg";
            document.getElementById('chkFullerton').checked = false;
        }
        else
        {
            document.getElementById('imgChkFullerton').src = "images/check_on.jpg";
            document.getElementById('chkFullerton').checked = true;
            
            //turn off world cat
            document.getElementById('imgChkWC').src = "images/check_off.jpg";
            document.getElementById('chkWC').checked = false;
     
       
        }
    }
    if(check==2)
    {
    //check union
        if(document.getElementById('chkUnion').checked == true)
        {
            document.getElementById('imgChkUnion').src = "images/check_off.jpg";
            document.getElementById('chkUnion').checked = false;
        }
        else
        {
            document.getElementById('imgChkUnion').src = "images/check_on.jpg";
            document.getElementById('chkUnion').checked = true;
            
            //turn off world cat
            document.getElementById('imgChkWC').src = "images/check_off.jpg";
            document.getElementById('chkWC').checked = false;
     
            
       
        }
    }
    
    if(check==3)
    {
   if(document.getElementById('chkWC').checked == true)
        {
            document.getElementById('imgChkWC').src = "images/check_off.jpg";
            document.getElementById('chkWC').checked = false;
        }
        else
        {
            document.getElementById('imgChkWC').src = "images/check_on.jpg";
            document.getElementById('chkWC').checked = true;
            
           
           //turn off the union searches 
            document.getElementById('imgChkFullerton').src = "images/check_off.jpg";
            document.getElementById('imgChkUnion').src = "images/check_off.jpg";
           
            document.getElementById('chkFullerton').checked = false;
            document.getElementById('chkUnion').checked = false;
            
       
        }
    }
    
    
    DefaultImage();
  
  }
  
 function setup()
    { 
        //PURPOSE : sets the form up in its default form without a previous search being entered
        //VARIABLES: none         
       
       
           document.getElementById('imgChkFullerton').src = "images/check_on.jpg";
           document.getElementById('chkFullerton').checked = true;
      
           document.getElementById('chkUnion').checked = false;
           document.getElementById('chkWC').checked = false;
      
}

function Search()
{// PURPOSE:    When a user clicks on a search they should be redirected to the default page with their search requirements
//              This is to stop the current javascript from executing and load in new results.  If prior javascript was 
//              running it will overload the new results or add incorrect data to the result list.


    var zone;
    
        //if no zone is passed default to home library
         if(document.getElementById('chkWC').checked == true)
            { zone=3;}
            else
            {
                if(document.getElementById('chkUnion').checked == true)
                { zone=2;}
                else
                { zone=1;}
            }
           //alert("you got zone: " + zone);
        
      
    
      //clear out previous results if any
      document.getElementById('divResults').innerHTML = '';
      document.getElementById('divShowMore').innerHTML = '';
      
      //get the limit the user wants to search in
      var limit = document.getElementById('lstLimit').options[document.getElementById('lstLimit').selectedIndex].value;
     
      //format the search string for the URL, replace the spaces with +
      var search = FormatSearchString(document.getElementById('txtSearch').value, 1, limit);
      // alert(search);
       
      if(search == '')
      {
        document.getElementById('divNoSearch').innerHTML = "<font size='4' color='#aa2222'>Search Term Required</font>";
        
      }else
      {
      //alert(search);
        //search home library or CSU Wide
        window.location.href= "default.aspx?zone=" + zone + "&search=" + search + "&limit=" + limit;
      }
      
}

function FormatSearchString(strSearch, type, limit)
    {
        //PURPOSE : takes the search string and formats it for either the URL or the text box
        //VARIABLES: type = 1 : format for url, else format for textbox; limit: format as a title or per word
               
        //clear out any quotes on the start or ends
       // if(strSearch.charAt(0) == '"') strSearch = strSearch.substring(1, strSearch.length-1);
       // if(strSearch.charAt(strSearch.length-1) == '"') strSearch = strSearch.substring(0, strSearch.length-2);
      
        if(type == 1)
        {
            //format the string for the querystring 
            //add + for spaces
            if(limit != '.tw')
            {
                while(strSearch.indexOf(' ') > -1)
                {
                    strSearch = strSearch.replace(' ', '+'); 
                }
            }
            else
            {
              // strSearch = '"' + strSearch + '"';
            }
            
           // while(strSearch.indexOf('&') > -1)
           // {
               strSearch = strSearch.replace('&', '&amp;'); 
           // }
       
        }
        else
        {
            //format the string for the textbox 
            //add spaces for +
            while(strSearch.indexOf('+') > -1)
            {
                strSearch = strSearch.replace('+', ' '); 
            }
            
            // while(strSearch.indexOf('&') > -1)
            //{
                strSearch = strSearch.replace('&amp;', '&'); 
            //}
           
             while(strSearch.indexOf('%22') > -1)
            {
                strSearch = strSearch.replace('%22', ''); 
            }
            
              while(strSearch.indexOf('%20') > -1)
            {
                strSearch = strSearch.replace('%20', ' '); 
            }
                
        }
        
        return strSearch;
    }
    
function FormatSearch()
{
        //PURPOSE : develop the URL that will show the results the user is requesting
        //          this function loads on the page if there's no previous search request being 
        //          transmitted we go to Setup for default page setup
        
        //VARIABLES: zone = 1 : home library, 2 : CSU union catalog, 3 : World Cat, 4 : individual record
      
      var ProcessRequest = '';
      
      ProcessRequest = getQueryVariable('search') + '1';
      zone = getQueryVariable('zone');
      
     // alert(ProcessRequest + " : " + zone);
      
      if(ProcessRequest != '1') //there is a search term and you should look for it
      {    
                 
         //clear out previous results for past search
         document.getElementById('ResultsText').innerHTML = "";
         document.getElementById('txtResults').value = 0;
         document.getElementById('txtCurrentPage').value = 0;
         document.getElementById('txtShowResults').value = 0;
         document.getElementById('txtMaxResults').value = 0;
         
         if(zone == '') zone = '1';
               
             //set the checkmarks for the right zone
            switch(zone)
            {
                case '1': //fullerton
                    SetCheck('1');
                    break;
                case '2': //CSU union
                     SetCheck('2');
                    break;
                case '3': //worldcat
                    SetCheck('3');
                    break;
            
            }
          
            //search is always considered to be a first pass at results so page will always show #1
            var PageNo = 1;
      
      
            //clear out previous results if any
            document.getElementById('divResults').innerHTML = '';
      
            //get the limit the user wants to search in
            var limit = document.getElementById('lstLimit').options[document.getElementById('lstLimit').selectedIndex].value;
     
            //format the search string for the URL, replace the spaces with +
            var search = FormatSearchString(document.getElementById('txtSearch').value, 1, limit);
    
            //now go get the results
            if(zone != 4)
            { 
                //search home library or CSU Wide
                SearchBooks(zone, search, limit, PageNo);
            }
            else
            {
                //show the individual item
                SearchRecord(search, getQueryVariable('itemid'));
            }
      }
      else
      {
        //first time to page we need the default setup
        setup()
      }
 }


function CorrectedSpelling(NewSpelling)
{
    document.getElementById("txtSearch").value = NewSpelling;
    Search()

}
   
function ShowItem(bibno, TheSession)
{
     document.getElementById('divResults').style.display = "none";
     document.getElementById('divShowMore').style.display = "none";
     document.getElementById('divSingleBook').innerHTML = "<h1><font color='#a9a9aa'>Loading Book Information . . . </font></h1>";
     document.getElementById('StatusText').innerHTML = "Requesting Item Information...";
 
     //move the page back to the top
     document.getElementById('divHeader').focus();
         
     //store the div where we want to go back and focus;
     document.getElementById('txtDivFocus').value = bibno;
     
     var XMLURL = "processor.aspx?bib=" + bibno + "&Session=" + TheSession + "&zone=4";
     getData(XMLURL, 'Item')  
 }
 
function BackToResults(bib)
{
     document.getElementById('divSingleBook').innerHTML = "";
     document.getElementById('divResults').style.display = "block";
     document.getElementById('divShowMore').style.display = "block";
     document.getElementById("StatusText").innerHTML = "Original search results"
    
    //pull out the div where the user last viewed results
     var divFocus;
     divFocus = '#' + document.getElementById('txtDivFocus').value;
     
     //focus back on their results     
     document.getElementById(divFocus).focus();
}
                    
 function ShowImage(imagename)
  {
                   var WorldCat = new Image(); WorldCat.src = 'images/searchworldcat.gif';
                   var Union = new Image(); Union.src = 'images/searchunion.gif';
                   var CSUF = new Image(); CSUF.src = 'images/searchfullerton.gif';
                   var CloseHoverOn = new Image(); CloseHoverOn.src = 'images/close_small_hover.gif';
                   var CloseHoverOff = new Image(); CloseHoverOff.src = 'images/close_small.gif';
                  
                
                    
                        if(imagename == 3)
                        {
                        document.getElementById('imgSearchAjax').src = WorldCat.src;
                        }
                        
                         if(imagename == 2)
                        {
                        document.getElementById('imgSearchAjax').src = Union.src;
                        }
                        
                          if(imagename == 1)
                        {
                        document.getElementById('imgSearchAjax').src = CSUF.src;
                        }
                    }
                   
 function DefaultImage()
  {
           var zone;
           if(document.getElementById('chkWC').checked == true)
           {zone = 3;}
           else
           {
            if(document.getElementById('chkUnion').checked == true)
            { zone=2;}
            else
            { zone=1;}
           }
                   ShowImage(zone);
  }
                                   
function ShowPage(page)
{
        //alert("Page " + page);
        
        var limit, search, zone;
        limit = document.getElementById('lstLimit').options[document.getElementById('lstLimit').selectedIndex].value;
        search =  FormatSearchString(document.getElementById('txtSearch').value,1);
     
        document.getElementById('ResultsText').innerHTML = "Found " + document.getElementById('txtResults').value + " items<br/>Now Showing Page " + page;
       
       
        document.getElementById('divShowMore').innerHTML = "<font size='4'>Fetching next set of results...</font><br/><br/>";
    
        if(document.getElementById('chkUnion').checked == true)
        {
            zone = 2
        }
        else
        {
            zone=1
        }
                
        SearchBooks(zone, search, limit, page)
        
       
  }
       
     
 function ShowZone(zone)
 {
        //PURPOSE : To show the results from the set the user has selected.  Home Library, CSU, or World Cat
        //VARIABLES:  Zone = 1 : Home Library, 2 : CSU Library, 3 : World Cat
        
         var limit, search;
         
        //get the current limit from the drop down box
        limit = document.getElementById('lstLimit').options[document.getElementById('lstLimit').selectedIndex].value;
      
       //get the current search term and format it for the URL
        search = FormatSearchString(document.getElementById('txtSearch').value, 1);
        
        //if no search found prompt user for input  
        if(search == '')
        {
            search = prompt("No Search Term Found", "Enter A Search Term Here");
            document.getElementById('txtSearch').value = search;
        }
       
       //going to Home Library or CSU union
        if(zone == 1 || zone == 2)
        {  
            
            if (zone == 1)
            {
                   document.getElementById('imgChkFullerton').src = "images/check_on.jpg";
                    document.getElementById('chkFullerton').checked = true;
                    document.getElementById('imgChkUnion').src = "images/check_off.jpg";
                    document.getElementById('chkUnion').checked = false;
                    
            }
            else
            {
                    document.getElementById('imgChkFullerton').src = "images/check_on.jpg";
                    document.getElementById('chkFullerton').checked = true;
                    document.getElementById('imgChkUnion').src = "images/check_on.jpg";
                    document.getElementById('chkUnion').checked = true;
            }
            
            Search(zone)
           } 
        else
       {
            //going to world cat
            
            var zip = 92834; // local zip code
            var url = "http://library.fullerton.edu/asp/ipcheck.aspx?EZURL=http://worldcatlibraries.org/search?qt=worldcat_org&q=" + search + '&loc=' + zip;
            var win = window.open(url,"WorldCat");
       }
       
       
  }
      
function Close_Hover()
    {
        //PURPOSE : To show the hover image when the user mouses over the close tag
        //VARIABLES: none
               
        document.getElementById("imgAuthClose").src = CloseHoverOn.src;                      
    }
      
function Close_Default()
    {
        //PURPOSE : To show the default hover image when the user mouses off the close tag
        //VARIABLES: none
               
        document.getElementById("imgAuthClose").src = CloseHoverOff.src;
    }
   
   
   function ExpandSearch(method)
   {
        //if no results are found this will help the user gets to more results by various methods
        switch(method)
        {
            case 2: //show books at all CSU libraries
                //set checkmarks
                SetCheck(2); //search CSU wide
                Search(); // run the search
                break;
            case 3: //Show books via worldcat
                SetCheck(3);
                Search();
                break;
        }
   }
                
//-->