﻿Utility.Google = function()
{
    var _divresults;
    Ext.onReady(this.Initialize.createDelegate(this));
}

Ext.extend(Utility.Google, Ext.util.Observable,
{
    Initialize : function()
    {
        this._divresults = Ext.get('GoogleResults');
        this.addEvents({"onData": true});
    },
    
    FirstSearch : function()
    {
        var qs = Ext.urlDecode(window.location.search.substring(1));
        Ext.get('keyword').dom.value = qs.Keyword;
        Google.Google.FirstSearch(qs.Keyword, this.Search_process.createDelegate(this));
    },
    
    Search : function(URL)
    {
        Google.Google.Search(URL, this.Search_process.createDelegate(this));
    },
    
    Search_process : function(response)
    {
        if (response.error)
        {
            alert('There was an error message from the AJAX call:\n\n' + response.error.Message);
        }
        else
        {
            this._divresults.update(response.value);
        }
    }
});
