﻿/*****************************************************
 * File Name: Search.js
 * Created By: Ken Goodson
 * Date Created: 10/01/2008
 * 
 * Summary:
 * This file defines all the client side script for the search functionality.
 *
 * Revisions:
 * Modified By      Date        Comments
 * -----------      ----        --------
 * 
 * 
 *****************************************************/

/* -----------------------------------------------------------------------------------
 * These functions will make a default hint message appear in the search textbox until
 * there is a click in the box and then it will clear out for the user to input search
 * text. This hint is used in the HeaderControl1_Load function. 
 * ----------------------------------------------------------------------------------- */
function clearText(ctrl,defaultText)
{
    //alert("in clearText");
    if(ctrl.value == defaultText)
    {
        ctrl.value = "";
        ctrl.style.color = "#000000";
    }
}
function resetText(ctrl,defaultText)
{
    if(ctrl.value == "")
    {   
        ctrl.value = defaultText;
        ctrl.style.color = "#E1E1E1";
    }
}

/* ---------------------------------------------------------------------------------
 * These functions will call the search program when either the enter key is pressed
 * or the search button is clicked.
 * ---------------------------------------------------------------------------------- */
var regx = /=|&|@|%|$/g
var noquotes = /\'|"/g;

function checkKeycode() {
   var keycode;
   if (window.event)
   {
       keycode = window.event.keyCode;
       if (keycode==13) 
       {
           var searchText = "";
           for (i=1; i < document.forms[0].elements.length; i++)
           {
                if (document.forms[0].elements[i].name.indexOf("txtSearchText") > 0)
                { 
                    searchText = document.forms[0].elements[i].value;
                    searchText.replace(regx,""); 
                    searchText.replace(noquotes,"");
                    //searchText.replace( /['"](?!\b)/g , "")
                    //searchText.replace( /([^\w])['"]/g, "$1" )
                    //searchText.replace( /^['"]|['"]$/g, "" );

                    break;
                }                                             
           }
           if (searchText == "") {
               alert("You must enter text in the search box before pressing enter!");
               return false;
           }
           else {
               window.location.href="Search.aspx?txt=" + searchText;                
               return false;  
           }
       }
   }
}

document.onkeydown = checkKeycode;

function CallSearch()
{
   var searchText = "";
   for (i=1; i < document.forms[0].elements.length; i++)
   {
        if (document.forms[0].elements[i].name.indexOf("txtSearchText") > 0)
        { 
            searchText = document.forms[0].elements[i].value;
            searchText.replace(regx,""); 
            searchText.replace(noquotes,""); 
            //searchText.replace( /['"](?!\b)/g , "")
            //searchText.replace( /([^\w])['"]/g, "$1" )
            //searchText.replace( /^['"]|['"]$/g, "" );                                               
            break;
        }                        
   }
   document.location.href="Search.aspx?txt=" + searchText;                
   //             
   // Load the page with the websearch server control in the bottom frame using Javascript
   // Set websearch properties using querystring parameters
   // Properties set here- search text,Orderby, FolderId, and SearchFor
   // SearchFor can be a value from all/html/documents/images/multimedia/discussionForum
   // Orderby can be one of these - editor,id,rank,title,datecreated,datemodified
   // OrderDirection can be ascending or descending
   //
}