//  Basic popup function
function popWin( winurl, w, h )
{
	if( w == undefined || w < 1 ) w = 480;
	if( h == undefined || h < 1 ) h = 360;
	var w = window.open(winurl,'newwindow','width='+w+',height='+h+',scrollbars=0,menubar=0,directories=0,location=0,resizable=0,status=0,toolbar=0');
}

//  Use the input elements to construct a search URL, and send the browser there.
function doSearch( isPopup )
{
	var searchpage = '/canadianfilmencyclopedia/search';
	var searchmodes = ['filmtitle','people','author','company'];

	var elem = document.getElementById('search_text');
	var str = elem.value;

	if( !str )
	{
		alert('You must enter some text to search for.');
		return;
	}

	var mode = null;

	for( var i = 0; i < searchmodes.length; ++i )
	{
		var m = searchmodes[i];
		elem = document.getElementById('search_'+m);
		if( elem.checked )
		{
			mode = m;
			break;
		}
	}

	var url = searchpage + '?search=' + str;

	if( mode )
		url = url + '&mode=' + mode;

	if( isPopup )
	{
		window.opener.location = url;
		window.close();
	}
	else
	{
		window.location = url;
	}
}

//  Handle 'enter' keypress for the search text box, to behave like a form.
function searchKeyPress( e, isPopup )
{
	//  Handle 'enter' keypress
	if( e && e.keyCode == 13 )
	{
		doSearch(isPopup);
		return false;  // we took that event
	}
	return true;
}

