// ----------------------------------------------------------------------------
// Lauyan Software Javascript Search Engine 1.0
//
// This file is the JavaScript search engine for a website created by TOWeb
//
// Copyright (C) LAUYAN SOFTWARE
// web: http://www.lauyan.com
// ----------------------------------------------------------------------------

STR_SEARCH_QUERY_MSG = "Résultats de la recherche pour";
STR_NO_RESULT = "Aucun résultat trouvé";
STR_SEARCH_BUTTON = "Rechercher";
STR_SCORE = "Score";
STR_TERMS = "Termes";
STR_SEARCH_SIZE = "40";
MIN_WORD_LEN = 2;
DISPLAY_SRCH_INFO = 1;
USE_UTF8 = 0;
REMOVE_ACCENTS = 1;
BOLD_LINKS = 0;
ONLINE_WEBSITE = 1;

namesArray = new Array(" bienvenue corossol  ",
" nos liens favoris  ",
" contactez-nous  ",
" nos partenaires  ",
" toute actualite saint-barth  ",
" evenement  ",
" informations diverses  ",
" videos saint-barth avec youtube  ",
" webcam  ",
" tous evenements sur site corossol  ",
" edouard magras  ",
" ingenu magras  ",
" pere rene danet  ",
" ulrich greaux  ",
" emile magras  ",
" saint-louis 2004  ",
" saint-louis 2005  ",
" saint-louis 2006  ",
" saint-louis 2007  ",
" saint-louis 2008  ",
" saint-louis 2009  ",
" saint-louis 2010  ",
" maquettes bruno questel dit nono  ",
" faune flore saint-barth  ",
" bons petits plats corossol  ",
" fil pic halle dan'l pongne  ",
" tribord mur  ",
" travail paille corossol  ",
" petite visite musee coquillage  ",
" tous commentaires suggestions  ",
" vie l'association  ",
" oui etait ainsi avant  ",
" saint-barth dan'l temps d'avant  ",
" juste histoire rigoler quoi  ",
" nou parle inne tite beke d'patois  ",
" passe temps  ",
" objets autrefois  ",
" histoire caleche  ",
" notre nature  ",
" differentes videos sur corossol info  ",
" album photo l'alc  ",
" maisons traditionnelles corossol  ",
" livre page  ",
" photos insolites saint-barth  ",
" photos insolites saint-barth  ",
" publicite  ",
" sortie adherents l'alc chez pompiers  ",
" deplacement adherents alc saint-martin  ",
" telethon l'alc  ",
" sortie sur ile tintamare samedi mai 2009  ",
" fete quartiers nord  ",
" fete quartiers vent  ",
" fete public  ",
" fete saint-louis 2009  ",
" journee patrimoine 2009  ",
" pere noel alc  ",
" ambiance noel regal  ",
" archives fevrier 2009  ",
" archives mars 2009  ",
" archives avril 2009  ",
" archives mai 2009  ",
" archives juin 2009  ",
" archives juillet 2009  ",
" archives aout 2009  ",
" archives septembre 2009  ",
" archives octobre 2009  ",
" archives novembre 2009  ",
" archives decembre 2009  ",
" archives janvier 2010  ",
" archives fevrier 2010  ",
" archives mars 2010  ",
" archives avril 2010  ",
" archives mai 2010  ",
" archives juin 2010  ",
" archives juillet 2010  ",
" archives aout 2010  ",
" archives sept 2010  ",
" archives octobre 2010  ",
" archives novembre 2010  ",
" archives decembre 2010  ",
" archives janvier 2011  ",
" archives fevrier 2011  ",
" archives mars 2011  ",
" archives avril 2011  ",
" archives mai 2011  ",
" archives juin 2011  ",
" archives juillet 2011  ",
" archives aout 2011  ",
" pique-nique alc petit cul-de-sac  ",
" bucket 2010  ",
" transat ag2r 2010  ",
" l'alc saint-martin  ",
" page speciale transat ag2r 2010  ",
" fete public 2010  ",
" fete aout 2010  ",
" fete saint-louis 2010  ",
" fete lorient 2010  ",
" gustavialoppet 2010  ",
" arbre noel l'alc 2010  ",
" carnaval bout-de- chou  ",
" carnaval 2011  ",
" poisson avril  ",
" bucket air show 2011  ",
" sortie tintamarre juin 2011  ");
urlsArray = new Array("../accueil/index.html",
"../liens/index.html",
"../contactez-nous/index.html",
"../nospartenaires/index.html",
"../vnement1/index.html",
"../evenement2/index.html",
"../informationsdive/index.html",
"../videosdesaint-ba/index.html",
"../webcam/index.html",
"../vosevenementssur/index.html",
"../portrait1/index.html",
"../portrait2/index.html",
"../portrait3/index.html",
"../portrait4/index.html",
"../portrait5/index.html",
"../saint-louis2004/index.html",
"../saint-louis2005/index.html",
"../saint-louis2006/index.html",
"../saint-louis2007/index.html",
"../saint-louis2008/index.html",
"../saint-louis2009/index.html",
"../saint-louis2010/index.html",
"../maquettes/index.html",
"../fauneetflore/index.html",
"../gastronomie/index.html",
"../peche/index.html",
"../voiletraditionne/index.html",
"../paille/index.html",
"../musee/index.html",
"../livredor/index.html",
"../alcassociationle/index.html",
"../leetaitunefoisst/index.html",
"../st-barthdanslete/index.html",
"../justepourrire/index.html",
"../lepatoisdecoross/index.html",
"../jeuxsurcorossoli/index.html",
"../corossolantique/index.html",
"../unehistoiredecal/index.html",
"../nature/index.html",
"../videos/index.html",
"../albumphotodemo/index.html",
"../lesmaisonstradit/index.html",
"../livredor1/index.html",
"../photosinsolites/index.html",
"../photosinsolites1/index.html",
"../publicite/index.html",
"../lalcchezlespompi/index.html",
"../lalcasaint-marti/index.html",
"../letelethondelalc/index.html",
"../sortieatintamare/index.html",
"../fetedesquartiers/index.html",
"../fetedesquartier1/index.html",
"../fetedepublic/index.html",
"../saint-louis20091/index.html",
"../journeedupatrimo/index.html",
"../leperenoelalalc/index.html",
"../ambiancedenoelau/index.html",
"../archivesfevrier2009/index.html",
"../archives/index.html",
"../archivesavril200/index.html",
"../archivesmai2009/index.html",
"../archivesjuin2009/index.html",
"../archivesjuillet2/index.html",
"../archivesaout2009/index.html",
"../archivesseptembre2009/index.html",
"../archivesoctobre2009/index.html",
"../archivesnovembre2009/index.html",
"../archivesdecembre2009/index.html",
"../archivesjanvier2/index.html",
"../archivesfevrier2/index.html",
"../archivesmars2010/index.html",
"../archivesavril201/index.html",
"../archivesmai2010/index.html",
"../archivejuin2010/index.html",
"../archivesjuillet1/index.html",
"../archivesaout2010/index.html",
"../archivessept2010/index.html",
"../archivesoctobre2/index.html",
"../archivesnovembre/index.html",
"../archivesdecembre/index.html",
"../archivesjanvier1/index.html",
"../archivesfevrier1/index.html",
"../archivesmars2011/index.html",
"../archivesavril202/index.html",
"../archivesma2011/index.html",
"../archivesjuin2011/index.html",
"../archivesjuillet3/index.html",
"../archivesaout2011/index.html",
"../pique-niquedelal/index.html",
"../buket2010/index.html",
"../specialtransatag/index.html",
"../lalcasaint-mart1/index.html",
"../specialetransata/index.html",
"../fetedepublic2010/index.html",
"../fetedu24aout2010/index.html",
"../fetedelasaint-lo/index.html",
"../fetedelorient201/index.html",
"../gustavialoppet20/index.html",
"../arbredenoeldelal/index.html",
"../carnavaldesbout-/index.html",
"../carnaval2011/index.html",
"../evenementiel/index.html",
"../bucketetairshow2/index.html",
"../sortieatintamar1/index.html");
titlesArray = new Array("le site de corossol",
"Nos liens favoris",
"Contactez-nous",
"Nos partenaires",
"Toute l' actualité à Saint-Barth.",
"le site de corossol",
"Informations diverses.",
"Vidéos de Saint-Barth avec YouTube.",
"Webcam",
"Tous vos événements sur le site de Corossol",
"Edouard MAGRAS",
"Ingénu MAGRAS",
"Père René DANET",
"Ulrich GREAUX",
"Emile MAGRAS",
"La Saint-Louis 2004",
"La Saint-Louis 2005",
"Saint-Louis 2006",
"Saint-Louis 2007",
"Saint-Louis 2008",
"Saint-Louis 2009",
"Saint-Louis 2010",
"Les maquettes de Bruno QUESTEL(dit Nono)",
"La faune et la flore de Saint-Barth",
"Les bons petits plats de Corossol",
"Fil, pic halle, mé dan'l pongné...",
"Tribord à mur...",
"Le travail de la paille de Corossol",
"Une petite visite au musée de coquillage",
"Tous vos commentaires et suggestions.",
"La vie de l'association",
"Eh oui!!! c' était ainsi avant...",
"Saint-Barth dan'l temps d'avant",
"Juste l' histoire de rigoler quoi!!!",
"A nou parlé inne tite béké d'patois",
"Passe temps",
"Les objets d' autrefois",
"L' histoire de la calèche",
"Notre nature",
"Différentes Vidéos sur corossol.info",
"Album photo de l'ALC",
"Les maisons traditionnelles de Corossol",
"Livre d' or page 2",
"Vos photos insolites de Saint-Barth !",
"Vos photos insolites de Saint-Barth.",
"publicité",
"Sortie des adhérents de l'ALC chez les pompiers",
"déplacement des adhérents de l' ALC à Saint-Martin.",
"Le Téléthon de l'ALC",
"Sortie sur l' île de Tintamare le samedi 9 mai 2009",
"Fête des quartiers du Nord",
"Fête des quartiers du vent",
"Fête de Public",
"Fête de la Saint-Louis 2009",
"Journée du patrimoine 2009",
"Le père noël à l' ALC",
"Ambiance de Noël au Régal.",
"Archives Février 2009",
"Archives Mars 2009",
"Archives Avril 2009",
"Archives Mai 2009",
"Archives Juin 2009",
"Archives Juillet 2009",
"Archives Août 2009",
"Archives Septembre 2009",
"Archives Octobre 2009",
"Archives Novembre 2009",
"Archives Décembre  2009",
"Archives Janvier 2010",
"Archives Février 2010",
"Archives Mars 2010",
"Archives Avril 2010",
"Archives Mai 2010",
"Archives Juin 2010",
"Archives Juillet 2010",
"Archives Août 2010",
"Archives Sept 2010",
"Archives Octobre 2010",
"Archives Novembre 2010",
"Archives Décembre 2010",
"Archives Janvier 2011",
"Archives Février 2011",
"Archives Mars 2011",
"Archives Avril 2011",
"Archives Mai 2011",
"Archives Juin 2011",
"Archives Juillet 2011",
"Archives août 2011",
"Pique-nique de l' ALC à Petit Cul-de-sac",
"Bucket 2010",
"Transat AG2R 2010",
"L'ALC à Saint-Martin",
"PAGE SPECIALE TRANSAT AG2R 2010",
"Fête de Public 2010",
"Fête du 24 août 2010",
"Fête de la Saint-Louis 2010",
"Fête de Lorient 2010",
"Gustavialoppet 2010",
"Arbre de Noël de l'ALC 2010",
"Carnaval des Bout-de- chou",
"Carnaval 2011",
"Poisson d' avril.",
"Bucket et Air Show 2011",
"Sortie à Tintamarre le 12 juin 2011");
descArray = new Array("",
"",
"",
"",
"",
"",
"",
"",
"",
"",
" ",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"");
sublinksArray = new Array(104);
var linksCount = 104;


ALLWORDSONLY = false;

// getParam returns the value of the specified GET parameter
function getParam(paramName)
{
    paramStr = document.location.search;
    if( paramStr == "" )
        return "";
    if( paramStr.charAt(0) == "?" )
        paramStr = paramStr.substr(1);
    arg = (paramStr.split("&"));
    for( i=0; i<arg.length; i++ ) 
    {
      arg_values = arg[i].split("=")
      if( unescape(arg_values[0]) == paramName ) 
      {
         if( USE_UTF8 == 1 && self.decodeURIComponent ) // check if decodeURIComponent() is defined
            ret = decodeURIComponent(arg_values[1]);
         else
            ret = unescape(arg_values[1]);  // IE 5.0 and older does not have decodeURI
         return ret;
      }
    }
    return "";
}

function replaceAll(str,from,to) 
{
    var idx = str.indexOf(from);
    while( idx > -1 ) {
        str = str.replace(from, to); 
        idx = str.indexOf(from);
    }
    return str;
}

// lowercase, remove quotes and accents
function formatChars(str) 
{
    str = str.toLowerCase();
    if( REMOVE_ACCENTS ) 
    {
      var a = "àáâãäåòóôõöèéêëçìíîïùúûüÿñ";
      var b = "aaaaaaoooooeeeeciiiiuuuuyn";
      for( i=0; i<a.length; i++ )
        str = replaceAll( str, a.charAt(i), b.charAt(i) );
    }
    str = replaceAll( str, "'", " " );
    return str;
}

function SortCompare(a, b)
{
  if( a[2] == b[2] )
  {  
    if (a[1] < b[1]) return 1;
    else if (a[1] > b[1]) return -1;
    else return 0;
  }
  else if (a[2] < b[2]) return 1;
    else return -1;
}

function jseSearch( internal )
{
  // get params
  var rootURL = '';
	var SelfURL = document.location.href;
  var paramIndex = SelfURL.indexOf("?");    
  if (paramIndex > -1)
     SelfURL = SelfURL.substr(0, paramIndex);
  paramIndex = SelfURL.indexOf("#");
  if (paramIndex > -1)
    SelfURL = SelfURL.substr(0, paramIndex);        
	if (ONLINE_WEBSITE) 
	{
		paramIndex = SelfURL.lastIndexOf('/');
		if (paramIndex > -1) 
		{
			rootURL = SelfURL.substr(0, paramIndex);
			paramIndex = rootURL.lastIndexOf('/');
			if (paramIndex > -1) {
				rootURL = SelfURL.substr(0, paramIndex+1);
			} else
			  rootURL = '';
		}
	}	
  SelfURL = SelfURL.replace(/\</g, "&lt;");
  SelfURL = SelfURL.replace(/\"/g, "&quot;");

  var query = getParam("jse_query");
  query = query.replace(/[\++]/g, " ");  // replace any '+' with spaces
  query = query.replace(/\</g, "&lt;");
  query = query.replace(/[\"+]/g, " ");

  // display the search form
  var lnktarget = "";
	if( internal == null || internal != 1 )
	{
    document.writeln("<form method=\"get\" action=\"" + SelfURL + "\">");
    document.writeln("<input type=\"text\" name=\"jse_query\" size=\"" + STR_SEARCH_SIZE + "\" value=\"" + query + "\" />");
    document.writeln("<input type=\"submit\" value=\"" + STR_SEARCH_BUTTON + "\" />");
    document.writeln("</form>");
  }	
	else
	{
	 lnktarget = "\" target=\"_blank";
  }
	query = formatChars(query);
  if( query.length == 0 ) return;
  
  var found=0, t=0, k=0, score=0, subscore=0, i=0;
  var keyword = "", tmp = "";
  var searchWords = new Array();

  // split search query by spaces
  searchWords = query.split(" ");
	if( internal == null || internal != 1 ) {
		document.writeln( "" + STR_SEARCH_QUERY_MSG + " : <strong>" +query+"</strong><br>");
  }
  // init result table information
  res_table = new Array(linksCount);
  for( t=0; t<linksCount; t++ )
  {
    res_table[t] = new Array(3);
    res_table[t][0] = 0;  // index
    res_table[t][1] = 0;  // score
    res_table[t][2] = 0;  // words found
    res_table[t][3] = ""; // sublinks (output string)
  }
  var significantwords = 0;
  
  // begin search ...
  for( i=0; i<searchWords.length; i++ )
  {
    keyword = searchWords[i];
    if( keyword.length > MIN_WORD_LEN ) // skip "small" words
	{
	  significantwords++;
	  for(var q=0; q<linksCount; q++ )
	  {
	    t = q;
	    score = 0;
	
	    // search for keywords (an exact word doubles the score)
		  tmp = formatChars(descArray[t]);
	    if( tmp.indexOf(keyword) != -1 ) score++;
	    if( tmp.indexOf(' '+keyword+' ') != -1 ) score+=2;
		  tmp = formatChars(titlesArray[t]);
	  	if( tmp.indexOf(keyword) != -1 ) score++;
		  if( tmp.indexOf(' '+keyword+' ') != -1 ) score+=2;
	    if( namesArray[t].indexOf(keyword) != -1 ) score++;
	    if( namesArray[t].indexOf(' '+keyword+' ') != -1 ) score+=2;
	
		// search for keywords in sublinks (i.e. bookmarks)
	    k = q+1;
		while( k <= linksCount )
		{
			tmp = descArray[k];
			if( tmp == null || tmp.charAt(0) != '&' ) break;
			subscore = 0;
			tmp = formatChars(descArray[k]);
			if( tmp.indexOf(keyword) != -1 ) subscore++;
			if( tmp.indexOf(' '+keyword+' ') != -1 ) subscore+=2;
			tmp = formatChars(titlesArray[k]);
			if( tmp.indexOf(keyword) != -1 ) subscore++;
			if( tmp.indexOf(' '+keyword+' ') != -1 ) subscore+=2;
			if( namesArray[k].indexOf(keyword) != -1 ) subscore++;
			if( namesArray[k].indexOf(' '+keyword+' ') != -1 ) subscore+=2;
			
			if( subscore > 0 )
			{
				if( res_table[t][3].indexOf( "\"" + urlsArray[k] + "\"" ) == -1 )
					res_table[t][3] += "<tr><td width='35'>&nbsp;</td><td><a href=\"" + urlsArray[k] + lnktarget + "\">" + titlesArray[k] + "</a></td></tr>";
//	           		if( B OLD_LINKS )  res_table[t][3] += "<tr><td width='50'>&nbsp</td><td><b><a href='" + urlsArray[k] +"'>" + titlesArray[k] + "</a></b></td></tr>";
				score += subscore;
			}	
			k++;
		}
		q = k-1;
		
	    if( score > 0 )
	    {
	      res_table[t][0] = t;
	      res_table[t][1] += score;
	      res_table[t][2]++;
	      found++;
	    }
	  }
	}
  }
  if( found == 0 ) 
  {
    document.write("<p><b>" + STR_NO_RESULT + "</b></p>");
  } 
  else 
  {
	 // sort by words found and scores
    res_table.sort(SortCompare);	
	
    // display the results
    for( q=0; q<found; q++ )
      if( res_table[q][1] > 0 ) // display only results with a positive score
	  if( !ALLWORDSONLY || (ALLWORDSONLY && res_table[q][2] == significantwords) )
	    {
        t = res_table[q][0];    // get page index
        if( BOLD_LINKS ) {
          document.writeln("<br><b>" + (q+1) + ". <a href=\"" + urlsArray[t] + lnktarget + "\">" + titlesArray[t] + "</a></b>" );
        } else
          document.writeln("<br><b>" + (q+1) + ".</b> <a href=\"" + urlsArray[t] + lnktarget + "\">" + titlesArray[t] + "</a>" );
        if( descArray[t].length > 2 )
          document.writeln("<br>" + descArray[t]);
        if( DISPLAY_SRCH_INFO ) 
		{
			document.write("<br><span style='font-size: 80%; font-style: italic;'>");
			if( !ALLWORDSONLY )
				document.write("" + STR_TERMS + ": " + res_table[q][2] + " - " );
			document.write("" + STR_SCORE + ": " + res_table[q][1] );
			if (ONLINE_WEBSITE) {
			  document.writeln(" - URL: " + rootURL + urlsArray[t].substr(3) + "</span>");
			}	else
			  document.writeln(" - URL: " + urlsArray[t] + "</span>");
      	}
				if( res_table[q][3].length > 0 ) { 
      	  document.writeln( '<table>' + res_table[q][3] + '</table>' );
      	} else document.writeln("<br>");
      }
  }
  document.writeln("<br>");
}

