// JavaScript Document
function SearchForm(holder_, urlPlus_)
{
	this.holder = holder_;
	this.searchInputText = null;
	this.makeSearchInputDefaultTextButton = null;
	this.tableHolder = null;
	this.defaultTekst = 'Search...';
	this.textIsDEfault = true;
	this.form = null;
	this.urlPlus = urlPlus_;
	this.thePage = this.urlPlus+'search/search.php?searchValue=';
	
	this.addSearchTextInput = function()
	{
		this.tableHolder = document.createElement('table');
		this.tableHolder.setAttribute('border','0');
		this.tableHolder.setAttribute('class','tableSearchForms');
		this.tableHolder.setAttribute('className','tableSearchForms');
		this.tableHolder.setAttribute('align','left');
		this.tableHolder.cellPadding = 0;
		this.tableHolder.cellSpacing = 0;
		var rowHolder = this.tableHolder.insertRow(0);
		var inputTextHolder = rowHolder.insertCell(0);
		
		//document.getElementById().on
		this.form = document.createElement('form');
		this.form.setAttribute('class','form_searchForm');
		this.form.setAttribute('className','form_searchForm');
		this.form.action = 'stranica.php?search=mako';
		this.form.method = 'POST';
		this.form.searchForm = this;
		this.form.onsubmit = function()
		{
			this.action = this.searchForm.thePage + this.searchForm.searchInputText.value;
		}
		inputTextHolder.appendChild(this.form);
		
		this.searchInputText = document.createElement('input');
		this.searchInputText.searchForm = this;
		this.searchInputText.onfocus = function()
		{
			if(this.value == this.searchForm.defaultTekst)
			{
				this.value = '';
			}
		}
		this.searchInputText.onkeydown = function()
		{
			if(this.searchForm.textIsDEfault == true)
			{
				this.searchForm.textIsDEfault = false;
				this.searchForm.makeVisibleButtonTekstToDefayult();
			}
		}
		this.searchInputText.setAttribute('class','searchTextInput');
		this.searchInputText.setAttribute('className','searchTextInput');
		
		this.form.appendChild(this.searchInputText);
		/**/
		this.makeSearchInputDefaultTextButton = document.createElement('div');
		this.makeSearchInputDefaultTextButton.setAttribute('class','divImageMakeDefaultTekst');
		this.makeSearchInputDefaultTextButton.setAttribute('className','divImageMakeDefaultTekst');
		this.makeSearchInputDefaultTextButton.searchForm = this;
		this.makeSearchInputDefaultTextButton.onclick = function()
		{
			this.searchForm.setToDefaultSearchForm();
		}
		
		var buttonClose = rowHolder.insertCell(1);
		buttonClose.appendChild(this.makeSearchInputDefaultTextButton);
		
		this.holder.appendChild(this.tableHolder);
		
	}
	this.makeVisibleButtonTekstToDefayult = function()
	{
		this.makeSearchInputDefaultTextButton.setAttribute('class','divImageMakeDefaultTekst');
		this.makeSearchInputDefaultTextButton.setAttribute('className','divImageMakeDefaultTekst');
	}
	this.setToDefaultSearchForm = function()
	{
		this.makeSearchInputDefaultTextButton.setAttribute('class','divImageMakeDefaultTekst_invisible');
		this.makeSearchInputDefaultTextButton.setAttribute('className','divImageMakeDefaultTekst_invisible');
		this.searchInputText.value = 'Search...';
		this.textIsDEfault = true;
	}
	this.addSearchTextInput();
	this.setToDefaultSearchForm();
	
	this.page_addEventsToSearchForm = function()
	{
		document.getElementById('inputTextSearchTool').onkeydown = function()
		{
			document.getElementById('makeDefaultSearch').style.visibility = 'visible';
		}
		document.getElementById('makeDefaultSearch').searchForm = this;
		document.getElementById('makeDefaultSearch').onclick = function()
		{
			this.searchForm.makeDefaultSearchFormOnPage();
		}
		document.getElementById('buttonSearch').searchForm = this;
		document.getElementById('buttonSearch').onclick = function()
		{
			this.searchForm.page_makeSearch();
		}
	}
	this.makeDefaultSearchFormOnPage = function()
	{
		document.getElementById('inputTextSearchTool').value = '';
		document.getElementById('makeDefaultSearch').style.visibility = 'hidden';
	}
	this.page_makeSearch = function()
	{
		if(document.getElementById("inputTextSearchTool").value == '')return;
		
		window.location.href = this.thePage + document.getElementById("inputTextSearchTool").value;
	}
	
	this.arrayGroupResults = new Array();
	this.totalCountResults = 0;
	this.keyWord = '';
	this.selectedPage = 0;
	this.printAllPageNumbers = function()
	{
		var index = 0;
		
		for(var i=0;i<this.arrayGroupResults.length;i++)
		{
			index = parseFloat(i)+1;
			this.arrayGroupResults[i].createPageButton(index);
		}
		this.selectPageNumber(0);
	}
	this.selectedPageNumber = null;
	this.selectPageNumber = function(index)
	{
		if(this.selectedPageNumber != null)
		{
			this.selectedPageNumber.Deselect();
		}
		this.selectedPageNumber = this.arrayGroupResults[index];
		this.selectedPageNumber.Select();
	}
	
	searchTopRightForm = this;
}
function Result(id_, title_, keywords_, details_, url_)
{
	this.id = id_;
	this.title = title_;
	this.keywords = keywords_;
	this.details = details_;
	this.url = url_;
	this.getResultHTML = function()
	{
		return '<a href="'+this.url+'" class="explanationDivSearchResultTitle"><div>'+this.title+'</div></a><div class="explanationDivSearchResult">'+this.details+'</div><div class="explanationDivSearchResultPage"><a href="'+this.url+'">'+this.url+'</a></div><hr class="hrDelimiterResults" />';
		
	}
}
function ResultGroup()
{
	this.arrayResults = new Array();
	this.cell = null;
	this.iCanWorking = true;
	this.index = -1;
	
	this.createPageButton = function(index)
	{
		this.cell = document.getElementById('holderAllPageNumbers').insertCell(document.getElementById('holderAllPageNumbers').cells.length);
		this.index = index;
		this.cell.innerHTML = '<div class="divPageNumberResults">'+index+'</div>';
		this.cell.resultGroup = this;
		this.cell.onclick = function()
		{
			if(this.resultGroup.iCanWorking == false)return;
			
			this.resultGroup.openResultsForThis();
			searchTopRightForm.selectPageNumber(parseFloat(this.resultGroup.index)-1);
		}
	}
	this.openResultsForThis = function()
	{
		document.getElementById('divTextAllResults').innerHTML = '';
		document.getElementById('divTextAllResults').innerHTML = '<div id="divTextAllTotalResultsCount" class="explanationDivSearchResult">About '+searchTopRightForm.totalCountResults+' results found for '+searchTopRightForm.keyWord+'.</div><hr class="hrDelimiterResults" /><br />';
		for(var i=0;i<this.arrayResults.length;i++)
		{
			document.getElementById('divTextAllResults').innerHTML += this.arrayResults[i].getResultHTML();
		}
	}
	this.Deselect = function()
	{
		this.iCanWorking = true;
		this.cell.innerHTML = '<div class="divPageNumberResults">'+this.index+'</div>';
	}
	this.Select = function()
	{
		this.iCanWorking = false;
		this.cell.innerHTML = '<div class="divPageNumberResults_clicked">'+this.index+'</div>';
	}
}
var searchTopRightForm = null;
