
/* //////////////////////////////////////////////////
 *
 * ÆÄÀÏ¸í : dBook.js
 * version : 2.0 e0324  (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() );
    }
    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 showHelp()
{
	var helpWin = window.open("help2.htm", "ebook_help", "width=300, height=420, left=5, top=72");
	if (helpWin != null)	helpWin.focus();
}


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 "";
}


function HD_getSlidePage() 
{	
	if (!bInitFinished)
		return;
	
	if (!bOnLoaded)
		return;

	var LPage = document.dBook.handle_getLeftSlidePage();
	var RPage = document.dBook.handle_getRightSlidePage();
	var SinglePage = document.dBook.handle_getCurSlidePage();     // for single-page DBook.
	var slideTot = document.dBook.handle_getSlideTotal();
	
	if (cur_page != null)	
	{
		if ( document.dBook.handle_isDoublePage() )
			cur_page.innerText = LPage + "-" +RPage + " / " + slideTot;
		else
		    cur_page.innerText = SinglePage + " / " + slideTot;    // for single-page DBook.
	}
}

function HD_setPageNum() 
{
	// call by applet when the applet load finishing.
	bInitFinished = true;

	HD_getSlidePage();
}


function HD_inputGotoPage() 
{		// goto some page
	document.dBook.handle_inputGotoPage(page_num.value);
	page_num.value="";
}

function HD_gotoPage(nPage) 
{		// goto some page
	document.dBook.handle_inputGotoPage(nPage);
}

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();
}
function HD_pressZoom() {			
	document.dBook.handle_pressZoom();
}
function HD_pressLeftZoom() {		
	document.dBook.handle_pressZoomPage(document.dBook.handle_getLeftSlidePage());
}
function HD_pressRightZoom() {			
	document.dBook.handle_pressZoomPage(document.dBook.handle_getRightSlidePage());
}
function HD_pressPause() {			
	document.dBook.handle_pressPause();
}
function HD_pressNextPage() {		
	document.dBook.handle_pressNextPage();
}
function HD_pressPreviousPage() {	
	document.dBook.handle_pressPreviousPage();
}
function HD_gotoFirstPage() {		
	document.dBook.handle_gotoFirstPage();
}
function HD_gotoEndPage() {			
	document.dBook.handle_gotoEndPage();
}

function HD_pressBackwardRotate() {	// auto sliding (backward)
	document.dBook.handle_pressBackwardRotate();
}
function HD_pressForwardRotate() {	// auto sliding (forward)
	document.dBook.handle_pressForwardRotate();
}

////////////////////////////////////////////////////////////////////////////////

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 printPage(direction) 
{
	if (!document.dBook)
	{
		alert("There is not exist Humandream 3Dmall DigitalBook");
		return;
	}

	if (!document.PrintCtrl)		// ÆäÀÌÁö ·ÎµùÈÄ Ã³À½ Print ÇÏ´Â °æ¿ì. PrintCtrl¿¡ ´ëÇÑ <Object> ÅÂ±×°¡ ¾øÀ» ¶§ //
	{
		installPrintCtrl();
	}
	else 
	{
		try
		{
			document.PrintCtrl.isRegistered();
		}
		catch (e1) 
		{ 
			installPrintCtrl();

			return;					// ¿©±â¼­ returnÀ» ÇÏ´Â °æ¿ì´Â ¼³Ä¡°¡ ¾ÈµÇ¾î ÀÖ´Â »óÅÂÀÌ±â ¶§¹®ÀÌ´Ù. //
		}
	}
			

	var strPrintArg = "";
	var bExistMediUrl = false;

	if ( direction == "" )      direction = 2;      // 2 == double page
	var strMediaURL = document.dBook.handle_getMediaURL();
	var page;

	if (strMediaURL != "")
	{
	
		if (document.dBook.handle_isDoublePage())
		{
			var	lpage = document.dBook.handle_getLeftSlidePage() - 1;
			var rpage = document.dBook.handle_getRightSlidePage() - 1;
			
			// var page;
				
			if (direction == 0)
				page = 	lpage;
			else if (direction == 1)
				page = 	rpage;
			else
				page = 	lpage + "-" + rpage;	
		}
		else
		{
			// var page = document.dBook.handle_getCurSlidePage() - 1;
			page = document.dBook.handle_getCurSlidePage() - 1;
		}
		
		strPrintArg = "\"" + strMediaURL + "\"";
		bExistMediUrl = true;
	}
	else
	{
		var validity;
		
		var strPrintImages;
		
		if (document.dBook.handle_isDoublePage())
		{
			if (direction != 2) {		
				if (direction == 0)
					validity = document.dBook.handle_getLeftPrintName()
				else
					validity = document.dBook.handle_getRightPrintName()
				
				if (validity > 0) {
					strPrintImages = "\"" + printTarget + "0.jpg\"" + " " + "\"" + printTarget + "1.jpg\"" + " " + "\"" + printTarget + "2.jpg\"" + " " + "\"" + printTarget + "3.jpg\"";

				}
				else {
					strPrintImages = "\"" + printTarget + ".jpg\""
				}
			}
			else { //  (direction == 2) {		
				validity = document.dBook.handle_getLeftPrintName()
				var leftPage = printTarget;
				validity = document.dBook.handle_getRightPrintName()
				var RightPage = printTarget;

				if (validity > 0) {
					strPrintImages = "\"" + leftPage + "0.jpg\"" + " " + "\"" + leftPage + "1.jpg\"" + " " + "\"" + leftPage + "2.jpg\"" + " " + "\"" + leftPage + "3.jpg\"" + " " + "\"" + RightPage + "0.jpg\"" + " " + "\"" + RightPage + "1.jpg\"" + " " + "\"" + RightPage + "2.jpg\"" + " " + "\"" + RightPage + "3.jpg\"";
				}
				else {
					strPrintImages = "\"" + leftPage + ".jpg\"" + " " + "\"" + RightPage + ".jpg\""
				}
			}
		}
		else
		{
			validity = document.dBook.handle_getCurPrintName();
			
			if (validity > 0) {
				strPrintImages = "\"" + printTarget + "0.jpg\"" + " " + "\"" + printTarget + "1.jpg\"" + " " + "\"" + printTarget + "2.jpg\"" + " " + "\"" + printTarget + "3.jpg\"";
			}
			else {
				strPrintImages = "\"" + printTarget + ".jpg\""
			}
		}

		strPrintArg = strPrintImages;
		bExistMediUrl = false;
	}

	try
	{
		if (bExistMediUrl)
		{
			PrintCtrl.PrintHDM(strPrintArg, -1, page);
		}
		else
			PrintCtrl.PrintImage(strPrintArg);
	}
	catch (e3)
	{

	}
}

function installPrintCtrl()
{
	var tempCurrentUrl = ""+document.location.href;
	tempCurrentUrl = tempCurrentUrl.substring(0,5);
	tempCurrentUrl.toUpperCase();

	if (tempCurrentUrl.indexOf("HTTP") > -1)	// case on-line 
	{
       	var htmlPrintTag = "";
		htmlPrintTag += '<OBJECT ID="PrintCtrl" WIDTH=0 HEIGHT=0 CLASSID="CLSID:6D3E22C5-8087-41DE-A898-6B5E44677DAA" ';
		htmlPrintTag += ' CODEBASE="http://www.humandream.com/dbook/release/HDMediaPrint.cab#version=1,0,1,18" ';
		htmlPrintTag += ' STANDBY="Please Wait...."> ';
		htmlPrintTag += '</OBJECT> ';
		document.dBook.insertAdjacentHTML("afterEnd",htmlPrintTag);
	}
	else			// case off-line 
	{
       	var htmlPrintTag = "";
		htmlPrintTag += '<OBJECT ID="PrintCtrl" WIDTH=0 HEIGHT=0 CLASSID="CLSID:6D3E22C5-8087-41DE-A898-6B5E44677DAA" ';
		htmlPrintTag += ' CODEBASE="appendix/Package/HDPrint/HDMediaPrint.cab#version=1,0,1,18" ';
		htmlPrintTag += ' STANDBY="Please Wait...."> ';
		htmlPrintTag += '</OBJECT> ';
		document.dBook.insertAdjacentHTML("afterEnd",htmlPrintTag);
	}
}


function printPage0(direction) {
	var tempFile=""
	var tempWindow = ""
	var validity

	if (direction != 2) {		
		if (direction == 0)
			validity = document.dBook.handle_getLeftPrintName()
		else
			validity = document.dBook.handle_getRightPrintName()

		printWindow=window.open(tempFile,tempWindow,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=0, top=0, width=700,height=600');
		printWindow.document.writeln("<HTML>")
		printWindow.document.writeln("<head>")
		printWindow.document.writeln("<scr"+"ipt lang" + "uage=jav"+"ascript>")
		printWindow.document.writeln("    funct" + "ion printPage() {")
		
		printWindow.document.writeln("    window.print()")
				
		printWindow.document.writeln("		setTimeout('window.close()', 1000);")
		printWindow.document.writeln("    } ")
		printWindow.document.writeln("</scr"+"ipt>")
		printWindow.document.writeln("</head>")
		printWindow.document.writeln("<BODY>")

		printWindow.document.writeln("<center>")
		printWindow.document.writeln("<table border='0' cellspacing='0' cellpadding='0' topmargin='0' marginwidth='0' marginheight='0'>")
		printWindow.document.writeln("<tr>")

		if (validity > 0) {
			printWindow.document.writeln("<td><img src=\"" + printTarget + "0.jpg\" width=325 height=485></td>")
			printWindow.document.writeln("<td><img src=\"" + printTarget + "1.jpg\" width=325 height=485></td>")
			printWindow.document.writeln("</tr><tr>")
			printWindow.document.writeln("<td><img src=\"" + printTarget + "2.jpg\" width=325 height=485></td>")
			printWindow.document.writeln("<td><img src=\"" + printTarget + "3.jpg\" width=325 height=485></td>")
		}
		else {
			printWindow.document.writeln("<td><img src=\"" + printTarget + ".jpg\" width=650 height=970></td>")
		}

		printWindow.document.writeln("</tr>")
		printWindow.document.writeln("</table>")
		printWindow.document.writeln("</center>")

		printWindow.document.writeln("</BODY>")
		printWindow.document.writeln("</HTML>")
		printWindow.location.reload();

//		printWindow.print()
		printWindow.setTimeout("printPage()", 1000);
		printWindow.setTimeout("window.close()",1000);
	}
	else { //  (direction == 2) {		
		validity = document.dBook.handle_getLeftPrintName()
		var leftPage = printTarget;
		validity = document.dBook.handle_getRightPrintName()
		var RightPage = printTarget;

		printWindow=window.open(tempFile,tempWindow,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes, left=0, top=0, width=910,height=700');
		printWindow.document.writeln("<HTML>")
		printWindow.document.writeln("<head>")

		printWindow.document.writeln("<scr"+"ipt lang" + "uage=jav"+"ascript>")
		printWindow.document.writeln("		var msg = 'Set the page orientaion of the printer to the landscape.'")
		printWindow.document.writeln("    funct" + "ion printPage() {")
		
		printWindow.document.writeln("    window.print()")
		
		printWindow.document.writeln("				setTimeout('alert(msg)', 1500)")
		printWindow.document.writeln("				setTimeout('window.close()', 2000);")
		printWindow.document.writeln("    } ")
		printWindow.document.writeln("</scr"+"ipt>")

		printWindow.document.writeln("</head>")
		printWindow.document.writeln("<BODY>")

		printWindow.document.writeln("<center>")
		printWindow.document.writeln("<table border='0' cellspacing='0' cellpadding='0' topmargin='0' marginwidth='0' marginheight='0'>")
		printWindow.document.writeln("<tr>")

		if (validity > 0) {
			printWindow.document.writeln("<td><img src=\"" + leftPage + "0.jpg\" width=225 height=322></td>")
			printWindow.document.writeln("<td><img src=\"" + leftPage + "1.jpg\" width=225 height=322></td>")
			printWindow.document.writeln("<td><img src=\"" + RightPage + "0.jpg\" width=225 height=322></td>")
			printWindow.document.writeln("<td><img src=\"" + RightPage + "1.jpg\" width=225 height=322></td>")
			printWindow.document.writeln("</tr><tr>")
			printWindow.document.writeln("<td><img src=\"" + leftPage + "2.jpg\" width=225 height=322></td>")
			printWindow.document.writeln("<td><img src=\"" + leftPage + "3.jpg\" width=225 height=322></td>")
			printWindow.document.writeln("<td><img src=\"" + RightPage + "2.jpg\" width=225 height=322></td>")
			printWindow.document.writeln("<td><img src=\"" + RightPage + "3.jpg\" width=225 height=322></td>")
		}
		else {
			printWindow.document.writeln("<td><img src=\"" + leftPage + ".jpg\" width=450 height=645></td>")
			printWindow.document.writeln("<td><img src=\"" + RightPage + ".jpg\" width=450 height=645></td>")
		}

		printWindow.document.writeln("</tr>")
		printWindow.document.writeln("</table>")
		printWindow.document.writeln("</center>")

		printWindow.document.writeln("</BODY>")
		printWindow.document.writeln("</HTML>")
		printWindow.location.reload();

		printWindow.setTimeout("printPage()", 1000);
	}
}

//function HD_startApplet() {
//	interval_id = window.setInterval("HD_setPageNum()", intervalTime);
//}

/// -------------------------------- Print
/***
function _change(val) {
	if( val != "" ) {
		printPage(val)
	}
}
***/
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 HD_OCX_changePage()
{
	try {
		your_changePage();
	}
	catch (e_ocx_01)
	{}
}

function HD_OCX_endRotate()
{
	try {
		your_endRotate();
	}
	catch (e_ocx_02)
	{}
}

function HD_OCX_notFlipPrev()
{
	try {
		your_notFlipPrev();
	}
	catch (e_ocx_03)
	{}
}

function HD_OCX_notFlipNext()
{
	try {
		your_notFlipNext();
	}
	catch (e_ocx_03)
	{}
}
