Twitter Pop-Up Box UrlEncode

I am trying to pre-fill the information in the Twitter Pop-up Tweet Box using this code I found on Twitter I believe and a couple of variables as well as a $URL function. However, when I attempt to click the link, I get this message:

 Not Found

The requested URL /https://twitter.com/share?           
text=I+Just+Downloaded+this+@MyTwitterHandle&u=http://example.com?my-     
category-information/12345/page-title.htm was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use     
an ErrorDocument to handle the request.

Here is the code I am using for this:

<a  style="width: 39px;" class="btn btn-success" title="Tweet This!"     
 href="#" 
  onclick="
   window.open(
    '<?=urlencode("https://twitter.com/share?text=I Just Downloaded this @MyTwitterHandle " . $thename . $f['Title'] . "&u=" . $this->URL("FileCloseup","",array('ID'=>$f['FileID'])))?>', 

   'twitter-share-dialog', 
    'width=626,height=436'); 
       return false;">

 <i class="fa fa-twitter fa"></i>

 </a>

Not sure what I am doing wrong here.