/*   */

      function dosearch(thisform) {
        var lookfor = thisform.search.value;
	lookfor = fixlookfor(lookfor);
	      
        if(lookfor!="" && lookfor!="Quicksearch..."){
          var url = "catalogue.php?&search=" + lookfor + "&";
          window.location = url;
        }
      }
      function searchgotfocus(fld){
	if(fld.value=='Quicksearch...'){fld.style.color='#CCEEFF';fld.value='';}
      }
      function searchlostfocus(fld){
	if(fld.value==''){fld.value='Quicksearch...';fld.style.color='#B29999'}
      }
      
      // For the advanced search on the listing pages...
      function advsearch(thisform, qryadd, qtype){
	var lookfor = thisform.advsearchtext.value;
	lookfor = fixlookfor(lookfor);
	      
	var searchwhat = thisform.advsearchwhat.options[thisform.advsearchwhat.selectedIndex].text;
	var qry = "";
	
	var title_start = "";
	if(qtype=="c"){
		title_start = "Childrens ";
	} else if(qtype=="s"){
		title_start = "Sale Books: "
	}
	
	if(searchwhat=="Title"){
		qry = "title=%25" + lookfor + "%25&ptitle=" + title_start + "Titles containing " + lookfor + "&";
	} else if(searchwhat=="Author") {
		qry = "auth=%25" + lookfor + "%25&ptitle=" + title_start + "Authors containing " + lookfor + "&";
	} else if(searchwhat=="Series") {
		qry = "series=%25" + lookfor + "%25&ptitle=" + title_start + "Series containing " + lookfor + "&";
	} else if(searchwhat=="Publisher") {
		qry = "pub=%25" + lookfor + "%25&ptitle=" + title_start + "Publishers containing " + lookfor + "&";
	} else if(searchwhat=="Category") {
		qry = "cat=%25" + lookfor + "%25&ptitle=" + title_start + "Categories containing " + lookfor + "&";
	} else if(searchwhat=="ISBN") {
		qry = "isbn=" + lookfor + "&"; 
	} else {
		qry = "search=" + lookfor + "&"; 
	}
	
	var url = "catalogue.php?&" + qry + "&" + qryadd;
        window.location = url;
      }
      
      function fixlookfor(lookfor){
	lookfor = lookfor.replace("'", "%26%23%33%39%3B");	// This replaces the apostrophe with the URL encoded html character "&#39;"
	lookfor = lookfor.replace("\"", "%26%23%33%34%3B");	// This replaces the quote with the URL encoded html character "&#34;"
	lookfor = lookfor.replace("&", "%26");			// This replaces the ampersand symbol with the URL encoded version (amp is used to delimit url parameters)
	return lookfor;      
      }
