function moleculeTextSearchAJAXResponse(response){

	// grab result
	$('body').innerHTML = response.responseText;
	
	if ($('noMoleculesFound') != null) {
                
                // log in Google Analytics
		pageTracker._initData();
		pageTracker._trackPageview('/Molecule-Text-Search-No-Results?SiteSearch=' + $('TextSearchValue').value);
                
                // change title
		document.title = 'No matches were found for this text search - MolPort';

		var array = new Array();
		var i = 0;

		array[i] = $('TextSearchValue').value;
		searchByGoogle('googleResults', array);
                
                // init tooltip
                myTooltip.initialize();                
	}
	else {

		// log in Google Analytics
		pageTracker._initData();
		pageTracker._trackPageview('/Molecule-Text-Search-Results?SiteSearch=' + $('TextSearchValue').value);
		
                // change title
		document.title = 'Text search - MolPort';
	}
	
}

function UpdateTimer(message, value) {

	value++;
	
	if ($('timer') != null) {
		$('timer').innerHTML = message + value;       
		setTimeout("UpdateTimer('" + message + "'," + value + ")", 1000);
	}

}

function submitTextSearchOnEnter(field, e, value) {

	var k;

	if (window.event) 
		k = window.event.keyCode;
	else if 
		(e)k = e.which;
	else 
		return true;

	if (k == 13)
		if (field.value != value) {
                        submitTextSearch('Please, specify the search value!');
			return false;
		}
                else
			return true;
	else
		return true;

}

function submitTextSearch(message) {
	if ($('searchValue').value == '')
		alert(message);
	else if ($('searchValue').value == 'Search the value...')
		alert(message);
        else {
                $('TextSearchForm').method = 'POST';
                $('TextSearchForm').submit();
        }
}

function onSearchInputFocusChange(id, type, value) {

	if ($(id).value == 'Search the value...' && type == 'focus') {
		$(id).value = '';
		return;
	}

	if ($(id).value == '' && type == 'blur') {
		$(id).value = 'Search the value...';
		return;
	}

}

function fillContainerWithProgresInfo(container, message){
	var a = 'index?object=searchresults&action=progressinfo&type=forsearch&ajax=yes';
	var p = 'timestamp' + parseInt(Math.random() * 99999999);
	var r = new Ajax.Request(a, {method: 'get', parameters: p, onComplete: function(request){ progressinfoAJAXResponse(request, message, container)}});      
}

function progressinfoAJAXResponse(response, message, container){
	$(container).innerHTML = response.responseText;
	UpdateTimer(message, -1);
}

// close progress bar
function doNotShowProgressStepsBox(){
	$('progressStepsBox').style.display='none'; 
	var a = 'my-account/index?saveProgresStepsParam=true&showProgresSteps=false';
	var p = 'timestamp' + parseInt(Math.random() * 99999999);
	var r = new Ajax.Request(a, {method: 'get', parameters: p});      
}