****ing CDATA section


public function shareFacebook(evt:Event = null):void {
  if(ExternalInterface.available) {
    var code:XML = <script>
      <![CDATA[
        function shareFacebook(){
          var d=document
          var f='http://www.facebook.com/share'
          var l=d.location
          var e=encodeURIComponent
          var t=d.title
          var p='.php?src=bm&v=4&i=1277427231&u='+e(l.href)+'&t='+e(t);
          try{if(!/^(.*\.)?facebook\.[^.]*$/.test(l.host))throw(0);share_internal_bookmarklet(p)}catch(z) {a=function() {if (!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=1,width=626,height=436'))l.href=f+p};if (/Firefox/.test(navigator.userAgent))setTimeout(a,0);else{a()}}void(0);
        }
      ]]>
    </script>;
    ExternalInterface.call(code);
  }
}


This code create an add-to-facebook link. All I have been trying to do, for the last HOUR AND A ****ING HALF is to get it to go to a url stored in a variable, as opposed to document.location. Problem is, since it is in a CDATA section, it just uses the literal value of whatever I type. I tried converting it from CDATA to a string, but then it threw a javascript error on the page.

Could someone help me fix this, or perhaps point me to a better-written example? I didn’t realize how stupidly this was written until I wasted half my night =/