var wait_content = "<center><br/><br/><br/>осуществляется поиск...</center>";
var enter_search_text = "<center><br/><br/><br/>введите текст поискового запроса</center>";

function setCollection(a_id){
	collection = a_id.replace(/bookmark_/,"");
	setBookmarkSelection(a_id);
	var searchValue = document.getElementById("main_search_tb").value;
	if(!writeEmptySearchWarning()) exec_search(0);
}

function exec_search(page){
    var searchValue = document.getElementById("main_search_tb").value;
    
    if(!writeEmptySearchWarning())
		//document.write("/ajax/search/?collection=" + ( collection == "" ? "games" : collection ) + "&currentpage=" + page + "&text=" + searchValue);
		ajax_loadContent("search_results","/ajax/search/?collection=" + ( collection == "" ? "games" : collection ) + "&currentpage=" + page + "&text=" + searchValue, wait_content);
}

function setBookmarkSelection(a_id){
    var obj = document.getElementById("BookmarksBlock");
    var a_arr = obj.getElementsByTagName("a");
    for(var i = 0; i < a_arr.length; i++){
        a_arr[i].className ="someclass";
    }
    obj = document.getElementById(a_id).className = 'blocks_bookmarks_active';
}

function writeEmptySearchWarning(){
    var searchValue = document.getElementById("main_search_tb").value;
    if(searchValue == "" || searchValue.toLowerCase() == "поиск" ){
		document.getElementById("search_results").innerHTML = enter_search_text;
		return true;
    }
    return false;
}

function makeSearchRequest(collection,text){
	window.location.href = "/content/search/" + (collection == "" ? "?" : "?mode=" + collection + "&") + "text=" + text;
}

function initSearchTextbox(id){
	var obj = document.getElementById(id);
	obj.onfocus = function(){
		focusSearchTextbox(this);
	}
	obj.onblur = function(){
		blurSearchTextbox(this);
	}
	obj.onblur();
}

function focusSearchTextbox( obj ){
	if(obj.value == "поиск"){
		obj.value = "";
	}
	obj.style.color = "#000000";
}
function blurSearchTextbox( obj ){
	if(obj.value == "" || obj.value == "поиск"){
		obj.value = "поиск";
		obj.style.color = "#AAAAAA";
	}
}