
var __notes = null;
function loadPaperNote(isCache, sendData, action) {
    if (isCache == null) isCache = true;
    var pathName = location.pathname;
    var lastDot = pathName.lastIndexOf(".");
    
    var kzm = pathName.substr(pathName.lastIndexOf(".") + 1);
    var noteFile = location.protocol + "//" + location.host + pathName.substring(0, lastDot) + ".n." + kzm + location.search;
    //alert(noteFile)
    $.ajax({
        type: "get",
        url: noteFile,
        data: sendData,dataType:"xml",
        processData: true,global:false,
        cache: isCache,
        async: true,
        success: function(data, textStatus) {
           var notesNode = data.selectSingleNode("/notes");
           __notes = new noteList(notesNode); 
           if ($.isFunction(action)) {
               action();
           }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            // 通常 textStatus 和 errorThrown 之中 + " Name:" +  JSON.parse(data).d.Name
        // 只有一个会包含信息
        //var t = XMLHttpRequest.responseText
       //alert(noteFile + XMLHtt.pRequest.responseText); 
        }
    });

}
function IsURL(str_url) {
    str_url = $.trim(str_url);
    if (str_url.indexOf(" ") != -1) return false;
    var strRegex = "^((https|http|ftp|rtsp|mms)://)" 
var re=new RegExp(strRegex); 
//re.test() 
if (re.test(str_url)){ 
return (true); 
}else{ 
return (false); 
} 
} 

function note(noteNode){
   var _noteNode=noteNode;

   this.textAddHref = function () {
       var t = _noteNode.text;
       if (IsURL(t)) { return "<a href='" + t + "' target='_blank'>查看</a>" }
       else return t;
   };
   this.text = function() {
       var t = _noteNode.text;
       return t;
   };
   
  this.getId = function() {
      var attr = _noteNode.getAttribute("id");
      if (attr == null) return "-1";
      return attr;
  }
   
   
}
function noteList(parentNote){
   var children=parentNote.selectNodes("note");
   var pNote=parentNote;
   this.count=function(){return children.length;}
   this.item=function(index){
      if(this.count()>0)
        return new note(children[index]);
      else
        return null;
   }
  this.getNoteById=function(noteId){
  if (this.count() > 0) {


      var k = pNote.selectSingleNode("note[@id='" + noteId + "']"); 
        if(k==null)return null;else
        return new note(k);
        
      }
      else
        return null;
  
  }
};


     
        
     