// ------------------------------- subproject object ----------------------------------------
function subProject(compObj,name,isSubProject,start,end) {
   this.company=compObj;
   this.name=name;
   this.isSubProject=isSubProject;
   this.con=new Array();            // of contact indices
   this.stats=new Array();
   this.status=[NOTSET,NOTSET];
   this.entry1=[NOTSET,NOTSET];
   this.entry2=[NOTSET,NOTSET];
   this.progressEntry1=[NOTSET,NOTSET];
   this.progressEntry2=[NOTSET,NOTSET];
   this.start=start;
   this.end=end;
   this.isTicked=false;
   this.isSelected=false;
   
   // methods
   //this.findErrors=findErrors;
   this.processActivities=processActivities;
   this.getContactList=getContactList;
   
   // method functions
   function processActivities(dateFrom) {
      // for current dateFrom is set as 0; calculates stats and errors at the same time
      _searchActivities(dateFrom,this,this.start,this.end,SEARCH_CON);
      var ind=(dateFrom==0) ?NOW :OLD;
      var ent=_searchActivities(dateFrom,this,this.start,this.end,SEARCH_FIRST);
      if (ent==NOTFOUND) {
         // no [1]
         this.status[ind]=ONFIRSTCALL;
         this.entry1[ind]=_searchActivities(dateFrom,this,this.start,this.end,SEARCH_ANY);
         if (this.entry1[ind]==NOTFOUND) this.progressEntry1[ind]=NOTFOUND;
         else this.progressEntry1[ind]=_searchActivities(dateFrom,this,this.start,this.entry1[ind],SEARCH_NOCODES);
      } else {
         // [1]
         this.entry1[ind]=ent;
         this.progressEntry1[ind]=ent;
         ent=_searchActivities(dateFrom,this,this.entry1[ind],this.end,SEARCH_DECISION);
         if (ent==NOTFOUND) {
            // no decision
            this.status[ind]=NODECISION;
            this.entry2[ind]=_searchActivities(dateFrom,this,this.entry1[ind]-1,this.end,SEARCH_ANY);
            this.progressEntry2[ind]=_searchActivities(dateFrom,this,this.entry1[ind]-1,this.end,SEARCH_NOCODES);
         } else {
            // decision
            this.status[ind]=this.company.activities[ent].decision;
            if (ent!=this.entry1[ind]) {
               this.entry2[ind]=ent;
               this.progressEntry2[ind]=_searchActivities(dateFrom,this,ent,this.end,SEARCH_NOCODES);
            }
         }
      }
   }
   
   function getContactList(withTitles) {
      var listText="";
      //if (this.company.name=="Heatherlea") alert("get list");
      for (var i=0;i<this.con.length;i++) {
         //if (this.company.name=="Heatherlea") alert(this.con[i]);
         //if (this.company.name=="Heatherlea") alert(this.company.contactRelations.length);
         if (listText.length>0) listText+=", ";
         listText+=contacts[this.company.contactRelations[this.con[i]]].name;
         if (contacts[this.company.contactRelations[this.con[i]]].position!="")
            listText+=" ("+contacts[this.company.contactRelations[this.con[i]]].position+")";
      }
      return listText;
   }
}    
