function getDimensions() {
if (document.all) {document.body.scroll='auto';}
var theheight = document.getElementById("pagebody").clientHeight;
var thewidth = document.getElementById("pagebody").clientWidth;
document.getElementById("wrapped").style.height = theheight + "px";
document.getElementById("wrapped").style.width = thewidth + "px";
var closeOverlayHeight = theheight - 2;
var closeOverlayWidth = thewidth - 2;
document.getElementById("wrapped").style.height = theheight + "px";
var overlayTop = (closeOverlayHeight - 360) / 2;
var overlayLeft = (closeOverlayWidth - 340) / 2;
if (document.getElementById("closeoverlay")) {
document.getElementById("closeoverlay").style.height = closeOverlayHeight + "px";
document.getElementById("closeoverlay").style.width = closeOverlayWidth + "px";
document.getElementById("overlay").style.top = overlayTop + "px";
document.getElementById("overlay").style.left = overlayLeft + "px";
}
if (document.all) {document.body.scroll='auto';}
}

function addToCart() {
document.getElementById("overlay-midshell").style.height = "120px";
document.getElementById("overlay-midshellin").style.height = "120px";
document.getElementById("overlay-inshell").style.height = "120px";
document.getElementById("overlay-contents").innerHTML = document.getElementById("overlay-contents-added").innerHTML;
openPop();
}



function openPop() {
displayItem("closeoverlay");
displayItem("overlay");
}

function closePopConfirm() {
if (confirm("Would you like to close the overlay window?")) {
closePop();

}
}

function closePop() {
hideItem("closeoverlay");
hideItem("overlay");
document.getElementById("overlay-contents").innerHTML = "";
}

/* */

function hideBDropItem(theid) {
hideItem(theid);
changeClass(theid + '-launch','bdrop-link');
}

function displayBDropItem(theid) {
displayItem(theid);
changeClass(theid + '-launch','bdrop-link bdrop-link-active');
}

function hideNavDrop(theid) {
hideItem(theid);
changeClass(theid + '-launch','navdrop-link');
}
function displayNavDrop(theid) {
displayItem(theid);
changeClass(theid + '-launch','navdrop-link navdrop-link-active');
}

function hideTechDrop(theid) {
hideItem(theid);
changeClass(theid + '-launch','tdrop-link');
}

function displayTechDrop(theid) {
displayItem(theid);
changeClass(theid + '-launch','tdrop-link tdrop-link-active');
}

function clearSearch(theid) {
if (theid.value == "Search keyword") {
theid.value = "";
}
}

function dropDestroyer() {
if (document.getElementById("navdrop-home")) {hideNavDrop("navdrop-home");}
if (document.getElementById("navdrop-ind")) {hideNavDrop("navdrop-ind");}
if (document.getElementById("bdrop-profiles")) {hideBDropItem("bdrop-profiles");}
if (document.getElementById("bdrop-resources")) {hideBDropItem("bdrop-resources");}
if (document.getElementById("tdrop-tech")) {hideTechDrop("tdrop-tech");}
}

function manageDetailPanel(theon) {
changeClass('dpanel-tab-authors','');
changeClass('dpanel-tab-reviews','');
changeClass('dpanel-tab-share','');
changeClass('dpanel-tab-' + theon,'panelon');
hideItem('dpanel-authors');
hideItem('dpanel-reviews');
hideItem('dpanel-share');
displayItem('dpanel-' + theon);
}

/* SEARCH */
function manageLeftPanelSearch(theval) {
if (theval == "BOOK") {
displayItem("search-criteria-book");
hideItem("search-criteria-sae");
} else {
hideItem("search-criteria-book");
displayItem("search-criteria-sae");
}
}


/* LIBRARY */

function manageLibCollapse(theact,theid) {
if (theact) {
displayItem('dlib' + theid + '-chapters');
hideItem('dlib' + theid + '-plus');
displayItem('dlib' + theid + '-minus');
displayItem('dlib' + theid + '-ch-exp');
hideItem('dlib' + theid + '-ch-coll');
} else {
hideItem('dlib' + theid + '-chapters');
displayItem('dlib' + theid + '-plus');
hideItem('dlib' + theid + '-minus');
hideItem('dlib' + theid + '-ch-exp');
displayItem('dlib' + theid + '-ch-coll');
}
}

function manageUnBought(theact,theid) {
if (theact) {
changeClass('dlib' + theid + '-chapters',"");
displayItem('dlib' + theid + '-sh-purch');
hideItem('dlib' + theid + '-sh-all');
} else {
changeClass('dlib' + theid + '-chapters',"gdl-hide-buyit");
hideItem('dlib' + theid + '-sh-purch');
displayItem('dlib' + theid + '-sh-all');
}
}


function downloadItem(prodCd,prc,epub,pdf) {
document.getElementById("overlay-midshell").style.height = "185px";
document.getElementById("overlay-midshellin").style.height = "185px";
document.getElementById("overlay-inshell").style.height = "185px";
var sdf = document.getElementById("overlay-contents");
if(prc!="" ||epub !="" ||pdf !="")
{
var a ='<strong>Select a Format to Download</strong><div class="overlay-select"><table>';

if(pdf!="")
{
var a = a + buildTableRow(pdf,'apub','PDF',prodCd);
}
if(epub!="")
{
var a = a + buildTableRow(epub,'epub','eBook',prodCd);
}
if(prc!="")
{
var a = a + buildTableRow(prc,'mpub','Mobi (.prc)',prodCd);
}
var a = a + '</table>';
sdf.innerHTML =sdf.innerHTML + a;
}
else
{
sdf.innerHTML =sdf.innerHTML + '<strong>No ebook type available for downlaod</strong>';
}
openPop();
}

function downloadFail() {
alert("Item needs to be purchased before it is available to download.");
}

function launchUpdate(theitem) {
document.getElementById("overlay-midshell").style.height = "205px";
document.getElementById("overlay-midshellin").style.height = "205px";
document.getElementById("overlay-inshell").style.height = "205px";
document.getElementById("overlay-contents").innerHTML = document.getElementById("overlay-contents-updated").innerHTML;


openPop();

}
function buildTableRow(isbn,type, name,prodCd) {
var row = '<tr><td class="gleft"><div class="overlay-select-format">'+name+'</div><div class="overlay-select-isbn">ISBN:'+ isbn +'</div></td><td class="gright"><div class="ordersmbtn"><div><a target="_blank" href="/servlets/bookstore/downloadMyItem.do?method=downloadMyItem&prodCd='+prodCd+'&pubType='+type+'">Select</a></div></div></td></tr>';
return row;
}


function trim(str)
{
	if(str == null) return '';   return str.replace(/^\s*/, '').replace(/\s*$/, '');
}

function selectPurchaseType(e,bookId,prc_prntBook,isbn_pdf,isbn_epub,isbn_mobi,prc_eBook,printFormatkAvl,eBookFormatAvl,onlineFormatkAvl,softwareFormatkAvl) {
try { if (!e) e = window.event;   e.returnValue = false; e.preventDefault();  } catch( ex ) { /* do Nothing */ }

	prc_eBook = prc_eBook.replace(/<.*?>/, '');
	prc_eBook = prc_eBook.replace(/<.*?>/, '');

	prc_prntBook = prc_prntBook.replace(/<.*?>/, '');
	prc_prntBook = prc_prntBook.replace(/<.*?>/, '');

	document.getElementById("overlay-midshell").style.height = "320px";
	document.getElementById("overlay-midshellin").style.height = "320px";
	document.getElementById("overlay-inshell").style.height = "320px";
	document.getElementById("overlay-contents").innerHTML = buildSelectPurchaseTypeInnerHTML(bookId,prc_prntBook,isbn_pdf,isbn_epub,isbn_mobi,prc_eBook,printFormatkAvl,eBookFormatAvl,onlineFormatkAvl,softwareFormatkAvl);

	openPop();
}

	/** return function hook for shopping cart*/
	function ebookPurchase() {

		document.getElementById("overlay-midshell").style.height = "300px";
		document.getElementById("overlay-midshellin").style.height = "300px";
		document.getElementById("overlay-inshell").style.height = "300px";
		var strg = '<div id="overlay-contents-ebook" class="overlay-resource1"><strong>eBook Added to Shopping Cart</strong>'+
				   '<div class="overlay-select-heading"><span>You will have access to all of the below eBook Downloadable Formats after purchase</span></div>'+
				   '<div class="overlay-select"><table><tr><td class="gleft"><div class="overlay-select-format">PDF</div>'+
				   '<div class="overlay-select-isbn">ISBN: '+isbnPdf+'</div>'+
				   '</td><td class="gright"></td></tr><tr><td class="gleft"><div class="overlay-select-format">eBook</div>'+
				   '<div class="overlay-select-isbn">ISBN: '+isbnEpub+'</div></td><td class="gright"></td></tr><tr>'+
				   '<td class="gleft"><div class="overlay-select-format">Mobi (.prc)</div>'+
				   '<div class="overlay-select-isbn">ISBN: '+isbnMobi+'</div></td><td class="gright"></td></tr>'+
				   '</table></div>'+
					'<div class="overlay-shopcart">'+
					'<table><tr>'+
					'<td class="gleft"><div class="ordersmbtn"><div><a href="javascript:closePop();">Continue Browsing</a></div></div></td>'+
					'<td class="gright"><div class="ordersmbtn"><div><a href="/servlets/MaintainCartServlet?REQUEST_TYPE=MaintainCart">Proceed to Shopping Cart</a></div></div></td></tr>'+
					'</table></div>'+
					'<div class="overlay-ebook-msg">*  Downloadable anytime, after purchase, from <a href="/servlets/bookstore/library.do">eLibrary</a>.</div>'+
					'</div>';
		document.getElementById("overlay-contents").innerHTML = strg;
		openPop();
	}


function printFormatPurchase(){formatPurchase('Print');}
function onlineFormatPurchase(){formatPurchase('Online');}
function softwareFormatPurchase(){formatPurchase('Software');}


function formatPurchase(formatType) {
document.getElementById("overlay-midshell").style.height = "140px";
document.getElementById("overlay-midshellin").style.height = "140px";
document.getElementById("overlay-inshell").style.height = "140px";
var strg ='<div id="overlay-contents-ebook" class="overlay-resource1"><strong>'+formatType+' Format Added to Shopping Cart</strong>'+
	'<div class="overlay-shopcart">'+
	'<table><tr>'+
	'<td class="gleft"><div class="ordersmbtn"><div><a href="javascript:closePop();">Continue Browsing</a></div></div></td>'+
	'<td class="gright"><div class="ordersmbtn"><div><a href="/servlets/MaintainCartServlet?REQUEST_TYPE=MaintainCart">Proceed to Shopping Cart</a></div></div></td>'+
	'</tr></table></div></div>';
			
document.getElementById("overlay-contents").innerHTML = strg;//buildPrintbookPurchaseInnerHTML();
openPop();
}



function printbookPurchase() {
document.getElementById("overlay-midshell").style.height = "140px";
document.getElementById("overlay-midshellin").style.height = "140px";
document.getElementById("overlay-inshell").style.height = "140px";
var strg ='<div id="overlay-contents-ebook" class="overlay-resource1"><strong>Print Book Added to Shopping Cart</strong>'+
	'<div class="overlay-shopcart">'+
	'<table><tr>'+
	'<td class="gleft"><div class="ordersmbtn"><div><a href="javascript:closePop();">Continue Browsing</a></div></div></td>'+
	'<td class="gright"><div class="ordersmbtn"><div><a href="/servlets/MaintainCartServlet?REQUEST_TYPE=MaintainCart">Proceed to Shopping Cart</a></div></div></td>'+
	'</tr></table></div></div>';
			
document.getElementById("overlay-contents").innerHTML = strg;//buildPrintbookPurchaseInnerHTML();
openPop();
}

var isbnPdf,isbnEpub,isbnMobi;
function buildSelectPurchaseTypeInnerHTML(bookId,prc_prntBook,isbn_pdf,isbn_epub,isbn_mobi,prc_eBook,printFormatkAvl,eBookFormatAvl,onlineFormatkAvl,softwareFormatkAvl)
{
isbnPdf=isbn_pdf;isbnEpub=isbn_epub;isbnMobi=isbn_mobi;

	var innerHtml = '<!-- ,start -->';//<div id="overlay-contents-selectpurch" class="overlay-resource">
	innerHtml = innerHtml+'<strong>Select Delivery Method</strong>';
	innerHtml = innerHtml+'<div class="overlay-selectdel"><table>';
	if(eBookFormatAvl!=null && eBookFormatAvl=='Y')
	{
		innerHtml = innerHtml+'<tr><td class="selectdel-title">eBook</td>';
		innerHtml = innerHtml+'<td class="selectdel-price">'+prc_eBook+'</td>';
		innerHtml = innerHtml+'<td class="selectdel-cart"><div class="ordersmbtn"><div><a href="#" onclick="';
//		innerHtml = innerHtml+'alert(\'shopping cart for '+bookId+'\')';
		innerHtml = innerHtml+'addToCart(event,\'/servlets/MaintainCartServlet?REQUEST_TYPE=AddItem&ITEM_ID='+bookId+'&DELIV_CD=DNL&PROD_TYP=BOOK&RENDER_TYP=JSON\',ebookPurchase);';
		innerHtml = innerHtml+'">Add to Cart</a></div></div></td></tr>';

		innerHtml = innerHtml+'<tr><td class="selectdel-group" colspan=3>';
		innerHtml = innerHtml+'<div class="overlay-select-heading">eBook Downloadable Formats</div>';
		innerHtml = innerHtml+'<div class="overlay-select">';
		innerHtml = innerHtml+'<table>';
		if(isbn_pdf!=null && isbn_pdf!='')
		{
			innerHtml = innerHtml+'<tr><td class="gleft"><div class="overlay-select-format">PDF</div>';
			innerHtml = innerHtml+'<div class="overlay-select-isbn">ISBN: '+isbn_pdf+'</div>';
			innerHtml = innerHtml+'</td><td class="gright"></td></tr>';
		}
		if(isbn_epub!=null && isbn_epub!='')
		{
			innerHtml = innerHtml+'<tr><td class="gleft">';
			innerHtml = innerHtml+'<div class="overlay-select-format">EPUB</div>';
			innerHtml = innerHtml+'<div class="overlay-select-isbn">ISBN: '+isbn_epub+'</div>';
			innerHtml = innerHtml+'</td><td class="gright"></td></tr>';
		}
		if(isbn_mobi!=null && isbn_mobi!='')
		{
			innerHtml = innerHtml+'<tr><td class="gleft">';
			innerHtml = innerHtml+'<div class="overlay-select-format">Mobi (.prc)</div>';
			innerHtml = innerHtml+'<div class="overlay-select-isbn">ISBN: '+isbn_mobi+'</div>';
			innerHtml = innerHtml+'</td><td class="gright"></td></tr>';
		}
		innerHtml = innerHtml+'</table></div></td></tr>';
	}

	if(printFormatkAvl!=null && printFormatkAvl=='Y')
	{
		innerHtml = innerHtml+'<tr><td class="selectdel-title">Print Format</td>';
		innerHtml = innerHtml+'<td class="selectdel-price">'+prc_prntBook+'</td>';
		innerHtml = innerHtml+'<td class="selectdel-cart"><div class="ordersmbtn"><div><a href="#" onclick="';
//		innerHtml = innerHtml+'alert(\'shopping cart for '+bookId+'\')';
		innerHtml = innerHtml+'addToCart(event,\'/servlets/MaintainCartServlet?REQUEST_TYPE=AddItem&ITEM_ID='+bookId+'&DELIV_CD=PST&PROD_TYP=BOOK&RENDER_TYP=JSON\',printbookPurchase);';
		innerHtml = innerHtml+'">Add to Cart</a></div></div></td></tr>';
	}
	if(onlineFormatkAvl!=null && onlineFormatkAvl=='Y')
	{
		innerHtml = innerHtml+'<tr><td class="selectdel-title">Online Format</td>';
		innerHtml = innerHtml+'<td class="selectdel-price">'+prc_eBook+'</td>';
		innerHtml = innerHtml+'<td class="selectdel-cart"><div class="ordersmbtn"><div><a href="#" onclick="';
//		innerHtml = innerHtml+'alert(\'shopping cart for '+bookId+'\')';
		innerHtml = innerHtml+'addToCart(event,\'/servlets/MaintainCartServlet?REQUEST_TYPE=AddItem&ITEM_ID='+bookId+'&DELIV_CD=DNL&PROD_TYP=BOOK&RENDER_TYP=JSON\',onlineFormatPurchase);';
		innerHtml = innerHtml+'">Add to Cart</a></div></div></td></tr>';
	}
	if(softwareFormatkAvl!=null && softwareFormatkAvl=='Y')
	{
		innerHtml = innerHtml+'<tr><td class="selectdel-title">Software Format</td>';
		innerHtml = innerHtml+'<td class="selectdel-price">'+prc_prntBook+'</td>';
		innerHtml = innerHtml+'<td class="selectdel-cart"><div class="ordersmbtn"><div><a href="#" onclick="';
//		innerHtml = innerHtml+'alert(\'shopping cart for '+bookId+'\')';
		innerHtml = innerHtml+'addToCart(event,\'/servlets/MaintainCartServlet?REQUEST_TYPE=AddItem&ITEM_ID='+bookId+'&DELIV_CD=PST&PROD_TYP=BOOK&RENDER_TYP=JSON\',softwareFormatPurchase);';
		innerHtml = innerHtml+'">Add to Cart</a></div></div></td></tr>';
	}
	innerHtml = innerHtml+'</table></div></div>';
	innerHtml = innerHtml+'<!-- ,end -->';
//	alert(innerHtml)
	return innerHtml;
}
