/////////////////////////////////////////////////////
//
//  Since 1998 Copyright(c)
//  Humandream, Inc.
//  All rights reserved
//  file name : dBook.js
//  version : 3.5 g1207  (made by Humandream, Inc.)
//
/////////////////////////////////////////////////////

var bInitFinished = false;	// the variable called by applet when the applet load finishing.
var bLoaded = false;		// the variable called by html document when the html document load finishing.

bInitFinished = false;
bOnLoaded = false;

function DigitalBookUnload()
{ 
    try
    {
    	//document.dBook.handle_addCRMData( getCRMData() );
    	document.dBook.handle_addCRMData();
    }
    catch (e)
    {
	/*
        try
        {
            document.dBook.handle_setURL( getMailingParam() );      // for old version viewer
        }
        catch (e2) {}
	*/
    }

    try
    {
       	document.dBook.handle_unload();
    }
    catch (e3)  {}
    // Please append 'onUnload=DigitalBookUnload()' at BODY open tag.
    // Please check that 'Port' number is 80 or not.
}

function doKey(e)
{
	whichASC = event.keyCode;

	if (whichASC == 13){
		HD_inputGotoPage();		
	}
}

function getCookie(name)
{
	var nameOfCookie = name + "=";
	var x = 0;
	while ( x <= document.cookie.length )
	{
		var y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie )
		{
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
				endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}
		x = document.cookie.indexOf( " ", x ) + 1;
		if ( x == 0 )
			break;
	}
	return "";
}

//***********************************************************************************************
// page Customize
var gPageOffset = 0;
var gHtmlHeight = 0;

function _getRealPageNo(nPage)
{    
   return gPageOffset + nPage;
}

function HD_setHtmlSkinHeight(htmlHeight)
{
	gHtmlHeight = htmlHeight;
}

function HD_getHtmkSkinHeight()
{
	return gHtmlHeight;
}

function HD_getSkinPageOffset()
{
	try{
		gPageOffset = document.dBook.handle_getPageOffset();
	}catch(e){}
	return gPageOffset;
}

function _printOffset(tStr)
{
	var strValue = "";

	if(tStr == "0"){
		strValue = tStr; 
	}
	else{
		var intValue = parseInt(tStr) + gPageOffset;
		strValue = intValue.toString();
	}
	return strValue;
}

//Check dbook.jar's page view mode
function HD_isDoublePage() {
	return document.dBook.handle_isDoublePage();
}

//get current left page no. applicable only if dobule page view mode
function HD_getLeftPage() {
	return document.dBook.handle_getLeftSlidePage();
}

//get current right page no. applicable only if dobule page view mode
function HD_getRightPage() {
	return document.dBook.handle_getRightSlidePage();
}

//get current page no. applicable only if single page view mode
function HD_getCurrentPage() {
	return document.dBook.handle_getCurSlidePage();     // for single-page DBook.
}

function HD_getSlideTotal() {
	return document.dBook.handle_getSlideTotal();
}

function HD_getSlidePage() 
{	
	
	if (!bInitFinished)
		return;
	
	if (!bOnLoaded)
		return;

	var LPage = HD_getLeftPage();
	var RPage = HD_getRightPage();
	var SinglePage = HD_getCurrentPage();     // for single-page DBook.
	var slideTot = HD_getSlideTotal();
	
	/** customize page Number****/ 
	HD_getSkinPageOffset();
	LPage = LPage - gPageOffset;
	RPage = RPage - gPageOffset;
	slideTot = slideTot - gPageOffset;

	if (LPage < 0)	{	LPage = 0;	}
	if (RPage < 0)	{	RPage = 0;	}
	/** to here ****************/
	var totalIn=document.getElementById("total_page");
	try{
		if(totalIn != null)
		{
			totalIn.innerHTML = " / " + slideTot;
			var pageIn=document.getElementById("cur_page");
			try{
				if (pageIn != null)
				{
					if ( HD_isDoublePage() )
						your_rePagenumber(pageIn, LPage);
					else
						your_rePagenumber(pageIn, SinglePage);
				}
			}
			catch(e){}
		}else{
				var pageIn=document.getElementById("cur_page");
				try{
					if (pageIn != null)	
					{
						if ( HD_isDoublePage() )
						{
							pageIn.innerHTML = LPage + "-" +RPage + " / " + slideTot;
							
							if(RPage < LPage){
								document.pageSlideBar.setCurrPos(slideTot, RPage);
							}else{
								document.pageSlideBar.setCurrPos(slideTot, LPage);
							}
						}
						else
						{
							pageIn.innerHTML = SinglePage + " / " + slideTot;    // for single-page DBook.
							
							document.pageSlideBar.setCurrPos(slideTot, SinglePage);
						}
					}
				}catch(e){}
		}
	}catch(e){}
}

function HD_setPageNum() 
{
	//HTML이 없는 Skin 에서 오류가 나기때문에
	//return;
	// call by applet when the applet load finishing.
	bInitFinished = true;

	HD_getSlidePage();
	
	try{
		your_treatSlidePage();
	}catch(e){}
}

function HD_inputGotoPage() 
{		// goto some page
	var slideTot = document.dBook.handle_getSlideTotal();
	var page = document.getElementById("page_num");
	try{
		if(page != null){
			nPage = _getRealPageNo(parseInt(page.value));
			if(nPage <= slideTot && nPage > 0 )
				document.dBook.handle_inputGotoPage(nPage);
			page_num.value="";
			document.dBook.focus();
		}else{
			var page = document.getElementById("cur_page");
			data = page.innerHTML;
			var index = data.indexOf("value");
			var index2 = data.indexOf(" name"); 
			data = data.substring(index, index2);
			index = data.indexOf("=");
			var cpage = data.substring(index+1, data.length);
			nPage = _getRealPageNo(parseInt(cpage));
			if(nPage <= slideTot && nPage > 0 )
				document.dBook.handle_inputGotoPage(nPage);
			document.dBook.focus();			
		}
	}catch(e){}
}

function HD_gotoPage(nPage) 
{		// goto some page
	var slideTot = document.dBook.handle_getSlideTotal();

	if(nPage <= slideTot && nPage > 0 )
		document.dBook.handle_inputGotoPage(nPage);
	document.dBook.focus();
}

function openReplace(win_url) 
{ 
    var screen_width = 1024 - 10; 
    var screen_height = 768 - 30; 
    strFeatures = "left=0,top=0,width=" + screen_width + ",height=" + screen_height + ","; 
    strFeatures += "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes"; 
    
    windowname=window.open( win_url, "NoticeJavaVM", strFeatures ); 
    windowname.focus(); 
    return; 
} 


function HD_pressCloseUp() {		
	document.dBook.handle_pressCloseUp();
	document.dBook.focus();
}
function HD_pressZoom() {			
	document.dBook.handle_pressZoom();
	document.dBook.focus();
}
function HD_pressLeftZoom() {		
	document.dBook.handle_pressZoomPage(document.dBook.handle_getLeftSlidePage());
	document.dBook.focus();
}
function HD_pressRightZoom() {			
	document.dBook.handle_pressZoomPage(document.dBook.handle_getRightSlidePage());
	document.dBook.focus();
}
function HD_pressPause() {			
	document.dBook.handle_pressPause();
	document.dBook.focus();
}

function HD_pressNextPage() {		
	document.dBook.handle_pressNextPage();
	document.dBook.focus();
}
function HD_pressPreviousPage() {	
	document.dBook.handle_pressPreviousPage();
	document.dBook.focus();
}
function HD_gotoFirstPage() {		
	document.dBook.handle_gotoFirstPage();
	document.dBook.focus();
}
function HD_gotoEndPage() {			
	document.dBook.handle_gotoEndPage();
	document.dBook.focus();
}

function HD_pressBackwardRotate() {	// auto sliding (backward)
	document.dBook.handle_pressBackwardRotate();
	document.dBook.focus();
}
function HD_pressForwardRotate() {	// auto sliding (forward)
	document.dBook.handle_pressForwardRotate();
	document.dBook.focus();
}
function HD_pressSpeedUp() {		// turn speed up when sliding
	document.dBook.handle_pressSpeedUp();
	document.dBook.focus();
}
function HD_pressSpeedDown() {		// turn speed down when sliding
	document.dBook.handle_pressSpeedDown();
	document.dBook.focus();
}
////////////////////////////////////////////////////////////////////////////////

function HD_openBrWindow(theURL,winName,features) 
{
	winName = theURL.replace(/[^a-zA-Z0-9]+/g,''); 
		
	if (features == "")
	{
		features = "toolbar=yes,width=800,height=600,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes";
	}

  HD_popup = window.open(theURL,winName,features);
  
  if (HD_popup != null)
  {
	  HD_popup.focus();
	}
}

var printTarget = ""

function HD_setPrintTarget(tempTarget) {
	printTarget = tempTarget
}

function _blur(obj,num){
	obj.options[ num ].selected = true;
}

function downSelect(obj, num) {
	if( obj.options[ num ] != null && obj.options[ num ].text=="PRINTING" ) {
		obj.options[ num ].text = "NONE PRINTING";
	}
	else if( obj.options[ num ].text == "NONE PRINTING" ) {
		obj.options[ num ].text = "NONE PRINTING"
	}
}
// -------------------------------------------


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

////////////////////////////////////////////////////////////////////////////////

//***********************************************************************************************
// ActiveX 
function
