function submit_resources_keyword_search ()
{
  var keyword_search_type = 'directory';
  try {
  	if( typeof($("keyword_search_type")) != null && $("keyword_search_type").value != ""){
  	  keyword_search_type = $("keyword_search_type").value;
    }
  }
  catch(e){}
	if( typeof($("keyword_search_value")) != null && $("keyword_search_value").value != "")
	{
		var k_value = $("keyword_search_value").value;
		if (k_value.length<3){
			alert("Please enter at least 3 characters");
			return false;
		}
		//window.location.href = sBasePath+"living_in_hk/directory/search.htm?keyword="+escape($("keyword_search_value").value)+"&page=1&search_type="+keyword_search_type;
		window.location.href = sBasePath+"living_in_hk/directory/search.htm?k="+escape($("keyword_search_value").value)+"&page=1&search_type="+keyword_search_type;
	}
}
function resuorces_keyword_search_text_btn (evt)
{
	try{
		if(evt.keyCode == 13)
		{
			submit_resources_keyword_search();
		}
	}
	catch(e){}
}

function resources_keyword_search_init ()
{
try{
	if(typeof($("keyword_search_btn")) != null && typeof($("keyword_search_value")) != null && $("keyword_search_btn").tagName == "IMG" && $("keyword_search_value").tagName == "INPUT")
	{
		$("keyword_search_btn").onclick = submit_resources_keyword_search.bindAsEventListener(null);
		$("keyword_search_value").onkeypress = resuorces_keyword_search_text_btn.bindAsEventListener(null);
	}
	if(typeof($("directory_sort_by")) != null && $("directory_sort_by").tagName == "SELECT")
	{
		$("directory_sort_by").onchange = direct_sort_by_change_listener.bindAsEventListener(null);
	}
}
catch(e){}
}
Event.observe(window, "load", resources_keyword_search_init);

function resource_keyword_search_bc (code)
{
	var qp = window.location.href.toQueryParams();
	qp.bc = code;
	qp.page = 1;
	var h = $H(qp);
	window.location.href = sBasePath+"living_in_hk/directory/search.htm?"+h.toQueryString();
}

function direct_sort_by_change_listener (evt)
{
	var bid='';
	var keyword='';
	var qp = window.location.href.toQueryParams();
	if (qp.bid!= null)
		bid = qp.bid;
	if (qp.keyword!= null)
		keyword = qp.keyword;
	qp.orderby = $("directory_sort_by").options[$("directory_sort_by").selectedIndex].value;
	qp.page = 1;
	var h = $H(qp);
	if (keyword!='')
		window.location.href = sBasePath+"living_in_hk/directory/search.htm?"+h.toQueryString();
	else if (bid!='')
		window.location.href = sBasePath+"living_in_hk/directory/search.htm?"+h.toQueryString();
	
}
