// in: var news_link (string)

//Regular expression function test for the string
function TestDemo(str, re){
   var s='', repl;
   var r_exp = new RegExp(re,"ig");
   var arr = r_exp.exec(str);
   s=RegExp.$1;
   repl =new RegExp("[\"']","ig");             //Create regular expression pattern.
   s=s.replace(repl, "");                      //Replace "' with empty.
   if(s==''){
     return false;
   }
   return(s);
}

//Get the content of the META Tag
aMeta=document.getElementsByTagName("META");
var charset=false;
if(encoding=="_autodetect"){
  aMeta=document.getElementsByTagName("META");
  for(i=aMeta.length; i>0; i--){
    charset=TestDemo(aMeta[i-1].content, "charset=(.+)");
    if(charset!=false){
      encoding=charset;
      break;
    }
  }
}
//alert(encoding);

var agent=navigator.userAgent;
if(charset==false && agent.indexOf("Microsoft")!=-1){   //try to get the charset for IE
  encoding=document.charset;
}

//Link to the news escape the URL of the page
/*replace the hash if such exists*/
news_link=news_link.replace(/#/g, '');
news_link+="&encoding=utf-8&agent="+agent+"&page="+escape(document.URL);

// build link 
var text = '<scr'+'ipt language="javascript" src="' + news_link + '"></scr'+'ipt>';

document.write(text);