SearchWordsPage = function()
{
	this.pageName = "";
	this.globalIndex = -1;
	this.searchWordsStr = "";
}

/*
  *
  *
  */
SearchWords = function()
{
	this.pages = new Array();
	//this.pagesCount = "";
}

SearchWords.prototype.AddPage = function()
{
	var p = new SearchWordsPage();
	this.pages[this.pages.length] = p;
	return p;
}


//String parent.SearchWords.setDataStringByID(int PageID;String ColumnName,String value)
SearchWords.prototype.findPagesWithWord = function(wordToSearch, ignoreCase)
{
	var pagesFound = new Array();
	wordToSearch = trim(wordToSearch); //remove all spaces from the begin and the end of word to be searched for
	var isManyWords = (wordToSearch.indexOf(" ") > -1); //pg2
	
	if (isManyWords) {
		var doubleSpace = "  ";
		while (wordToSearch.indexOf(doubleSpace) > -1) { //pg2-replace all double spaces to single one
			wordToSearch = wordToSearch.replace(doubleSpace, " "); 
		}
		while (wordToSearch.indexOf(" ") > -1) { //pg2-replace all spaces to ":" - so it would be similar to all texts extracted from the page
			wordToSearch = wordToSearch.replace(" ", ":");
		}
		if (ignoreCase) {
			wordToSearch = wordToSearch.toUpperCase();
		}
		
		for (var i = 0; i < this.pages.length; i++) {
			var searchWordsFromPageStr = this.pages[i].searchWordsStr;
			while (searchWordsFromPageStr.indexOf("&nbsp;") > -1) { //pg2-if between words were two spaces, one is as ":", and the second is 'sticked' to some word (at its end) as "&nbsp;"
				searchWordsFromPageStr = searchWordsFromPageStr.replace("&nbsp;", "");
			}
			if (ignoreCase) {
				searchWordsFromPageStr = searchWordsFromPageStr.toUpperCase();
			}
			if (searchWordsFromPageStr.indexOf(wordToSearch) > -1) {
				pagesFound[pagesFound.length] = i;
			}
		}
	} else { //pg2-szukanie pojedynczego slowa
		for (var i = 0; i < this.pages.length; i++)
		{
			var searchWordsArr = this.pages[i].searchWordsStr.split(":");
			for (var j = 0; j < searchWordsArr.length; j++) {
				if (ignoreCase)
				{
					if (searchWordsArr[j].toUpperCase() == wordToSearch)
					{
						pagesFound[pagesFound.length] = i;
						break;
					}
				} else {
					if (searchWordsArr[j] == wordToSearch)
					{
						pagesFound[pagesFound.length] = i;
						break;
					}
				}
			}
		}
	}
	return pagesFound;
}

SearchWords.prototype.toString = function()
{
	return "SearchWords!!!";
}


var sw = new SearchWords();
