function OnDivScroll(list)
{
    //var sourceList = document.getElementById("keywordList");
	var sourceList = document.getElementById(list);

    if (sourceList.options.length > 15)
    {
        sourceList.size=sourceList.options.length;
        sourceList.style.height = sourceList.options.length * 14;
    }
    else
    {
        sourceList.size=15;
        sourceList.style.height = 210;
    }
}

function OnSelectFocus(divList, list)
{
/*    if (document.getElementById("divKeywordList").scrollLeft != 0)
    {
        document.getElementById("divKeywordList").scrollLeft = 0;
    }
*/
   if (document.getElementById(divList).scrollLeft != 0)
    {
        document.getElementById(divList).scrollLeft = 0;
    }
    
    //var sourceList = document.getElementById('keywordList');
    var sourceList = document.getElementById(list);

    if( sourceList.options.length > 15)
    {
        sourceList.focus();
        sourceList.size=15;
        sourceList.style.height = 210;
    }
}

function collectKeywords()
{
	var count = document.getElementById('count').value;
	if (self.document.selectForm.keywordList.selectedIndex >=0)
	{
		var i=0;
		
		for (i = 0; i < count; i++)
		{
			if (self.document.selectForm.keywordList.options[i] != null)
			{
				if (self.document.selectForm.keywordList.options[i].selected)
				{
					if (opener.document.getElementById("keyword").value != "")
					{						
						opener.document.getElementById("keyword").value = opener.document.getElementById("keyword").value + ' or ' ;
					}
					
					if (opener.document.forms['simpleSearch'].keyword_id.value != "")
					{
						opener.document.forms['simpleSearch'].keyword_id.value = opener.document.forms['simpleSearch'].keyword_id.value + ' ' ;
					}
					
					opener.document.getElementById("keyword").value = opener.document.getElementById("keyword").value + "{" + self.document.selectForm.keywordList.options[i].text+ "}";
					opener.document.forms['simpleSearch'].keyword_id.value = opener.document.forms['simpleSearch'].keyword_id.value + self.document.selectForm.keywordList.options[i].value;
				}
			}
		}
	}
	parent.close();
}

function collectLibraries()
{
//	var count = document.getElementById('count').value;
	var libList = self.document.getElementById("libraryList");
	var libIds = opener.document.getElementById("library_id");
	var library = opener.document.getElementById("library");
	
	if (libList.selectedIndex >=0)
	{
		var i=0;
		for (i = 0; i < libList.options.length; i++)
		{
			if (libList.options[i] != null)
			{
				if (libList.options[i].selected)
				{
					library.value = library.value + libList.options[i].text + ", ";
					libIds.value = libIds.value + libList.options[i].value + ", ";
				}
			}
		}
	}
	parent.close();
}

function selectLibraries()
{
	var libList = document.getElementById("libraryList");
	var libIds = document.getElementById("library_id");
	if (libList.selectedIndex >= 0)
	{
		var i=0;
		for (i = 0; i < libList.options.length; i++)
		{
			if (libList.options[i] != null)
			{
				if (libList.options[i].selected)
				{
					libIds.value = libIds.value + libList.options[i].value + ", ";
				}
			}
		}
	}
}

function clearMyForm()
{
	var clearTrigger = document.getElementById('clearForm');
	var doSearch = document.getElementById('doSearch');
	var submitButton = document.getElementById('submitButton');
	
	var field = undefined;
	field = document.getElementById('keyword');
	if (field == undefined)
		field = document.getElementById('library');
	
	field.value = '';
	
	clearTrigger.value = 'true';
	//if (doSearch != null)
	//	doSearch.value = '0';
	//submitButton.click();   // DS. nepraeina validavimo
}

function validateKeywordSearchForm(form){
	var inputFields = form.getElementsByTagName("input");
	var existsInput = false;
	for (var i = 0; i < inputFields.length; i++){
		if ((inputFields[i].type == "text") && (inputFields[i].value != "")){
			existsInput = true;
			break;
		}
	}
	if (true == existsInput){
		setRelation();
		return existsInput;
	}
	else{
		alert(message2);
		return existsInput;
	}
}

function setRelation()
{
	var relationChckb = document.getElementById('relChkb');
	var relationField = document.getElementById('relation');
	if (relationChckb.checked == true)
		relationField.value = 'like';
	else relationField.value = 'any';
}