/*
* File: quickSearch.js
*
* Write a BGSU QuickSearch form into the current document
*
* Usage:
*
* <script type="text/javascript"
* src="http://www.bgsu.edu/scripts/quickSearch.js">
* </script>
*
* Insert the <script> element into the <head> or <body> of your document.
*
* Constructors: QuickSearch() create a QuickSearch object
* QuickSearch( url, name ) employ a special search option
*
* Methods: setColumns( cols ) set the width of the text field
* setLabel( label ) set the label for the search button
* useImage( img ) use an image as the search button
* useImages( img1, img2 ) use dynamic images (rollovers)
* setBorder( border ) set border of image (in pixels)
* setAlign( align ) set alignment of image
* setTarget( target ) set the target of search results page
* (default: "_self")
* write() write the search tool into the doc
*
* Example 1: quickSearchTest1.html
*
* <script type="text/javascript"
* src="http://www.bgsu.edu/scripts/quickSearch.js">
* </script>
* <script type="text/javascript">
* var quicksearch = new QuickSearch();
* quicksearch.write();
* </script>
*
* Example 2: quickSearchTest2.html
*
* <script type="text/javascript"
* src="http://www.bgsu.edu/scripts/quickSearch.js">
* </script>
* <script type="text/javascript">
* var quicksearch = new QuickSearch();
* quicksearch.setColumns( 12 );
* quicksearch.setLabel( "Go!" );
* quicksearch.write();
* </script>
*
* Example 3: quickSearchTest3.html
*
* <script type="text/javascript"
* src="http://www.bgsu.edu/scripts/quickSearch.js">
* </script>
* <script type="text/javascript">
* var url = "http://www.bgsu.edu/offices/execvp/";
* var name = "Exec VP";
* var quicksearch = new QuickSearch( url, name );
* quicksearch.setColumns( 10 );
* quicksearch.write();
* </script>
*
* Example 4: quickSearchTest4.html
*
* <script type="text/javascript"
* src="http://www.bgsu.edu/scripts/quickSearch.js">
* </script>
* <script type="text/javascript">
* var button = new Image();
* button.src = "http://www.bgsu.edu/scripts/quickSearchGo.gif";
* var quicksearch = new QuickSearch();
* quicksearch.setColumns( 10 );
* quicksearch.useImage( button );
* quicksearch.write();
* </script>
*
* Example 5: quickSearchTest5.html
*
* <script type="text/javascript"
* src="http://www.bgsu.edu/scripts/quickSearch.js">
* </script>
* <script type="text/javascript">
* var buttonUp = new Image();
* buttonUp.src = "http://www.bgsu.edu/scripts/quickSearchUp.gif";
* var buttonDown = new Image();
* buttonDown.src = "http://www.bgsu.edu/scripts/quickSearchDown.gif";
* var quicksearch = new QuickSearch();
* quicksearch.setColumns( 12 );
* quicksearch.useImages( buttonUp, buttonDown );
* quicksearch.setBorder( 0 );
* quicksearch.setAlign( "top" );
* quicksearch.setTarget( "_blank" );
* quicksearch.write();
* </script>
*
*/
// The QuickSearch constructor takes zero or two arguments:
function QuickSearch( url, name ) {
this.cols = null;
this.label = "Search";
if ( arguments.length == 2 ) {
this.searchURL = url;
this.searchName = name;
} else {
this.searchURL = null;
this.searchName = null;
}
this.buttonUp = null;
this.buttonDown = null;
this.border = null;
this.align = null;
this.target = "_self";
}
// Method to set the width of the text field:
function QS_setColumns( cols ) {
// Try to parse the argument as an integer:
cols = parseInt( cols );
// Test for a non-negative integer:
if ( !isNaN( cols ) && cols >= 0 ) this.cols = cols;
}
QuickSearch.prototype.setColumns = QS_setColumns;
// Method to set the label for the search button:
function QS_setLabel( label ) {
if ( label != null ) this.label = label;
}
QuickSearch.prototype.setLabel = QS_setLabel;
// Method to specify image to use as the search button:
function QS_useImage( image ) {
this.useImages( image );
}
QuickSearch.prototype.useImage = QS_useImage;
// Method to specify rollover images to use as the search button:
function QS_useImages( image1, image2 ) {
if ( image1 != null ) {
this.buttonUp = new Image();
this.buttonUp.src = image1.src;
if ( image2 != null ) {
this.buttonDown = new Image();
this.buttonDown.src = image2.src;
}
}
}
QuickSearch.prototype.useImages = QS_useImages;
// Method to set the border of the image button (in pixels):
function QS_setBorder( border ) {
// Try to parse the argument as an integer:
border = parseInt( border );
// Test for a non-negative integer:
if ( !isNaN( border ) && border >= 0 ) this.border = border;
}
QuickSearch.prototype.setBorder = QS_setBorder;
// Method to set the alignment of the image button:
function QS_setAlign( align ) {
if ( align != null ) {
if ( align == "bottom" || align == "middle" || align == "top" ) {
this.align = align;
}
}
}
QuickSearch.prototype.setAlign = QS_setAlign;
// Method to set the target of the search results:
function QS_setTarget( target ) {
if ( target != null ) {
this.target = target;
}
}
QuickSearch.prototype.setTarget = QS_setTarget;
// Method to write the search tool into the current document:
function QS_write() {
// Local variables:
var cols = this.cols;
var label = this.label;
var searchName = this.searchName;
var searchURL = this.searchURL;
var buttonUp = this.buttonUp;
var buttonDown = this.buttonDown;
var border = this.border;
var align = this.align;
// Write the form into the document:
document.writeln( '' );
document.writeln( '<form name="search" method="get" target="' + this.target + '"' );
document.writeln( ' onsubmit="submitForm()"' );
document.writeln( ' action="http://search.bgsu.edu/query.html">' );
// This anonymous text field must be the *first* field in the form:
document.writeln( ' <input type="text"' );
if ( cols != null ) {
document.writeln( ' size="' + cols + '"' );
}
document.writeln( ' maxlength="2033">' );
// Write the submit button:
if ( buttonUp != null ) {
//document.writeln( ' <input type="image" src="' + buttonUp.src + '" alt="Search">' );
document.writeln( ' <a href="javascript:submitForm()"' );
document.writeln( ' onmouseover="return doMouseover()"' );
document.writeln( ' onmouseout ="doMouseout()">' );
document.writeln( ' <img src="' + buttonUp.src + '"' );
document.writeln( ' width="' + buttonUp.width + '"' );
document.writeln( ' height="' + buttonUp.height + '"' );
if ( align != null ) {
document.writeln( ' align="' + align + '"' );
}
if ( border != null ) {
document.writeln( ' border="' + border + '"' );
}
document.writeln( ' alt="Search" name="submitButton"><\/a>' );
} else {
//document.writeln( ' <input type="submit" value="' + label + '">' );
document.writeln( ' <input type="button" value="' + label + '"' );
document.writeln( ' onclick="submitForm()"' );
document.writeln( ' onmouseover="return doMouseover()"' );
document.writeln( ' onmouseout ="doMouseout()">' );
}
// Write a select object:
document.writeln( ' <select name="rq" size="1">' );
// The special search option must be the *first* option listed, if at all:
if ( searchName != null ) {
document.writeln( ' <option value="0">' + searchName + '<\/option>' );
}
document.writeln( ' <option value="0">BGSU Web<\/option>' );
document.writeln( ' <option value="2">The Internet<\/option>' );
document.writeln( ' <\/select>' );
// Write numerous hidden fields:
document.writeln( ' <input type="hidden" name="qt" value="">' );
document.writeln( ' <input type="hidden" name="col" value="bigweb">' );
document.writeln( ' <input type="hidden" name="ht" value="0">' );
document.writeln( ' <input type="hidden" name="qp" value="">' );
document.writeln( ' <input type="hidden" name="qs" value="">' );
document.writeln( ' <input type="hidden" name="qc" value="">' );
document.writeln( ' <input type="hidden" name="pw" value="100%">' );
document.writeln( ' <input type="hidden" name="ws" value="0">' );
document.writeln( ' <input type="hidden" name="la" value="">' );
document.writeln( ' <input type="hidden" name="qm" value="0">' );
document.writeln( ' <input type="hidden" name="st" value="1">' );
document.writeln( ' <input type="hidden" name="nh" value="10">' );
document.writeln( ' <input type="hidden" name="lk" value="1">' );
document.writeln( ' <input type="hidden" name="rf" value="0">' );
document.writeln( ' <input type="hidden" name="oq" value="">' );
document.writeln( ' <input type="hidden" name="si" value="1">' );
document.writeln( '<\/form>' );
// Store data so that handlers have access (a kludge):
document.search.searchURL = searchURL;
document.search.searchName = searchName;
document.search.buttonUp = buttonUp;
document.search.buttonDown = buttonDown;
}
QuickSearch.prototype.write = QS_write;
// Check the form before submitting:
function submitForm() {
var form = document.search;
// Store the search string in a hidden field called 'qt':
form.qt.value = form.elements[0].value;
// Process special search option, if it exists:
if ( form.searchName != null && form.rq.selectedIndex == 0 ) {
if ( form.searchURL != null ) {
form.qt.value += " AND url:" + form.searchURL;
}
}
form.submit();
}
function doMouseover() {
window.status = "Press button to search the web";
var form = document.search;
if ( form.buttonDown != null ) {
document.submitButton.src = form.buttonDown.src;
}
return true;
}
function doMouseout() {
window.status = "";
var form = document.search;
if ( form.buttonDown != null ) {
document.submitButton.src = form.buttonUp.src;
}
}