// ------------------------------- update Object ----------------------------------------
var UPDATE_COMPANY=0;
var UPDATE_CONTACT=1;
var UPDATE_NEWCONTACT=2;
//
var UPDATE_INFO=0;
var UPDATE_EDITACTIVITY=1;
var UPDATE_NEWACTIVITY=2;
var UPDATE_DELETEACTIVITY=3;
//
function solveUpdate(proj,comp,sub) {
   this.proj=proj;
   this.comp=comp;
   this.sub=sub;
   this.actions=new Array();
   
   // methods
   this.processUpdates=processUpdates;
   
   // method functions
   function processUpdates() {
      alert("process updates (combine as necessary) and add to actionList");
   }
}

function solveUpdateAction(type,action,data) {
   this.type=type;
   this.action=action;
   
   //var indx=0;
   if (type==UPDATE_NEWCONTACT) {
   } else {
      switch (action) {
         case UPDATE_INFO:
            break;
         case UPDATE_EDITACTIVITY:
         case UPDATE_NEWACTIVITY:
            // companyId/contactId,actType,date,comment,(actId, caller)
            this.targetId=data[0];
            this.entryType=data[1];
            this.date=data[2];
            //alert(data[3]);
            this.comment=_tagAndCodeComment(data[3]);
            //alert(this.comment);
            this.entryId=data[4];
            if (action==UPDATE_EDITACTIVITY) {
               this.actNumber=data[5];
               // this.caller=data[6]; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< need to add!
            } else {
               this.caller=settings.caller;
            }
            break;
         case UPDATE_DELETEACTIVITY:
            break;
      }
   }
}

function _tagAndCodeComment(text) {
   var checkedList=_findCheckedValues("entryUnderRadio");
   if (checkedList[0]==="+" || settings.entryType!=SET_CALL) {
      // no con= required
   } else if (!settings.no1 && !settings.no2) {
      var subst=substitutions[3]+contacts[checkedList[0]].name;
      if (text.indexOf(subst)!=NOTFOUND) {
         var pos=text.indexOf(subst);
         text=text.slice(0,pos)+"con='"+contacts[checkedList[0]].name+"'"+text.slice(pos+subst.length);
      } else {
         if (text.indexOf("{con=")==NOTFOUND) text="{con='"+contacts[checkedList[0]].name+"'}"+text;
      }      
   }
   
   if (settings.no1) {
      var strippedText=_tidyText(_hideBraces(text));
      if (strippedText.indexOf(substitutions[0])!=NOTFOUND) {
         var pos=text.indexOf(substitutions[0]);
         text=text.slice(0,pos)+"no1"+text.slice(pos+substitutions[0].length);
      } else {
         if (text.indexOf("{no1}")==NOTFOUND) text="{no1}"+text;
      }
   }
   if (settings.no2) {
      var strippedText=_tidyText(_hideBraces(text));
      if (checkedList[0]==="+") var substText=substitutions[1]+substitutions[2];
      else var substText=contacts[checkedList[0]].name+substitutions[2];
      if (strippedText.indexOf(substText)!=NOTFOUND) {
         var pos=text.indexOf(substText);
         text=text.slice(0,pos)+"no2"+text.slice(pos+substText.length);
      } else {
         if (text.indexOf("{no2}")==NOTFOUND) text="{no2}"+text;
      }
   }
      
   /*settings.entryType=SET_CALL;
   settings.no1=false;
   settings.no2=false;
   settings.first=false;
   settings.decision=SET_NONE;
   settings.plus=false;*/
   
   // need to check that text doesn't already contain [1],[r], etc. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
   switch (settings.decision) {
      case SET_RED:
         text="[red] "+text;
         break;
      case SET_YELLOW:
         text="[yellow] "+text;
         break;
      case SET_GREEN:
         text="[green] "+text;
         break;
   }
   if (settings.first) text="[1] "+text;   
   if (settings.entryType==SET_PRIVATE) text="[*] "+text;
   return text;
}