// ----------------------------------------------------------------------------
// 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("  ",
" deblocage reseau code delais d'obtention varie entre minute jours ouvres tout depend l'operateur marque telephone plus rapides arriver sont ceux samsung longs sony ericsson sous android attention telephones simples cable est souvent moins cher terminal devra etre confie 24h maximum bas formulaire commande ajoutez instructions modele reference indiquee sur l'autocollant dessous batterie numero imei obtenu tapant actuel  ",
"",
"",
"",
"",
"",
" articles stock comme savez lintermediaire97 n'a pratiquement pas travaille surtout pre-commande cependant denichons parfois tres bonnes affaires avant qu'elle fassent l'objet d'une rubrique aujourd'hui montre avons d'immediatement disponible  ",
" saisissez texte paragraphe ici ",
" original apple iphone 3gs 16go noir debloque officiellement tres bon etat avec traces frottement l'arriere ainsi quelques rayures aux angles boite accessoires fournis telephone disponible prix ferme pas d'echange recuperer sur schoelcher contactez moi preference mail via whatsapp garantie mois  ",
" saisissez texte paragraphe ici ",
" original apple iphone 3gs 16go noir debloque officiellement excellent etat micro-rayures discretes l'arriere boite accessoires fournis telephone disponible prix ferme pas d'echange recuperer sur schoelcher contactez moi preference mail via whatsapp garantie mois  ",
" saisissez texte paragraphe ici ",
" questions frequemment posees trouverez egalement nombreuses reponses lisant  ",
" conditions generales vente lisant cette rubrique saurez exactement quoi nous engageons mutuellement teeteev lintermediaire97 rosemont steeve siret 510 148 224 00015 tel 0696 site internet www com ",
" formulaire contact bonjour pouvez joindre telephone 16h00 20h30 digicel 0696 weekend partir 12h30 dehors ces horaires veuillez utiliser autre moyen e-mail sms recois e-mails temps reel sur mon preferez cette methode contacte plus pratique  ",
" iphone noir 16go etat livre avec boite chargeur cable usb kit pieton notice compatible supplementaire protege ecran coller cause d'une coque protection mauvaise qualite telephone presente dos quelques marques rayures partie noire reste bon photos prises maniere accentuer defauts ",
" iphone blanc 3gs 16go bon etat original apple debloque officiellement petites fissures niveau port chargement jack telephone reste boite accessoires fournis disponible prix ferme pas d'echange recuperer sur schoelcher contactez moi preference mail via whatsapp garantie mois ",
" iphone noir 3gs 32go parfait etat excellent debloque apple boite notice accessoires inclus chargeur cable usb extracteur sim ecouteurs neufs garantie mois voir conditions generales vente ");
urlsArray = new Array("../topic/index.html",
"../deblocage/index.html",
"../deblocage/page1.html",
"../deblocage/page2.html",
"../deblocage/page3.html",
"../deblocage/page4.html",
"../deblocage/page5.html",
"../aujourdhui1/index.html",
"../aujourdhui1/index.html",
"../demain/page1.html",
"../demain/page1.html",
"../demain/page2.html",
"../demain/page2.html",
"../faqs/index.html",
"../mapage/index.html",
"../contact/index.html",
"../c902/index.html",
"../iphoneblanc3gs16/index.html",
"../iphonenoir3gs32g/index.html");
titlesArray = new Array(" ",
"Déblocage réseau par code",
"Titre de paragraphe",
"Code déblocage Réseau Samsung",
"Titre de paragraphe",
"Titre de paragraphe",
"Titre de paragraphe",
"Articles en stock",
"Iphone Noir 3GS 32Go",
"iPhone 3GS Noir",
"Titre de paragraphe",
"iPhone Noir 3GS 16Go",
"Titre de paragraphe",
"Questions fréquemment posées",
"Conditions générales de vente",
"Formulaire de contact",
"Iphone Noir 3G 16Go        (état 7,5/10)",
"Iphone blanc 3GS 16Go Bon état",
"Iphone Noir 3GS 32Go parfait état");
descArray = new Array("",
"Le délais d'obtention de votre code varie entre 30 minute et 4 jours ouvrés. Tout dépend de l'opérateur et de la marque du téléphone.. Les plus rapide...",
"&",
"&",
"&",
"&",
"&",
"Comme vous le savez, LINTERMEDIAIRE97 n'a pratiquement pas de stock et travaille surtout en pré-commande.  Cependant, nous dénichons parfois de très b...",
"&",
"&",
"&",
"&",
"&",
"Vous trouverez également de nombreuses réponses à vos questions en lisant le C.G.V.",
"En lisant cette rubrique, vous saurez exactement à quoi nous nous engageons mutuellement.  TeeTeev  LINTERMEDIAIRE97 ROSEMONT Steeve N° SIRET : 510 14...",
"Bonjour, vous pouvez me joindre par téléphone de 16h00 à 20h30  (Digicel 0696 29 39 41) Le weekend, à partir de 12h30  En dehors de ces horaires, veui...",
"Livré avec boîte, chargeur, câble USB, kit piéton. Notice FR, câble usb compatible supplémentaire, protège écran à coller. A cause d'une coque de prot...",
"Original Apple iPhone 3gs 16go blanc débloqué officiellement. Petites fissures niveau port de chargement et jack mais le téléphone reste en bon état. ...",
"Iphone Noir 3GS 32Go en excellent état. Débloqué par Apple. Boîte, notice et accessoires inclus (chargeur, câble usb, extracteur SIM, écouteurs neufs)...");
sublinksArray = new Array(19);
var linksCount = 19;


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>");
}

