// ----------------------------------------------------------------------------
// 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 = "Search results for";
STR_NO_RESULT = "No results found";
STR_SEARCH_BUTTON = "Search";
STR_SCORE = "Score";
STR_TERMS = "Terms";
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= les 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 ",
" par shermin movaffaghi psychologue fapse specialise musicotherapie asmt  ",
" concert musique geneve musiques mondes conferences ",
"  ",
" traditions orales  ",
"  ",
" titre votre album photo page construction ",
"",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
"",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre 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 les poesies rumi hafez melant silencieusement aux chants des instruments nous invitent ainsi lointain voyage prix frs ",
" saisissez texte paragraphe ici ",
" concert live 1997 est une magnifique retrouvaille entre ostad lotfi afsharnia grand joueur ney ces derniers sont accompagnes tombak par talentueux ghavihelm setar omid deuxieme partie solo kamancheh qui interpretation selon tradition ancienne cet instrument prix frs ",
" saisissez texte paragraphe ici ",
" live improvisation concert ostad lotfi and ghavihelm mahour modes dashti splendid moments when mix classical music persian with the repertories soufi mystic price frs ",
" saisissez texte paragraphe ici ",
" the unequalled reference persan ney flute reed osatd kassai offers his magic breath its years fantastic ",
" saisissez texte paragraphe ici ",
" improvisations aux tar setar tombak chant sur les recitations grand poete contemporain sayeh prix frs ",
" saisissez texte paragraphe ici ",
" periodique consacre musique savante persane monde publications shayda les articles est l'erreur lotfi systemes des dasgahs radif traditions vocales chez turkmens interview ghavihelm mystique hajjarian prix frs ",
" saisissez texte paragraphe ici ",
" the tombak drum-chalice with case out wooden drown mulberry tree mahogany creuse mass and single skin played two hands according extremely elaborate digital technique became familiar musicians european music lover this instrument considered specialists one most complex eastern percussion well counted indian price 200 frs ",
" saisissez texte paragraphe ici ",
" tar the was preferred instrument majority large masters iranian erudite music which whole flowering opened out particularly with nineteenth century but does not remain about less very favour nowadays belongs family fights its case resonance double bulge wood mulberry tree and form evokes two hearts joined together points one plays plectre generally made plates brass crimped beeswax pellets extent approximately octaves half all chromatisms eastern fine membrane covers table instruments confers him sound heat color marie well tombak  ",
" saisissez texte paragraphe ici ",
" santour seems that the origin goes with babylonian assyrian and persians acts sitar vital trapezoid metal cords are tended two lines nine small rests normal extent three octaves instrumentalist strikes fine rods drowning whose end cut out allow gripping first fingers each hand other which slightly raised its construction has extraordinary natural resonance  ",
" saisissez texte paragraphe ici ",
" daf est l'instrument sacre des mystiques orientaux par resonance son jeux circulaire relie l'homme danse l'univers  ",
" saisissez texte paragraphe ici ",
" the setar drift one most former families lutte tanbour which finds ancestors pre-islamic iran this instrument besides origin indian sitar plays while passing cords with nail right index effleurant same movement open strings obtain effect pedal its sonority confidential and refined preferred well-read men dervishes ",
" saisissez texte paragraphe ici ",
" instrument invented the slaves private tziganes their traditional percussions cajon was doubtless its beginnings cases intended for gathering fruits fish not having access another thing only domestic materials current generally has element moreover stamp which returns close relation that battery dynamics marie well with music flamenca  ",
" saisissez texte paragraphe ici ",
" les archives jam  ",
" entrez une recherche conference concerts stages sur contenu site jam ",
" liens favoris  ",
"  ",
" clip musique  ",
" titre votre album  ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ",
" saisissez description votre image ici ");
urlsArray = new Array("../topic/index-en.html",
"../mapage1/index-en.html",
"../topic1/index-en.html",
"../coursstagesconfe/index-en.html",
"../mapage/index-en.html",
"../mapage4/index-en.html",
"../topic2/index-en.html",
"../topic2/page1-en.html",
"../topic2/page2-en.html",
"../topic2/page3-en.html",
"../topic2/page4-en.html",
"../topic2/page5-en.html",
"../topic2/page6-en.html",
"../topic2/page7-en.html",
"../topic2/page8-en.html",
"../topic2/page9-en.html",
"../topic2/page10-en.html",
"../topic2/page11-en.html",
"../topic2/page12-en.html",
"../topic2/page13-en.html",
"../topic2/page14-en.html",
"../topic2/page15-en.html",
"../topic2/page16-en.html",
"../topic2/page17-en.html",
"../topic2/page18-en.html",
"../topic2/page19-en.html",
"../topic2/page20-en.html",
"../topic2/page21-en.html",
"../topic2/page22-en.html",
"../topic3/index-en.html",
"../topic3/page1-en.html",
"../topic3/page1-en.html",
"../topic3/page2-en.html",
"../topic3/page2-en.html",
"../topic3/page3-en.html",
"../topic3/page3-en.html",
"../topic3/page4-en.html",
"../topic3/page4-en.html",
"../topic3/page5-en.html",
"../topic3/page5-en.html",
"../topic3/page6-en.html",
"../topic3/page6-en.html",
"../topic3/page7-en.html",
"../topic3/page7-en.html",
"../topic3/page8-en.html",
"../topic3/page8-en.html",
"../topic3/page9-en.html",
"../topic3/page9-en.html",
"../topic3/page10-en.html",
"../topic3/page10-en.html",
"../topic3/page11-en.html",
"../topic3/page11-en.html",
"../topic3/page12-en.html",
"../topic3/page12-en.html",
"../mapage2/index-en.html",
"../mapage3/index-en.html",
"../topic4/index-en.html",
"../lesmusicienspers/index-en.html",
"../mapage5/index-en.html",
"../albumphoto/index-en.html",
"../albumphoto/page2-en.html",
"../albumphoto/page3-en.html",
"../albumphoto/page4-en.html",
"../albumphoto/page5-en.html",
"../albumphoto/page6-en.html",
"../albumphoto/page7-en.html",
"../albumphoto/page8-en.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",
"Persian music lessons",
"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>");
}
