
/**
 * Provides suggestions for state names (USA).
 * @class
 * @scope public
 */
function AWNode() {
}


/**
 * Request suggestions for the given autosuggest control. 
 * @scope protected
 * @param oAutoSuggestControl The autosuggest control to provide suggestions for.
 */
AWNode.prototype.requestNodeTree = function (oTreeControl /*:AutoSuggestControl*/) {
    
    var iLibraryId = oTreeControl.newspaperId;
    SimpleSearchService.getRootNodesByLibraryId(iLibraryId,function(node) {
    
    var aNames = []; 
    var aIds = [];
    var pheader = '';
    //node.sort();
    for (var i=0; i < node.length; i++) { 
       aNames.push(node[i][1]);
       aIds.push('node_'+node[i][0]);
    }    
    oTreeControl.autosuggest(aNames,aIds);
    });
};


AWNode.prototype.requestRootNodeTree = function (oTreeControl /*:AutoSuggestControl*/) {
    
    NodeUpdateMonitor.getMyWareFavoriteRootFolders(function(result){
       var aNames = []; 
       var aIds = [];    
       if(result && result.length>0){
         for (var i=0; i < result.length; i++) { 
           aNames.push(result[i][1]);
           aIds.push('node_'+result[i][0]);
         }         
       }
       oTreeControl.autosuggest(aNames,aIds);
    });
    //var aNames = ['eBooks','Demo Documents','Historical Archive','MHI Documents']; 
    //var aIds = ['47788','1','9232','48689'];
    //oTreeControl.autosuggest(aNames,aIds);
}
    
    
AWNode.prototype.requestNodeChildes = function (oTreeControl,oBranch /*:TreeBranch*/,branch2) {
    
    var npid = oBranch.id;
    if(npid!=null && npid.indexOf('_')>-1){
       npid = npid.substring(npid.indexOf('_')+1);
    }
    NodeUpdateMonitor.getMyWareFavoriteFolderChilds(npid,function(node){
    //node.sort();
    if(oBranch.leaves.length>0){
       oBranch.leaves.splice(0,oBranch.leaves.length);
    }
    if(node!=null && node.length>0){
      var iar = 1;
      var iad = 1;
      for (var i=0; i < node.length; i++) { 
         iad++;
         if(node[i][2]!='0'){
            var branch1 = new branch('branch_'+node[i][0],node[i][1]);
            oBranch.add(branch1);
         }else{
            var leaf1 = new leaf(node[i][1],'leaf_'+node[i][0]); //name,id
            oBranch.add(leaf1);         
         }
      }
    }
       //if(node.length>0){
	  currentoBranchId = oBranch.id;
	  currentoBranchDocumentId = -1;
	  oTreeControl.reWriteTree(branch2);
	//}
    });
};
