/*
Desc.: Func to support add as favorite process.
*/


//Global to store sTableLinkId
var sAddFavTableLinkId_g = "";

//siIdTableLink: Html id of the table where the link to "add as favorite" is.
function addFavDialog(siBoxId, siScore1Id, siScore2Id, siScore3Id, siTextAreaId, siIdTableLink){
   this.sBoxId = siBoxId;
   this.sScore1Id = siScore1Id;
   this.sScore2Id = siScore2Id;
   this.sScore3Id = siScore3Id;
   this.sTextAreaId = siTextAreaId;
   this.sTableLinkId = siIdTableLink; //Id of the link item that initiated this dialog.
   sAddFavTableLinkId_g = siIdTableLink;
   this.show = showAddFavBox;   
   this.yesSelected = addFavPressed;
   this.noSelected = addFavCancelPressed;
   this.privComplete = addFavComplete;
   this.iRevPropId = 0; //Associate review prop id.
}

function showAddFavBox(iiRevPropId){
   this.iRevPropId = iiRevPropId;
   return sm(this.sBoxId, csFavDialogWidth, csFavDialogHeight);
}


/*
Desc.:
In:
   iiReviewId: Id of the review to be favorite    
*/
function addFavPressed(){
   var url = csServerUrlRoot + '/add_fav_update';   
   var iFavScore = 1;
   
   if ($(this.sScore1Id).checked){
      iFavScore = 1;
   }
   else if ($(this.sScore2Id).checked){
      iFavScore = 2;
   }
   else{
      iFavScore = 3;
   }
   
   sFavNote = $(this.sTextAreaId).value;
   
   var myAjax = new Ajax.Request(
      url,
      {
         method: 'post',
         parameters: {rev_prop_id: this.iRevPropId, fav_score: iFavScore, fav_note: sFavNote},
         onComplete: this.privComplete
      });
}

/*

Note: All ajax on complete function are callback where only the func is passed and not the obj.  Inside callbacks, you cannot access 
   object data members.
*/
function addFavComplete(iRequest){
   if (csAjaxRespPass == iRequest.responseText){
      //Hide the "add as favorite link".  
      //document.getElementById(sAddFavTableLinkId_g).deleteRow(0);
      //$(sAddFavTableLinkId_g).style.display = "none";
      
      notifBoxJsObj.show("Review has been added as favorite.");
      setTimeout("",csNotifTimeout);
      window.location.reload();
   }
   else{
      notifBoxJsObj2.show("An error occured while trying to add review as favorite");
   }
}

/*
Desc.:
In:

*/
function addFavCancelPressed(){
   //We just don't proceed if the user presses no.
}
