// This JavaScript script file is used to add a Google/Yahoo search option to your Web pages.
//  7/02/2006.

//
// This script was from; The JavaScript Source
// at; http://javascript.internet.com
// This code was created by; Mr. Ivan Iraola   at; http://www.cybexmag.com                  (Version 0.01)
// Edited and updated by   ; Mr. Mark A. Agius at; http://members.aol.com:/MarkAgius        (Version 0.02)
// Script file moved by    ; Mr. Mark A. Agius to; http://MarkAgius.co.uk/webpages/scripts  (Version 0.03)

/* To use this script add the following code to your Web page;
<HEAD>
<SCRIPT TYPE="text/javascript" SRC="Search.js"></SCRIPT>
// Note; when  SRC="Search.js"   is the path to this file.
// Eg.         SRC=""Mark's WEB site\MarkAgius\WebPages\Search.js"
</HEAD>

<BODY>
<FORM NAME="ToolBox" STYLE="line-height: 2em;">
<FONT FACE="Arial" SIZE="2">
<B>Search using;</B> &nbsp;<INPUT TYPE="radio" NAME="SearchOption" VALUE="Google">Google&nbsp;
<INPUT TYPE="radio" NAME="SearchOption" VALUE="Yahoo">Yahoo&nbsp;
<INPUT TYPE="radio" CHECKED NAME="SearchOption" VALUE="Both">Both search engings&nbsp;<BR>
<B>Enter search text;</B> <INPUT TYPE="text" NAME="SearchBox" SIZE="24">&nbsp;
<BUTTON TYPE="button" OnClick="DoSearch('_blank')">&nbsp; Search &nbsp;</button>
<NOSCRIPT>
<BR>
<FONT COLOR="#FF2F2F" SIZE="3">
<B><U>Please note</U>;</B><BR>
This search engine will not work on this browser as it is not supporting Java Script.<BR>
Please turn on your Java Script option and <A HREF="On-line web sites.htm">reload this page</A>,<BR>
or click on one of the following links;<BR>
<LI><A HREF="http://www.google.com" TARGET="_blank">http://www.google.com</A>
<LI><A HREF="http://search.yahoo.com" TARGET="_blank">http://search.yahoo.com</A>
</FONT>
</NOSCRIPT>
</FONT>
</FORM>

</BODY>

Note; You must also have a blank web page 'blank.htm' in the same directory as
      the page that calls this code.
*/

// ---------------------------------------------------------------------------

function DoSearch(WindowTarget){
  if(WindowTarget==undefined){WindowTarget="_this"}
  var Flag = 0;
  var GoogleURL = "http://www.google.com/search?hl=en&q=";
  var YahooURL  = "http://search.yahoo.com/search?p=";
  if (document.ToolBox.SearchOption[0].checked==true){
    // 'Google' option was checked.
    var Flag = 1;
    var Engine = document.ToolBox.SearchOption[0].value;
    var Query = document.ToolBox.SearchBox.value;
    var locName = GoogleURL;
      if (Query == "") {
        alert("Google search error.\n\nPlease enter search text.");
        return;
      }
     // location.href = (locName + Query)
     window.open(locName + Query, WindowTarget)
  }
  if (document.ToolBox.SearchOption[1].checked==true){
    // 'Yahoo' option was checked.
    var Flag = 1;
    var Engine = document.ToolBox.SearchOption[1].value;
    var Query = document.ToolBox.SearchBox.value;
    var locName = YahooURL;
      if (Query == "") {
        alert("Yahoo search error.\n\nPlease enter search text.");
        return;
      }
     // location.href = (locName + Query)
     window.open(locName + Query, WindowTarget)
  }
  if (document.ToolBox.SearchOption[2].checked==true){
    // The 'Both' option was checked.
    var Flag = 1;
    var Engine = document.ToolBox.SearchOption[2].value;
    var Query = document.ToolBox.SearchBox.value;
      if (Query == "") {
        alert("Search engine error.\n\nPlease enter search text.");
        return;
      }
    var searchPage = "<HTML>";
      searchPage += "\n";
      searchPage += "<HEAD>";
      searchPage += "\n";
      searchPage += "<TITLE>Search results for; "+Query+"</TITLE>";
      searchPage += "\n";
      searchPage += "</HEAD>";
      searchPage += "\n";
      searchPage += "<FRAMESET ROWS=\"50%,50%\">";
      searchPage += "\n";
      searchPage += "<FRAME SRC=\""+GoogleURL+"" + Query + "\">";
      searchPage += "\n";
      searchPage += "<FRAME SRC=\""+YahooURL+"" + Query + "\">";
      searchPage += "\n";
      searchPage += "</FRAMESET>";
      searchPage += "\n";
      searchPage += "</HTML>";
      if(WindowTarget=="_this"){
        document.write(searchPage);
      } else {
        TextInPopUpWindow(searchPage)
      }
  }
  if (Flag==0) {alert("You have not selected a search engine.\n\nPlease select a search engine first.");}
}

function TextInPopUpWindow(HtmlText, WindowName){
  // This function will openup a window (HTML_File) and and display the HtmlText message. (HtmlText is HTML code)
  // NOTE; This function will work whether the HTML_File exists or not.
  //       But Netscape will display an error message saying that this file dose not exist, if it can't find it.
  var WindowProperties = "" // status=no; scrollbars=yes; toolbar=no; menubar=yes; ";
  var HTML_File        = "blank.htm";
  if(WindowName=="undefined" || WindowName==""){WindowName = "MyPopupWindow";}
  // Add '<HTML><BODY>' to the start of the text if it doesn't already have it.
  if(HtmlText.toUpperCase().substring(0,6)!="<HTML>") {
    if(HtmlText.toUpperCase().substring(0,5)!="<BODY") {
      HtmlText = "<BODY>\n"+HtmlText
    }
    HtmlText = "<HTML>\n"+HtmlText
  }
  // Add '</BODY></HTML>' to the end of the text if it doesn't already have it.
  if(HtmlText.toUpperCase().substring(HtmlText.length-7)!="</HTML>") {
    if(HtmlText.toUpperCase().substring(HtmlText.length-7)!="</BODY>") {
      HtmlText = HtmlText+"\n</BODY>"
    }
    HtmlText = HtmlText+"\n</HTML>"
  }
  // Open and write the text to the HTML_File.
  var win2 = open(HTML_File, WindowName, WindowProperties);
  // If win2 is already open, then you must first close it.
  // If not on-line and Internet Explorer then, close then open window.
  if(is_IE_code()){
    if(this.location.href.substring(0,7)=="file://"){
      win2.close()
      win2 = open(HTML_File, WindowName, WindowProperties);
    }
  }

  win2.document.open();
  win2.document.write(HtmlText);
  win2.document.close();
  // alert("The new window is\nnow opening.\n\n\tEnjoy!");
}
function isInternetExplorer(){
  // This function will return true if this browser supports DIV's. (E.g. Microsoft Internet Explorer)
  return document.all?true:false;
}
function is_IE_code(){
  // This function will return true if 'MSIE' string found in browser . (E.g. Microsoft Internet Explorer)
  return (navigator.appVersion.indexOf("MSIE")>=0);
}

