/******************************************************************************
* Cookie functions.                                                           *
******************************************************************************/

function getCookie(name) {

  var search;

  search = name + "="
  offset = document.cookie.indexOf(search) 
  if (offset != -1) {
    offset += search.length ;
    end = document.cookie.indexOf(";", offset) ;
    if (end == -1)
      end = document.cookie.length;
    return unescape(document.cookie.substring(offset, end));
  }
  else
    return "";
}

function IsWin2k3() {
    if ( navigator.userAgent.indexOf("Windows NT 5.2") > 1 ) { return true ; }
    return false // WinMe, Win9x, Win2k  
  }     

function GetWinStyle() {
    this.ViewerStyleList = new Array("eBookFull", "eBookCustomer", "eBookDefault", "FullScreen");
    this.winLimitWidth   = 1024;
    this.winLimitHeight  = 768;

    var tmpFullScreen = ""  ;   
    if ( this.winStyle = "null" ) {this.winStyle = 2 ; }
    if( (IsWin2k3() != true ) &&  ( screen.width <= this.winLimitWidth || screen.height <= this.winLimitHeight) ) { this.winStyle = 0 ; }
    
// alert(this.winStyle); 
    switch ( this.winStyle ) {              
      case 0  : // full screen window 
                this.winStyleName  = this.ViewerStyleList[0]; 
                this.winTop     = 0 ;                                   
                this.winLeft    = 0 ;
                this.winWidth   =  screen.width  ;
                this.winHeight  =  screen.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 : 
                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 ;
  }
  
function openMyEbook(bookCode, regularBookCode, corporation, ui, fp)
{     
   var url="http://mag.qq.com/cgi-bin/openebook?bc=" + bookCode + "&rbc=" + regularBookCode + "&co=" + corporation + "&ui=" + ui + "&fp=" + fp;
   this.GetWinStyle();
   var win = window.open(url,
                         this.winStyleName +"_"+ Math.round(Math.random() * 100),
                         this.winStyle);
   win.moveTo(-3, -25);
}

function openMyEbook2(bookCode, regularBookCode, corporation, pageno, ui, fp)
{       
   var url="http://mag.qq.com/cgi-bin/openebook?bc=" + bookCode + "&rbc=" + regularBookCode + "&co=" + corporation + "&pg=" + pageno + "&ui=" + ui + "&fp=" + fp;
   this.GetWinStyle();
   var win = window.open(url,
                         this.winStyleName +"_"+ Math.round(Math.random() * 100),
                         this.winStyle);
   win.moveTo(-3, -25);
}
