
function addPaginationLinks() {
	// The cursor object has all things to do with pagination
	var cursor = webSearch.cursor;
	var curPage = cursor.currentPageIndex; // check what page the app is on
	var pagesDiv = document.createElement('div');
	for (var i = 0; i < cursor.pages.length; i++) {
		var page = cursor.pages[i];
		if (curPage == i) { // if we are on the curPage, then don't make a link
			var label = document.createTextNode(' ' + page.label + ' ');
			pagesDiv.appendChild(label);
		} else {
			// If we aren't on the current page, then we want a link to this page.
			// So we create a link that calls the gotoPage() method on the searcher.
			var link = document.createElement('a');
			link.href = 'javascript:webSearch.gotoPage('+i+');';
			link.innerHTML = page.label;
			link.style.marginRight = '2px';
			pagesDiv.appendChild(link);
		}
	}

	var contentDivCenterRight = document.getElementById('nav-center-right'); 
	var contentDivCenter = document.getElementById('nav-center'); 
	var contentDiv;
	if (document.getElementById('nav-center')) 
		contentDiv=document.getElementById('nav-center');
	else
		contentDiv=document.getElementById('nav-center-right');
	contentDiv.appendChild(pagesDiv);
}

function searchComplete(title) {
	// Check that we got results
	var contentDivCenterRight = document.getElementById('nav-center-right'); 
	var contentDivCenter = document.getElementById('nav-center'); 
	var contentDiv;
	if (document.getElementById('nav-center')) 
		contentDiv=document.getElementById('nav-center');
	else
		contentDiv=document.getElementById('nav-center-right');
	contentDiv.innerHTML = '<h2>'+title+'</h2><br/>'; 
	if (webSearch.results && webSearch.results.length > 0) {
		// Loop through our results, printing them to the page.
		var results = webSearch.results;
		for (var i = 0; i < results.length; i++) {
			var result = results[i];
			var resContainer = document.createElement('div');
			resContainer.className='gw1';
			
			var title = document.createElement('div'); 
			title.className='gw2'; 
			titulek='<a href="' + result.url + '">' + result.title + '</a>'; 
			title.innerHTML = titulek;
			var content = document.createElement('div'); 
			content.className='gw3'; 
			content.innerHTML = result.content; 
			
			/* 
			var newImg = document.createElement('img');
			// There is also a result.url property which has the escaped version
			newImg.src = result.tbUrl;
			*/ 
			resContainer.appendChild(title);
			resContainer.appendChild(content); 
			// imgContainer.appendChild(newImg);
			
			// Put our title + image in the content
			contentDiv.appendChild(resContainer);
		
		}
		
		// Now add the paging links so the user can see more results.
		addPaginationLinks(webSearch);
		
		// setResultSetSize
		
		var b= gSearch.getBranding(); 
		contentDiv.insertBefore(b, contentDiv.firstChild); 
	} 
	else {
		contentDiv.innerHTML = 'no results'; 
	}
}
function OnLoad(lang,title,site) {
	gSearch= google.search.Search;
	// Our ImageSearch instance.
	// imageSearch = new google.search.ImageSearch();
	webSearch = new google.search.WebSearch(); 
	
	// Restrict to extra large images only
	webSearch.setSiteRestriction(site);
	
	// Here we set a callback so that anytime a search is executed, it will call
	// the searchComplete function and pass it our WebSearch searcher.
	
	webSearch.setResultSetSize(gSearch.LARGE_RESULTSET); 
	//searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
	//gSearch.setNoResultsString(gSearch.NO_RESULTS_DEFAULT_STRING);
	 var extendedArgs = google.search.Search.RESTRICT_EXTENDED_ARGS;
	  webSearch.setRestriction(extendedArgs, {lr:'lang_'+lang});
	webSearch.setSearchCompleteCallback(this, searchComplete, [title]);
	var query = document.getElementById("q");
	
	webSearch.execute(query.value); 
}
