// ----------------------------------------------------------------------------
// 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(" <meta name='description' lang='fr' content= traditions orales musiques musicotherapie traditionnelles enseignement concert spectacles name='keywords' musicotherapies music therapy perse inde flamenco initiation musicale psychologie tar setar kamancheh sitar guitare violon zarb derbouka tabla name='author' shermin movaffaghi name='identifier-url' http musiques-therapies-traditions com name='revisit-after' 10 ",
" shermin movaffaghi psychologue fapse specialise musicotherapie asmt  ",
" concert musique geneve musiques mondes conferences ",
"  ",
" traditions orales  ",
"  ",
" titre album photo page construction ",
"",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
"",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" video livres instruments  ",
" dernier disque grand maitre ostad lotfi ghavihelm cet enregistrement live setar kamancheh est chef-d'oeuvre l'art l'improvisation persane poesies rumi hafez melant silencieusement aux chants instruments invitent ainsi lointain voyage prix frs ",
" saisissez texte paragraphe ici ",
" concert live 1997 est magnifique retrouvaille entre ostad lotfi afsharnia grand joueur ney ces derniers sont accompagnes tombak talentueux ghavihelm setar omid deuxieme partie solo kamancheh interpretation selon tradition ancienne cet instrument prix frs ",
" saisissez texte paragraphe ici ",
" improvisation concert live ostad lotfi ghavihelm modes mahour dashti magnifiques instants melent musique classique persane aux repertoires soufi mystique prix frs ",
" saisissez texte paragraphe ici ",
" reference inegalee ney persan flute roseau osatd kassai offre son souffle magique dans ses ans incontournable ",
" saisissez texte paragraphe ici ",
" improvisations aux tar setar tombak chant sur recitations grand poete contemporain sayeh prix frs ",
" saisissez texte paragraphe ici ",
" periodique consacre musique savante persane monde publications shayda articles est l'erreur lotfi systemes dasgahs radif traditions vocales chez turkmens interview ghavihelm mystique hajjarian prix frs ",
" saisissez texte paragraphe ici ",
" tombak tambour-calice caisse bois noyer murier acajou creuse dans masse unique peau joue avec deux mains suivant technique digitale extremement elaboree est devenu familier aux musiciens melomane europeen cet instrument considere specialistes comme plus complexe percussion orientale meme titre tabla indien prix 200 frs ",
" saisissez texte paragraphe ici ",
" tar fut l'instrument prefere plupart grands maitres musique savante iranienne dont toute floraison s'est epanouie particulierement dix-neuvieme siecle n'en demeure pas moins tres faveur nos jours appartient famille luttes caisse resonance double renflement est bois murier forme evoque deux coeurs reunis pointes joue avec plectre fait generalement d'une lamelles laiton serties dans boulettes cire d'abeille l'etendue d'environ octaves demie tous chromatismes orientale fine membrane recouvre table instruments lui confere chaude couleur sonore marie bien tombak ",
" saisissez texte paragraphe ici ",
" santour semble l'origine remonte babyloniens assyriens aux perses s'agit d'une sitar trapeze vital cordes metalliques sont tendus sur deux rangees neuf petits chevalets l'etendue normale est trois octaves l'instrumentaliste frappe avec fines baguettes noyer dont extremite decoupee maniere permettre prehension premiers doigts chaque main l'autre legerement relevee construction extraordinaire resonance naturelle  ",
" saisissez texte paragraphe ici ",
" daf est l'instrument sacre mystiques orientaux resonance son jeux circulaire relie l'homme danse l'univers  ",
" saisissez texte paragraphe ici ",
" setar derive l'une plus anciennes familles lutte tanbour dont trouve ancetres dans l'iran pre-islamique cet instrument est d'ailleurs l'origine sitar indien joue passant cordes avec l'ongle l'index droit effleurant meme mouvement vide obtenir effet pedale sonorite confidentielle raffine l'instrument prefere lettres derviches ",
" saisissez texte paragraphe ici ",
" instrument invente esclaves tsiganes prives leurs percussions traditionnelles cajon fut tres certainement ses debuts caisses destinees cueillette fruits poisson n'ayant pas acces autre chose materiaux domestiques actuel possede generalement element plus timbre rend son proche celui d'une batterie dynamique marie bien avec musique flamenca  ",
" saisissez texte paragraphe ici ",
" archives jam  ",
" entrez recherche conference concerts stages sur contenu site jam ",
" liens favoris  ",
"  ",
" clip musique  ",
" titre album  ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ",
" saisissez description image ici ");
urlsArray = new Array("../topic/index.html",
"../mapage1/index.html",
"../topic1/index.html",
"../coursstagesconfe/index.html",
"../mapage/index.html",
"../mapage4/index.html",
"../topic2/index.html",
"../topic2/page1.html",
"../topic2/page2.html",
"../topic2/page3.html",
"../topic2/page4.html",
"../topic2/page5.html",
"../topic2/page6.html",
"../topic2/page7.html",
"../topic2/page8.html",
"../topic2/page9.html",
"../topic2/page10.html",
"../topic2/page11.html",
"../topic2/page12.html",
"../topic2/page13.html",
"../topic2/page14.html",
"../topic2/page15.html",
"../topic2/page16.html",
"../topic2/page17.html",
"../topic2/page18.html",
"../topic2/page19.html",
"../topic2/page20.html",
"../topic2/page21.html",
"../topic2/page22.html",
"../topic3/index.html",
"../topic3/page1.html",
"../topic3/page1.html",
"../topic3/page2.html",
"../topic3/page2.html",
"../topic3/page3.html",
"../topic3/page3.html",
"../topic3/page4.html",
"../topic3/page4.html",
"../topic3/page5.html",
"../topic3/page5.html",
"../topic3/page6.html",
"../topic3/page6.html",
"../topic3/page7.html",
"../topic3/page7.html",
"../topic3/page8.html",
"../topic3/page8.html",
"../topic3/page9.html",
"../topic3/page9.html",
"../topic3/page10.html",
"../topic3/page10.html",
"../topic3/page11.html",
"../topic3/page11.html",
"../topic3/page12.html",
"../topic3/page12.html",
"../mapage2/index.html",
"../mapage3/index.html",
"../topic4/index.html",
"../lesmusicienspers/index.html",
"../mapage5/index.html",
"../albumphoto/index.html",
"../albumphoto/page2.html",
"../albumphoto/page3.html",
"../albumphoto/page4.html",
"../albumphoto/page5.html",
"../albumphoto/page6.html",
"../albumphoto/page7.html",
"../albumphoto/page8.html");
titlesArray = new Array("musicotherapie Geneve, centre des musiques du monde",
"www.musiques-therapies-traditions.com",
"www.musiques-therapies-traditions.com",
"www.musiques-therapies-traditions.com",
"Traditions Orales",
"www.musiques-therapies-traditions.com",
"Titre de votre album photo",
"Jam musical du XIXème",
"Agha Hoseingholi , joueur de tar",
"Darvish Khan, tar et setar",
"Ghamar, grande chanteuse de la tradition persane",
"Ostad Jallil Shahnaz, tar",
"Ostad h. Tehrani, tombak",
"Ostad DjamchidChemirani(tombak)",
"Ostad Kassai, ney",
"Ostad Saba, setar et violon",
"M.R Lotfi,  tar, setar et kamancheh",
"Tar de Yahya, Luthiers du 19ème",
"Ravi Shankar, joueur de sitar",
"Ostad Hormozi, tar et setar",
"Ostad Kamalian, luthier (setar)",
"Ostad Bahari, Joueur de Kamncheh",
"Talai et Sarvestani, tar setar, chant",
"Musiciens ghadjars",
"Ostad Navai, ney",
"Paco de Lucia, joueur de guitare flamenca",
"Nusrat Fatheh Ali Khan, grand chanteur de la tradition pakistanaise",
"instruments persan",
"tombeau de Hafez, poète du 14ème",
"CD, Vidéo, Livres, Instruments,...",
"Silencieusement, setar, kamancheh, tombak",
"Titre de paragraphe",
"Concert live musique persane",
"Titre de paragraphe",
"Mystery of Love, chant, tar, setar, tombak et daf",
"Titre de paragraphe",
"Ostad Kassai, le ney",
"Titre de paragraphe",
"Vidéo du Concert de Köln",
"Titre de paragraphe",
"Livre: Ketabe sale Shayda",
"Titre de paragraphe",
"percussion persane, Tombak",
"Titre de paragraphe",
"Tar",
"Titre de paragraphe",
"Santour",
"Titre de paragraphe",
"Daf, percussion soufie",
"Titre de paragraphe",
"Le Setar",
"Titre de paragraphe",
"Cajon",
"Titre de paragraphe",
"Les archives de JAM",
"www.musiques-therapies-traditions.com",
"Liens favoris",
"www.musiques-therapies-traditions.com",
"Clip de musique",
"Titre de votre album",
"azer_prog_2.jpg",
"azer_prog_3.jpg",
"Titre de paragraphe",
"azer_prog_6.jpg",
"azer_prog_7.jpg",
"azer_prog_8.jpg",
"azer_prog_9.jpg");
descArray = new Array("musiques traditionelles iran, inde, flamenco, arabe musicothérapie",
"musicotherapeute geneve shermin movaffaghi psychologue",
"",
"",
"",
"",
"page en construction",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"&",
"",
"Entrez une recherche ( CD, conférence, concerts, stages,...) sur le contenu du site de JAM:  %TW-SEARCH%",
"",
"",
"",
"",
"&",
"&",
"&",
"&",
"&",
"&",
"&");
sublinksArray = new Array(67);
var linksCount = 67;


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>");
}
