function set_win_target(type)
{
	if (type)
	{
		// Search opens a new browser window
		document.db_search.target = "_blank";
	}
	else
	{
		// Search stays in current window
		document.db_search.target = "";
	}
}

function set_forum_target()
{
	document.db_search.query.name = "search_keywords";
	return "http://www.phpbbhacks.com/forums/search.php";
}

function set_db_target()
{
	document.db_search.query.name = "query";
	return "http://www.phpbbhacks.com/searchresults.php";
}

function set_search_type(search_method)
{
	var temp = '';
	switch (search_method)
	{
		case "7":  // All downloads

		case "16":  // All downloads, new window

			temp = "4";

			break;
		case "8":  // All downloads, phpBB 3

		case "17":  // All downloads, phpBB 3, new window

			temp = "8";

			break;

		case "5":  // Images

		case "14":  // Images, new window

			temp = "2";

			break;
		case "6":  // Images, phpBB 3

		case "15":  // Images, phpBB 3, new window

			temp = "6";

			break;

		case "3":  // Templates

		case "12":  // Templates, new window

			temp = "3";

			break;
		case "4":  // Templates, phpBB 3

		case "13":  // Templates, phpBB 3,  new window

			temp = "7";

			break;

		case "1":  // Hacks

		case "10":  // Hacks, new window

			temp = "1";

			break;
		case "2":  // Hacks, phpBB 3

		case "11":  // Hacks, phpBB 3, new window

			temp = "5";

			break;

		case "9":  // Forums
		case "18":  // Forums, new window
			//temp = "";
			break;
	}
	document.db_search.search_type.value = temp;
}

function hacksdb_search()
{
	var search_method = document.db_search.search_method.options[document.db_search.search_method.selectedIndex].value;
	var search_action = '';
	if (search_method <= 9)
	{
		set_win_target(0);
	}
	else
	{
		set_win_target(1);
	}

	if ( search_method == 9 || search_method == 18 )
	{
		search_action = set_forum_target();
	}
	else
	{
		search_action = set_db_target();
	}

	set_search_type(search_method);

	if (search_action != "")
	{
		document.db_search.action = search_action;
		return true;
	}
	else
	{
		return false;
	}
}
