  //*************************************************************************//
  //  ModuleName  : Deco_Scrap.js                   //
  //                                     //
  //  Last Update : 2004_05_09 by tews                     //
  //*************************************************************************//
  //  History                                //
  //    2004_05_09  : valiable port Support ( gsPort ':81')        //
  //*************************************************************************//

  function Scrap2(  ) {  // arg_oParentDiv, arg_Left, arg_Top, arg_Movable
    this.id               = "oScrap2"  ;
    this.oParentDiv       = arguments[0] ;
    this.oScrapTable      = null  ;
    this.cssText          = "position:absolute;left:0; top:0; width:400; height:400; visibility:hidden; z-index:4000; " ;
    this.Clicked          = false ;
    this.ScrapAreaLeft    = 0   ;
    this.ScrapAreaTop     = 0   ;
    this.ScrapClicked_X   = 0   ; 
    this.ScrapClicked_Y   = 0   ; 
    this.ImgPath          = gsProtocol + gsSrv_Cache +  ":" + gsPort +  "/engine/java/Deco/Scrap/" ;

    this.LimitPos         = new Limit();

    this.ResizeLeft       = 0   ;
    this.ResizeTop        = 0   ;
    this.ResizeClicked_X  = 0   ;
    this.ResizeClicked_Y  = 0   ;
    this.ResizeWidth      = 0   ;
    this.ResizeHeight     = 0   ;
  
    this.BookIndex        = null  ;
    this.BookName         = null  ;
    this.BookDate         = null  ;
    this.Page		          = null  ;
    this.TileHCount       = 0   ;
    this.TileVCount       = 0   ;
    this.TileW	          = 0   ;
    this.TileH	          = 0   ;
    this.ScrapL	          = 0   ;
    this.ScrapT	          = 0   ;
    this.ScrapW	          = 0   ;
    this.ScrapH	          = 0   ;
    this.TileBaseUR       = ""  ;
    this.TileImages       = ""  ;

    this.GetLimit         = GetLimit  ;
    this.ScrapHide        = ScrapHide ;
    this.SetScrapData     = SetScrapData;
    this.CallScrapFunc    = CallScrapFunc ;

    this.DoDark           = DoDark ;
    this.DoSoft           = DoSoft ;
    
  
    this.OnMouseDownScrapDiv  = OnMouseDownScrapDiv ;
    this.OnMouseMoveScrapDiv  = OnMouseMoveScrapDiv ;
    this.OnMouseUpScrapDiv    = OnMouseUpScrapDiv   ;

    this.OnMouseDownResize    = OnMouseDownResize   ;
    this.OnMouseMoveResize    = OnMouseMoveResize   ;
    this.OnMouseUpResize      = OnMouseUpResize   ;

  
    this.OnMouseDown          = OnMouseDown     ;

    this.dscShowScrap = dscShowScrap  ;
    this.dscDoScrap   = dscDoScrap  ;          
    this.dscViewScrap = dscViewScrap  ;        
    this.dscInitial   = dscInitial  ;          
                            
    this.dscInitial();                
  }                           

  function Point() {
    this.x = 0;
    this.y = 0;
  }  

  function Limit () {
    this.MinLeft = 0;
    this.MinTop  = 0;
    this.MaxLeft = 0;
    this.MaxTop  = 0;
  }   
                            
  function dscInitial () {
    if (typeof(this.oParentDiv) == "undefined") {
      this.oParentDiv = oBook.oBookBaseDiv;  
    }    

    this.BookIndex  = oBook.oBookInfo.iBookCode ;   
    this.BookName   = gsBookTitle   ; // need new item add to frame.html 
    this.BookDate   = gsRegDate     ; // need new item add to frame.html 

    //   
    var tmpScrapDiv = document.createElement("DIV") ;
  //  var tmpScrapDiv = document.createElement("DIV") ;
    this.oParentDiv.appendChild(tmpScrapDiv); 
  /*
    tmpScrapDiv.outerHTML =  "<div id=\"oScrapTable\" "+ "\n"+ 
                 "    onmousedown=\" " + "" + this.id + ".OnMouseDownScrapDiv(" + "oMiniMapBaseDiv" + " )\" " + "\n" + 
                 "    onmousemove=\" " + "" + this.id + ".OnMouseMoveScrapDiv(" + "oMiniMapBaseDiv" + " )\" " + "\n" +  
                 "    onmouseup=\" "   + "" + this.id + ".OnMouseUpScrapDiv  (" + "oMiniMapBaseDiv" + " )\" " + "\n" +    
                 "</div>";


    tmpScrapDiv.outerHTML =  "<DIV id=\"oScrapTable\" "+ "\n" +
                 "    onmousedown=\" " + this.id + ".OnMouseDownScrapDiv( )\" " + "\n" + 
                 "    onmousemove=\" " + this.id + ".OnMouseMoveScrapDiv( )\" " + "\n" +  
                 "    onmouseup=\" "   + this.id + ".OnMouseUpScrapDiv  ( )\" " + "\n" +    
               
  */
    tmpScrapDiv.outerHTML = "  <table id=\"oScrapTable\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >                                                   " + "\n" +  
                            "    <tr >                                                                                           " + "\n" +
                            "      <td id=\"nw\" onmousedown=\"" + "" + this.id + ".OnMouseDownResize(nw)\" onmousemove=\"" + "" + this.id + ".OnMouseMoveResize(nw, 'LT')\" onmouseup=\"" + "" + this.id + ".OnMouseUpResize(nw)\" style=\"width:1; height:5; cursor:nw-resize\"><img src=\"" + this.ImgPath + "Border_LT.gif\"></td>  " + "\n" +
                            "      <td id=\"n\"  onmousedown=\"" + "" + this.id + ".OnMouseDownResize(n)\"  onmousemove=\"" + "" + this.id + ".OnMouseMoveResize(n, 'T')\"   onmouseup=\"" + "" + this.id + ".OnMouseUpResize(n)\"  style=\"height:5; cursor:n-resize; background-Image:url(" + this.ImgPath + "Border_T.gif)\"  ></td>   " + "\n" +
                            "      <td id=\"ne\" onmousedown=\"" + "" + this.id + ".OnMouseDownResize(ne)\" onmousemove=\"" + "" + this.id + ".OnMouseMoveResize(ne, 'RT')\" onmouseup=\"" + "" + this.id + ".OnMouseUpResize(ne)\" style=\"width:1; height:5; cursor:ne-resize\"><img src=\"" + this.ImgPath + "Border_RT.gif\"></td>  " + "\n" +
                            "    </tr>                                                                                          " + "\n" +
                            "    <tr>                                                                                           " + "\n" +
                            "      <td id=\"w\" onmousedown=\"" + "" + this.id + ".OnMouseDownResize(w)\" onmousemove=\"" + "" + this.id + ".OnMouseMoveResize(w, 'L')\" onmouseup=\"" + "" + this.id + ".OnMouseUpResize(w)\" style=\"width:5; height:1;cursor:w-resize; background-Image:url(" + this.ImgPath + "Border_L.gif)\"></td>  " + "\n" +
                            "      <td id=\"oCaption\"  onmousedown=\" " + "" + this.id + ".OnMouseDownScrapDiv(this)\" onmousemove=\" " + "" + this.id + ".OnMouseMoveScrapDiv(this)\" onmouseup=\" " + "" + this.id + ".OnMouseUpScrapDiv(this)\" style=\"width:100%; height:100%;background-Color:blue; cursor:move; filter:alpha(Opacity=20); \" > " + "\n" + 
                            "      <table cellpadding=\"0\" cellspacing=\"1\" style=\"position:absolute; right:5; top:5; \"  >                                                                   " + "\n" +
                            "        <tr>                                                                                     " + "\n" +
                            "        <td style=\"cursor:hand;\" onmousedown=\"" + " " + this.id + ".DoDark();" + this.id + ".dscDoScrap(); "+ this.id + ".DoSoft();" + "\"><img src=\"" + this.ImgPath + "scrap_mouseout.gif\"></td>                                                                " + "\n" +
                            "        <td style=\"cursor:hand;\" onmousedown=\"" + this.id + ".ScrapHide();" + "\"><img id=\"oImg\" colspan=\"3\" src=\"" + this.ImgPath + "close_mouseout.gif\" ></td>                                                                " + "\n" +
                            "        </tr>                                                                                    " + "\n" +
                            "      </table>                                                                                     " + "\n" +

                            "      </td> " + "\n" +
                            "      <td id=\"e\" onmousedown=\"" + "" + this.id + ".OnMouseDownResize(e)\" onmousemove=\"" + "" + this.id + ".OnMouseMoveResize(e, 'R')\" onmouseup=\"" + "" + this.id + ".OnMouseUpResize(e)\" style=\"width:5; height:1;cursor:e-resize; background-Image:url(" + this.ImgPath + "Border_R.gif)\"></td>  " + "\n" +
                            "    </tr>                                                                                          " + "\n" +
                            "    <tr>                                                                                           " + "\n" +
                            "      <td id=\"sw\" onmousedown=\"" + "" + this.id + ".OnMouseDownResize(sw)\" onmousemove=\"" + "" + this.id + ".OnMouseMoveResize(sw, 'LB')\" onmouseup=\"" + "" + this.id + ".OnMouseUpResize(sw)\" style=\"width:1; height:5; cursor:sw-resize\"><img src=\"" + this.ImgPath + "Border_LB.gif\"></td>  " + "\n" +
                            "      <td id=\"s\"  onmousedown=\"" + "" + this.id + ".OnMouseDownResize(s)\"  onmousemove=\"" + "" + this.id + ".OnMouseMoveResize(s, 'B')\"   onmouseup=\"" + "" + this.id + ".OnMouseUpResize(s)\"  style=\"height:5; cursor:s-resize; background-Image:url(" + this.ImgPath + "Border_B.gif)\"  ></td>   " + "\n" +
                            "      <td id=\"se\" onmousedown=\"" + "" + this.id + ".OnMouseDownResize(se)\" onmousemove=\"" + "" + this.id + ".OnMouseMoveResize(se, 'RB')\" onmouseup=\"" + "" + this.id + ".OnMouseUpResize(se)\" style=\"width:1; height:5; cursor:se-resize\"><img src=\"" + this.ImgPath + "Border_RB.gif\"></td>  " + "\n" +
                            "    </tr>                                                                                          " + "\n" +
                            "  </table>                                                                                           " ;
    this.oScrapTable = oScrapTable ;
    this.oScrapTable.style.cssText = this.cssText ;



  
  //   alert(this.oScrapTable.outerHTML); 
  
  }



  
   

  

  function GetLimit () {
    this.MinLeft = 0 ;
    this.MinTop  = 0 ;
    this.MaxLeft = parseInt(this.oParentDiv.style.width)  - parseInt(this.oScrapTable.style.width) ;
    this.MaxTop  = parseInt(this.oParentDiv.style.height) - parseInt(this.oScrapTable.style.height);
  }  

  function ScrapHide () { this.oScrapTable.style.visibility ="hidden" ;  }
  function dscShowScrap () { this.oScrapTable.style.visibility ="visible" ;  }

  function SetScrapData () {
    var iIdx ;
    var jIdx ;
    var aTmpTileName = new Array() ;
    var iTargetLevelIdx  = oBook.cobGetCurrLevelIdx() ;
    var Click_X     = 0;
    var Click_Y     = 0;
    var r, re;          //Declare variables.
    var iMod  ; 
    var iDiv  ;
    this.Page     = oBook.cobGetCurrPage() ; 
    var iMaxTileHCount  = oBook.oBookInfo.aLevelInfo[iTargetLevelIdx][4] ; 
    var iMaxTileVCount  = oBook.oBookInfo.aLevelInfo[iTargetLevelIdx][5] ;

  
    if (iTargetLevelIdx == 0 ) {
      this.ScrapL   = parseInt(this.oScrapTable.style.left ) -  parseInt(oBook.oBasicLevelDiv.style.left) ;
      this.ScrapT   = parseInt(this.oScrapTable.style.top  ) -  parseInt(oBook.oBasicLevelDiv.style.top)  ;
    } else {
      this.ScrapL   = parseInt(this.oScrapTable.style.left ) - parseInt(MgrLevel.Levels[iTargetLevelIdx].oLevelDiv.style.left) ;
      this.ScrapT   = parseInt(this.oScrapTable.style.top  ) - parseInt(MgrLevel.Levels[iTargetLevelIdx].oLevelDiv.style.top)  ;
    }
    this.ScrapW   = parseInt(this.oScrapTable.style.width ) ;
    this.ScrapH   = parseInt(this.oScrapTable.style.height) ;

    this.TileW    = oBook.oBookInfo.aLevelInfo[iTargetLevelIdx][0]  ;
    this.TileH    = oBook.oBookInfo.aLevelInfo[iTargetLevelIdx][1]  ;
  
    this.TileBaseURL = oDecoder2.cdeGetImgPath(iTargetLevelIdx, this.Page ) ;
    this.TileImages  ="" ; 

    Click_X  = this.ScrapL ; 
    Click_Y  = this.ScrapT ; 

    this.ScrapL  %= oBook.oBookInfo.aLevelInfo[iTargetLevelIdx][0] ;
    this.ScrapT  %= oBook.oBookInfo.aLevelInfo[iTargetLevelIdx][1] ;

    // <---- °è»êÁ» ÀßÇØ¶ó.. 
    iMod = 0 ;
  
    iDiv = Math.floor((this.ScrapL + this.ScrapW ) / this.TileW)  ;
    if ((this.ScrapL + this.ScrapW ) % this.TileW != 0) { iMod = 1 };
    this.TileHCount = iDiv + iMod  ; 
  //   if ( this.TileHCount >  iMaxTileHCount ) {   this.TileHCount = iMaxTileHCount ; }

    iMod = 0 ;
    iDiv = Math.floor((this.ScrapT + this.ScrapH ) / this.TileH)  ;
    if ((this.ScrapH + this.ScrapH ) % this.TileH != 0) { iMod = 1 };
    this.TileVCount = iDiv + iMod ;
    if ( this.TileVCount >  iMaxTileVCount ) {   this.TileVCount = iMaxTileVCount ; }

  
    var ClicedTilePos = new Point() ; 
      ClicedTilePos = MgrLevel.GetClickedTilePos( iTargetLevelIdx,  Click_X , Click_Y  );
      
    re = new RegExp( this.TileBaseURL ,"g") ;
   
    var kIdx = 0;
  
    if ( iTargetLevelIdx == 0  ) {
      if (Click_X < this.TileW  ) {
      tmpTileName = oDecoder2.cdeGetTileName(iTargetLevelIdx , (this.Page - 0.5), 0, 0) ;
      tmpTileName = tmpTileName.replace(re,"");   
      aTmpTileName[kIdx] = tmpTileName  ; 
      kIdx++ ; 
      }  

      if ( (Click_X >= this.TileW ) || (this.ScrapL + this.ScrapW ) > this.TileW ) {
      tmpTileName = oDecoder2.cdeGetTileName(iTargetLevelIdx , (this.Page + 0.5), 0, 0) ;
      tmpTileName = tmpTileName.replace(re,"");   
      aTmpTileName[kIdx] = tmpTileName  ;  
      }

    } else {

    //  iTargetPageNum = oBook.iCurrPageNo - (0.5 * giLeafDirect ) ;
  
      for (jIdx = ClicedTilePos.y ; jIdx <  (ClicedTilePos.y + this.TileVCount) ; jIdx++) {
       for (iIdx = ClicedTilePos.x ; iIdx < (ClicedTilePos.x + this.TileHCount) ; iIdx++) {
        tmpTileName = oDecoder2.cdeGetTileName( iTargetLevelIdx , this.Page, jIdx , iIdx ) ;
        tmpTileName = tmpTileName.replace(re,"");   
        aTmpTileName[kIdx] = tmpTileName  ;  
        kIdx++ ;
      } 
      }
    }
  
    this.TileImages = aTmpTileName.join(",");
  }            
  
  function CallScrapFunc () {
  /*
    alert(
                       
    "this.BookIndex   " + this.BookIndex   + "\n" +  
    "this.BookName    " + this.BookName  + "\n" +   
    "this.BookDate    " + this.BookDate  + "\n" +   
    "this.Page		    " + Math.floor(this.Page)		   + "\n" +  
    "this.TileHCount  " + this.TileHCount  + "\n" +   
    "this.TileVCount  " + this.TileVCount  + "\n" +   
    "this.TileW	    " + this.TileW	   + "\n" +  
    "this.TileH	    " + this.TileH	   + "\n" +  
    "this.ScrapL	    " + this.ScrapL	   + "\n" +  
    "this.ScrapT	    " + this.ScrapT	   + "\n" +  
    "this.ScrapW	    " + this.ScrapW	   + "\n" +   
    "this.ScrapH	    " + this.ScrapH	   + "\n" +  
    "this.TileBaseURL   " + this.TileBaseURL + "\n" +   
    "this.TileImages  " + this.TileImages     
    ) ;

  */

  //  if ( bCreatedScrapX  == false) return ;    //  2004_03_30 frame.html  by tews 

    oScrapX.Scrap (
      this.BookIndex  ,
      this.BookName   ,
      this.BookDate   ,
      Math.floor(this.Page) ,
      this.TileHCount   ,
      this.TileVCount   ,
      this.TileW	    ,
      this.TileH	    ,
      this.ScrapL	    ,
      this.ScrapT	    ,
      this.ScrapW	    ,
      this.ScrapH	    ,
      this.TileBaseURL,
      this.TileImages ,
      "",
      true,             // for preview 
      false             // for sagawa
    ) ;
  }
  


  function DoDark () {
    oCaption.style.filter = "alpha(Opacity=60);" ;
  }

  function DoSoft () {
    oCaption.style.filter = "alpha(Opacity=20);" ;
  }

  function OnMouseDownScrapDiv (arg_Obj) {
    this.ScrapAreaLeft  = parseInt(this.oScrapTable.style.left);
    this.ScrapAreaTop   = parseInt(this.oScrapTable.style.top);
    this.Clicked        = true ;
  
    this.ScrapClicked_X =  event.clientX;
    this.ScrapClicked_Y =  event.clientY;

    arg_Obj.setCapture();   
     
  } 
  
  function OnMouseMoveScrapDiv(){
  //  window.status = "X : " + event.clientX + "Y : " +  event.clientY ;  
    if (this.Clicked == false ) return ;

    var tmpLeft     = this.ScrapAreaLeft - ( parseInt(this.ScrapClicked_X ) - parseInt( event.clientX) );
    var tmpTop      = this.ScrapAreaTop  - ( parseInt(this.ScrapClicked_Y ) - parseInt( event.clientY) );
    var tmpRight    = tmpLeft + parseInt(this.oScrapTable.style.width) ;
    var tmpBottom   = tmpTop  + parseInt(this.oScrapTable.style.height) ;

    this.oScrapTable.style.left = tmpLeft ;
    this.oScrapTable.style.top  = tmpTop  ;  
  }

  function OnMouseUpScrapDiv (arg_Obj) {
    this.Clicked  = false  ;
    arg_Obj.releaseCapture();
    this.GetLimit();
  }   

  function OnMouseDownResize (arg_Obj) {
    this.ResizeLeft     = parseInt(this.oScrapTable.style.left);
    this.ResizeTop      = parseInt(this.oScrapTable.style.top);
    this.ResizeWidth    = parseInt(this.oScrapTable.style.width);
    this.ResizeHeight   = parseInt(this.oScrapTable.style.height);
  
    this.Clicked      = true ;
    this.ResizeClicked_X  = event.clientX;
    this.ResizeClicked_Y  = event.clientY;

    arg_Obj.setCapture();  
  }

  function OnMouseMoveResize( arg_Obj, arg_Direct) {
    if (this.Clicked == false ) return ;
    var tmpLeft   = 0 ;
    var tmpTop  = 0 ;
    var tmpWidth  = 0 ;
    var tmpHeight = 0 ;



    var iVarX  = parseInt(this.ResizeClicked_X ) - parseInt(event.clientX) ;
    var iVarY  = parseInt(this.ResizeClicked_Y ) - parseInt(event.clientY) ;

    if ((this.ResizeWidth < iVarX + 40) || (this.ResizeHeight < iVarY + 30 ) ) { return }  
  
    switch (arg_Direct) {
      case "L"  :        
            if ((this.ResizeLeft   - iVarX) < 0 ) { tmpLeft = 0 } 
            this.oScrapTable.style.left   = tmpLeft ;
            this.oScrapTable.style.width  = this.ResizeWidth  + iVarX ;
            break;
      case "T"  : 

            this.oScrapTable.style.top    = this.ResizeTop    - iVarY ;  
            this.oScrapTable.style.height = this.ResizeHeight + iVarY ; 
            break;
      case "R"  : 
            this.oScrapTable.style.width  = this.ResizeWidth  - iVarX ;
            break;
      case "B"  : 
            this.oScrapTable.style.height = this.ResizeHeight - iVarY ;    
            break;
          
      case "LT"  : 
            this.oScrapTable.style.left   = this.ResizeLeft   - iVarX ;
            this.oScrapTable.style.top    = this.ResizeTop    - iVarY ;   
            this.oScrapTable.style.width  = this.ResizeWidth  + iVarX ;
            this.oScrapTable.style.height = this.ResizeHeight + iVarY ;
            break;
      case "RT"  : 
            this.oScrapTable.style.top    = this.ResizeTop    - iVarY ;    
            this.oScrapTable.style.width  = this.ResizeWidth  - iVarX ;
            this.oScrapTable.style.height = this.ResizeHeight + iVarY ;    
            break;
      case "LB"  : 
            this.oScrapTable.style.left   = this.ResizeLeft   - iVarX ;
            this.oScrapTable.style.width  = this.ResizeWidth  + iVarX ;
            this.oScrapTable.style.height = this.ResizeHeight - iVarY ;    
            break;
      case "RB"  : 
            this.oScrapTable.style.width  = this.ResizeWidth  - iVarX ;
            this.oScrapTable.style.height = this.ResizeHeight - iVarY ;    
            break;
    }
  }

  function OnMouseUpResize(arg_Obj) {
    this.Clicked  = false  ;
    arg_Obj.releaseCapture() ;
  }

  
  function OnMouseDown ( arg_FileName ) {
    arg_Obj.src = arg_FileName ;   
    window.status = arg_Obj.src ;
  }
    
  
  function dscDoScrap () {
    event.cancelBubble = true; 
    this.SetScrapData();
    setTimeout ( this.id + ".CallScrapFunc()" , 10)  ;
    //this.CallScrapFunc() ; 
  }

  function dscViewScrap () {
  
  //  if ( bCreatedScrapX  == false) return ;    //  2004_03_30 frame.html  by tews 
    /*oScrapX.ViewScrap(
      this.BookIndex  , 
      this.BookName   ,
      this.BookDate  
    ) ;*/

    oScrapX.ViewScrap(
      ""  , 
      ""   ,
      "" 
    ) ;  
  }

  



  
  
  

