  function eBookOpener() {
    this.winLimitWidth   = 1024;
    this.winLimitHeight  = 768;
    this.winWidth        = 0;
    this.winHeight       = 0;
    this.winStyle        = null;
    this.winStyleName    = null;
   
    this.Port            = "80" ; 
    this.eBookHost       = "http://v2main.trueebook.com";
    this.eBookUrl        = this.eBookHost + ":" + this.Port + "/engine/isapi/frame.dll?";

    this.ParameterList   = new Array("bc", "co", "gp", "sbp", "sep", "ui", "ct");
    this.ViewerStyleList = new Array("eBookFull", "eBookCustomer", "eBookDefault", "FullScreen");

    this.SetLaunchHTML   = SetLaunchHTML;
    
    this.GetQuery        = GetQuery;
    this.GetWinStyle     = GetWinStyle;
    this.GetBorderSize   = GetBorderSize;
    this.IsWinXP         = IsWinXP;
    this.OpenBook        = OpenBook;        // BookCode Open Interface : new window open
    this.SelfOpen        = SelfOpen;        // BookCode Open Interface : self window open
    this.OpenBookname    = OpenBookname;    // BookName and IssueNumber Open Interface : new window open 
    this.SelfOpenBookname= SelfOpenBookname;// BookName and IssueNumber Open Interface : self window open
  }

  function SetLaunchHTML(arg_URL) {  //  open window in HTML

	var OpenHTML  = "<html>" + "\n" 
				  + '<script>' + "\n" 
				  + 'window.onload=function(){' + "\n" 
				  + 'location.href="' + this.eBookUrl  + arg_URL + '"' + "\n"     
				  + '}' + "\n"
                  + "</script>" + "\n" 
                  + "<body onload=\"oLaunch.click()\">" + "\n" 
                  + "<a id=\"oLaunch\" style=\"visibility:hidden\" href=\"" + this.eBookUrl  + arg_URL + "\">OpenEBook</a>" + "\n"     
                  + "</body>" + "\n"
                  + "</html>" ;
    return OpenHTML;
/*
    var p = arg_URL.split("&");
    var k = new Array();
    var v = new Array();
    var insert = '';

    for(var i=0; i<p.length;i++)
    {
      var result = p[i].split("=");
      k[i] = result[0];
      v[i] = result[1];

    }

    for(var i=0; i<k.length; i++)
    {
      insert += "<input type=\"hidden\" name=\""+k[i]+"\" value=\""+v[i]+"\">";
    }

  	var OpenHTML  = "<html>" + "\n"
				  + "<meta http-equiv=Cache-Control content=No-Cache> " + "\n"
				  + "<meta http-equiv=Pragma content=No-Cache /> " + "\n"
				  + "<meta http-equiv=Expires content=now />  " + "\n"
				  + "<script>" + "\n"
				
				  + "document.onkeydown=KeyEventHandle;" + "\n"
				  + "document.onkeyup=KeyEventHandle;" + "\n"
				  + "function KeyEventHandle() {" + "\n"
				  + "if((event.ctrlKey == true && (event.keyCode == 78 || event.keyCode == 82)) || (event.keyCode >= 112 && event.keyCode <= 123)) { " + "\n"
				  + "event.keyCode = 0; event.cancelBubble = true; event.returnValue = false; }}" + "\n"
				  
				  + "var senditGO = function(){ document.theForm.submit(); }" + "\n"		  
				  + "<\/script>" + "\n"
				  + "<body onload=\"senditGO();\" onkeydown=\"KeyEventHandle();\">" + "\n" 
				  + "<form name=\"theForm\" method=\"post\" action=\""+this.eBookHost+"/engine/rise7/viewer.php\">" + "\n" 
          + insert 
				  + "<input type=\"hidden\" name=\"param\" value=\""+arg_URL+"\">" + "\n"
				  + "</form>" + "\n" 
				  + "\n" + "</body>" + "\n" + "</html>" ;
  	return OpenHTML;	
*/
  }

  function GetQuery(arg_Param) {
    var sParam    = "";
    if(arg_Param.length) {
      for(var i=0;i<arg_Param.length;i++) {
        if(arg_Param[i] != "") {
          // Section Confuse Error Process
          switch (this.ParameterList[i]) {
            case "gp"   :
            case "sbp"  : if(arg_Param[i] % 2 != 0) { arg_Param[i] = parseInt(arg_Param[i]) - 1;  } 
                          break;
            case "sep"  : if(arg_Param[i] % 2 == 0) { arg_Param[i] = parseInt(arg_Param[i]) + 1;  }
                          break;
          }
          sParam += this.ParameterList[i] + "=" + arg_Param[i]  + "&";           
        }      
      }
      sParam += "ul=" + navigator.browserLanguage;
      return sParam;
    }  else {
      return false;
    }
  }
  
  function IsWin2k3() {
    if ( navigator.userAgent.indexOf("Windows NT 5.2") > 1 ) { return true ; }
    return false // WinMe, Win9x, Win2k  
  }      
  
  function GetWinStyle() {  
    var tmpFullScreen = ""  ;   
    
    if ( this.winStyle == null ) { this.winStyle = 2 ; }
    if( ( screen.width <= this.winLimitWidth || screen.height <= this.winLimitHeight) ) {  this.winStyle = 0 ; }
     
// alert(this.winStyle) ;  
   
    switch ( this.winStyle ) {              
      case 0  : // Digitomi Default window 
                this.winStyleName  = this.ViewerStyleList[0]; 
                this.winTop     = 0 ;                                   
                this.winLeft    = 0 ;
                this.winWidth   =  screen.width  ;
                this.winHeight  =  screen.height ;
                if ( screen.width  != screen.availWidth  ) { this.winWidth  = screen.width  - 57 } // TaskBar Width
                if ( screen.height != screen.availHeight ) { this.winHeight = screen.height - 27 } // TaskBar Height

                break;
      
      case 1  : // corporation customer window 
                this.winStyleName  = this.ViewerStyleList[1]; 
                if(this.winWidth < this.winLimitWidth)    {  this.winWidth  = this.winLimitWidth; }
                if(this.winHeight < this.winLimitHeight)  {  this.winHeight  = this.winLimitHeight; }
                this.winLeft    = (screen.width  - this.winWidth) / 2;
                this.winTop     = (screen.height - this.winHeight) / 2;
                break;
    
      case 2 : // user customer window environemnt
                this.winStyleName  = this.ViewerStyleList[2]; 
                this.winWidth      = this.winLimitWidth;  
                this.winHeight     = this.winLimitHeight;  
                this.winLeft       = (screen.width  - this.winWidth) / 2;
                this.winTop        = (screen.height - this.winHeight) / 2;
                break;
            
      case 3 :  // Full Screen  
                this.winStyleName  = this.ViewerStyleList[3]; 
                this.winWidth      = screen.width;  
                this.winHeight     = screen.height;  
                this.winLeft       = 0;
                this.winTop        = 0;

                // Windows 2003 
                if( !(IsWin2k3()) ){ tmpFullScreen  = ", fullscreen=yes";    }
                break; 
      default : ;                            
    }
    this.winStyle    = "top=" + this.winTop + ", left=" + this.winLeft + ", width=" + this.winWidth + ", height=" + this.winHeight + ", directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no" + tmpFullScreen ;
  }

  //  Book open function : bc, co, gp, sbp, sep, ct, ui
  function OpenBook() {
    // NOTE : process v1.6 , v1.8 param type for naver 
    if(arguments.length > 7){
      if(arguments.length >= 11) //We should call Open_eBook() with arg_bc, arg_ml, arg_vr. Because, Open_eBook() uses those parameter directly.
      Open_eBook(arguments[0], "", "", "", "", arguments[5], "", "fromv20", arguments, "tov16", arguments[10]);
      else Open_eBook(arguments[0], "", "", "", "", arguments[5], "", "fromv20", arguments, "tov16", "");
      return;
    }

    var sQuery = this.GetQuery(arguments);
  
    if(!sQuery) {
      alert("service fail!!");
      return false;
    }
    this.GetWinStyle();
    var eBookClient = window.open("about:blank", this.winStyleName +"_"+ Math.round(Math.random() * 100), this.winStyle);

    eBookClient.document.write(this.SetLaunchHTML(sQuery));
    eBookClient.document.close();
//    eBookClient.document.location.reload();
  }


  function OpenBookname() {//  Book open function : bn, in, co, gp, sbp, sep, ct, ui
    var sQuery = this.GetQuery(arguments, "bn");
    if(!sQuery) {
      alert("service fail!!");
      return false;
    }
    this.GetWinStyle();
    var eBookClient = window.open("about:blank", this.winStyleName +"_"+ Math.round(Math.random() * 100), this.winStyle);
    eBookClient.document.write(this.SetLaunchHTML(sQuery));
    eBookClient.document.close();
  }


  function SelfOpen() {
    var sQuery = this.GetQuery(arguments);

    if(!sQuery) {
      alert("service fail!!");
      return false;
    }

    this.GetWinStyle();
    var aBorderInfo = this.GetBorderSize();
    this.winWidth   += 2 * aBorderInfo[0];
    this.winHeight  += aBorderInfo[0] + aBorderInfo[1];

    var iRemovePosLeft  = (screen.width - this.winWidth) / 2;
    var iRemovePosTop   = (screen.height - this.winHeight) / 2;
    if(iRemovePosLeft < 0)  {  iRemovePosLeft = 0;  }
    if(iRemovePosTop < 0)   {  iRemovePosTop = 0;   }
    moveTo(iRemovePosLeft, iRemovePosTop);

    document.write(this.SetLaunchHTML(sQuery));
    document.close();
    window.name = this.winStyleName;
    resizeTo(this.winWidth, this.winHeight);
    document.location.reload();
  }


  function SelfOpenBookname() {
    var sQuery = this.GetQuery(arguments, "bn");

    if(!sQuery) {
      alert("service fail!!");
      return false;
    }
    location.href = this.eBookUrl + sQuery; 	
  }

  function GetBorderSize () {
    var aBorderInfo = new Array();
    if (this.IsWinXP() ) {
      aBorderInfo[0]  = 6 ;
      aBorderInfo[1]  = 32 ;
    } else {
      aBorderInfo[0]  = 5 ;
      aBorderInfo[1]  = 24 ;
    }
    return aBorderInfo;
  }  
  
  function IsWinXP() {
    if ( navigator.userAgent.indexOf("Windows NT 5.1") > 1 ) { return true ; }
    return false ; // WinMe, Win9x, Win2k, Win2k  
  }     

  OpenEBook = new eBookOpener();
