function displaySections(sections, grouptype, pagetype, pagename) {
  myHTMLOutput = "";
  var nSections = sections.length;
  
  if(nSections >= 1)
  {
	  for (var i = 0; i < nSections; i++) 
	  {
		pagename = pagename.replace(/ /g,"+");
		section_name = sections[i].tag.replace(/ /g,"+");
		if(pagename.indexOf("search:") != 0)
		{
			view_all_link = "/matlabcentral/linkexchange/?term=exact_tagpair%3A%221179%2Facademic%22+exact_tagpair%3A%221179%2F" + pagename + "%22+exact_tagpair%3A%221179%2F" + section_name + "%22";
		}
		else
		{	
			search_term = pagename.substring(7,pagename.length)
			view_all_link = "/matlabcentral/linkexchange/?term=exact_tagpair%3A%221179%2Facademic%22+exact_tagpair%3A%221179%2F" + section_name + "%22+" + search_term;
		}
		//alert(view_all_link);
		myHTMLOutput += '<div class="resource_group">';
		myHTMLOutput += '<h3>' + sections[i].label + '</h3>';  
		//myHTMLOutput += '<h3><a href="' + view_all_link + '">' + sections[i].label + '</a></h3>';  
		myHTMLOutput += '<table class="resources" width="100%" cellspacing="0" cellpadding="0">';
		myHTMLOutput += '<thead></thead><tbody>';
		//myHTMLOutput += '<thead><th colspan="3"><a href="' + view_all_link + '">' + sections[i].label + '</a></th></thead><tbody>';
		//myHTMLOutput += '<thead><th colspan="3">' + sections[i].label + '</th></thead><tbody>';
		
		
		var items = sections[i].items;
		
		for (var j = 0; j < items.length; j++) 
		{                
		  if(j%2 != 0)
				myHTMLOutput += '<tr class="odd">';
		  else
				myHTMLOutput += '<tr>';
		  myHTMLOutput += '<td>' + '<a href="';
		  if(pagename == "mw+article")
		  {	 myHTMLOutput += items[j].url + '\" target=\"_blank\"'; }
		  else
		  {	 myHTMLOutput += items[j].le_url + '\"';	}
		  
		  myHTMLOutput +=  '>' + items[j].title + '</a>' + '</td>';
		  myHTMLOutput += '<td>' + items[j].summary + '</td>';
		  
		  if(pagetype == "topic")
				if(grouptype == "department")
					myHTMLOutput += '<td>' + items[j].resourcetype + '</td>';
				else if(grouptype == "resourcetype")
					myHTMLOutput += '<td>' + items[j].department + '</td>';
				else
					myHTMLOutput += '<td>' + items[j].resourcetype + '</td>';
		  else if(pagetype == "department")
				if(grouptype == "topic")
					myHTMLOutput += '<td>' + items[j].resourcetype + '</td>';
				else if(grouptype == "resourcetype")
					myHTMLOutput += '<td>' + items[j].topic + '</td>';
				else
					myHTMLOutput += '<td>' + items[j].resourcetype + '</td>';
		  else
				if(grouptype == "topic")
					myHTMLOutput += '<td>' + items[j].department + '</td>';
				else if(grouptype == "department")
					myHTMLOutput += '<td>' + items[j].topic + '</td>';
				else
					myHTMLOutput += '<td>' + items[j].department + '</td>';
		  myHTMLOutput += '</tr>';
		}             
		myHTMLOutput += '</tbody></table>';
		if(pagename != "mw+article")
			myHTMLOutput += '<p class="view_all"><a href="'+ view_all_link + '">More at MATLAB Central</a></p>';
		myHTMLOutput += '</div>';
		
	  }
	  $('#results').html(myHTMLOutput);
  }
  else
  {
	  //alert("no results");	  
	  $('#search_no_results').html("No matching records.");
	  $('.resourcecontainer').hide();
  }
} 



