var userSearchTimer = 0;

function checkSearchTimer() {			
	var this_time = new Date();			
//	var search_box = document.searchform.str.value;			 
	var search_box = $('#search_str').val();			 

	//checking how much time passed since the last key pressed			
	var nowTime = this_time.getTime();			 

	if (nowTime - userSearchTimer >= 1000 && userSearchTimer > 0) {				
		//more then 2 seconds passed since the last key pressed
		
		//clearing the function timer
		clearTimeout(suggest_timer);
		userSearchTimer = -1;		 
	
		//if the box is not empty, fire the event				
		if (search_box.length > 2) {				
			get_search_suggestions(search_box);				
		} else {				
			$('#suggest-searches').hide();
		}				
	} else {
		//not enough time passed, setting this to fire up again in 2 seconds				
		var suggest_timer = setTimeout("checkSearchTimer()",1000);

		if (search_box.length == 0) {				
			$('#suggest-searches').hide();
		}
	}
}

function initSearchSuggest() {			
	var this_time = new Date();			
	userSearchTimer = this_time.getTime(); //resetting timer every keystroke
	checkSearchTimer();		
}

function get_search_suggestions(s) {
	$('#suggest-searches').load(_APP_URL + '/search/frontend/suggest-searches/isAjaxCall/1/?str='+escape(s));
	$('#suggest-searches').slideDown('fast');				
	$('#last-searches').hide();
	$('#ajax_loader').hide();
	
}

function loginActions(){
	$('#last-searches').hide();
	$('#suggest-searches').hide();
	$('#register').hide();
	$('#login').toggle('fast');
}

function registerActions(){
	$('#last-searches').hide();
	$('#suggest-searches').hide();
	$('#login').hide();
	//$('#register').toggle('fast');
	document.location = _APP_URL + "/creeaza-cont.html";
}