  /*
   * Esta función es obligatoria: procesa el google_ads objeto JavaScript,
   * que contiene anuncios de AFS relevantes para la consulta de búsqueda del usuario. El nombre de
   * esta función <i>debe</i> ser <b>google_afs_request_done</b>. Si no se nombra correctamente
   * esta función, su página no mostrará anuncios de AFS.
   */


      function google_afs_request_done(google_ads)
      {
    	  // controlamos si hay algun anuncio para mostrar, si no ocultamos los divs
      	  if (google_ads.length <= 0)
          {
        	  if(bTopAdSense)
        	  {
        		  document.getElementById("wide_ad_unit_top").style.display = "none";
        	  }
        	  document.getElementById("wide_ad_unit").style.display = "none";
        	  return;
          }
          
          if(bTopAdSense)
          {

        	  //definimos la cabecera del adsense de arriba
        	  var wideAdsTop = '<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0"> ' +
								'<TBODY> ' +
				  				'<TR> ' +
				  				'<TD vAlign="top"> ' +
				  				'<DIV id="div_results"> ' +
				  				'<DIV id="bannerAdsenseSuperior" style="DISPLAY: block"> ' +
				  				'<DIV style="DISPLAY: block; PADDING-LEFT: 5px"> ' +
				  				'<DIV class="ad_header" style="text-align:left">' +
				  				'<a style="text-decoration:none" href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation">Annunci Google' +
				  				'</a></DIV> ';
	
	          //iteramos sobre 3 anuncios y los mostramos
        	  for(i = 0; i < google_ads.length; i++)
	          {
	        	  wideAdsTop += '' + 
		              			'<DIV class="content_Addsense">' +
		              				'<a style="text-decoration:none" onmouseover="javascript:window.status=\'' + google_ads[i].url + '\';return true;" ' +
		                            'onmouseout="javascript:window.status=\'\';return true;" href="' + google_ads[i].url + '" target="_blank">' +
		                            '<SPAN class="ad_line1">' +
		              					google_ads[i].line1 +
		              				'</SPAN></a>' +
		                            '<a style="text-decoration:none" onmouseover="javascript:window.status=\'' + google_ads[i].url + '\';return true;" ' +
		                            'onmouseout="javascript:window.status=\'\';return true;" href="' + google_ads[i].url + '" target="_blank">' +
		                            '<SPAN class="ad_url"> ' +
		              					google_ads[i].visible_url +
		              				'</SPAN> </a> <BR />' +
		              				'<SPAN class="ad_text">' +
		              					google_ads[i].line2 +
		              				'</SPAN><BR />' +
		              			'</DIV>';  	  		
	              
	        	  if(i==2){ break; }
	          }
          	
          	  // agregamos el cierre de los tags del adsense de arriba
          	  wideAdsTop +=' </DIV> ' +
						' <DIV></DIV>' +
						' </DIV>' +
						' </DIV>' +
						' </TD>' +
						' </TR>' +
						' </TBODY>' +	
						' </TABLE>';          
          
	          var wideAds = '';
          	  // preguntamos si hay anuncios para la parte de abajo
          	  if(3 < google_ads.length)
	          {	  
          	  	  /* ** ahora definimos la parte de abajo ** */
	          	  //definimos la cabecera del adsense de abajo
	        	  wideAds = '<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0"> ' +
	        	  			'<TBODY> ' +
					  		'<TR> ' +
					  		'<TD vAlign="top"> ' +
					  		'<DIV id="div_results"> ' +
					  		'<DIV id="bannerAdsenseSuperior" style="DISPLAY: block"> ' +
					  		'<DIV style="DISPLAY: block; PADDING-LEFT: 5px"> ' +
					  		'<DIV class="ad_header" style="text-align:left">' +
					  		'<a style="text-decoration:none" href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation">Annunci Google' +
					  		'</a></DIV> ';
		
		          //iteramos sobre 3 anuncios y los mostramos
	        	  for(i = 3; i < google_ads.length; i++)
		          {
		        	  wideAds += '' + 
			              			'<DIV class="content_Addsense">' +
			              				'<a style="text-decoration:none" onmouseover="javascript:window.status=\'' + google_ads[i].url + '\';return true;" ' +
			                            'onmouseout="javascript:window.status=\'\';return true;" href="' + google_ads[i].url + '" target="_blank">' +
			                            '<SPAN class="ad_line1">' +
			              					google_ads[i].line1 +
			              				'</SPAN></a>' +
			                            '<a style="text-decoration:none" onmouseover="javascript:window.status=\'' + google_ads[i].url + '\';return true;" ' +
			                            'onmouseout="javascript:window.status=\'\';return true;" href="' + google_ads[i].url + '" target="_blank">' +
			                            '<SPAN class="ad_url"> ' +
			              					google_ads[i].visible_url +
			              				'</SPAN> </a> <BR />' +
			              				'<SPAN class="ad_text">' +
			              					google_ads[i].line2 +
			              				'</SPAN><BR />' +
			              			'</DIV>';  	  		
		          }
	          	
	          	  // agregamos el cierre de los tags del adsense de abajo
	          	  wideAds +=' </DIV> ' +
							' <BR />' +
							' <DIV></DIV>' +
							' <BR />' +
							' </DIV>' +
							' </DIV>' +
							' </TD>' +
							' </TR>' +
							' </TBODY>' +	
							' </TABLE>';          
              }	  
          	  
          	  //Agregamos el HTML a cada div correspondiente
	          document.getElementById("wide_ad_unit_top").innerHTML = wideAdsTop;
	          document.getElementById("wide_ad_unit").innerHTML = wideAds;
          }
          else
          {
	          /* ** dejamos como funcionaba antes para las busquedas sin resultados ** */
        	  // texto html de bloque de anuncios anchos
	          var wideAds = '<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0"> ' +
	          				'<TBODY> ' +
	          				'<TR> ' +
	          				'<TD vAlign="top"> ' +
	          				'<DIV id="div_results"> ' +
	          				'<DIV id="bannerAdsenseSuperior" style="DISPLAY: block"> ' +
	          				'<DIV style="DISPLAY: block; PADDING-LEFT: 5px"> ' +
	          				'<DIV class="ad_header" style="text-align:left">' +
	          				'<a style="text-decoration:none" href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation">Annunci Google' +
	          				'</a></DIV> ';
	          for(i = 0; i < google_ads.length; i++)
	          {
	              if (google_ads[i].type=="text/wide")
	              {
	                  // render a wide ad
	                  wideAds+= '' +
		              			'<DIV class="content_Addsense">' +
		              				'<a style="text-decoration:none" onmouseover="javascript:window.status=\'' + google_ads[i].url + '\';return true;" ' +
		                            'onmouseout="javascript:window.status=\'\';return true;" href="' + google_ads[i].url + '" target="_blank">' +
		                            '<SPAN class="ad_line1">' +
	                  					google_ads[i].line1 +
	                  				'</SPAN></a>' +
	                                '<a style="text-decoration:none" onmouseover="javascript:window.status=\'' + google_ads[i].url + '\';return true;" ' +
	                                'onmouseout="javascript:window.status=\'\';return true;" href="' + google_ads[i].url + '" target="_blank">' +
	                                '<SPAN class="ad_url"> ' +
	                  					google_ads[i].visible_url +
	                  				'</SPAN> </a> <BR />' +
	                  				'<SPAN class="ad_text">' +
	                  					google_ads[i].line2 +
	                  				'</SPAN><BR />' +
	                  			'</DIV>';  	  		
	              }
	          }
	          
	          wideAds +=' </DIV> ' +
	          			' <BR />' +
	          			' <DIV></DIV>' +
	          			' <BR />' +
	          			' </DIV>' +
	          			' </DIV>' +
	          			' </TD>' +
	          			' </TR>' +
	          			' </TBODY>' +	
	          			' </TABLE>';
	          // Escriba texto HTML para anuncios anchos y estrechos para los elementos <div> adecuados
	          document.getElementById("wide_ad_unit").innerHTML = wideAds;
          }
      }
