var App_GoogleSearch = { googleOnLoad: function(key) { var customSearchControl = new google.search.CustomSearchControl(key); customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); var options = new google.search.DrawOptions(); options.enableSearchResultsOnly(); customSearchControl.draw('cse', options); var queryFromUrl = this.parseQueryFromUrl(); if (queryFromUrl) { customSearchControl.execute(queryFromUrl); } }, parseQueryFromUrl: function() { var queryParamName = "q"; var search = window.location.search.substr(1); var parts = search.split('&'); for (var i = 0; i < parts.length; i++) { var keyValuePair = parts[i].split('='); if (decodeURIComponent(keyValuePair[0]) == queryParamName) { return decodeURIComponent(keyValuePair[1].replace(/\+/g, ' ')); } } return ''; } };