// ----------------------------------------------------------------------------
// 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(" guesthouses apartments tokyo japan cheap accommodation cheap cheap cheap accommodationapartments cheap cheap accommodation guesthouse apartment japanguesthouse apartment apartment ",
" guesthouses  ",
" guesthouses apartments tokyo japan cheap accommodation cheap cheap cheap accommodationapartments cheap cheap accommodation  ",
" guesthouses apartments tokyo japan cheap accommodation cheap cheap cheap accommodationapartments cheap cheap accommodation  ",
" apartments green court tokyo provides private convenient locations and outside close various stations well all shopping facilities our come with key money agency fee minimum one month deposit usually required move in ",
" apartment tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo  ",
" apartment tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo  ",
" guesthouses apartments tokyo japan cheap accommodation cheap cheap cheap accommodationapartments cheap cheap accommodation  ",
" apartment tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo  ",
" guesthouse apartment tokyo japan cheap accommodation cheap guesthouses apartments apartments apartments accommodationapartments apartments apartments accommodation  ",
" hattori apartment location shin koenji 5mins foot the station marunouchi line just mins from shinjuku train room 1ldk price 142 000 yen per month elect water included deposit one type fully furnished apt nearby market street many restaurants etc ",
" apartment tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo  ",
" toyotama tei house location nogata mins foot the station seibu-ikebukuro line just from shinjuku train nerima 13mins oedo just10 room 3ldk mansion price 172 000 yen per month deposit one type fully furnished apt nearby market street many restaurants etc ",
" nemoto heights location itabashi-honcho 4mins foot the station toei mita line just mins from ikebukuro train room 1dk price 000 yen per month deposit one type fully furnished apt nearby market street many restaurants etc ",
" apartment tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo  ",
" kanamecho 201 location 10mins foot the station yurakucho line just mins from ikebukuro train 17mins room 1dk rent ЃЏ85 000 month deposit fully refundable utilities not included internet optional but wifi holder can use free with one full prior notice water ",
" minamidai 203 location honan 4mins foot the station marunouchi line just mins from shinjuku train room 1dk price 105 000 yen per month deposit one type fully furnished apt nearby market street many restaurants etc ",
" nakai house location ochiai 3mins foot the station tozai line mins oedo seibu shinjuku 12mins higashi nakano chuo room brand new 1dk 38m square two floor price 120 000 yen per month deposit one type fully furnished apt nearby market street many restaurants etc ",
" court akasaka 201 location nogizaka 6mins foot the station chiyoda line mins mitsuke ginza marunouchi honzomon 15mins roppongi just from omotesando train room 25m square price 120 000 yen per month deposit one type fully furnished apt nearby market street many restaurants etc ",
" guesthouses apartments tokyo japan cheap accommodation cheap cheap cheap accommodationapartments cheap cheap accommodation  ",
" yutaka-so apartment 207 location shin koenji 7mins foot the station marunouchi line just mins from shinjuku train room 1dk price 000 yen per month deposit one type fully furnished apt nearby market street many restaurants etc ",
" apartment tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo  ",
" mta shin koenji 105 location 6mins foot the station marunouchi line just mins from shinjuku train room 1dk price 000 yen per month deposit one type fully furnished apt nearby market street many restaurants etc r ",
" shetowa hiroo102 location hiroo 5mins foot the station hibiya line just mins from roppongi train ebisu 7mins and shibuya room 2ldk 50m2 mansion garden price 190 000 yen per month deposit one type fully furnished apt nearby market street many restaurants etc ",
" okachimachi apartment location 5mins foot the station yamanote line oedo hibiya akihabara and ueno room free-internet price 105 000 yen per month deposit 000yen half type fully furnished apt nearby market street many restaurants etc ",
" apartment tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo  ",
" monarch suginami apartment location honancho and higashi-koenji 8mins foot the station marunouchi line just mins from shinjuku train room price 000 yen per month deposit one type fully furnished apt nearby market street many restaurants etc ",
" hoyoso location nakano sakaue mins foot the station marunouchi line just from shinjuku train also roppongi oedo room 1dk price 115 000 yen per month deposit one type fully furnished apt nearby market street many restaurants etc ",
" apartment tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo  ",
" coppe bianese honancho 803 location 2mins foot the station marunouchi line just mins from shinjuku train room 1dk mansion price 115 000 yen per month deposit one type fully furnished apt nearby market street many restaurants etc ",
" apartment tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo tokyo  ",
" guesthouses apartments tokyo japan cheap accommodation cheap cheap cheap accommodationapartments cheap cheap accommodation  ",
" contact please give some informations that can help find place comfortable for you soon possible info@greencourttokyo com ",
" guesthouses apartments tokyo japan cheap accommodation cheap cheap cheap accommodationapartments cheap cheap accommodation  ",
" data  ",
" data ",
" data ",
" data ",
" data ",
" data ",
" moving service  ",
" guesthouses apartments tokyo japan cheap accommodation cheap cheap cheap accommodationapartments cheap cheap accommodation  ");
urlsArray = new Array("../topic/index.html",
"../groupoftopics1/index.html",
"../topic1/index.html",
"../guesthouses/index.html",
"../groupoftopics/index.html",
"../albumphoto/index.html",
"../albumphoto2/index.html",
"../albumphoto10/index.html",
"../albumphoto1/index.html",
"../albumphoto19/index.html",
"../hattoriapartment/index.html",
"../setagayadaita3dk/index.html",
"../photoalbum6/index.html",
"../nemotoheights/index.html",
"../photoalbum/index.html",
"../kanamecho/index.html",
"../minamidai203/index.html",
"../nakai/index.html",
"../photoalbum5/index.html",
"../albumphoto3/index.html",
"../yutaka-soapartme/index.html",
"../albumphoto4/index.html",
"../photoalbum4/index.html",
"../photoalbum1/index.html",
"../photoalbum3/index.html",
"../ukimafunatohouse/index.html",
"../monarchsuginamia/index.html",
"../hoyoso2f/index.html",
"../tokyuheim1k/index.html",
"../photoalbum2/index.html",
"../shirakabaheights/index.html",
"../map/index.html",
"../mapage/index.html",
"../forsale/index.html",
"../forsale/page1.html",
"../forsale/page2.html",
"../forsale/page3.html",
"../forsale/page4.html",
"../forsale/page5.html",
"../forsale/page6.html",
"../home/index.html",
"../links/index.html");
titlesArray = new Array("guesthouse apartment cheap tokyo japan",
"Guesthouses",
"Green Court Tokyo",
"Green Court Tokyo",
"Apartments",
"Green Court Tokyo",
"Green Court Tokyo",
"Green Court Tokyo",
"Green Court Tokyo",
"Green Court Tokyo",
"Hattori apartment",
"Green Court Tokyo",
"Toyotama Tei House",
"NEMOTO HEIGHTS",
"Green Court Tokyo",
"Kanamecho 201",
"MINAMIDAI 203",
"Nakai House",
"COURT AKASAKA 201",
"Green Court Tokyo",
"Yutaka-so Apartment 207",
"Green Court Tokyo",
"MTA SHIN KOENJI 105",
"SHETOWA HIROO102",
"Okachimachi Apartment",
"Green Court Tokyo",
"Monarch suginami Apartment",
"Hoyoso 2 F",
"Green Court Tokyo",
"COPPE BIANESE HONANCHO 803",
"Green Court Tokyo",
"Green Court Tokyo",
"Green Court Tokyo",
"Green Court Tokyo",
"Accord",
"Accord",
"Accord",
"Accord",
"Accord",
"Accord",
"Moving Service",
"Green Court Tokyo");
descArray = new Array("apartment tokyo japan cheap accommodation guesthouse apartments tokyo japan cheap guesthouses apartments tokyo japan cheap guesthouses apartments toky...",
"",
"guesthouses apartments tokyo japan cheap accommodation guesthouses apartments tokyo japan cheap guesthouses apartments tokyo japan cheap guesthouses a...",
"guesthouses apartments tokyo japan cheap accommodation guesthouses apartments tokyo japan cheap guesthouses apartments tokyo japan cheap guesthouses a...",
"Green Court Tokyo provides private apartments in convenient locations in and outside Tokyo. Close to various stations as well as all shopping faciliti...",
"apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartm...",
"apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartm...",
"guesthouses apartments tokyo japan cheap accommodation guesthouses apartments tokyo japan cheap guesthouses apartments tokyo japan cheap guesthouses a...",
"apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartm...",
"guesthouse apartment tokyo japan cheap accommodation guesthouse apartment tokyo japan cheap guesthous apartments tokyo japan cheap guesthouses apartme...",
"Location: Shin Koenji  , 5mins on foot  to the station (Marunouchi line) just 10 mins. from  Shinjuku by train.  Room:    1LDK or 2K  Price:      142,...",
"apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartm...",
"Location: NOGATA  , 12 mins on foot to the station (Seibu-Ikebukuro line) just 7 mins. from  Shinjuku by train. Location: Nerima  , 13mins on foot to ...",
"Location: Itabashi-Honcho  , 4mins on foot to the station (Toei Mita line) just 13 mins. from Ikebukuro by train.  Room:    1DK  Price:      90,000 ye...",
"apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartm...",
"Location: Kanamecho  , 10mins on foot  to the station (Yurakucho line) just 1 mins. from  ikebukuro by train, or  17mins on foot  to ikebukuro station...",
"Location: Honan  , 4mins on foot  to the station (Marunouchi line) just 10 mins. from  Shinjuku by train.  Room:    1DK  Price:      105,000 yen per m...",
"Location: Ochiai 3mins on foot to the station (Tozai line), Nakai 3 mins on foot to the station (Oedo, Seibu shinjuku line), 12mins on foot to Higashi...",
"Location: Nogizaka6mins on foot to the station (Chiyoda line)  , Akasaka 4 mins on foot to the station (Chiyoda line),Akasaka Mitsuke 4 mins on foot t...",
"guesthouses apartments tokyo japan cheap accommodation guesthouses apartments tokyo japan cheap guesthouses apartments tokyo japan cheap guesthouses a...",
"Location: Shin Koenji  , 7mins on foot  to the station (Marunouchi line) just 10 mins. from  Shinjuku by train.  Room:    1DK  Price:      95,000 yen ...",
"apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartm...",
"Location: Shin Koenji  , 6mins on foot  to the station (Marunouchi line) just 10 mins. from  Shinjuku by train.  Room:    1DK  Price:      95,000 yen ...",
"Location: Hiroo  , 5mins on foot  to the station (Hibiya line) just 5 mins. from  Roppongi by train.  Location: Ebisu  , 7mins on foot  to the station...",
"Location: Okachimachi  , 5mins on foot to the station Yamanote line, Oedo line, Hibiya line 1 station to Akihabara and Ueno  Room:    1K + free-intern...",
"apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartm...",
"Location: Honancho  and Higashi-koenji  , 8mins on foot  to the station (Marunouchi line) just 10 mins. from  Shinjuku by train.  Room:    1K  Price: ...",
"Location: Nakano Sakaue  , 5 mins on foot to the station (Marunouchi line) just 6 mins. from  Shinjuku by train, also 15 mins to Roppongi on Oedo line...",
"apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartm...",
"Location: Honancho  , 2mins on foot  to the station (Marunouchi line) just 10 mins. from  Shinjuku by train.  Room:    1DK mansion  Price:      115,00...",
"apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartment tokyo apartment tokyo,apartm...",
"guesthouses apartments tokyo japan cheap accommodation guesthouses apartments tokyo japan cheap guesthouses apartments tokyo japan cheap guesthouses a...",
"guesthouses apartments tokyo japan cheap accommodation guesthouses apartments tokyo japan cheap guesthouses apartments tokyo japan cheap guesthouses a...",
"guesthouses apartments tokyo japan cheap accommodation guesthouses apartments tokyo japan cheap guesthouses apartments tokyo japan cheap guesthouses a...",
"&",
"&",
"&",
"&",
"&",
"&",
"",
"guesthouses apartments tokyo japan cheap accommodation guesthouses apartments tokyo japan cheap guesthouses apartments tokyo japan cheap guesthouses a...");
sublinksArray = new Array(42);
var linksCount = 42;


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>");
}
