var d, dnlWidth, dnlHeight, dnlMaj, dnlMin, dnlBld, l, p, pr, path, sp, ns, dnlInstalled, viewStr, instStr, prog, speed, progTim, dispWS, controlsAbove, pid, scriptable, tbType, pvImageName, pvMode, imPath, manInst, brTitle;
var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var opera = navigator.userAgent.toLowerCase().indexOf("opera") >= 0;

var win=false;
var mac=false;
var lin=false;
var manInst=false;

if(navigator.platform.indexOf("Win")>-1) win=true;
if(navigator.platform.indexOf("Mac")>-1) mac=true;
if(navigator.platform.indexOf("Linux")>-1) lin=true;
var vstr="";
viewStr = "";

if ((navigator.userAgent.toLowerCase().indexOf("msie 8") >= 0) && (navigator.userAgent.toLowerCase().indexOf("nt 5") >= 0)) manInst=true;
if (navigator.userAgent.toLowerCase().indexOf("fox/3") >= 0) manInst=true;

if (mac){
	vstr = "<table width=\"500\" border=\"0\" align=\"center\"><tr height=\"20\"><td colspan=\"2\">&nbsp;</td></tr><tr> <td colspan=\"2\" class=\"LargeBlueHeading\" align=\"center\">Note for Mac Users</td>";
	vstr += "</tr><tr height=\"20\"><td colspan=\"2\">&nbsp;</td></tr><tr><td class=\"WelcomeText\">You may need to install some software to view this eBook on a Mac.</td>";
	vstr += "</tr><tr height=\"20\"><td colspan=\"2\">&nbsp;</td></tr><tr>";
	vstr += "<td class=\"BodyBlack\">This eBook has been created using the DNL eBook format from <a href=\"http://www.dnaml.com\" class=\"BodyBlack\">DNAML</a>.  The DNL format displays interactive 3-D page-turning eBooks that run inside a browser in Internet Explorer, Firefox or standalone.  You need Windows to view DNL files, but they can be viewed on a Mac using these products:";
	vstr += "<ul><li class=\"BodyBlack\"><a href=\"http://www.parallels.com/en/products/desktop/\" class=\"BodyBlack\" target=\"_blank\">Parallels</a></li>";
	vstr += "<li class=\"BodyBlack\"><a href=\"http://www.vmware.com/beta/fusion/index.html\" class=\"BodyBlack\" target=\"_blank\">VMWare Fusion</a></li>";
	vstr += "<li class=\"BodyBlack\"><a href=\"http://www.apple.com/macosx/features/bootcamp.html\" class=\"BodyBlack\" target=\"_blank\">Boot Camp</a></li>";
	vstr += "<li class=\"BodyBlack\">If you are using a pre-OSX Mac, consider using <a href=\"http://www.microsoft.com/mac/downloads.mspx\" class=\"BodyBlack\" target=\"_blank\">Virtual PC</a></li>";
	vstr += "</ul> When you have one of these products running, please return to this page using Internet Explorer or Firefox inside Windows running in the selected product.  <br><br>Please click <a href=\"http://www.dnaml.com/contact.asp\" class=\"BodyBlack\"><u>here</u></a> to contact us if you have any problems.</td></tr><tr height=\"20\"><td colspan=\"2\">&nbsp;</td></tr></table>";
}
if (lin){
	vstr = "<table width=\"500\" border=\"0\" align=\"center\"><tr height=\"20\"><td colspan=\"2\">&nbsp;</td></tr><tr> <td colspan=\"2\" class=\"LargeBlueHeading\" align=\"center\">Note for Linux Users</td>";
	vstr += "</tr><tr height=\"20\"><td colspan=\"2\">&nbsp;</td></tr><tr><td class=\"WelcomeText\">You may need to install some software to view this eBook under Linux.</td>";
	vstr += "</tr><tr height=\"20\"><td colspan=\"2\">&nbsp;</td></tr><tr>";
	vstr += "<td class=\"BodyBlack\">This eBook has been created using the DNL eBook format from <a href=\"http://www.dnaml.com\" class=\"BodyBlack\">DNAML</a>.";
	vstr += " The DNL format displays interactive 3-D page-turning eBooks that run inside a browser in Internet Explorer, Firefox or standalone.  You need Windows to view DNL files, but they can be viewed on a Linux computer using Wine. <br><br>";
	vstr += "If you do no have WINE installed, click <a href=\"https://help.ubuntu.com/8.04/add-applications/C/index.html\" class=\"BodyBlack\" target=\"_blank\"><u>here</u></a> for instructions on how to install software under Linux.<br><br>";
	vstr += "Once, WINE is installed, follow these steps:<br>";
	vstr += "<ol><li class=\"BodyBlack\">Download DNL Reader Installer and save to Desktop.  Download from <a href=\"http://www.dnlreader.com/reader/dtaplugin.exe\" class=\"BodyBlack\">here</a>.</li>";
	vstr += "<li class=\"BodyBlack\">Download DNL File and save to Desktop.  Download from <a href=\"images/<%=dnl%>\" class=\"BodyBlack\">here</a>.</li>";
	vstr += "<li class=\"BodyBlack\">Right-click on \"dtaplugin.exe\" on your Desktop and select \"Open with WINE Windows Emulator\".</li>";
	vstr += "<li class=\"BodyBlack\">Open a Linux terminal (command line) and type 'wine dbplugin.exe \"z:\\\\home\\loginname\\Desktop\\dnlname\"'.</li>";
	vstr += "</ol>";
	vstr += "<br><br>Please click <a href=\"http://www.dnaml.com/contact.asp\" class=\"BodyBlack\"><u>here</u></a> to contact us if you have any problems.";
	vstr += "</td></tr></table>";
}

function GetObj(id) {
if (isDOM) return document.getElementById(id);
if (isIE4) return document.all[id];
}

function GetStyle(id) {
return GetObj(id).style;
}

function Ready(){
	var o;
	HideProgress();
	o = GetObj("dnlplyr");
	if (o){
		o.AtTop = 1;
		o.LoadBook(path + d);
	}
}

function NoReader(){
	var o;
	HideProgress();
	o = GetObj("bookspace");
	o.innerHTML = instStr;
}

function HideProgress(){
	var st;
	st = GetStyle("ProgressLayer");
	st.visibility = "hidden";
	st = GetStyle("ProgressBarLayer");
	st.visibility = "hidden";
	st = GetStyle("BookLayer");
	st.visibility = "hidden";
	speed = 5;
	prog = 1;
	if (progTim > 0) clearInterval(progTim);
}

function DisplayBook(){
	var o;
	if ((!ns) && (!dnlInstalled)) DisplayProgress();
	o = GetObj("bookspace");
	o.innerHTML = viewStr;
	o = GetObj("dnlplyr");
	if (o){
		o.AtTop = 1;
		o.LoadBook(path + d);
	}
}

function Install(){
	var o;
	if (!ns) DisplayProgress();
	o = GetObj("bookspace");
	o.innerHTML = viewStr;
	if (ns){
		xpi={'Install DNL Viewer':'xpinst.xpi'};
		if (InstallTrigger.compareVersion("DNL_Viewer",dnlMaj + "." + dnlMin + ".0." + dnlBld) < 0)
			InstallTrigger.install(xpi);
	}
}

function UpdateProgress(){
var img, s;
prog += speed;
if (prog > 198) prog = 198;
else {
	s = Math.round(prog/40);
	switch(s){
	case 0: speed = 5; break;
	case 1: speed = 4; break;
	case 2: speed = 3; break;
	case 3: 
		if (speed > 2){
			clearInterval(progTim);
			progTim = setInterval("UpdateProgress()",1000);
		}
		speed = 2; 
	break;
	case 4: 
		if (speed > 1){
			clearInterval(progTim);
			progTim = setInterval("UpdateProgress()",2000);
		}
		speed = 1; 
	break;
	}
}
img = GetObj("ProgressBar");
img.width = prog;
}

function DisplayProgress(){
	var st, l, t, w, h, img;
	w = document.body.offsetWidth-20;
	h = dnlHeight + 20;
	l = (w - 250) / 2;
	t = 400;
	st = GetStyle("BookLayer");
	st.visibility = "visible";
	st = GetStyle("ProgressLayer");
	st.left = l;
	st.top = t;	
	img = GetObj("ProgressBar");
	img.width = prog;
	st.visibility = "visible";
	st = GetStyle("ProgressBarLayer");
	st.left = l + 46;
	st.top = t + 21;
	st.visibility = "visible";
	progTim = setInterval("UpdateProgress()",300);
}

function InitData(tb){
var o;
progTim = 0;
tbType = tb;
instStr = "<table width=" + dnlWidth + " height=" + dnlHeight + " align='center' border=0><tr valign='top'>";
instStr += "<td align='center' class='instText'>This page contains a Digital Web Book.<br>";
instStr += "To view this digital web book, you must install the DNL Reader.<br><br>";
instStr += "Click <a href='javascript:Install();'>here</a> to install the DNL Reader.<br><strong>Please be ";
instStr += "sure to close all other Internet Explorer sessions and DNL Powered eBooks before installing.</strong><br><br><br>";
instStr += "If you are unable to install, click <a href='http://dnlreader.com/reader/'>here</a> to manually install the DNL Reader.<br><br><br>";
instStr += "For more information on Digital Web Books, visit <a href='http://digitalwebbooks.com' target='_blank'>digitalwebbooks.com</a></td>";
instStr += "</tr></table>";

speed = 5;
prog = 1;
l = new String(window.location);
path = "";

ns = (((document.layers) || (document.getElementById && !document.all)) ? true: false);

if (manInst){
	if (ns)
		vstr = "<span class=\"LargeBlueHeading\">Due to Firefox 3 restrictions, to view this eBook, you first need to install the DNL Reader</span><br>";
	else
		vstr = "<span class=\"LargeBlueHeading\">Due to Internet Explorer 8 restrictions under Windows XP, to view this eBook, you first need to install the DNL Reader</span><br>";
	vstr += "<br><br><span class=\"WelcomeText\">1. Download the small file size DNL Reader";
	vstr += " &nbsp;&nbsp;&nbsp; <a href=\"http://dnlreader.com/reader\"><img src=\"" + imPath + "getdnlreader2.gif\" border=\"0\" width=\"71\" height=\"28\" alt=\"Get DNL Reader\"></a>";
	vstr += "<br><br>2. Click <a href=\"" + d + "\"><u>here to download '" + brTitle + "'</u></a></span>";
}

dnlInstalled = false;
scriptable = false;
if (ns){
	var agt=navigator.userAgent.toLowerCase();
	var majorVer = parseInt(navigator.appVersion);
	if ((majorVer >= 5) && (agt.indexOf("netscape6") < 0)) scriptable = true;
} else {
 	scriptable = true;
}
if (opera) {
	ns = true;
	scriptable = false;
}
	o = GetObj("bookspace");
	o.innerHTML = vstr;
}

function InsertBook(){
if (ns){
	dnlInstalled = navigator.mimeTypes && navigator.mimeTypes["application/x-dnl"] && navigator.mimeTypes["application/x-dnl"].enabledPlugin;
	if (opera){
		viewStr = "<table align='center'><tr valign=\"center\" height=\"" + (dnlHeight + 40) + "\"><td align=\"center\">";
		if (dnlInstalled){
			viewStr += "<embed id=\"dnlplyr\" type=\"application/x-dnl\"";
			viewStr += "SRC=\"" + path + d + "\" width=" + dnlWidth + " height=" + (dnlHeight + 40) + "	codebase=\"http://www.digitalwebbooks.com/reader/xpinst.xpi\"></embed>";
		} else {
			viewStr += "<p>To view this eBook, you need to install the DNL Reader.</p><p><a href=\"http://digitalwebbooks.com/reader\">Click here to install the DNL Reader</a></p>";
			viewStr += "<p>After installation, please restart this browser</p>";
		}
		viewStr += "</td></tr></table>";
	} else {
		if (dnlInstalled){
			viewStr = "<table align='center'><tr><td>";
			viewStr += "<embed id=\"dnlplyr\" type=\"application/x-dnl\"";
			viewStr += "SRC=\"" + path + d + "\" width=" + dnlWidth + " height=" + (dnlHeight + 40) + "	codebase=\"http://www.digitalwebbooks.com/reader/xpinst.xpi\">";
			viewStr += "</embed></td></tr></table>";
		}
	}
} else {
	viewStr = "<table id='dnltab' align='center'><tr><td>";
	viewStr += "<object classid=\"clsid:164B406B-0FD6-4E7F-BA7E-64D227D4CA37\" ";
	viewStr += "codebase=\"http://www.digitalwebbooks.com/reader/dbplugin.cab#version=" + dnlMaj + "," + dnlMin + ",0," + dnlBld + "\" ";
	viewStr += "name=\"dnlplyr\" id=\"dnlplyr\" data=\"DATA:application/x-oleobject;BASE64,a0BLFtYPf066fmTSJ9TKNwADAADIMAAAUhwAAA==\" ";
	viewStr += "width=" + dnlWidth + " height=" + (dnlHeight + 40) + " onreadystatechange=\"Ready();\" onerror='NoReader();'>";
	viewStr += "</object></td></tr></table>";
}
if (win){
	if (scriptable) InsertControlBar();
	if (dnlInstalled){
		DisplayBook();
	} else {
		if (!manInst)
			Install();
	}
}
}

function GoForward(){
 var d = GetObj("dnlplyr");
 if (d) d.GoForward();
}

function GoBack(){
 var d = GetObj("dnlplyr");
 if (d) d.GoBack();
}

function Standalone(){
 var d = GetObj("dnlplyr");
 if (d) d.GoStandAlone();
}

function Save(){
 var d = GetObj("dnlplyr");
 if (d) d.Save();
}

function Mail(){
 var d = GetObj("dnlplyr");
 if (d) d.Mail();
}

function Website(){
 window.open("http://desktopauthor.com/?pid=" + pid, target="_blank");
}

function InsertControlBar(){
var s;
s = "<table id=\"buttons\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
s += "<tr><td><img src=\"" + imPath + "design2_arrow_left.gif\" onClick=\"GoBack()\" title=\"Go Back One Page\"></td>";
s += "<td><img src=\"" + imPath + "design2_blue_logo.gif\" onClick=\"Website()\" title=\"Visit the Software Creator's Website\"></td>";
s += "<td><img src=\"" + imPath + "design2_envelope.gif\" onClick=\"Mail()\" title=\"Email this Book\"></td>";
s += "<td><img src=\"" + imPath + "design2_pop_out.gif\" onClick=\"Standalone()\" title=\"Detach book from Browser\"></td>";
s += "<td><img src=\"" + imPath + "design2_save.gif\" onClick=\"Save()\" title=\"Save this Book\"></td>";
s += "<td><img src=\"" + imPath + "design2_arrow_right.gif\" onClick=\"GoForward()\" title=\"Go Forward One Page\"></td></tr>";
s += "</table><br>";
viewStr = s + viewStr;
}

