// this function prevents this page from being loaded outside
// the frameset. Change index.htm to the name of your frameset
// document.
/*
if (parent.location.href.indexOf("index.html") == -1)
 top.location.href = "index.html";
*/
/*
 * By M.Robin-Vinet for ELDA (S.A.) - 27 June 2006
 * Function used to retrieve keywords and boolean operator from a search form
 *
 * Modified 01 Dec 2008 : New search engine (htdig) with new parameters and uri
 */
function extractKeywords(language)
{
        var keywords = document.catsearch.keywords.value;               // Retrieving of the keywords from the form
        var cleankwrd = keywords.replace((/^\s+/),"");                  // Replace spaces at the start of the string by nothing
        cleankwrd = cleankwrd.replace((/\s+$/),"");                     // Replace spaces at the end of the string by nothing
	var config = document.catsearch.config.value;							// Htdig config file name to use for the search
//        var operator = document.catsearch.operator.value;               // Retrieving of the boolean operator from the form
//        var expr = /\s/gi;                                              // Define the regexp used to retrieve the spaces between keywords
//        var query = "";                                                 // The final query sended to the search engine
        var formurl = "http://catalog.elra.info/search.php"; // Url of the search engine script
        
        // If the form is empty, displays a message box
        if ((document.catsearch.keywords.value.length == 0) || (document.catsearch.keywords.value == " "))
        {
                alert("First you must enter at least one keyword to search for.");
        }
        // Else, try to define the boolean operator, include operator between each keyword before sending to php script with language value
        else
        {
/*                if ((operator == "all words (AND)") || (operator == "Tous les mots (ET)"))      // AND
                {
                        query = cleankwrd.replace(expr," AND ");
//DEBUG                        alert(formurl+"?keywords="+query+"?language="+language);
                        // Now we can redirect to the appropriate script with arguments
                        this.location.href = (formurl+"?keywords="+query+"&language="+language);
                }
                else if ((operator == "any word (OR)") || (operator == "n'importe quel mot (OU)")) // OR
                {
                        query = cleankwrd.replace(expr," OR ");
//DEBUG                        alert(query);
                        // Now we can redirect to the appropriate script with arguments
                        this.location.href = (formurl+"?keywords="+query+"&language="+language);
                }
                else                                  // Unknown/default case
                {
*/
//                        query = cleankwrd.replace(expr," AND ");
//DEBUG                        alert(formurl+"?keywords="+query+"?language="+language);
                        // Now we can redirect to the appropriate script with arguments
                        this.location.href = (formurl+"?page=1&affichage=long&restrict=;exclude=products_all;config="+config+";method=and;format=normal;sort=score;matchesperpage=;words="+keywords);
//                }
        }
        return false;
}

