// ----------------------------------------------------------------------------
// 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 = 0;
ONLINE_WEBSITE = 1;
ALLWORDSONLY = 0;
namesArray = new Array(" allomonsite propose ses services creer espace sur internet  ",
" exemple sites demonstration themes creation site personnel professionnel presentation creer web creer son blog blog site internet internet faire fait faire web weblog album photo photos albums retouche image debutant association entreprise particulier expert unique original hebergement commerce e-commerce panier commande publier ligne online fabriquer ecommerce vendre catalogue boutique virtuelle vente distance associatif collectivite commite programmer soi-meme appareil apn numerique page perso telecharger essai gratuit concevoir partager tout seul moi meme contenu effets graphiques bouton menu banniere ",
" prorata pas frais caches periode facture modulaire creation site internet conception creer web dynamique hebergement referencement moteurs google tous constructeur inplace cms facile presque gratuit peu cher sit wib creez cree facilement positionnement boutique ligne paiement securise souple word dreamweaver golive frontpage paris outil e-commerce artisan pme pmi association mariage album photo webagency agence developpement weeb faire construire page perso curiculum familial famille entreprise auto-gestion modele graphique espace prive blog forum livre d'or ",
" site internet html banniere compteur visites cgi javascripts client ftp tutorial gif referencement moteur recherche augmenter son traffic hebergement ecommerce boutique ligne cercle nom domaine creation gratuit webmaster dossiers ",
" pourquoi avoir site e-commerce devrais-je afin montrer l'importance l'impact sites aujourd'hui propose consulter articles recents sur sujet pourrez ainsi forger propre opinion ",
" guide e-commerce  ",
" vendre sur site e-commerce  ",
" achat sur site e-commerce  ",
"  ",
"  ",
"  ",
"  ",
" 1and1  ",
" fiche technique disque dur externe 320 verbatim alu  ",
" contactez l'equipe allomonsite com  ",
" pack site vitrine  ",
" allomonsite com mentions legales  ",
" notre facebook  ",
" comment internautes ont-ils trouve notre site mois-ci  ",
" plan site  ",
" pack site vitrine location  ");
urlsArray = new Array("../accueil/creation-site-web.html",
"../exemples-de-sites-realises/site-internet-et-site-e-commerce.html",
"../faq/index.html",
"../pourquoi-avoir-un-site-vitrine/site-internet.html",
"../pourquoi-avoir-un-site-e-commerce/ecommerce.html",
"../guide-du-e-commerce/index.html",
"../vendre/index.html",
"../achat/index.html",
"../e-mailling/index.html",
"../referencement/index.html",
"../siteweb/index.html",
"../logo/index.html",
"../1and1/index.html",
"../parrainage-pour-la/creation-site-vitrine.html",
"../contact-agence-web-idf/allomonsite.html",
"../pack-s-site-internet-vitrine/index.html",
"../mentions-legales/index.html",
"../facebook/index.html",
"../comment-les-internautes-ont-ils-trouve-notre-site-ce-mois-ci/mots-cles.html",
"../site-map/plan-du-site.html",
"../pack-s-site-vitrine-location/site-internet.html");
titlesArray = new Array("Agence web Paris ,création site internet sur IDF Val D'oise Ile de France création site web. site e-commerce webmaster et hébergement",
"Exemples de sites web réalisés, site vitrine et e-commerce",
"Vos questions sur la creation site internet et marketing internet",
"Pourquoi avoir un site web avec AlloMonSite.com ? 8 raisons d'avoir un site internet pro",
"Pourquoi avoir un site E-commerce ?",
"Guide pour vendre et acheté en toute sécurité",
"Vendre avec un site web E-commerce",
"Acheter  en toute sécurité des produits sur des sites web E-commerce",
"Conception E-mailling pour les secteur BtoB",
"Solution de référencement pour votre site Internet naturel ou adword",
"Création de sites internet à la carte selon vos besoins",
"Création de logo personnalisée à la carte",
"1and1",
"Gagnez un disque dur d'une valeur de 69,90€ si vous connaissez une personnes qui souhaite avoir un site web",
"Contactez notre agence web IDF Ile de France Val D'oise",
"Création d'un site internet vitrine à partir 999€",
"AlloMonSite.com Mentions légales Agence web IDF",
"Notre Facebook",
"AlloMonSite.com Comment les internautes ont-ils trouvé notre site ce mois-ci ?",
"Plan du site",
"Création d'un site internet vitrine à partir 199€ +35 € mois");
descArray = new Array("Spécialiste de la création de site Internet e-commerce ou éditorial, AlloMonSite.com propose une solution complète incluant le web design, l'hébergeme...",
"Voici quelques sites Web que j'ai réaliser pour des particuliers et entreprises.",
"Site web réalisé pour des sociétés qui souhaitait avoir la capacité de vendre sur le Web et d'augmenter la visibilité de son entreprise grace a l'intè...",
"Creation de site internet pour les professionnels, artisans, pme, professions liberales : javascripts, scripts php, dhtml, images, kits design, compte...",
"pourquoi avoir un Site web E-commerce nous essayons de répondre à cette question avec des exemples concrets.",
"sur cette page nous essayons de donner des conseils pratiques pour vendre et acheter sur Internet.",
"plusieurs astuces pour vendre dans les meilleures conditions avec un site e-commerce",
"Sur cette page nous allons apportaient des conseils pour acheter en toute sérénité, et surtout éviter les mauvaises surprises",
"de la récolte des e-mails pour une base solide jusqu'à l'envoi de nos serveurs SMTP en passant par la création du mail, nous apportons une solution co...",
"",
"Nous sommes là pour apporter des solutions à vos problèmes de présence sur Internet",
"",
"",
"Gagnez un disque dur d'une valeur de 69,90 si une personnes qui souhaite avoir un site web",
"",
"",
"Mentions légales d'allomonsite.com Global SSII 95440 Ecouen",
"",
"",
"",
"");
sublinksArray = new Array(21);
var linksCount = 21;


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>");
}
