var http_request;
function getRequest(){
      if (window.XMLHttpRequest) { // Mozilla, Safari, ...
              return new XMLHttpRequest();
      } else if (window.ActiveXObject) { // IE
              return new ActiveXObject("Microsoft.XMLHTTP");
      }
}
function addToFavorite(typeStr,titleStr,postStr){
    var http_request = getRequest();
    var url=window.location.href.replace('&','%26');
    var type = changeToEncode(typeStr);
    var title = changeToEncode(titleStr);
    http_request.open('post', postStr, true);
    http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    http_request.send("method=addFavorite&title="+title+"&type="+type+"&url="+url);
    alert('成功将当前页面添加到[我的收藏]中!');
}
function changeToEncode(str){
    var type = '';
    for(var i=0;i< str.length;i++){
      type = type + escape(encodeURIComponent(str.substr(i,1)));
    }
    return type;
}

