// mini search include v1.2
// developed for Google Mini search on PIRSA Internet
// determines which search collection to use based on the url ( e.g. the channel )
// Peter M. Nov 2009
// Nic T. Jan 2012

var loc = window.document.location + "";
//var loc = "http://www.pir.sa.gov.au/forestry";
var url = loc.substring(35,25);

var collection = "pirsa"; // default collection for PIRSA website
var googleChannels = Array();

googleChannels['aghistory'] = Array("aghistory");
googleChannels['pirsa'] = Array("pirsa");
googleChannels['pirsa_about'] = Array("pirsa");
googleChannels['pirsa_agwine'] = Array("foodsafety", "gmc", "grains", "wine", "horticulture", "livestock", "planthealth", "ruralchem", "valuechains", "wid", "food");
googleChannels['pirsa_aquaculture'] = Array("aquaculture");
googleChannels['pirsa_fisheries'] = Array("fisheries");
googleChannels['pirsa_forestry'] = Array("forestry");
googleChannels['pirsa_minerals'] = Array("minerals");
googleChannels['pirsa_petroleum'] = Array("petroleum");
googleChannels['pirsa_geothermal'] = Array("geothermal");
googleChannels['pirsa_regions'] = Array("regions");

function getCollection(url, googleChannels, default_collection)
{
	var collection = default_collection;
	var collection_names = Array("aghistory", "pirsa", "pirsa_about", "pirsa_agwine", "pirsa_aquaculture", "pirsa_fisheries", "pirsa_forestry", "pirsa_geothermal", "pirsa_minerals", "pirsa_petroleum");
	
	for(var i=0; i<collection_names.length; i++)
	{
		var testChannel = collection_names[i];
		tcArray = Array();
		tcArray = googleChannels[testChannel];
		for( var j=0; j<tcArray.length; j++)
		{
			var url_suffix = tcArray[j];
			if(url.indexOf(url_suffix) > -1)
			{
				collection = testChannel;
			}
		}
	}
	return collection;
}


function doSearch()
{
	//alert(url); alert(loc)

        //if(document.minisearch.search_channel[0].checked)
        if((document.minisearch.search_channel[1] != undefined) && !document.minisearch.search_channel[1].checked) //To handle hidden field in place of radio buttons
	{
		collection = getCollection(url, googleChannels, "pirsa");
	}
	else
	{
		collection = "pirsa";
	}
	
	document.minisearch.site.value = collection;
	
        document.minisearch.submit();
}



