# File ads/ad_sense.rb, line 92
      def getAd(keywords,adClient)
        doTinyUrl=true

        @@userId=request.env['HTTP_USERID'] 
        if (@@userId.nil?)
          @@userId="101"
        end
        # build up the various arguments in the adArgs hash
        adArgs= SequencedHash.new
        adArgs["ad_type"]="text"
        adArgs["client"]=adClient 
        adArgs["format"]="mobile_single"
        adArgs["ip"]=request.remote_ip
        adArgs["markup"]="xhtml"
        adArgs["output"]="wml"
        adArgs["oe"]="utf-8"
        adArgs["url"]="http:%3A%2Fwww.getmobio.com"  # mobio's home site
        # adArgs["useragent"]=request.user_agent - doesn't actually work with the supplied useragent from the browser!
        adArgs["useragent"]||=@@mobioUseragent # its our runner so default to our useragent if no other one is available
        adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20]  # oneway hashed userid
        if (keywords)
          adArgs["kw"]=CGI::escape(keywords) 
          adArgs["kw_type"]="broad"
        end
        # now built the URL to call out to based upon the base URL and ad hash
        adURL=@@adServer + "?"
        first=1 # dont put ampersand on first one
        adArgs.each_key do |x|
          if adArgs[x]
            (adURL=adURL+"&") unless first
            first=nil # start putting in &s
            adURL = adURL + x + "=" + adArgs[x]   
          end
        end
        # ok, now call google's mobile adSense service and get back the full ad 
        @ad=open(adURL).read
        if @ad
          logger.info "Returned ad" + @ad 
          adDoc = REXML::Document.new @ad
          @text = adDoc.elements['//p']
          if @text  # do we have a <p> element
            # ok, now text has the full ad display content including links
            # grab @url, @urltext (link text for url), @phone, @phonetext (link text for call)      
            if defined? @text[1].attributes['href'] and @text[1].attributes['href']
              @adurl = doTinyUrl ? tinyUrl(@text[1].attributes['href']) : @text[1].attributes['href']
            else
              @adurl = "nolink.rwap" 
            end
            @urltext=@text[1].text
            @extratext=@text[2].to_s if @text[2] # this should have everything else that is not a child element
            if (@text.size>3 and @text[3]) # only process @text[3] for phone stuff if it exists
              @phone = (doTinyUrl ? tinyUrl(@text[3].attributes['href']) : @text[3].attributes['href']) if defined? @text[3].attributes['href'] and @text[3].attributes['href']
              @phonetext=@text[3].text if defined? @text[3].text and @text[3].text          
            end
          end
        end # if we get an ad back from adsense
        @ad # return the full ad text 

      end