var searchUrl = '';

// Redirects to a page, including the currently entered search criteria.
function doSearch() {
	var parameters = '';

	var searchFieldIds = ['country', 'where', 'venue', 'category', 'theme', 'period', 'searchtext', 'when', 'sortorder', 'sourceid', 'locationidlist'];
	
	if (jqOxynade('#where').val() == jqOxynade('#prevWhere').val())
	{
		searchFieldIds.push('distance');
		searchFieldIds.push('latitude');
		searchFieldIds.push('longitude');
	}
	
	for (var i=0; i<searchFieldIds.length; i++) {
		var searchFieldValue = jqOxynade('#' + searchFieldIds[i]).val();
		
		if (jqOxynade('#' + searchFieldIds[i]).length && jqOxynade('#' + searchFieldIds[i]).val() != '')
		{
			if (parameters != '')
				parameters += '&';
			parameters += searchFieldIds[i] + '=' + searchFieldValue;
			if(searchFieldIds[i]=='sourceid') {
				//also add the 'name' as a url parameter: sourceshortname has to be passed as well as sourceid
				parameters += '&sourceshortname='+jqOxynade('#sourceid').attr('name');
			}
		}
	}

	var fullSearchLink = searchUrl;
	if (parameters != '')
	{
		if (fullSearchLink.indexOf('?') == -1)
			fullSearchLink += '?';
		else
			fullSearchLink += '&';
	}
	fullSearchLink += parameters;
	window.location = fullSearchLink;
}

jqOxynade().ready(function() {
	jqOxynade("#searchButton").click(doSearch);
});
