How to separate a js function?
<pre><code>&lt;!-- 
  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
--&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8"/&gt;
&lt;/style&gt;
&lt;script src="https://www.google.com/jsapi?key=ABQIAAAAeEJvEumzGBw8dvenGPw1bRTcyTBaKMmwi780-Sh78Ay3Pg36mBRsO3t_v4eega6kiiiRMl84WG-4eA"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
    google.load('search', '1');

    onload = function() {
    google.search.Search.getBranding('branding');
    //google branding
    var searchResultsContainer = document.getElementById('searchResults');

    var newsSearch = new google.search.NewsSearch();
    newsSearch.setSearchCompleteCallback(this, function() {
        if (newsSearch.results &amp;&amp; newsSearch.results.length &gt; 0) {
            searchResultsContainer.style.display = 'block';
            for (var i=0; i&lt;newsSearch.results.length; i++) {
                var wrapper = document.createElement('div');
                var node = newsSearch.results[i].html.cloneNode(true);
                wrapper.className = 'gs-result';
                wrapper.appendChild(node);
                searchResultsContainer.appendChild(wrapper);
            }
        }
    },null);

    newsSearch.execute("sport");
    //keyword
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div&gt;
    &lt;div id="branding" style="float:left;"&gt;&lt;/div&gt;
    &lt;div id="searchResults"&gt;&lt;/div&gt;   
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Hi, I want to make a Google news search, the above code is run well.
but I want to separate a js function. I use following code, but the result show nothing. How to modify it correctlly? Thanks.</p>

<pre><code>&lt;!-- 
  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
--&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8"/&gt;
&lt;/style&gt;
&lt;script src="https://www.google.com/jsapi?key=ABQIAAAAeEJvEumzGBw8dvenGPw1bRTcyTBaKMmwi780-Sh78Ay3Pg36mBRsO3t_v4eega6kiiiRMl84WG-4eA"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
    google.load('search', '1');
    function searchcomplete() {
        var newsSearch = new google.search.NewsSearch();
        if (newsSearch.results &amp;&amp; newsSearch.results.length &gt; 0) {
            searchResultsContainer.style.display = 'block';
            for (var i=0; i&lt;newsSearch.results.length; i++) {
                var wrapper = document.createElement('div');
                var node = newsSearch.results[i].html.cloneNode(true);
                wrapper.className = 'gs-result';
                wrapper.appendChild(node);
                searchResultsContainer.appendChild(wrapper);
            }
        }
    }    
    onload = function() {
    google.search.Search.getBranding('branding');
    //google branding
    var searchResultsContainer = document.getElementById('searchResults');

    var newsSearch1 = new google.search.NewsSearch();
    newsSearch1.setSearchCompleteCallback(this, searchcomplete ,null);

    newsSearch1.execute("sport");
    //keyword
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div&gt;
    &lt;div id="branding" style="float:left;"&gt;&lt;/div&gt;
    &lt;div id="searchResults"&gt;&lt;/div&gt;   
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
