function google_ws_request_done(google) {

    /*
     * Verify that there are actually ads to display.
     */
	 
    var google_num_ads = google.ads.length;
    if (google_num_ads > 0) { 

	var wideAds = '';    //wide ad unit html text
	var wideAds2 = '';   //wide ad unit html text

	var headerText = '<div class="sponsored_box">' +
			 '<div class="sponsored_head"></div>' +
    			 '<div class="sponsored_main"><span><a href="http://www.startlap.hu/sub/adatved.html">Szponzorált linkek</a></span>' +
			 '<span style="margin-left:415px;font-size:10px">' + 
			 '<a href="http://adwords.google.com/" target="_blank">' +
			 'Hogyan kerülhet ide a hirdetésed?</a></span>';
	var footerText = '</div>' +
			 '<div class="sponsored_foot"></div>' +
			 '</div>';
 
	for(i = 0; i < 6; i++) {
 	  if (google.ads[i])
	    wideAds+='<div class="result">' +
		'<a href="' + google.ads[i].url + '" ' +
		'onmouseout="window.status=\'\';return true" ' +
		'onmouseover="window.status=\'go to ' +
		google.ads[i].visible_url + '\';return true" ' +
		'><span class="title">' + google.ads[i].line1 + '</span><br />' +
		'<span class="desc">' + google.ads[i].line2 + '</span><br /> ' +
		'<span class="url">' + google.ads[i].visible_url + '</span>' +
	  	'</a>' +
	  	'</div>';
	}
    
	for(i = 6; i < 10; i++) {
	   if (google.ads[i])	
	    wideAds2+='<div class="result">' +
		'<a href="' + google.ads[i].url + '" ' +
		'onmouseout="window.status=\'\';return true" ' +
		'onmouseover="window.status=\'go to ' +
		google.ads[i].visible_url + '\';return true" ' +
		'><span class="title">' + google.ads[i].line1 + '</span><br />' +
		'<span class="desc">' + google.ads[i].line2 + '</span><br /> ' +
		'<span class="url">' + google.ads[i].visible_url + '</span>' +
		'</a>' +
		'</div>';
	}

	if (wideAds != "") {
		wideAds = headerText + wideAds + footerText;
	}

	if (wideAds2 != "") {
		 wideAds2 = headerText + wideAds2 + footerText;
	}

	document.getElementById("wide_ad_unit_1").innerHTML = wideAds;
	document.getElementById("wide_ad_unit_2").innerHTML = wideAds2;
    }

    /*
     * Verify that there are actually search results to display
     */

    var google_num_ws = google.res.r.length;
    if (google_num_ws > 0) {
	var timeTaken = Math.round(google.tm*Math.pow(10,2))/Math.pow(10,2);
	var resultsDisplay = addDots(google.res.m);

	var wideWS = '';   //wide ws unit html text
    
	var wsHeaderText = '<div id="search_info">';
    if (google.spelling) {
        wsHeaderText += '<span style="font-size:medium;"><span style="color:#cc0000">Keresési javaslat:</span> <a href="?q=' + google.spelling.q + '">' + google.spelling.text + '</a></span><br /><br />';
    }
	wsHeaderText += 'A(z) <b>"' + google.q +
		'"</b> kifejezés <b>' + google.res.sn +
		'-' + google.res.en  +
		'.</b> találata az összes, kb. <b>' + resultsDisplay +
		'</b> találatból. (<b>' + timeTaken +
		'</b> másodperc)' + 
		'</div>'; 

	for(i = 0; i < google_num_ws; i++) {
	   
       var newURL = parseURL(google.res.r[i].u);
       newURL = google.res.r[i].u.replace(newURL.protocol + '://', '');
       
        // construct the search element
	    wideWS+='<div class="result">' +
		'<div class="title">' +
		'<a href="' + google.res.r[i].u + '" ' +
		'onmouseout="window.status=\'\';return true" ' +
		'onmouseover="window.status=\'go to ' +
		google.res.r[i].ue + '\';return true" ' +
		'>' + google.res.r[i].t + '</a></div>' +
		'<div class="desc">' + google.res.r[i].s + '</div>' +
		'<div class="url">' + newURL +
		' - ';

	    // if the cache size element exists, show it
	    if (google.res.r[i].sz) {
		wideWS+=google.res.r[i].sz + ' - ';
	    }

	    // if the cache link element exists, show a cache link
	    if (google.res.r[i].cid) {
		wideWS+='<a href=' +
		    '"http://www.google.hu/search?hl=hu&amp;q=cache:' +
		    google.res.r[i].cid + ':' +
		    google.res.r[i].u + '">Tárolt változat</a>' + ' - ';
	    }

	    // end search element with related link
	    wideWS+='<a href="?q=related:' + google.res.r[i].u +
		'">Hasonló oldalak</a>' + '</a></div></div>';
	}

	if (wideWS != "") {
	    wideWS = wsHeaderText + wideWS;
	}

	document.getElementById("websearch_unit").innerHTML = wideWS;

	/*
	 * Create the page selector
	 */

	// how many pages to show in the pager
	var resPerPage = 10;
	var maxPages = Math.ceil(google.res.m/resPerPage);

	// current page and min/max pages (maximum window of -10 to +9)
	var currentPage = Math.floor(google.res.sn/resPerPage) + 1;
	var startPage = currentPage - 10;
        if ( startPage < 1 ) { startPage = 1 };
	var endPage = currentPage + 9;
	if ( endPage > maxPages ) { endPage = maxPages };

	// page start values
	var currentPageStart = (currentPage-1) * resPerPage;
	var nextPageStart = currentPage * resPerPage;
	var lastPageStart = (currentPage-2) * resPerPage;
	var maxPageStart = (maxPages-1) * resPerPage;
	if (maxPageStart > 390) { maxPageStart = 390; }

	var pageHTML = "";

	// show last button
	if (currentPage > 1) {
	    pageHTML+='<img src="i/arrow_left.gif" align="bottom" class="last" alt="Vissza" />'
		+ '\n<a href="?q=' + encodeURIComponent(google.q) + '&amp;start='
		+ lastPageStart + '">Vissza</a>\n';
	}

	// calculate page start
	var thisPageStart = resPerPage * (startPage-1);
	for (i = startPage; i <= endPage; i++) {
	    // if page num higher than 1, add ...
	    if ((i == startPage) && (startPage > 1 )) {
		pageHTML+= '<a href="?q=' + encodeURIComponent(google.q) +
			'&amp;start=0">...</a> | ';
	    }

	    // don't provide link for current page
	    if (i == currentPage) {
		pageHTML+= i;
	    } else { 
		pageHTML+='<a href="?q=' + encodeURIComponent(google.q) +
			'&amp;start=' + thisPageStart + '">' + i + '</a>';
	    }

	    // put a pipe after the page num unless final page
	    if (i < endPage ) {
		pageHTML+= ' | ';
		thisPageStart += resPerPage;
	    } 
	}

	// put ... at the end if there are pages not showing
	if ((endPage + 1) <= maxPages) {
	    pageHTML+=' <a href="?q=' + encodeURIComponent(google.q) +
			'&amp;start=' + maxPageStart + '">...</a>';
	}

	// put next page link if not on the last page
	if (currentPage < maxPages) {	
	    pageHTML+=' <a href="?q=' + encodeURIComponent(google.q) +
		'&amp;start=' + nextPageStart + '">Következő</a>\n' +
		'<img src="i/arrow_right.gif" align="bottom" class="next"' +
		' alt="Következő" />';
	}
    
	document.getElementById("spacer").innerHTML = '<div class="hr"></div>';
	document.getElementById("pager").innerHTML = pageHTML;
	
	// set the style of the bottom search box
	document.getElementById('footer').style.position = 'relative';

    } else if (google.q) {

	// no search results found
	var emptyHTML = '<ul>A keresett kifejezés (<b>' + google.q +
		'</b>) egyetlen dokumentumban sem található meg.\n' +
		'<p>Javaslatok:</p>\n' +
		'<ul style="list-style-type: square;">\n' +
		'<li>Győződjön meg arról, hogy valamennyi szót helyesen írta.</li>\n' +
		'<li>Próbálkozzon más kulcsszavakkal.</li>\n' +
		'<li>Próbálkozzon több általános kulcsszóval.</li>\n';
		'</ul>\n</ul>';
	document.getElementById("websearch_unit").innerHTML = emptyHTML;

    }
}

function addDots(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}

