//‘S‘Ì•Ï�”�Fƒy�[ƒWƒ“ƒO‚·‚é‘Î�Û
var paging = new showPages("paging");

/**
 * ŒŸ�õ‰æ–Ê‚Ìƒ�ƒCƒ“ŠÖ�”
 */
function searchBooks()
{
	try {
		var searchWords = getKeyWords();
		var searchBookName = get_key_from_url()["bookname"];
		var searchRange = get_key_from_url()["fromSeachResultPage"];
		
		// ŒŸ�õƒ��[ƒh•Ï�”‚ÌŽæ“¾
		var w = window.location.search.substring(0,5);
		
		//ŒŸ�õƒ��[ƒh‚ÆŒŸ�õ‘Î�Û•ª�û‚ðŠù‚É•\Ž¦‚·‚é�B
		if (w == "?word")
		{
			var wordDisplay = get_key_from_url()["word"];
			if (wordDisplay == null || typeof(wordDisplay) == "undefined") 
			{
				wordDisplay = "";
			}
			document.getElementById("seek").value = wordDisplay;
		}
		else
		{
			var seekDisplay = get_key_from_url()["seek"];
			if (seekDisplay == null || typeof(seekDisplay) == "undefined") 
			{
				seekDisplay = "";
			}
			document.getElementById("seek").value = seekDisplay;
		}
		//ƒ}ƒjƒ…ƒAƒ‹ˆê——‚ ‚é�ê�‡�A•ª�ûƒvƒ‹ƒ_ƒEƒ“‚ð•\Ž¦‚·‚é�B
		
		displayBooks();
		for (i = 0; i < document.getElementById("selectbook").options.length; i++)
		{
			if ((document.getElementById("selectbook").options[i].value == searchBookName) && (searchRange == 1))
			{
				document.getElementById("selectbook").options[i].selected = "selected";
				break;
			}
		}
		
		//ŒŸ�õƒ��[ƒh‚ð�³‹K‰»‚·‚é�B
		var regSearchWords = new Array();
		var noRegSearchWords = new Array();
		for (y = 0; y < searchWords.length; y++)
		{
			
			var tmp = searchWords[y].toLowerCase();
			tmp =  removeSpace(tmp);
			// ‹L�†‚Ì�ˆ—�
			tmp = dealOtherLanguageMark(tmp);
			
			if (tmp.length > 0) 
			{
				regSearchWords[regSearchWords.length] = tmp;
				noRegSearchWords[noRegSearchWords.length] = searchWords[y];
			}
		}
		//ŒŸ�õƒ��[ƒh‚ª4ƒ��[ƒhˆÈ�ã�A‹ó”’�A‚Ü‚½‚ÍƒXƒy�[ƒX‚Ì‚Ý‚Ì�ê�‡�AƒGƒ‰�[‚ð•\Ž¦‚·‚é�B
		if (regSearchWords.length >= 4 || regSearchWords.length == 0)
		{
			document.getElementById("errorMessage").style.display = "block";
			var innerHtml = '';
			if (regSearchWords.length >= 4)
			{
				var messages = "Использовано слишком много ключевых слов.\nПоиск производится с помощью 3 или менее слов.";
				var messArray = messages.split("\n");
				for (i = 0; i < messArray.length; i++)
				{
					innerHtml += '<p>' + escapeHTML(messArray[i]) + '</p>';
				}
			}
			else  if (regSearchWords.length == 0 && document.getElementById("seek").value.length != 0) 
			{
				var messages = "Введите ключевое слово для поиска.";
				var messArray = messages.split("\n");
				for (i = 0; i < messArray.length; i++)
				{
					innerHtml += '<p>' + escapeHTML(messArray[i]) + '</p>';
				}
				
			}
			else if (regSearchWords.length == 0 && document.getElementById("seek").value.length == 0) 
			{
				var messages = "Введите ключевое слово для поиска.";
				var messArray = messages.split("\n");
				for (i = 0; i < messArray.length; i++)
				{
					innerHtml += '<p>' + escapeHTML(messArray[i]) + '</p>';
				}
			}
			document.getElementById("errorMessage").innerHTML = innerHtml;
			document.getElementById("searchResultText").style.visibility = "hidden";
			return;
		}
		//ŠÖ˜AŒê�E—Þ‹`Œê‚Ì•\Ž¦(ŒŸ�õƒ��[ƒh‚ª1‚Â‚Ì�ê�‡‚Ì‚Ý•\Ž¦‚·‚é)
		//ŠÖ˜AŒê�E—Þ‹`Œê‚ÌƒL�[‚Í�³‹K‰»‚³‚ê‚Ä‚¢‚é�B
		if (regSearchWords.length ==1 && regSearchWords[0].length != 0) 
		{
			// ŒŸ�õ‰æ–Ê‚©‚çŒŸ�õ‚·‚é�ê�‡
			if (searchRange == 1)
			{
				relatedAndSynonym(regSearchWords[0], searchBookName, searchRange, noRegSearchWords[0]);
			} 
			// ŒŸ�õ‰æ–ÊˆÈŠO‚Ì�ê�‡‚Í‘S•ª�û‚ÌŒŸ�õ‚É‚È‚é
			else 
			{
				relatedAndSynonym(regSearchWords[0], "", searchRange, noRegSearchWords[0]);
			}
		}
		//ŒŸ�õƒ��[ƒh‚ª•¡�”‚Ì�ê�‡•\Ž¦‚µ‚È‚¢
		else if (regSearchWords.length > 1)
		{
			document.getElementById("relatedAndSynonym").style.display = "none";
		}
		//ŒŸ�õŒ‹‰Ê‚ðŽæ“¾
		var searchresult = new Array();
		// ŒŸ�õ‰æ–Ê‚©‚çŒŸ�õ‚·‚é�ê�‡
		if (searchRange == 1)
		{
			searchresult = search(regSearchWords, searchBookName);
		} 
		// ŒŸ�õ‰æ–ÊˆÈŠO‚Ì�ê�‡‚Í‘S•ª�û‚ÌŒŸ�õ‚É‚È‚é
		else 
		{
			searchresult = search(regSearchWords, "");
		}
		//ŒŸ�õŒ‹‰ÊŒ��”‚Ì•\Ž¦
		document.getElementById("pageCount").innerHTML = searchresult.length;
		//ƒGƒ‰�[ƒ�ƒbƒZ�[ƒW‚Ì•\Ž¦�E”ñ•\Ž¦:�Å‘åŒ��”ˆÈ�ãˆ½‚¢‚Í0Œ�‚Ì�ê�‡ƒGƒ‰�[‚ð•\Ž¦‚·‚é
		if ((searchresult.length == 0) || (searchresult.length == 200 && overMaxCountFlag))
		{
			document.getElementById("errorMessage").style.display = "block";
			var innerHtml = '';
			if (searchresult.length == 0)
			{
				var messages = "Не было найдено ни одной страницы, содержащей ключевое слово.";
				var messArray = messages.split("\n");
				for (i = 0; i < messArray.length; i++)
				{
					innerHtml += '<p>' + escapeHTML(messArray[i]) + '</p>';
				}
				document.getElementById("errorMessage").innerHTML = innerHtml;
				return;
			}
			else if (searchresult.length == 200 && overMaxCountFlag) 
			{
				var messages = "Найдено более % результатов.\nПоказано % самых значимых результатов.\nВведите дополнительные ключевые слова или задайте поиск с другим ключевым словом, чтобы сузить область поиска.";
				var re = new RegExp("%", "g");
				messages = messages.replace(re, "200");
				var messArray = messages.split("\n");
				for (i = 0; i < messArray.length; i++)
				{
					innerHtml += '<p>' + escapeHTML(messArray[i]) + '</p>';
				}
				document.getElementById("errorMessage").innerHTML = innerHtml;
			}
		}
		else
		{
			document.getElementById("errorMessage").style.display = "none";
		}
		//Œ‹‰Ê‚ðƒ\�[ƒg‚·‚é�B
		searchresult = sortResult(searchresult);
		//—v–ñ‚ðŽæ“¾‚·‚é
		var summarys = getTextSummary(searchresult, regSearchWords, noRegSearchWords);
		//ŒŸ�õŒ‹‰Ê•\Ž¦
		paging.pageCount = Math.ceil(searchresult.length / 10);
		paging.showpage = 5;
		paging.searchResult = searchresult;
		paging.summarys = summarys;
		paging.printHtml();
		//ƒnƒCƒ‰ƒCƒg•\Ž¦
		change();
	} catch (error) {
	} finally {
		adjust();
	}
}
/*
* adjust the width of the select box
*/
function adjust() {

    var tmp_s = document.getElementById("selectbook");
    setTimeout(function(){
	var m = Math.min($(tmp_s).innerWidth(), 395);
	$(tmp_s).width(m + 'px').css({"box-sizing": "content-box"}); // need content-box for Safari
    }, 0 * 1000); // need setTimeout for IE6.

	return;
}

/**
 * ƒ}ƒjƒ…ƒAƒ‹ˆê——‚ ‚é�ê�‡�A•ª�ûƒvƒ‹ƒ_ƒEƒ“‚ð•\Ž¦‚·‚é�B
 *books.length
 */
function displayBooks()
{
	document.getElementById("selectbook").options[0] = new Option('Все руководства', '');
	document.getElementById("selectbook").options[0].selected = "selected";
	for (var i = 0; i < books.length; i++)
	{
		document.getElementById("selectbook").options[i + 1] = new Option(books[i].bookname, books[i].bookFolderName);
	}
}
/**
 * ŠÖ˜AŒê�E—Þ‹`Œê‚Ì•\Ž¦(ŒŸ�õƒ��[ƒh‚ª1‚Â‚Ì�ê�‡‚Ì‚Ý•\Ž¦‚·‚é)
 */
function relatedAndSynonym(searchWord, searchBookName, searchRange, noRegSearchWord)
{
	var relatedWord = searchRelatedWord(searchWord, searchBookName);
	var synonym = searchSynonym(searchWord, searchBookName);
	if (relatedWord.length > 0 || synonym.length > 0)
	{
		document.getElementById("relatedAndSynonym").style.display = "block";
	}
	else if(relatedWord.length == 0 && synonym.length == 0)
	{
		document.getElementById("relatedAndSynonym").style.display = "none";
	}
	var bannerInnerHTML = "";
	//ŠÖ˜AŒê‚Ì•\Ž¦
	if (synonym.length > 0)
	{
		bannerInnerHTML += '<dl class="synonym"><dt>';
		bannerInnerHTML += escapeHTML('Поиск с похожим словом:');
		bannerInnerHTML += '</dt>';
		for (i = 0; i < synonym.length; i++)
		{
			bannerInnerHTML += '<dd><a href="';
			if (searchRange == 1) 
			{
				bannerInnerHTML += "search_results.htm?seek=" + escape(synonym[i]) + "&bookname=" + escape(searchBookName) + "&fromSeachResultPage=1";
			}
			else
			{
				bannerInnerHTML += "search_results.htm?seek=" + escape(synonym[i]) + "&bookname=" + escape(searchBookName);
			}	
			
			//bannerInnerHTML += '" onclick=javascript:searchBooks();';
			bannerInnerHTML += '"';
			
			bannerInnerHTML += '>';
			bannerInnerHTML += escapeHTML(synonym[i]);
			bannerInnerHTML += '</a></dd>';
		}
		bannerInnerHTML += '</dl>';
	}
	//—Þ‹`Œê‚Ì•\Ž¦
	if (relatedWord.length > 0)
	{
		bannerInnerHTML += '<dl class="related"><dt>';
		bannerInnerHTML += escapeHTML('Поиск по результатам:');
		bannerInnerHTML += '</dt>';
		for (i = 0; i < relatedWord.length; i++)
		{
			bannerInnerHTML += '<dd><a href="';
			if (searchRange == 1) 
			{
				bannerInnerHTML += "search_results.htm?seek=" + escape(noRegSearchWord) + escape(" ") + escape(relatedWord[i]) + "&bookname=" + escape(searchBookName) + "&fromSeachResultPage=1";
			}
			else
			{
				bannerInnerHTML += "search_results.htm?seek=" + escape(noRegSearchWord) + escape(" ") + escape(relatedWord[i]) + "&bookname=" + searchBookName;
			}
			
			//bannerInnerHTML += '" onclick=javascript:searchBooks();';
			bannerInnerHTML += '"';
			
			bannerInnerHTML += '>';
			bannerInnerHTML += escapeHTML(noRegSearchWord);
			bannerInnerHTML += ' ';
			bannerInnerHTML += escapeHTML(relatedWord[i]);
			bannerInnerHTML += '</a></dd>';
		}
		bannerInnerHTML += '</dl>';
	}
	document.getElementById("relatedAndSynonym").innerHTML = bannerInnerHTML;
}
/**
 * ŒŸ�õŒ‹‰Ê‰æ–Ê‚ÅŒŸ�õ‚·‚éŽž‚ÌURL‚ð�¶�¬
 */
function send_message_search() {
	//ƒ}ƒjƒ…ƒAƒ‹ˆê——‚ª‚È‚¢�ê�‡�Abookname‚ÍŽ©•ª‚Ì•ª�û–¼‚É‚·‚é�B
	var bookname = "";
	if (document.getElementById("selectbook") != null)
	{
		bookname = document.getElementById("selectbook").value;
	} 
	else
	{
		bookname = get_key_from_url()["bookname"];
	}
	var word = document.getElementById("seek").value;
	location.href = "search_results.htm?seek=" + escape(word) + "&bookname=" + escape(bookname) + "&fromSeachResultPage=1";
}

/**
 * ƒy�[ƒWƒ“ƒOƒIƒuƒWƒFƒNƒg‚ð’è‹`‚·‚é�B
 */
function showPages(name,location)
{
	//�‰Šú‰»
	this.name = name; //ƒy�[ƒWƒ“ƒO‚·‚é‘Î�Û‚Ì–¼�Ì
	//�¡‚Ìƒy�[ƒWNo‚ð‹�‚ß‚é
	this.page = 1; 
	this.pageCount = 1; //‘�ƒy�[ƒW�”
	this.showpage = 5; //ˆêŠ‡‚Å•\Ž¦‚Å‚«‚éƒy�[ƒW�”
	this.id = "searchResult";// Œ‹‰Ê•\Ž¦—Ìˆæ‚ÌID
	this.searchResult = null;//ŒŸ�õŒ‹‰Ê
	this.summarys = null;//—v–ñ
}

/**
 * ƒy�[ƒWƒ“ƒO•\Ž¦�F�¡‚Ìƒy�[ƒW�”‚Æ‘�ƒy�[ƒW�”‚ÌŒŸ�¸
 */ 
showPages.prototype.checkPages = function()
{
	//isNaN ‚Í�A“n‚³‚ê‚½ˆø�”‚ð�”‚É•ÏŠ·‚Å‚«‚é‚©‚Ç‚¤‚©‚ðŽŽ‚Ý‚Ü‚·�B
	//‚»‚Ìˆø�”‚ª•ÏŠ·‚Å‚«‚È‚©‚Á‚½�ê�‡�Atrue ‚ð•Ô‚µ‚Ü‚·�B‚»‚¤‚Å‚È‚¢�ê�‡‚Í�Afalse ‚ð•Ô‚µ‚Ü‚·�B
	if (isNaN(parseInt(this.page)))
	{
		this.page = 1;
	}
	if (isNaN(parseInt(this.pageCount)))
	{
		this.pageCount = 1;
	}
	if (this.page < 1)
	{
		this.page = 1;
	}
	if (this.pageCount < 1)
	{
		this.pageCount = 1;
	}
	if (this.page > this.pageCount)
	{
		this.page = this.pageCount;
	}
	this.page = parseInt(this.page);
	this.pagecount = parseInt(this.pageCount);
}

/**
 * ƒy�[ƒWƒ“ƒO•\Ž¦HTML‚ð�¶�¬‚·‚é
 */ 
showPages.prototype.createHtml = function()
{
	//‰æ–Ê•\Ž¦‚ÌHTML�iinnerHTML�j‚ð�¶�¬‚·‚é
	var strHtml = '';
	var prevPage = this.page - 1;
	var nextPage = this.page + 1;
	if (prevPage < 1)
	{
		strHtml += '<li class="prevoff"><img src = "../../web/gen/i_prev_g.gif" alt="' + escapeHTML('') + '">' + escapeHTML('Предыдущая страница') + '</li>';
		strHtml += '<li class="sep"><img src = "../../web/gen/sep.gif" alt="' + escapeHTML('') + '"></li>';
	} 
	else 
	{
		strHtml += '<li class="prevoff"><a href = "javascript:' +this.name + '.toPage(' + prevPage + ');change();window.scrollTo(0,0);"' + ' title="Предыдущая страница"' + '><img src = "../../web/gen/i_prev.gif" alt="' + escapeHTML('') + '">' + escapeHTML('Предыдущая страница') + '</a></li>';
		strHtml += '<li class="sep"><img src = "../../web/gen/sep.gif" alt="' + escapeHTML('') + '"></li>';
	}
	if (this.page < this.showpage)
	{
		var startPage = this.page - this.page % this.showpage + 1;
	}
	else if (this.page == this.showpage && this.page == this.pageCount) 
	{
		var startPage = 1;
	}
	else if (this.page >= this.showpage && this.pageCount > this.showpage )
	{
		strHtml += '<li class="no"><a href = "javascript:' + this.name + '.toPage(' + 1 + ');change();window.scrollTo(0,0);">' + 1 + '</a></li><li class="econt">...</li>';
		startPage = this.page - Math.ceil((this.showpage - 1) / 2);
	}
	if (this.page > this.showpage && this.pageCount < startPage + this.showpage - 1)
	{
		var startPage = this.pageCount - this.showpage + 2;
	}
	for (var i = startPage; i < startPage + this.showpage; i++)
	{
		if (i > this.pageCount) break;
		if (startPage > 1 && i == startPage + this.showpage - 1) break;
		if (i == this.page)
		{
			//ŒŸ�õŒ‹‰Ê‚ª0Œ�‚Ì�ê�‡�Aƒy�[ƒW‚Í•\Ž¦‚µ‚È‚¢�B
			if (this.searchResult.length == 0)
			{
				strHtml += '<li class="this"></li>';
			}
			else
			{
				strHtml += '<li class="this">' + i + '</li>';
			}
		}
		else
		{
			strHtml += '<li class="no"><a href = "javascript:' + this.name + '.toPage(' + i + ');change();window.scrollTo(0,0);">' + i + '</a></li>';
		}
	}
	if (this.pageCount != this.showpage && this.pageCount >= startPage + this.showpage - 1)
	{
		strHtml += '<li class="econt">...</li>';
	}
	if (nextPage > this.pageCount)
	{
		strHtml += '<li class="sep"><img src = "../../web/gen/sep.gif" alt="' + escapeHTML('') + '"></li>'
		strHtml += '<li class="nextoff">' + escapeHTML('Следующая страница') + '<img src = "../../web/gen/i_next_g.gif" alt="' + escapeHTML('') + '"></li>';
	}
	else
	{
		strHtml += '<li class="sep"><img src = "../../web/gen/sep.gif" alt="' + escapeHTML('') + '"></li>'
		strHtml += '<li class="nexton"><a href="javascript:' + this.name + '.toPage(' + nextPage + ');change();window.scrollTo(0,0);"' +  ' title="Следующая страница"' + '>' + escapeHTML('Следующая страница') + '<img src = "../../web/gen/i_next.gif" alt="' + escapeHTML('') +  '"></a></li>';
	}
	strHtml += '</span><br />';
	return strHtml;
}

/**
 * ƒy�[ƒWƒ“ƒO�Fiƒy�[ƒW–Ú‚Ì“à—e‚ð•\Ž¦‚·‚é
 */
function display(i)
{
	var startNo = 10 * (i - 1);
	var endNo = 10 * i;
	var resultHtml = '';
	// ŒŸ�õƒ��[ƒh•Ï�”‚ÌŽæ“¾
	var w = window.location.search.substring(0,5);
	
	if (endNo > paging.searchResult.length)
	{
		endNo = paging.searchResult.length;
	}
	for (i = startNo; i < endNo; i++)
	{
		var src = "../../" +  books[paging.searchResult[i].bookId].bookFolderName + "/int/" + pages[paging.searchResult[i].pageId].fileName;
		if (w == "?word")
		{
			src += "?&word=" + escape(get_key_from_url()["word"]);
		}
		if (w == "?seek")
		{
			src += "?&seek=" + escape(get_key_from_url()["seek"]);
		}
		resultHtml += '<div class="fpage">';
		resultHtml += '<h2><a href = "';
		resultHtml += src;
		resultHtml += '">' + paging.searchResult[i].pageTitle + '</a>';
		
		resultHtml += '<a href="';
		resultHtml += src;
		resultHtml += '" target="_blank"><img src = "../../web/int/newwin.gif" alt="' + escapeHTML('') + '"' + ' title="Открыть ссылку в новом окне"' + '></a>';
		
		resultHtml += '</h2><ul><li class="book" id="bookname';
		resultHtml += i;
		resultHtml += '">';
		resultHtml += books[paging.searchResult[i].bookId].bookname;
		resultHtml += '</li><li class="summary">';
		if (paging.summarys[i].indexOf("<") > 0)
		{
			paging.summarys[i]=paging.summarys[i].replace(RegExp("<","g"),'&lt;');
		}
		if (paging.summarys[i].indexOf(">") > 0)
		{
			paging.summarys[i]=paging.summarys[i].replace(RegExp(">","g"),'&gt;');
		}
		resultHtml += paging.summarys[i];
		resultHtml += '</li></ul></div>';
	}
	return resultHtml;
}

/**
 * ƒy�[ƒWƒ“ƒO�Fƒy�[ƒW‘JˆÚ
 */
showPages.prototype.toPage = function(page)
{
	this.page = page;
	document.getElementById("paging").innerHTML = this.createHtml();
	//ŒŸ�õŒ‹‰Ê‚ð•\Ž¦‚·‚éHTML
	var resultHtml = '';
	//�Å�‰‚Í1ƒy�[ƒW–Ú‚ð•\Ž¦‚·‚é�B
	resultHtml = display(page);
	document.getElementById("replace").innerHTML = resultHtml;
}

/**
 * ƒy�[ƒWƒ“ƒO‚ð�¶�¬‚·‚é
 */
showPages.prototype.printHtml = function()
{
	this.checkPages();
	//�Å�‰‚Í1ƒy�[ƒW–Ú‚ð•\Ž¦‚·‚é�B
	document.getElementById("replace").innerHTML = display(1);
	document.getElementById("paging").innerHTML = this.createHtml();
}

/**
 * —v–ñ‚ðŽæ“¾‚·‚é
 */
function getTextSummary(searchresult, searchWords, noRegSearchWords)
{
	//“ÁŽê‹L�†‚Ì�ˆ—�
	for (i = 0; i < noRegSearchWords.length; i++)
	{
		noRegSearchWords[i] = dealOtherLanguageMark(noRegSearchWords[i]);
	}
	
	var textSummary = new Array();
	for (j = 0; j < searchresult.length; j++)
	{
		var marks = new Array(' ', '.', ',', ':', ';', '?', '!');
		var regText = pages[searchresult[j].pageId].regText;
		var text = pages[searchresult[j].pageId].text;
		//first‚Ì�\�¬‚Í {offset, key}
		var first = GetFirstOffSet(text, noRegSearchWords);	
		//–{•¶‚ª100•¶Žš–¢–ž
		if (text.length <= 100)
		{
			textSummary[j] = text;
		}
		//–{•¶‚ÉŒŸ�õƒ��[ƒh‚ª‚È‚¢
		else if (!searchresult[j].textHitFlag || (typeof(first[1]) == "undefined"))
		{
			
			var location = getStringUntilMark(text, 99, 1);
			if (location > 0)
			{
				textSummary[j] = text.substring(0,location) + "...";
			}
			else
			{
				textSummary[j] = text;
			}
			
		}
		//ˆê”Ô–Ú‚ÌŒŸ�õƒL�[ƒ��[ƒh‚ª100ˆÈ�ã‚Ì�ê�‡�AƒL�[ƒ��[ƒh‚Ì‚Ý•\Ž¦‚·‚é�B
		else if (noRegSearchWords[0].length >= 100)
		{
			if (first[0] > 0) 
			{
				textSummary[j] = "...";
				textSummary[j] += noRegSearchWords[0];
			}
			else{
				textSummary[j] =  noRegSearchWords[0];
			}
			
			if ((first[0] + first[1].length) < text.length)
			{
				textSummary[j] += "...";
			}
		}
		//ŒŸ�õƒ��[ƒh‚Ì‘O20•¶Žš‚ª�æ“ª50•¶Žš‚É‚©‚©‚é
		else if (first[0] <= 70)
		{
			
			var location = getStringUntilMark(text, 99, 1);
			if (location > 0)
			{
				textSummary[j] = text.substring(0,location) + "...";
			}
			else
			{
				textSummary[j] = text;
			}
			
		}
		//ŒŸ�õƒ��[ƒh‚ÌŒã20•¶ŽšˆÈ“à‚ª––”ö‚É‚È‚é
		else if ((first[0]+ first[1].length + 20) > text.length)
		{
			
			var hasMarks = false;
			var objectString = text.substring(50, first[0]-20);
			for (var x = 0; x < marks.length; x++)
			{
				if (objectString.indexOf(marks[x]) != -1)
				{
					hasMarks = true;
					break;
				}
			}
			if (hasMarks == false)
			{
				textSummary[j] = text;
			}
			else
			{
				var location1 = getStringUntilMark(text.substring(0,first[0]-20-1), 49, 1);
				var location2 = getStringUntilMark(text.substring(0,first[0]-20-1), 49, 0);
				//"..."‚Ì’†‚É‚Í1‚Â‚Ì‹L�†‚µ‚©‚È‚¢�B
				if (location1 == location2)
				{
					textSummary[j] = text;
				}
				else
				{
					textSummary[j] = text.substring(0,location1);
					textSummary[j] += "...";
					textSummary[j] += text.substring(location2);
				}
			}
			
		}
		//ˆê”Ê“I‚È�ê�‡
		else
		{
			
			//1‚Â–Ú‚Ì"..."‚Ì�ˆ—�
			var hasMarks = false;
			var objectString = text.substring(50, first[0]-20);
			for (var x = 0; x < marks.length; x++)
			{
				if (objectString.indexOf(marks[x]) != -1)
				{
					hasMarks = true;
					break;
				}
			}
			if (hasMarks == false)
			{
				textSummary[j] = text.substring(0, first[0] + first[1].length + 20);
			}
			else
			{
				var location1 = getStringUntilMark(text.substring(0,first[0]-20-1), 49, 1);
				var location2 = getStringUntilMark(text.substring(0,first[0]-20-1), 49, 0);
				//1‚Â–Ú‚Ì"..."‚Ì’†‚É‚Í1‚Â‚Ì‹L�†‚µ‚©‚È‚¢�B
				if (location1 == location2)
				{
					textSummary[j] = text.substring(0, first[0] + first[1].length + 20);
				}
				else
				{
					textSummary[j] = text.substring(0,location1);
					textSummary[j] += "...";
					textSummary[j] += text.substring(location2, first[0] + first[1].length + 20);
				}
			}
			//2‚Â–Ú‚Ì"..."‚Ì�ˆ—�
			var location3 = getStringUntilMark(text, first[0] + first[1].length + 20, 1);
			if (location3 > 0)
			{
				textSummary[j] += text.substring(first[0] + first[1].length + 20 ,location3);
				textSummary[j] += "...";
			}
			
		}
	}
	return textSummary;
}
/**
 * —v–ñ‚Ì•\Ž¦�F“ú–{Œê�A’†�‘Œê�AŠØ�‘ŒêˆÈŠO‚Ì�ê�‡�B
 * Žw’è‚³‚ê‚Ä‚¢‚é‚Æ‚±‚ë‚Í(' ', '.', ',', ':', ';', '?', '!')‚Å‚Í‚È‚¢�ê�‡‚Í�A‚±‚ê‚ç‚ª�o‚é‚Ü‚Å•\Ž¦‚·‚é�B
 * ‚±‚ÌŠÖ�”‚Í�ã‹L‹L�†‚ª�Å�‰(ˆ½‚¢‚Í�ÅŒã)‚É�o‚Ä‚­‚é�ê�Š‚ð’T‚·�B
 * textString‚Í–{•¶•¶Žš—ñ
 * offset‚ÍŽw’è‚³‚ê‚Ä‚¢‚é�ê�Š
 * directionFlag‚Í’T‚·•ûŒü�B1‚Ì�ê�‡‚Í‘O‚©‚çŒã‚Ö�B0‚Ì�ê�‡‚Í‚»‚Ì‹t�B
 */
function getStringUntilMark(textString, offset, directionFlag)
{
	var marks = new Array(' ', '.', ',', ':', ';', '?', '!');
	// •¶Žš—ñ‚Ì’†‚Å�Å�‰‚É�o‚Ä‚«‚é‹L�†‚Ì�ê�Š‚ð’T‚·
	var startOffsets = new Array();
	for (m = 0; m < marks.length; m++)
	{
		var markOffset = textString.substring(offset + 1).indexOf(marks[m]);
		if (markOffset != -1)
		{
			startOffsets[startOffsets.length] = markOffset;
		}
	}
	// •¶Žš—ñ‚Ì’†‚Å�ÅŒã‚É�o‚Ä‚«‚é‹L�†‚Ì�ê�Š‚ð’T‚·
	var endOffsets = new Array();
	for (m = 0; m < marks.length; m++)
	{
		var markOffset = textString.substring(offset + 1).lastIndexOf(marks[m]);
		if (markOffset != -1)
		{
			endOffsets[endOffsets.length] = markOffset;
		}
	}

	if (directionFlag == 1)
	{
		var startOffset = startOffsets[0];
		for (m = 0; m < startOffsets.length; m++)
		{
			startOffset = Math.min(startOffsets[m], startOffset);
		}
		return (startOffset + offset + 2);
	}
	else
	{
		var endOffset = endOffsets[0];
		for (m = 0; m < endOffsets.length; m++)
		{
			endOffset = Math.max(endOffsets[m], endOffset);
		}
		return endOffset + offset + 2;
	}
}
/**
 * �Å�‰‚Ékey‚ªŒ»‚ê‚éˆÊ’u‚Æ‚»‚Ìkey‚ðŽæ“¾‚·‚é
 * –ß‚è’l�Fresult = {offset, key}
 */
function GetFirstOffSet(text, searchWords)
{
	var offset = new Array();
	var result = new Array();
	//�Å�‰‚Ékey‚ªŒ»‚ê‚éˆÊ’u
	var firstOffset;
	//�Å�‰‚ÉŒ»‚ê‚ékey
	var firstKey;
	//ŒŸ�õƒL�[ƒ��[ƒh‚Ì‚»‚ê‚¼‚ê‚ª�Å�‰‚ÉŒ»‚ê‚éˆÊ’u‚ðŽæ“¾‚·‚é
	for (i = 0; i < searchWords.length; i++)
	{
		var reg = new RegExp(searchWords[i], "i");
		if (text.search(reg) != -1)
		{
			offset[offset.length] = text.search(reg);
		}
	}
	firstOffset = offset[0];
	for (i = 0; i < offset.length; i++)
	{
		firstOffset = Math.min(offset[i], firstOffset);
	}
	
	result[0] = firstOffset;
	//�Å�‰‚ÉŒ»‚ê‚ékey‚ðŽæ“¾‚·‚é
	for (i = 0; i < searchWords.length; i++)
	{
		var reg = new RegExp(searchWords[i], "i");
		if (text.search(reg) == firstOffset)
		{
			firstKey = searchWords[i];
		}
	}
	result[1] = firstKey;
	return result;
}

/**
 * ŒŸ�õŒ‹‰Ê‚ðƒ\�[ƒg‚·‚é�B
 * ƒ\�[ƒg�‡‚Í‰º‹L‚Ì‚æ‚¤‚É‚È‚Á‚Ä‚¨‚è‚Ü‚·�B
 * ?	ŒŸ�õƒ��[ƒh‚ªƒ^ƒCƒgƒ‹‚ÉŠÜ‚Ü‚ê‚éƒy�[ƒW
 * ?	ŒŸ�õƒ��[ƒh‚Ì“o�ê‰ñ�”‚ª‘½‚¢�‡
 * ?	ƒy�[ƒWƒ^ƒCƒgƒ‹‚Ì•¶ŽšƒR�[ƒh�‡
 * ?	ƒy�[ƒW”Ô�†�i‰B‚µ‹@”\�j
 */
function sortResult(searchresult)
{
	// ƒ\�[ƒg�‡?‚Åƒ\�[ƒg‚·‚é
	// ŒŸ�õƒ��[ƒh‚ªƒ^ƒCƒgƒ‹‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚éŒ‹‰Ê‚Ì”z—ñ
	var titleTagTrue = new Array();
	var t = 0;
	// ŒŸ�õƒ��[ƒh‚ªƒ^ƒCƒgƒ‹‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚È‚¢Œ‹‰Ê‚Ì”z—ñ
	var titleTagFalse = new Array();
	var f = 0;
	for (i = 0; i < searchresult.length; i++)
	{
		if (searchresult[i].titleHitFlag)
		{
			titleTagTrue[t] = searchresult[i];
			t++;
		}
		else
		{
			titleTagFalse[f] = searchresult[i];
			f++;
		}
	}
	
	//ƒ\�[ƒg�‡?�A?�A?‚Åƒ\�[ƒg‚·‚é
	titleTagTrue.sort(compareResult);
	titleTagFalse.sort(compareResult);
	return titleTagTrue.concat(titleTagFalse);
}

/**
 * ƒqƒbƒg‰ñ�”‚Å�~�‡ƒ\�[ƒg‚Ì”äŠrŠÖ�”
 */
function compareResult(a, b)
{
	//ƒ\�[ƒg�‡?‚Åƒ\�[ƒg‚·‚é
	if (Number(b.hitTimes) - Number(a.hitTimes) != 0)
	{
    	return Number(b.hitTimes) - Number(a.hitTimes);
	}
	else
	{
		//ƒ\�[ƒg�‡?‚Åƒ\�[ƒg‚·‚é
		if (a.pageTitle != b.pageTitle)
		{
			return (a.pageTitle > b.pageTitle)?1:-1;
		}
		else
		{
			//ƒ\�[ƒg�‡?‚Åƒ\�[ƒg‚·‚é
			if (a.pageId != b.pageId)
			{
				return Number(a.hitTimes) - Number(b.hitTimes);
			}
			else
			{
				return 0;
			}
		}
	}
}

/**
 * ŒŸ�õƒL�[ƒ��[ƒh‚ðŽæ“¾‚·‚é�B
 * ‚»‚µ‚Ä�AANDŒŸ�õ‚©ˆêŒêŒŸ�õ‚Ì”»’f‚à‚¨‚±‚È‚¤�B
 * �õˆø‰æ–Ê‚ÌƒŠƒ“ƒN‚©‚ç‚ÌŒŸ�õ‚ÍˆêŒêŒŸ�õ�B‚»‚Ì‘¼‚ÍANDŒŸ�õ�B
 */
function getKeyWords()
{
	var words = new Array();
	var result = new Array();
	
	// ŒŸ�õƒ��[ƒh•Ï�”‚ÌŽæ“¾
	var w = window.location.search.substring(0,5);
	
	//�õˆøƒŠƒ“ƒN‚ÌŒŸ�õƒ��[ƒh•Ï�”‚Í�Fword
	if (w == "?word")
	{
		words[0] = get_key_from_url()["word"];
	}
	else if (w == "?seek") 
	{
		var wordFromUrl = get_key_from_url()["seek"];
		//ŒŸ�õ•¶Žš—ñ‚Ì’†‚ÉƒXƒy�[ƒX(‘SŠp�E”¼Šp)‚ª‚ ‚é
		if (wordFromUrl != null && wordFromUrl != '' && typeof(wordFromUrl) != "undefined")
		{
			if (wordFromUrl.indexOf(" ") != -1 || wordFromUrl.indexOf("�@") != -1)
			{
				var tempWords = wordFromUrl.split(" ");
				for (var s = 0; s < tempWords.length; s++)
				{
					if (tempWords[s].indexOf("�@") != -1)
					{
						words = words.concat(tempWords[s].split("�@"));
					}
					else
					{
						var tempWords2 = new Array(tempWords[s]);
						words = words.concat(tempWords2);
					}
				}
			}
			//ŒŸ�õ•¶Žš—ñ‚Ì’†‚ÉƒXƒy�[ƒX‚ª‚È‚¢
			else
			{
				words[0] = wordFromUrl;
			}
		}
	}
	//ŒŸ�õƒL�[ƒ��[ƒhƒŠƒXƒg‚©‚ç’·‚³‚ª0‚ÌƒL�[ƒ��[ƒh‚ð�œ‹Ž‚·‚é�B
	for (i = 0; i < words.length; i++)
	{
		if (words[i].length != 0)
		{
			result[result.length] = words[i];
		}
	}
	return result;
}

/**
 * JavaScript‚Ì�³‹K•\Œ»‚ðŽg‚Á‚Ä‚¢‚é‹L�†‚Ì�ˆ—�
 */
function dealOtherLanguageMark(value)
{
	/*
	var regMarks = new Array("\\\\", "\\&", "\\(", "\\)", "\\*", "\\+", "\\?", "\\[", "\\]", "\\{", "\\}");
	for (i = 0; i < regMarks.length; i++)
	{
		var reg = new RegExp(regMarks[i], "g");
		value = value.replace(reg, "\\\\" + regMarks[i]);
	}
	return value;
	*/
	
	return value.replace(/([^A-Za-z0-9])/g , "\\$1");
}

/**
 * ƒeƒLƒXƒg’†‚ÌƒXƒy�[ƒX�i‘SŠp�E”¼Šp�j�Aƒ^ƒu‚ð�œ‹Ž‚·‚é�B
 */
function removeSpace(value)
{
	if (value != null && value != '' && typeof(value) != "undefined") 
	{
		while (value.indexOf("\t") >= 0) 
		{
			value = value.replace("\t", "");
		}
		while (value.indexOf(" ") >= 0)
		{
			value = value.replace(" ", "");
		}
		while (value.indexOf("�@") >= 0)
		{
			value = value.replace("�@", "");
		}
	}
	return value;
}

function escapeHTML(str) {
	var div = document.createElement('div');
	var text = document.createTextNode(str);
	div.appendChild(text);
	return div.innerHTML;
}
