// ----------------------------------------------------------------------------
// Lauyan Software Javascript Search Engine 1.1
//
// 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_SCORE = "Score";
STR_TERMS = "Termes";
STR_SEARCH_SIZE = "20";
MIN_WORD_LEN = 2;
DISPLAY_SRCH_INFO = 1;
USE_UTF8 = 0;
REMOVE_ACCENTS = 1;
BOLD_LINKS = 1;
ONLINE_WEBSITE = 1;
ALLWORDSONLY = 0;
namesArray = new Array(" academie farciennes www academiedefarciennes musique art parles danse parole baltuch david direction agenda farciennes inscription coppens jacky ",
" plan  ",
" direction horaire baltuch david ",
" equipe pedagogique  ",
" fonctionnement  ",
" inscription formulaire ",
"  ",
"  ",
" liens face  ",
" codec xvid  ",
" professeurs annee 2006  ",
" professeurs coppens jacky remacle barbara guilmin stephanie nathalie berkcmans adresse mail  ",
" preparatoire annexes aiseau vendredi 15h30 16h20 ferrer jeudi pont loup lundi 15h20 16h10 presles mercredi 12h20 13h10 formation 17h10 15h10 16h00 13h30 mardi 16h30 17h20 qualifications 18h00 18h10 adulte 19h00 20h40 18h50 20h30 qualification violon mme acke roselies 16h50 adresse mail mady@hotmail fr ",
" piano melle baivy lundi 15h10 18h30 histoire musique 19h20 adresse mail marianne@hotmail fr ",
" atelier declamation melle basta lundi 17h15 18h55 adresse mail antoinette@hotmail fr ",
" guitare bayet mardi 14h10 20h00 vendredi cours complementaires accompagnement 17h30 18h20 ",
" atelier art-dramatique melle berckmans jeudi 17h40 20h10 adresse mail nathalie@hotmail fr ",
" chant mme catalano mercredi 15h30 20h30 adresse mail carmelina@hotmail fr ",
" danse classique barre sol melle dedola lundi 15h30 17h10 mercredi 15h10 16h00 initiation 17h40 f4a 19h20 f4b 21h00 adresse mail elisa@hotmail fr ",
" percussion depuis mardi 14h40 20h30  ",
" preparatoire annexes louat mardi 15h20 16h10 piano melle dewilde 14h30 19h30 adresse mail michele@hotmail fr ",
" preparatoire centre samedi 9h50 10h40 formation 12h20 adresse mail guilmin stephanie@hotmail fr ",
" piano ketelbuters mercredi 13h30 20h10 vendredi 15h00 20h00 jeudi 16h00 21h00 presles adresse mail david@hotmail fr ",
" atelier theatre lucaselli marelle lundi 15h20 17h00 aiseau centre jeudi 15h40 17h20 presles communal mercredi 12h30 14h10 adresse mail damien@hotmail fr ",
" clarinette manderlier mardi 16h00 20h10 saxophone adresse mail eric@hotmail fr ",
" flute mme remacle vendredi 14h30 18h40 adresse mail barbara@hotmail fr ",
" secretariat delhaute nathalie horaire ",
" agenda michael jackson ",
" cours horaire danse formation musicale chant professeurs arts parles ",
"  ",
"  ",
"",
"",
"",
"",
"",
"",
"",
"",
" mediatheque extrait spectacle video jjg coppens  ",
"",
" veuillez attendre quelques instants chargement cette video merci ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
"",
" veuillez attendre quelques instants chargement cette video merci ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
" saisissez texte paragraphe ici ",
" mediatheque extrait spectacle video jjg coppens  ",
"",
" interprete selle alessia duree 6'20 ",
" interprete mollet simon duree 5'29 ",
" interprete mollet simon duree 4'44 ",
" interprete puccini matthieu duree 11'40 ",
" interprete bulla pamela duree 2'09 ",
" interprete pamela anthony bulla duree 3'11 ",
" interprete pamela anthony bulla duree 3'48 ",
" interprete coppens jeremy duree 3'15 ",
"  ",
"  ");
urlsArray = new Array("../topic/index.html",
"../plan/index.html",
"../direction/index.html",
"../equipepedagogiqu/index.html",
"../fonctionnement/index.html",
"../inscription/index.html",
"../audio-video-phot/index.html",
"../administration/index.html",
"../liens/index.html",
"../codec/index.html",
"../prof/index.html",
"../professeurs/index.html",
"../professeurs/page1.html",
"../professeurs/page2.html",
"../professeurs/page3.html",
"../professeurs/page4.html",
"../professeurs/page5.html",
"../professeurs/page6.html",
"../professeurs/page7.html",
"../professeurs/page8.html",
"../professeurs/page9.html",
"../professeurs/page10.html",
"../professeurs/page11.html",
"../professeurs/page12.html",
"../professeurs/page13.html",
"../professeurs/page14.html",
"../secrtariat/index.html",
"../agenda/index.html",
"../cours/index.html",
"../conges/index.html",
"../albumphoto/index.html",
"../albumphoto/page1.html",
"../albumphoto/page2.html",
"../albumphoto/page3.html",
"../albumphoto/page4.html",
"../albumphoto/page5.html",
"../albumphoto/page6.html",
"../albumphoto/page7.html",
"../albumphoto/page8.html",
"../mediatheque/index.html",
"../mediatheque/page1.html",
"../mediatheque/page1.html",
"../mediatheque/page1.html",
"../mediatheque/page1.html",
"../mediatheque/page1.html",
"../mediatheque/page1.html",
"../mediatheque/page1.html",
"../mediatheque/page1.html",
"../mediatheque/page1.html",
"../mediatheque/page2.html",
"../mediatheque/page2.html",
"../mediatheque/page2.html",
"../mediatheque/page2.html",
"../mediatheque/page2.html",
"../mediatheque/page2.html",
"../mediatheque/page2.html",
"../mediatheque/page2.html",
"../mediatheque/page2.html",
"../mediatheque2/index.html",
"../mediatheque2/index.html",
"../mediatheque2/index.html",
"../mediatheque2/index.html",
"../mediatheque2/index.html",
"../mediatheque2/index.html",
"../mediatheque2/index.html",
"../mediatheque2/index.html",
"../mediatheque2/index.html",
"../mediatheque2/index.html",
"../youtube/index.html",
"../document/index.html");
titlesArray = new Array("Académie de Farciennes",
"Académie de Farciennes",
"Académie de Farciennes",
"Equipe pédagogique",
"Fonctionnement",
"Académie de Farciennes",
"Académie de Farciennes",
"Académie de Farciennes",
"Académie de Farciennes",
"Académie de Farciennes",
"Les professeurs  -  Année 2006",
"Académie de Farciennes",
"ACKE Mady(violon et formation musicale)",
"BAIVY Marianne (piano et histoire de la musique)",
"BASTA Antoinette (déclamation et orthophonie)",
"BAYET Michaël (guitare et accompagnement guitare)",
"BERCKMANS Nathalie (art dramatique)",
"CATALANO Carmelina (chant)",
"DEDOLA Elisa (danse classique et barre au sol)",
"DEPUIS Pierre (percussion)",
"DEWILDE Michèle (piano)",
"GUILMIN Stéphanie (formation musicale)",
"KETELBUTERS David (piano)",
"LUCASELLI Damien (art dramatique)",
"MANDERLIER Eric (clarinette et saxophone)",
"REMACLE Barbara (flûte)",
"Académie de Farciennes",
"Académie de Farciennes",
"Académie de Farciennes",
"Académie de Farciennes",
"Académie de Farciennes",
"Fête de l'amitié - 22 mai 2011",
"Fête de l'amitié - 22 mai 2011",
"Fête de l'amitié - 22 mai 2011",
"Fête de l'amitié - 22 mai 2011",
"Fête de l'amitié - 22 mai 2011",
"Fête de l'amitié - 22 mai 2011",
"Fête de l'amitié - 22 mai 2011",
"Fête de l'amitié - 22 mai 2011",
"Académie de Farciennes",
"Spectacle J-J GOLDMAN",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Spectacle de danse",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Académie de Farciennes",
"Les jeunes virtuoses de l'académie de Farciennes",
"Burlesque en six formes de Jacques Stehman",
"Sonate n° 5, 1er mouvement de Ludwig Van BEETHOVEN",
"Danses Roumaines op. 8a de Bela BARTOK",
"Funérailles de Franz LISZT",
"Murmure andalou de Takashi IWAGAMI",
"Andante en mi mineur de Antonio VIVALDI",
"Morenita da Brazil de Giuseppe FARRAUTO",
"Bermudes de J-F JUSKOWIAK  /  O. LACAU",
"Académie de Farciennes",
"Académie de Farciennes");
descArray = new Array("www.academiedefarciennes.be Académie de farciennes Académie de musique, art parlés, danse de Farciennes Académie de Farciennes Musique Farciennes Art ...",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"",
"",
"",
"",
"",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"",
"");
sublinksArray = new Array(70);
var linksCount = 70;


function SubmitSearch(n)
{
	var p = document.getElementsByName("jse_query");
	var idx = n;  if( p < 0) return false;
	if( p && p[idx] && p[idx].value != "" ) {
	if( (p[idx].value).replace(/^\s+|\s+$/g, '') != "" ) {
		p = document.getElementsByName("jse_form");
		if( p && p[idx] )
			p[idx].submit();
		return true;
	  }
	}
	return false;
}
function switchSearchLang(lang,emptycart)
{
	var params = "";
	var currURL = document.location.href;
	var newURL = (currURL.lastIndexOf('_frame/search2') >= 0) ? "search2":"search";
	if( lang != "" )
		newURL += "-"+lang;
	newURL += ".html";
	var paramIndex = currURL.lastIndexOf('?');
	if( paramIndex > -1 )
		newURL += "?" + currURL.substr( paramIndex + 1 );
	if( emptycart && typeof(CleanShopcart) != "undefined" )
		CleanShopcart();
	document.location.href = newURL;
	return 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 getQueryParam()
{
  var query = getParam("jse_query");
  query = query.replace(/[\++]/g, " ");  // replace any '+' with spaces
  query = query.replace(/\</g, "&lt;");
  query = query.replace(/[\"+]/g, " ");
	return query;
}

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 = getQueryParam();

  // 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>");
  }
  */
  if( internal == 1 ) {
	 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( "<span class='wg-paragraph'>" + STR_SEARCH_QUERY_MSG + " : <strong>" +query+"</span></strong><br>");
  }
  // init result table information
  res_table = new Array(linksCount);
  for( t=0; t<linksCount; t++ )
  {
    res_table[t] = new Array(4);
    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 )
			{
				var idx = urlsArray[t].indexOf('@');
				if( idx > 0 ) 
				{
					var lnk = urlsArray[k].substr(0, idx)
					if( res_table[t][3].indexOf( lnk ) == -1 )
						res_table[t][3] += "<tr><td width='35'>&nbsp;</td><td><a href=\"" + urlsArray[k].substr(idx+1) + "\" name=\"" + lnk + "\">" + titlesArray[k] + "</a></td></tr>";
				} else 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 class='wg-paragraph'><b>" + STR_NO_RESULT + "</b></p>");
  } 
  else 
  {
/*	if( ALLWORDSONLY )
	{
		//  if all words only then we recount and filter amoung the results to get the total of found items
		found = 0;
		for( var z=0; z<itemsCount; z++ )
			if( res_table[z][1] > 0 ) // display only results with a positive score
			if( !ALLWORDSONLY || (ALLWORDSONLY && res_table[z][2] == significantwords) )
				found++;
	}
  */
	// sort by words found and scores
    res_table.sort(SortCompare);	
    // display the results
	document.writeln( '<div class="wg-paragraph">' );
    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

		var lnk = urlsArray[t] + lnktarget;
		var idx = urlsArray[t].indexOf('@');
		if( idx > 0 ) 
			lnk = urlsArray[t].substr(idx+1);
			
		if( BOLD_LINKS ) {
		  document.writeln("<br><b>" + (q+1) + ". <a href=\"" + lnk + "\">" + titlesArray[t] + "</a></b>" );
		} else
		  document.writeln("<br><b>" + (q+1) + ".</b> <a href=\"" + lnk + "\">" + 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( urlsArray[t].indexOf('@') > 0 ) {
			  document.writeln(" - URL: 'TOWeb demonstration'</span>");
			} else 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 class="wg-paragraph">' + res_table[q][3] + '</table>' );
      	} else document.writeln("<br>");
      }
 	document.writeln( '</div>' );
  }
  document.writeln("<br>");
}

