google.load('search', '1');
// the cse class encapsulates a left and right search control
// both controls are driven by a shared search form
function cse(){
    var sFormDiv = document.getElementById("searchForm");
    var leftScDiv = document.getElementById("leftSearchControl");
    var rightScDiv = document.getElementById("rightSearchControl");
    
    // create a left, right search control
    // create a custom search form
    this.leftControl = new google.search.SearchControl();
    this.rightControl = 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 small result sets
    this.leftControl.setResultSetSize(google.search.Search.SMALL_RESULTSET);
    this.rightControl.setResultSetSize(google.search.Search.SMALL_RESULTSET);
    
    var searcher;
    var options;
    
    // configure right control for
 
 	// This one uses the custom search engine to hit www.law.ucdavis.edu
	// leaving out /news/
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction("000625840180408643694:cxgpssvrejq");
    searcher.setUserDefinedLabel("General Information");
    this.rightControl.addSearcher(searcher, options);
    
	// This one hits just news
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction("http://www.law.ucdavis.edu/news/news.aspx");
    searcher.setUserDefinedLabel("News");
    this.rightControl.addSearcher(searcher, options);
    
	// This one hits just events
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction("http://www.law.ucdavis.edu/news/event.aspx");
    searcher.setUserDefinedLabel("Events");
    this.rightControl.addSearcher(searcher, options);
    
	
	// This one hits just documents
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction("http://www.law.ucdavis.edu/ [http://www.law.ucdavis.edu/] filetype:pdf OR doc OR docx OR xls OR xlsx OR ppt OR pptx");
    searcher.setUserDefinedLabel("Documents");
    this.rightControl.addSearcher(searcher, options);
    
   // searcher = new google.search.WebSearch();
    //this.rightControl.addSearcher(searcher);
    
    // draw the left and right controls
    // the right control is drawn in tabbed mode
    var drawOptions = new google.search.DrawOptions();
    drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
    
    this.leftControl.draw(leftScDiv);
    this.rightControl.draw(rightScDiv, drawOptions);
    
    // execute a starter search
	var searchTerm = location.href.substr(location.href.indexOf('?')+1,location.href.length);
	searchTerm = searchTerm.replace(/%20/i, " ");
	if(location.href.indexOf('?') != -1)
    	this.searchForm.execute(searchTerm);
	else
    	this.searchForm.execute('Admissions');
}

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

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

function OnLoad(){
    new cse();
}

google.setOnLoadCallback(OnLoad, true);

