      /*
      * This function retrieves the search query from the URL.
      */

      function GetParam(name)
      {
          var match = new RegExp(name + "=(.+)[&]","i").exec(location.search);
          if (match==null)
          {
              match = new RegExp(name + "=(.+)","i").exec(location.search);
          }

          if (match==null)
          {
              return null;
          }

          match = match + "";
          result = match.split(",");
          return result[1];
      }


      /*
       * 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)
      {
          /*
           * Verify that there are actually ads to display.
           */
          var google_num_ads = google_ads.length;
          if (google_num_ads <= 0)
          {
              return;
          }

          var wideAds = "";   // texto html de bloque de anuncios anchos
          var wideAds2 = "";   // texto html de bloque de anuncios anchos
          var narrowAds = "";   // texto html de bloque de anuncios estrechos

          for(i = 0; i < google_num_ads; i++)
          {
              if (google_ads[i].type=="text/wide")
              {
				  if (i >= 0 && i <= 2) {
    	              // render a wide ad
        	          wideAds+='<li><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 + '">' +

                        	  '<span class="ad_line1">' + google_ads[i].line1 + '</span></a><br>' +
                          
	                          '<span class="ad_text">' + google_ads[i].line2 + '</span>' +
                          
    	                      '<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 + '">' +
                          
                    	      '<span class="ad_url">' + google_ads[i].visible_url + '</span><br></a>';
	              }

				  if (i > 2 && i <= 5) {
    	              // render a wide ad
        	          wideAds2+='<li><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 + '">' +

                        	  '<span class="ad_line1">' + google_ads[i].line1 + '</span></a><br>' +
                          
	                          '<span class="ad_text">' + google_ads[i].line2 + '</span>' +
                          
    	                      '<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 + '">' +
                          
                    	      '<span class="ad_url">' + google_ads[i].visible_url + '</span><br></a>';
	              }

				}

              else
              {
                  // mostrar un anuncio estrecho
                  narrowAds+='<li><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 + '">' +

                          '<span class="ad_line1">' + google_ads[i].line1 + '</span></a><br>' +

                          '<span class="ad_text">' + google_ads[i].line2 + '</span><br>' +

                          '<span class="ad_text">' + google_ads[i].line3 + '</span><br>' +

                          '<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 + '">' +

                          '<span class="ad_url">' + google_ads[i].visible_url + '</span><br></a>';
              }
          }

          if (narrowAds != "")
          {
              narrowAds = '<li><a style="text-decoration:none" ' +
                          'href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation">' +
                          '<span class="ad_header" style="text-align:left">Anuncios Google</span><br></a>' + narrowAds;
          }

          if (wideAds != "")
          {
              wideAds = '<li><a style="text-decoration:none" ' +
                        'href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation">' +
                        '<span class="ad_header" style="text-align:left">Anuncios Google</span><br></a>' + wideAds;
          }

          if (wideAds2 != "")
          {
              wideAds2 = '<li><a style="text-decoration:none;" ' +
                        'href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation">' +
                        '<span class="ad_header" style="text-align:left">Anuncios Google</span><br></a>' + wideAds2;
          }

          // Escriba texto HTML para anuncios anchos y estrechos para los elementos <div> adecuados
          if (document.getElementById(wide_ad_unit) != undefined ) document.getElementById(wide_ad_unit).innerHTML = '<ul>'+wideAds+'</ul>';
          if (document.getElementById(wide_ad_unit2) != undefined ) document.getElementById(wide_ad_unit2).innerHTML = '<ul>'+wideAds2+'</ul>';
          if (document.getElementById(narrow_ad_unit) != undefined ) document.getElementById(narrow_ad_unit).innerHTML = '<ul>'+narrowAds+'</ul>';
      }
