/*
	Copyright (c) 2008 Google Inc.

	You are free to copy and use this sample.
	License can be found here: http://code.google.com/apis/ajaxsearch/faq/#license
*/
google.load('search', '1');

// the cse class encapsulates a search control and a search form
function cse(startSearch)
{
	var sFormDiv = document.getElementById("searchForm");
	var sContrDiv = document.getElementById("searchControl");

	// create search control and a custom search form
	this.searchControl = new google.search.SearchControl();
	this.searchForm = new google.search.SearchForm(true, sFormDiv);

	// bind clear and submit functions
	this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
	this.searchForm.setOnClearCallback(this, cse.prototype.onClear);

	// set up for large result sets
	this.searchControl.setResultSetSize(GSearch.LARGE_RESULTSET);
	this.searchControl.setLinkTarget(GSearch.LINK_TARGET_SELF);

	var searcher;
	var options;

	// Site Restrict to CSE ID
	var cseId = "008742922050479854700:sgrtw8uh7hc"; 
	// This is for a complete *.ubuntu-it.org search.
	//var cseId = "008949059787096431823:nzsphralfw4";
	searcher = new google.search.WebSearch();
	options = new google.search.SearcherOptions();
	searcher.setSiteRestriction(cseId, null);
	options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
	this.searchControl.addSearcher(searcher, options);

	this.searchControl.draw(sContrDiv);

	// execute a starter search
	if (startCustomSearch && startCustomSearch != "")
		this.searchForm.execute(startCustomSearch);
}

// when the form fires a submit, grab its
// value and call the search control
cse.prototype.onSubmit = function(form)
{
	var q = form.input.value;
	if (q && q!= "") {
		this.searchControl.execute(q);
	}
	return false;
}

// when the form fires a clear, call the search control
cse.prototype.onClear = function(form)
{
	this.searchControl.clearAllResults();
	form.input.value = "";
	return false;
}

function OnLoad()
{
	new cse();
}

google.setOnLoadCallback(OnLoad, true);
