﻿   var _MyList_basketurl = "/blog/popup/BasketPush.aspx"; 
   var _MyList_moveurl = "/blog/popup/MoveItem.aspx"; 
   var _MyList_savelisturl = "/blog/popup/SaveListPush.aspx";
   
   var MyListParams = function(blogid, communityType, paperid, divName){
      this.blogid = blogid;
      this.communityType = communityType;
      this.paperid = paperid;
      this.divName = divName;
      this.checked = false;
   }
   
   MyListParams.prototype.Make = function(url, item){
      return url  + "?blogid=" + this.blogid
                  + "&communitytype=" + this.communityType
                  + "&paperid=" + this.paperid
                  + "&items=" + item;
   }
   
   //아이템 유효성을 체크하여 반환
   MyListParams.prototype.GetItems = function(item){
      return (item == null) ? getCheckedCheckboxForDiv($(this.divName)) : item;
   }
   
   //장바구니 담기
   MyListParams.prototype.SaveBasket = function(item){
      var item = this.GetItems(item);
      if(item == null || item == "")
      {
         alert('선택된 상품이 없습니다. 장바구니에 담을 상품을 선택해주세요');
         return false;
      }
      var url = this.Make( _MyList_basketurl, item);
      window.open(url, 'mylistWin','width=420,height=240,resizable=0,scrollbars=0');
   }
   
   
   //보관리스트로 보내기
   MyListParams.prototype.CopySaveList = function(item){
      var item = this.GetItems(item);
      if(item == null || item == "")
      {
         alert('선택된 상품이 없습니다. 보관리스트로 보낼 상품을 선택해주세요');
         return false;
      }
      var url = this.Make( _MyList_savelisturl, item);
      window.open(url, 'mylistWin','width=420,height=240,resizable=0,scrollbars=0');
   }
 
   
   //다른리스트로 보내기
   MyListParams.prototype.MoveItems = function(item){
      var item = this.GetItems(item);
      if(item == null || item == "")
      {
         alert('선택된 상품이 없습니다. 다른리스트로 보낼 상품을 선택해주세요');
         return false;
      }
      var url = this.Make( _MyList_moveurl, item);
      window.open(url, 'mylistWin','width=420,height=420,resizable=0,scrollbars=0');
   }
   
   
   //삭제
   MyListParams.prototype.DeleteItems = function(item, div){
      var item = this.GetItems(item);
      if(item == null || item == "")
      {
         alert('선택된 상품이 없습니다. 삭제할 상품을 선택해주세요');
         return false;
      }
      var isDelete = confirm("선택한 상품을 삭제하시겠습니까?");
      if(isDelete){
            var param = {  paperid: this.paperid, 
                           blogid:  this.blogid,
                           communitytype : this.communityType, 
                           itemid: item
                        };

            req = Alajax.invoke( "MyListAjax", 
                                 "DeleteItem", 
                                 param, 
                                 function(res){ 
                                     if(div == null)
                                          document.location.reload();
                                      else   
                                          $(div).style.display = 'none';
                                 }, 
                                 MyListFormFailHandler);   
      }
   }
   
   //상품 추가
   MyListParams.prototype.AddItem = function(item){
      var param = {paperid: this.paperid, 
                  blogid:  this.blogid,
                  communitytype : this.communityType, 
                  itemid: item
                  };
  
      req = Alajax.invoke( "MyListAjax", "AddItem", param, function(res){ document.location.reload(); }, MyListFormFailHandler);           
   } 
   
   //상품 코멘트 입력 ui 보이기
   MyListParams.prototype.ShowItemComment = function(item){
      var divBtn = $('divItemCommentBtn_' +  item);
      var divComment = $('divItemComment_' + item);
      var txtComment = $('txtItemComment_' + item);
      
      divComment.style.display = "none";
      txtComment.style.height = "100px";
      txtComment.style.display = "block";
      txtComment.focus();
      divBtn.style.display = "block";
   }
   
   //상품 코멘트 입력 ui 감추기- 이전상태로 복구
   MyListParams.prototype.HideItemComment = function(item){
      var divBtn = $('divItemCommentBtn_' + item);
      var divComment = $('divItemComment_' + item);
      var txtComment = $('txtItemComment_' + item);
      
      divComment.style.display = "block";
      txtComment.style.display = "none";
      txtComment.value = divComment.innerHTML.replace(/<br>/gi, "\r\n");
      divBtn.style.display = "none";
   }
   
   //상품 코멘트 설정 
   MyListParams.prototype.ExecItemComment = function(item){
      var txtComment = $('txtItemComment_' + item);
      
      //유효하지 않은 문자열은 제거 
      txtComment.value = txtComment.value.stripScripts();
      
      var param = {paperid: this.paperid, 
                  blogid:  this.blogid,
                  communitytype : this.communityType, 
                  itemPkid: item,
                  comment: txtComment.value
                  };

      var obj = this;
      req = Alajax.invoke( "MyListAjax", "SetItemComment", param, function(res){ obj.UpdateItemComment(item) }, MyListFormFailHandler);           
   }

   
   //상품 코멘트 입력 ui 감추기- 코멘트 설정 완료 처리
   MyListParams.prototype.UpdateItemComment = function(item){
      var divBtn = $('divItemCommentBtn_' + item);
      var divComment = $('divItemComment_' + item);
      var txtComment = $('txtItemComment_' + item);
      
      divComment.style.display = "block";
      divComment.innerHTML = txtComment.value.replace(/\r\n/gi, "<br>");
      txtComment.style.display = "none";
      divBtn.style.display = "none";
   }

   //전체선택
   MyListParams.prototype.AllCheck = function(){
        var f = $(this.divName);
        checkAllCheckboxForDiv(f);
   }  
  
   function MyListFormFailHandler(res){
      alert('작업을 처리하는 도중 오류가 발생하였습니다 \n오류메시지 : ' + res);
   }

 