// ----------------------------------------------------------------------------
// Lauyan Software Javascript Search Engine 2.0
//
// This file is the JavaScript search engine for a website created by TOWeb
//
// Copyright (C) LAUYAN SOFTWARE 2006
// web: http://www.lauyan.com
// ----------------------------------------------------------------------------

STR_SEARCH_QUERY_MSG = "Keresés";
STR_NO_RESULT = "A keresett termék vagy kifejezés nem található";
LBL_QUERY_RESULT = "Találat :&nbsp";
LBL_ITREFERENCE  = "Reference";
LBL_ITPRICE = 'Ár';
LBL_PRICEERROR = "Ár hiba";
MIN_WORD_LEN = 2;
DISPLAY_SRCH_INFO = 1;
USE_UTF8 = 0;
REMOVE_ACCENTS = 1;
BOLD_LINKS = 0;
ONLINE_WEBSITE = 1;
ALLWORDSONLY = 0;
SHOWREFERENCES = 0;
BORDERCOLOR = "#C0C0C0";
SORTCOMPARE = 0;
itNamesArray = new Array("11-001 szines kamera sharp ccd 420tvl 24db led idojarasallo femhaz 20m infra latotav zart terben 12m kulteren 1ev garancia ",
"11-002 3'' panasonic ccd dsp szines ipari kamera 480 sor 1ev garancia ",
"11-003 szines kompakt vizallo kulteri infrakamera sharp ccd 420tvsoros 36db infraled 30m infratav varifokalis 4-9mm lencse  ",
"11-004 szines szoftveres day night led kamera sharp ccd 480tvl lux garancia ",
"11-005 3'' panasonic ccd dsp szines 230vac ipari kamera 480 tvl 1ev garancia ",
"11-006 szines ipari kamera sony 480tvl 12v beepitett varifokalis auto irisz 1ev garancia ",
"11-007 szines ipari kamera vizallo kulteri Éjjel-nappali uzemmod 1ev garancia  ",
"11-008 Éjjel-nappali ipari kamera szines 600 sor 12v valos day-night 1ev garancia  ",
"11-009 Éjjel-nappali ipari kamera szines 600 sor 230v valos day-night 1ev garancia  ",
"11-010 100m infralatotav day night 480tv sor lux 230v tap line lock Éjjel-nappali uzemmod kep illusztracio garancia  ",
"11-011 vizallo kulteri varifokalis kamera 3'' sony super had ccd 420tv sor 1ev garancia ",
"11-012 sony szines kamera 3'' superexwave ccd lux 540tv irisz 1ev garancia  ",
"NM-K674 csatornas digitalis multiplexes keprogzito 100fps video audio 1ev garancia ",
"12-002 csatornas keprogzito 100 fps hang taviranyito lan internet megtekinthetoseg 1ev garancia  ",
"12-003 csatornas keprogzito 100 fps hang lan usb taviranyito 1ev garancia interneten elerheto  ",
"12-004 csatornas digitalis asztali keprogzito 200 fps lan internetes hozzaferes 1ev garancia ",
"12-005 csatornas 200fps asztalirogzito lan internetes hozzaferes 1ev garancia ",
"12-006 csatornas dvr ntsc pal mpeg4 tomorites 400fps lan ",
"12-007 csatornas asztali szamitogepbe epitheto pci dvr kartya ntsc pal 25fps lan mozgaserzekeles idozitett felvetel ",
"12-008 csatornas pci csatolos 100fps sebessegu rogzito kartya ",
"12-009 csatornas pci csatolos 240fps sebessegu rogzito kartya  ",
"12-010 enter your paragraph text here ",
"13-001 bnc-utp passziv video jel erositett csatlakozo kamerak videojelenek atalakitasahoz ",
"13-002 enter your paragraph text here ",
"13-003 koaxialis kabel bel- kulterre egyarant ",
"13-004  ",
"13-005 kulteri ftp kabel videojel tovabbitashoz Árnyekolt merevszalas vezetek  ",
"13-006 kulteri ftp cat5e behuzo kabel arnyekolt 4x2 erpar tomor rezvezeto  ",
"13-007 kulteri ftp cat5e lÉgkabel arnyekolt 4x2 erpar tomor rezvezeto vezetoszal  ",
"18-001 dom kamera 3'' panasonic ccd dsp 480 sor garancia ",
"18-002 4''-os szines dome sharp ccd 420 tvl 4lux 1ev garancia ",
"18-003 vandal biztos day night kamera szines 480 sor 12v Éjjel-nappali uzemmod 1ev garancia  ",
"18-004 vandal biztos day night kamera szines 420 tvsor 6mm 12v Éjjel-nappali uzemmod 1ev garancia  ",
"18-005 szines ccd 4'' sharp sony 420 480 lines 4-9mm varifokalis optika beepitett 36db infraled max 30m megvilagitas ejjel  ",
"18-006 sony super had ccd 6mm  ",
"18-007 szines inframegvilagitos dome kamera 3'' sony had ccd infra latotavolsag 480 sor 1ev garancia ",
"18-008 kulteri nagyfelbontasu vandalbiztos professzionalis dom kamera 550tv sor valos 1ev garancia  ",
"18-009 kulteri speed dom kamera 500tv sor 10x motoros zoom valos 1ev garancia  ",
"18-010 kulteri speed dom kamera 480tv sor 27x motoros zoom valos 1ev garancia ",
"20-001 dom kamera 67fokos latoszog 10db led 5-10meter mozgathato wifi kapcsolat garancia  ",
"20-002 4''-os szines ccd fokos latoszog led 15-20meter infratav wifi 1ev garancia  ",
"20-003 4''-os szines ccd ledes kulteri infratav 10-15m fokos latoszog wifi 1ev garancia ",
"20-004 5''-os szines ccd 60fokos latoszog 30db led 20m infratav wifi 1ev garancia  ",
"20-005 valodi day night kamera szines 12v Éjjel-nappali uzemmod 1ev garancia  ");
itUrlsArray = new Array("javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptycatalog/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop1/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop1/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop1/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop1/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop1/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop1/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /emptyeshop1/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /kamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /kamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /kamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /kamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /kamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /kamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /kamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /kamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /kamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /kamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /ipkamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /ipkamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /ipkamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /ipkamerk/ is not available with the TOWeb edition you use.')",
"javascript:alert('TOWeb Demonstration : this result link /ipkamerk/ is not available with the TOWeb edition you use.')");
itTitlesArray = new Array("NM-1044    BR. 9.700 Ft",
"CP6CB18     Br. 13.000 Ft",
"NM-2044      Br. 14.900 Ft",
"K1PC38       Br. 15.500 Ft",
"CP6CB19     Br. 16.490 Ft",
"GBX-SONY     27.400 Ft",
"WPH-Sony   27.400 Ft",
"NM-BM21F   Br.32.490 Ft",
"NM-BM27F    37.490 Ft",
"Amaxs100    50.400 Ft",
"ASMWP5   75.400 Ft",
"SonySSE4     62.238 Ft",
"NM-67N4       Br.37.000Ft",
"NM-Q4npr     Br.38.400 Ft",
"NM-G4pro     Br.38.900 Ft",
"NM-G8pro     Br.64.500 Ft",
"NM-Q8npr     Br.67.900 Ft",
"NM-G16pr     Br.85.500 Ft",
"NM-PCI1044    Br.7.500Ft",
"NM-PCI1204   Br.9.800 Ft",
"NM-PCI2408   Br.19.500 Ft",
"Térfigyelő Pc kártyák rendelésre szintén nagy választékban.",
"UTP-BNC csatlakozó 1490Ft-tól",
"Kültériház 9.900FT-tól",
"Koax kábel 80Ft/m",
"FTP kábel  99Ft/m",
"Kültéri FTP Kábel 110Ft /m",
"NM-KFTPLe Kültéri  164 Ft/m",
"NM-KFTPEU  Kültéri  177 Ft/m",
"NM-K1PC    Br. 8.500 Ft",
"NM-1040   Br. 9.900 Ft",
"NM-1042    11.400 Ft",
"NM-ASM9016    15.900 Ft",
"NM-2040    Br. 16.500 FT",
"NM-ASM930   Br.22.000Ft",
"NM-AV206ZP    Br.37.490 Ft",
"NM-CNB281    Br.59.590 Ft",
"NM-CNBSM20     172.490 Ft",
"NM-CNBS276    202.490 Ft",
"NM-F3040    Br. 34.500 Ft",
"NM-F3043   Br. 37.900 Ft",
"NM-F3044   Br. 38.900 Ft",
"NM-F304   Br. 114.900 Ft",
"NM-CNB3048    141.400 Ft");
itDescArray = new Array("Színes kamera SHARP IR CCD,420TVL,24db LED,időjárásálló fémház, 20m infra látótáv zárt térben. 12m kültéren. 1év garancia",
"1/3'' Panasonic CCD & DSP színes ipari kamera, 480 TV sor, 1év garancia",
"Színes,kompakt,vízálló, kültéri infrakamera 1/4 Sharp CCD, 420Tvsoros, 36db infraled, 30m infratáv, varifokális 4-9mm lencse",
"Színes szoftveres Day&Night IR LED kamera, 1/3 Sharp CCD, 480TVL, színes (0.6 lux), FF (0.3 lux), Szoftveres Day&Night, 1 év garancia",
"1/3'' Panasonic CCD & DSP színes 230VAC ipari kamera, 480 TVL, 1év garancia",
"Színes ipari kamera Sony 480TVL 12V,Beépített varifokális auto irisz, 1év garancia",
"Színes Ipari kamera.Vízálló kültéri IR kamera D&N.Éjjel-nappali üzemmód! 1év garancia",
"Éjjel-nappali ipari kamera SZINES 600 sor, 12V, Valós day-night 1év garancia",
"Éjjel-nappali ipari kamera SZINES 600 sor, 230V, Valós day-night 1év garancia",
"100m infralátótáv,Day&Night, 480TV sor, 0.01 Lux, 230V táp, Line Lock. Éjjel-nappali üzemmód!A kép illusztráció! 1 év garancia",
"Vízálló kültéri varifokális IR kamera.1/3'' SONY Super HAD CCD, 420TV sor, 1év garancia",
"SONY színes kamera 1/3'' IT SuperExwave CCD 0,55 lux(F1,2) 540TV; CCD írisz, 1év garancia",
"4 csatornás digitális multiplexes képrögzítő,100Fps, 4 video, 4 audio, 1év garancia",
"4 csatornás képrögzítő 100 fps 4 hang. Távirányító LAN Internet megtekinthetőség,1év garancia",
"4 csatornás képrögzítő 100 fps 1 hang. LAN, USB, Távirányító! 1év garancia Interneten is elérhető!",
"8 csatornás digitális asztali képrögzítő,200 Fps, Lan,internetes hozzáférés, 1év garancia",
"8 csatornás,200Fps, asztalirögzítő Lan,internetes hozzáférés,1év garancia",
"16 csatornás DVR, NTSC/PAL, MPEG4 tömörítés,400Fps,Lan,",
"4 csatornás asztali számítógépbe építhető PCI DVR kártya,NTSC/PAL,25Fps,Lan, Mozgásérzékelés,időzített felvétel",
"4 csatornás, PCI csatolós, 100Fps sebességű rögzítő kártya",
"8 csatornás, PCI csatolós, 240Fps sebességű rögzítő kártya",
"Enter your paragraph text here",
"BNC-UTP passzív videó jel erősített csatlakozó kamerák videójelének átalakításához.",
"Enter your paragraph text here",
"Koaxiális kábel bel- és kültérre egyaránt",
"",
"Kültéri FTP kábel videójel továbbításhoz. Árnyékolt merevszálas vezeték.",
"Kültéri FTP Cat5E behúzó kábel (árnyékolt 4x2 érpár tömör rézvezető)",
"Kültéri FTP Cat5E LÉGkábel (árnyékolt 4x2 érpár tömör rézvezető+tömör vezetőszál)",
"Dóm kamera, 1/3'' Panasonic CCD,DSP,480 TV sor,     1 év garancia",
"1/4''-os színes D&N dome Sharp CCD .420 TVL, 0,4lux/F2.0,   1év garancia",
"Vandál biztos,Day & Night.KAMERA SZINES 480 Sor 12V.Éjjel-nappali üzemmód! 1év garancia",
"Vandál biztos,Day & Night.KAMERA SZINES 420 TVSor, 6mm 12V. Éjjel-nappali üzemmód! 1év garancia",
"Színes  CCD 1/4'' SHARP/Sony,420/480 TV Lines 4-9mm varifokális optika Beépített 36db infraled, max 30m megvilágítás éjjel.",
"1/3 Sony Super HAD CCD, 6mm IR",
"Színes inframegvilágítós dome kamera, 1/3'' SONY HAD CCD, 30 m infra látótávolság,480 TV sor, 1év garancia",
"Kültéri nagyfelbontású vandálbiztos professzionális IR dóm kamera, 550TV sor, valós D&N, 1év garancia",
"Kültéri speed dóm kamera, 500TV sor, 10x motoros zoom, valós D&N, 1év garancia",
"Kültéri speed dóm kamera, 480TV sor, 27x motoros zoom, valós D&N, 1év garancia",
"Dóm kamera, 1/4,67fokos látószög,10db IR led/5-10méter, Mozgatható, WIFI kapcsolat 1 év garancia",
"1/4''-os színes D&N  CCD, 42 fokos látószög, 24 IR led/15-20méter infratáv, WIFI ,1év garancia",
"1/4''-os színes D&N CCD .24 IR ledes kültéri/Infratáv 10-15m,60 fokos látószög,WiFI,   1év garancia",
"1/2,5''-os színes D&N CCD . 60fokos látószög, 30db IR led 20m infratáv,WIFI   1év garancia",
"Valódi Day & Night.KAMERA SZINES r 12V.Éjjel-nappali üzemmód! 1év garancia");
itImgArray = new Array("../emptycatalog/bv000002.thumb.jpg",
"../emptycatalog/bv000014.thumb.jpg",
"../emptycatalog/bv000020.thumb.jpg",
"../emptycatalog/bv000019.thumb.jpg",
"../emptycatalog/bv000005.thumb.jpg",
"../emptycatalog/bv000006.thumb.jpg",
"../emptycatalog/bv000003.thumb.jpg",
"../emptycatalog/bv000009.thumb.jpg",
"../emptycatalog/bv000010.thumb.jpg",
"../emptycatalog/bv000007.thumb.jpg",
"../emptycatalog/bv000017.thumb.jpg",
"../emptycatalog/bv000012.thumb.jpg",
"../emptyeshop/bv000005.thumb.jpg",
"../emptyeshop/bv000001.thumb.jpg",
"../emptyeshop/bv000003.thumb.jpg",
"../emptyeshop/bv000002.thumb.jpg",
"../emptyeshop/bv000014.thumb.jpg",
"../emptyeshop/bv000006.thumb.jpg",
"../emptyeshop/bv000007.thumb.jpg",
"../emptyeshop/bv000008.thumb.jpg",
"../emptyeshop/bv000009.thumb.jpg",
"../emptyeshop/bv000004.thumb.jpg",
"../emptyeshop1/bv000004.thumb.jpg",
"../emptyeshop1/bv000003.thumb.jpg",
"../emptyeshop1/bv000001.thumb.jpg",
"../emptyeshop1/bv000014.thumb.jpg",
"../emptyeshop1/bv000002.thumb.jpg",
"../emptyeshop1/bv000005.thumb.jpg",
"../emptyeshop1/bv000006.thumb.jpg",
"../kamerk/bv000001.thumb.jpg",
"../kamerk/bv000015.thumb.jpg",
"../kamerk/bv000011.thumb.jpg",
"../kamerk/bv000002.thumb.jpg",
"../kamerk/bv000021.thumb.jpg",
"../kamerk/bv000003.thumb.jpg",
"../kamerk/bv000008.thumb.jpg",
"../kamerk/bv000013.thumb.jpg",
"../kamerk/bv000016.thumb.jpg",
"../kamerk/bv000018.thumb.jpg",
"../ipkamerk/bv000001.thumb.jpg",
"../ipkamerk/bv000015.thumb.jpg",
"../ipkamerk/bv000002.thumb.jpg",
"../ipkamerk/bv000003.thumb.jpg",
"../ipkamerk/bv000011.thumb.jpg");
itRefArray = new Array("11-001",
"11-002",
"11-003",
"11-004",
"11-005",
"11-006",
"11-007",
"11-008",
"11-009",
"11-010",
"11-011",
"11-012",
"NM-K674",
"12-002",
"12-003",
"12-004",
"12-005",
"12-006",
"12-007",
"12-008",
"12-009",
"12-010",
"13-001",
"13-002",
"13-003",
"13-004",
"13-005",
"13-006",
"13-007",
"18-001",
"18-002",
"18-003",
"18-004",
"18-005",
"18-006",
"18-007",
"18-008",
"18-009",
"18-010",
"20-001",
"20-002",
"20-003",
"20-004",
"20-005");
itPricesArray = new Array(0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00,
0.00);
var itemsCount = 44;
var catalogdirs = 0;
var catalognames = 0;

			
function SubmitSearch(n)
{
	var p = document.getElementsByName("jse_query");
	if( p < 0) return false;
	if( p && p[n] && p[n].value != "" ) 
	{
	  if( (p[n].value).replace(/^\s+|\s+$/g, '') != "" ) 
	  {
		var idx = 0;
		p = document.getElementsByName("minprice");
		if( p && p[idx] )
		{
			if( p[idx].value != "" && isNaN(p[idx].value) )
			{
				if( LBL_PRICEERROR != "" )
					alert( LBL_PRICEERROR );
				return false;
			}
		}
		p = document.getElementsByName("maxprice");
		if( p && p[idx] )
		{
			if( p[idx].value != "" && isNaN(p[idx].value) )
			{
				if( LBL_PRICEERROR != "" )
					alert( LBL_PRICEERROR );
				return false;
			}
		}
		p = document.getElementsByName("jse_form");
		if( p && p[n] )
			p[n].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 SortCompare2(a, b)
{
	if( SORTCOMPARE == 1 ) 
	{
	    if (a[3] < b[3]) return 1;
	    else if (a[3] > b[3]) return -1;
	    else return 0;
	}
	else if( SORTCOMPARE == 0 )
	{
	    if (a[3] > b[3]) return 1;
	    else if (a[3] < b[3]) return -1;
	    else return 0;
	}
	return -1;
}

function jseSearch2( 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();
  var sortp = getParam("sort");
  if( sortp == "0" ) {
	SORTCOMPARE = 0;
  } else if( sortp == "1" ) {
	SORTCOMPARE = 1;
  } else if( sortp == "2" )
	SORTCOMPARE = 2;
  var catfilterp = getParam("cat");
  var minPrice = getParam("minprice");
  var maxPrice = getParam("maxprice");
 
  // display the search form
  var lnktarget = "";
	query = formatChars(query);
  if( query.length == 0 ) return;
  
  var found=0, t=0, k=0, score=0, i=0;
  var keyword = "", tmp = "";
  var searchWords = new Array();

  // split search query by spaces
  searchWords = query.split(" ");
  // init result table information
  res_table = new Array(itemsCount);
  for( t=0; t<itemsCount; 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] = 0;  // price
  }

  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<itemsCount; q++ )
	  {
		// catalog filter verification
	    if( catfilterp != "" && catfilterp != "allcat" && itUrlsArray[q].indexOf(catfilterp) == -1 ) 
			continue;
		// min and max price filter
	    if( minPrice > 0 && itPricesArray[q] < minPrice )
			continue;
	    if( maxPrice > 0 && itPricesArray[q] > maxPrice )
			continue;
		// search for keywords (an exact word doubles the score)
		score = 0;
		tmp = formatChars(itDescArray[q]);
	    if( tmp.indexOf(keyword) != -1 ) score++;
	    if( tmp.indexOf(' '+keyword+' ') != -1 ) score+=2;
		  tmp = formatChars(itTitlesArray[q]);
	  	if( tmp.indexOf(keyword) != -1 ) score++;
		  if( tmp.indexOf(' '+keyword+' ') != -1 ) score+=2;
		  tmp = formatChars(itNamesArray[q]);
	    if( tmp.indexOf(keyword) != -1 ) score++;
	    if( tmp.indexOf(' '+keyword+' ') != -1 ) score+=2;
			
	    if( score > 0 ) // && itPricesArray[q] > 0 )  // add this test in order not to display 0.00 prices 
	    {
		  if( res_table[q][1] <= 0 ) 
			found++;	// increment only if not already found with a previous keyword
	      res_table[q][0] = q;
	      res_table[q][1] = 1; // itPricesArray[q];
	      res_table[q][2]++;
	      res_table[q][3] = itPricesArray[q];
	    }
	  }
	}
  }
  if( found == 0 ) {
    document.write("<br><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++;
	}
	if( internal == null || internal != 1 ) {
		document.writeln( "<span class='wg-paragraph'>" + found + " " + LBL_QUERY_RESULT + "<strong>" +query+"</strong></span>" );
	}
	// sort by words found and scores
	if( SORTCOMPARE >= 0 && SORTCOMPARE <= 1 )
		res_table.sort(SortCompare2);	
    // display the results
	document.writeln("<table border='1' class='wg-paragraph' bordercolor='"+BORDERCOLOR+"' style='border-collapse:collapse;margin:4px;' cellspacing='2' cellpadding='2' >");

	for( var q=0; q<itemsCount; 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
		document.writeln("<tr valign='top'><td>");
		if( itImgArray[t] != "" ) {
			document.writeln("<a href=\"" + itUrlsArray[t] + lnktarget + "\">" + "<img src='"+itImgArray[t]+"' border='0' width=\"48\" height=\"48\" /></a>" );
		}
		document.writeln("</td><td>");
		if( 1 ) { //BOLD_LINKS ) {
          document.writeln("<b><a href=\"" + itUrlsArray[t] + lnktarget + "\">" + itTitlesArray[t] + "</a></b><br>" );
        } else
          document.writeln("<a href=\"" + itUrlsArray[t] + lnktarget + "\">" + itTitlesArray[t] + "</a><br>" );
		if( SHOWREFERENCES && itRefArray[t] != "" ) {
			var ref = itRefArray[t].split(' ');
			if( ref && ref[0] != "" ) 
				document.writeln( LBL_ITREFERENCE+" : "+ref[0]+"<br>" );
		}
        if( itDescArray[t].length > 2 )
			document.writeln( itDescArray[t]);
		document.writeln("</td><td nowrap>");
		if( itPricesArray[t] != ""  && itPricesArray[t] > 0 )
			document.writeln( LBL_ITPRICE+"<br><b>"+AddMonetarySymbol(moneyFormat(itPricesArray[t]))+"</b>" );
		else
			document.writeln( "&nbsp;" );
		document.writeln("</td></tr>");
      }
	}
	document.writeln("</table>");			
  }
  document.writeln("<br>");
}

