//	book_ad.js - Javascript to generate ads
//
//	Copyright (C) 2003-2009 Charles A Upsdell, All Rights Reserved; www.upsdell.com

// Set list of books and software

	var Book = 0;
	var Software = 1;
	var Hardware = 2;
	var jpg = 'jpg';
	var png = 'png';
	var Item = new Array();
	var ISBN = new cItemList();
	var nPrevItem = 0;

	// AJAX
	// C#
	AddItem(  0, Book, jpg, 'C# in Depth, 2ndEd', '', '1935182471', 'This details the changes in C# from 2.0. Updated for C# 4.0' );
	AddItem(  9, Book, jpg, 'Head First C# 2008, 2ndEd', '', ['1449380344'], 'A learner&rsquo;s guide to C#, updated to Visual Studio 2010 and .NET 4.0' );
	// CSS + HTML + xHTML
	AddItem( -1, Book, jpg, 'Bulletproof Web Design, 2ndEd', 'Improving flexibility and protecting against worst-case scenarios with XHTML and CSS', '0321509021', 'Outlines strategies for creating standards-based designs that provide flexibility, readability, and user control', 0, '1430219203 0321643380' );
	AddItem(-99, Book, png, 'Cascading Style Sheets: The Definitive Guide, 3rdEd', '', '0596527330', 'A comprehensive CSS 2 reference and guide, updated for CSS 2.1, today\'s prime CSS standard. Updated for IE 7, and includes info on positioning, lists and generated content, table layout, user interface, paged media, and more. Details each CSS property, how it interacts with other properties, and how to avoid common errors. By Eric Meyer, <i>the</i> CSS guru</i>' );
	AddItem(  4, Book, jpg, 'CSS Detective Guide', 'The Tricks for Solving Tough CSS Mysteries', ['0321683943','B003KTMWCW'], 'learn how to track clues, analyze the evidence, and get to the truth behind CSS mysteries causing unexpected layout problems' );
	AddItem( -1, Book, png, 'CSS : The Missing Manual, 2ndEd', '', ['0596802447','B0026OR2QI','B002AWX8QE'], 'Learn how to use CSS to create highly functional, professional looking, cross browser compatible sites: with clear explanations, real examples, and dozens of tutorials' );
	AddItem( -1, Book, jpg, 'CSS Mastery, 2ndEd', 'Advanced Web Standards Solutions', ['1430223979','B000SEHEFM'], 'Learn the advanced CSS techniques you need to master CSS and to craft modern, standards compliant web pages' );
	AddItem( -1, Book, png, 'Dynamic HTML: The Definitive Reference, 3rdEd', '', '0596527403', 'A comprehensive dHTML reference book' );
	AddItem( -1, Book, jpg, 'Handcrafted CSS', 'More Bulletproof Web Design', ['0321643380','B003EINO6C'], 'A guide to using innovative and effective CSS techniques that make design easier while improving the end user&rsquo;s experience', 0, '1430219203 0321509021' );
	AddItem( -1, Book, png, 'Head First HTML with CSS &amp; XHTML', '', '059610197X', 'A starter book for those interested in web design' );
	AddItem( 64, Book, png, 'HTML 5', 'Up and Running', '0596806027', 'This provides a concise first look at HTML 5 elements, attributes, and JavaScript' );
	AddItem(  0, Book, png, 'HTML5 &amp; CSS3', 'Develop with Tomorrow&rsquo;s Standards Today', '1934356689', 'This gets you up to speed on the new HTML5 elements and CSS3 features you can use right now, and backwards compatible solutions ensure you don&rsquo;t leave users of older browsers behind' );
	AddItem( 16, Book, png, 'Introducing HTML 5', '', '0321687299', 'Learn the elements of HTML 5 which you can use today' );
	AddItem( 64, Book, jpg, 'Pro HTML5 Programming', 'Powerful APIs for Richer Internet Application Development', '1430227907', 'Shows how to create real-time HTML5 applications &#8212; with real-world examples, shows which HTML5 features are supported in current browsers, and covers all the new HTML5 APIs' );
	AddItem( -1, Book, jpg, 'Stylin&rsquo; with CSS', 'A Designer&rsquo;s Guide', '0321525566', 'This teaches everything you need to know to start using CSS in your web development work, starting from the basics' );
	AddItem( -1, Book, jpg, 'Transcending CSS', 'The Fine Art of Web Design', '0321410971', 'Shows how to implement highly original designs through visual demonstrations of the creative possibilities using markup and CSS' );
	// Design
	AddItem(  0, Book, jpg, 'Communicating Design, 2ndEd', 'Developing Web Site Documentation for Design and Planning', ['0321712463'], 'Shows how to make website documentation: usability reports, project plans, content maps, flow charts, wireframes, site maps, etc' );
	AddItem( -1, Book, png, 'Content Strategy for the Web', '', ['0321620062','B002LGGJHE'], 'This explains how to create and deliver useful, usable online content; this also shares best practices so you can get your next redesign right, on time, on budget' );
	AddItem( -1, Book, jpg, 'Designing Interfaces', 'Patterns for Effective Interaction Design', ['0596008031','B0026OR2W2'], 'This presents the best practices of user interface design as design patterns, each pattern presented with practical advice, examples, recommendations, design alternatives, and caveats' );
	AddItem( -1, Book, jpg, 'Designing with Web Standards, 3rdEd', '', ['0321616952','B002WIG3UO'], 'This explains how designers can best use standards &#8212; primarily XHTML and CSS, plus ECMAScript and the DOM &#8212; to increase their productivity and maximize site availability', 0, '0321646924' );
	AddItem( -1, Book, jpg, 'Developing with Web Standards', '', ['0321646924','B002YYWEGS'], 'This teaches current best practices in standards-based development, with a focus on emerging aspects of HTML, CSS, and other web standards', 0, '0321616952' );
	AddItem( -1, Book, png, 'High Performance Web Sites', 'Essential Knowledge for Front-End Engineers', ['0596529309','B0028N4WHY'], 'This teaches 14 techniques for making websites which load faster', 0, '059680279X' );
	AddItem( -1, Book, jpg, 'Learning Web Design, 3rdEd', 'A Beginner&rsquo;s Guide to (X)HTML, StyleSheets, and Web Graphics', '0596527527', 'A starter book for those interested in web design' );
	AddItem( -1, Book, png, 'Search Engine Advertising, 2<sup>nd</sup>Ed', 'Buying Your Way to the Top to Increase Sales', ['0321495993','B002BVLQHC'], 'Outlines the strategy in buying specific keyword positions to lead users to the page you want, describes how to turn poor-performing ad copy into targeted sales-getters, and shows how to evaluate and correct low visitor-to-buyer conversions' );
	AddItem( -1, Book, png, 'Web Anatomy', 'Interaction Design Frameworks that Work', ['0321635027','B002ZY5FCW'], 'This introduces interaction design frameworks, sets of design patterns and other elements which serve as the basis for cutting-edge innovations and superior user experiences' );
	AddItem( -1, Book, jpg, 'Web Design for Developers', 'A Programmer&rsquo;s Guide to Design Tools and Techniques', '1934356131', 'Learn the basic concepts of design, color theory, typography, and accessibility, and how to apply these to make better looking web pages' );
	AddItem( -1, Book, jpg, 'Web ReDesign 2.0', 'Workflow that Works, 2ndEd', '0735714339', 'Aimed at project managers, this presents a disciplined process for designing and redesigning websites on time and on budget' );
	AddItem( -1, Book, png, 'Website Optimization', 'Speed, Search Engine, &amp; Conversion Rate Secrets', '0596515081', 'Shows how to improve your site&rsquo;s performance by boosting search engine visibility for more traffic, increasing conversion rates to maximize leads and profits, revving up site speed to retain users, and measuring your site&rsquo;s effectiveness with best-practice metrics and tools' );
	AddItem( -1, Book, png, 'Web Standards Solutions', 'The Markup and Style Handbook, Special Edition', '1430219203', 'Explains how to create markup and style, exploring multiple techniques for handling situations when building with web standards', 0, '0321509021 0321643380' );
	// Java
	AddItem( -1, Book, jpg, 'Head First Java, 2<sup>nd</sup>Ed', '', '0596009208', 'A complete introduction to object-oriented programming and Java, from the fundamentals to advanced topics' );
	// JavaScript
	AddItem( -1, Book, png, 'High Performance JavaScript', '', '059680279X', 'Learn why JavaScript is slow, how to identify bottlenecks, and how to create faster code', 0, '0596529309' );
	AddItem( -1, Book, png, 'JavaScript: The Definitive Guide, 5thEd', '', ['0596101996','','B002AWX8CI'], 'Comprehensive guide to JavaScript, JScript, and ECMAScript, plus DOM elements they often manipulate, including advanced material on the latest developer topics, such as scripting Flash with JavaScript, HTTP and Ajax, SVG, XML, web services, and remote scripting. Tutorial sections show how to program in JavaScript. Reference sections summarize syntax and options, with copious examples' );
	AddItem( -1, Book, png, 'JavaScript and DHTML Cookbook, 2ndEd', '', ['0596514085', 'B0028N4WEM','B002AWX8L4'], 'An extensive collection of problems, solutions, and practical examples for JavaScript programmers, applying state-of-the-art standards and best practices' );
	// Perl
	// PHP
	AddItem(  9, Book, jpg, 'PHP Objects, Patterns, and Practice, 3<sup>rd</sup>Ed', '', '143022925X', 'This will teach you about object features, about design patterns and the principles that make patterns powerful, and how to put it all into practice; updated for PHP 5.3' );
	// Search Engine Optimization
	AddItem( -1, Book, jpg, 'The Art of SEO', '', '0596518862', 'This has guidelines for planning and executing a comprehensive website search engine strategy: for novices this is a thorough education on SEO; for the experienced this is an extensive reference for ongoing projects' );
	AddItem( -1, Book, jpg, 'Building Findable Websites', 'Web Standards SEO and Beyond', ['0321526287','B001JNJDNM'], 'Shows how sites can be built with SEO coding strategies, microformats, standards, accessibility guidelines, and third party APIs, all in an effort to drive traffic' );
	AddItem( -1, Book, jpg, 'Search Engine Marketing, Inc, 2ndEd', 'Driving Search Traffic to Your Company&rsquo;s Web Site', ['0136068685','B000SEI9D8'], 'This helps you define your SEO/SEM goals, craft a best practices program for achieving them, and implement it flawlessly' );
	AddItem( -1, Book, png, 'Search Engine Optimization For Dummies, 3rdEd', '', ['0470262702','B0017SYP5K'], 'This shows how to build sites that rank high in the search engines and that generate high traffic' );
	AddItem( -1, Book, jpg, 'When Search Meets Web Usability', '', ['0321605896','B0023SDQPS'], 'This shows how to make an effective Web site that is search engine friendly, to result in better search rankings, how to bridge the gap between a Google search and a Web site, and how to improve the users&rsquo; experience once they get to the site' );
	// SQL
	// Usability
	AddItem( -1, Book, png, 'Eyetracking Web Usability', '', ['0321498364','B000UZNQZG'], 'Learn how much a user&rsquo;s goal or task affects how they read and traverse a website, which parts of a page users attend to first, how readers react to ads and design elements that look like ads, where people look first for common page elements and navigation, how they respond to text, pictures, and multimedia, and more' );
	AddItem( -1, Book, png, 'Handbook of Usability Testing', 'How to Plan, Design, and Conduct Effective Tests', ['0470185481','B001DA42S2'], 'This provides clear, step-by-step guidelines to help you test your product for usability' );
	AddItem( -1, Book, jpg, 'Letting Go of the Words', 'Writing Web Content that Works', ['0123694868','B0027G6X92'], 'A thorough overview of the issues in writing for the web, showing how to write so that visitors will read what you write' );
	AddItem( -1, Book, png, 'Prioritizing Web Usability', '', ['0321350316','B000SEGT1W'], 'Learn about site design, user experience and usability testing, navigation and search capabilities, old guidelines and prioritizing usability issues, page design and layout, content design, and more' );
	AddItem( -1, Book, png, 'Rocket Surgery Made Easy', 'The Do-It-Yourself Guide to Finding and Fixing Usability Problems', ['0321657292','B002UXRGNO'], 'Details an approach to usability testing that anyone can easily apply to their own web site' );
	// Visual Basic
	// XML
	// Other
	AddItem( 16, Book, jpg, 'Adobe Dreamweaver CS5', 'Classroom in a Book', ['0321701771','B003R0KZ00'], 'This has 18 lessons on creating pages using Adobe Dreamweaver CS5, written by Adobe' );
	AddItem( -1, Book, png, 'Fonts &amp; Encodings', '', '0596102429', 'A comprehensive guide to using fonts and typography on the Web, across a variety of operating systems and application software', 0, '059610121X' );
	AddItem(  0, Book, png, 'Google Analytics', '', '0596158009', 'A guide showing how to probe general traffic, marketing, and ecommerce information with Google Analytics tools, and how to supplement the tools with add-ons and external tools when you want to dig deeper' );
	AddItem(  5, Book, jpg, 'Talent Is Not Enough, 2ndEd', 'Business Secrets For Designers', '0321702026', 'This discusses key issues facing designers, from freelancing to managing established design firms' );
	AddItem( -1, Book, png, 'Unicode Explained', '', '059610121X', 'A comprehensive guide to using Unicode', 0, '0596102429' );
	// Software
	AddItem( 99, Software, 'adv/sw_adobe_cs4.png', 'Adobe Creative Suites and Programs', '', 'store_sw.htm#adobe', 'Adobe&rsquo;s leading edge creative tools' );
	AddItem( -1, Software, 'png', 'Adobe Dreamweaver', '', 'B001EUDIZE', 'This is the industry-leading web development tool, enabling users to efficiently design, develop and maintain standards-based websites and applications' );
	AddItem( -1, Software, 'jpg', 'Microsoft Expression Web 3', '', 'B002CNIR7G', 'Microsoft&rsquo;s replacement for FrontPage for the budget-conscious, with better standards support' );
	AddItem( -1, Software, jpg, 'CSE HTML Validator Professional', '', '_2830-1', 'This highly configurable code checker finds HTML, CSS, and Link errors', 1 );
	// Hardware
	AddItem(-99, Hardware, 'adv/pic_kindle3_G.png', 'Amazon Kindle 3', '', 'B002FQJT3Q', 'this innovative eBook reader can put 3500+ books in your hand', 0, 'B002GYWHSQ' );
	AddItemProperty( 'isBorder', false );
	AddItem(-99, Hardware, 'adv/pic_kindle3_W.png', 'Amazon Kindle 3', '', 'B002FQJT3Q', 'this innovative eBook reader can put 3500+ books in your hand', 0, 'B002GYWHSQ' );
	AddItemProperty( 'isBorder', false );
	AddItem(-99, Hardware, png, 'Amazon Kindle DX Graphite', '', 'B002GYWHSQ', 'this innovative large format eBook reader can put 3500+ books in your hand', 0, 'B002FQJT3Q' );
	AddItem(-99, Hardware, png, 'Apple iPad', '', 'B002C7481G', 'Apple&rsquo;s astonishing tablet PC and eBook Reader', 0, '' );
	AddItemProperty( 'isBorder', false );
	AddItem(-99, Hardware, png, 'Sony PRS-300', '', 'B002MSNS4S', 'one of Sony&rsquo;s renowned pocket eBook readers, available in several colors', 0, 'B002MSJNHO B002YC0N4K' );
	AddItem(-99, Hardware, png, 'Sony PRS-600', '', 'B002MSJNHO', 'one of Sony&rsquo;s renowned touch eBook readers, available in several colors', 0, 'B002MSNS4S B002YC0N4K' );
	AddItem(-99, Hardware, png, 'Sony PRS-900', '', 'B002YC0N4K', 'one of Sony&rsquo;s renowned touch eBook readers', 0, 'B002MSJNHO B002MSNS4S' );
	AddItemProperty( 'isBorder', false );


// Define cItem class
function cItem ( priority, type, filename, title, subtitle, code, description, pages, related )
{
	this.upcoming = false;
	if ( (priority == 98) || (priority == 99) )
	  {
		this.priority = 0;			// Priority or weight to assign to the item; 0 => N/A
		this.newitem  = true;		// True => new item
		this.highlight = true;		// True => item to highlight, not to randomly list
		this.new_edition = (priority%2 == 1);	// True => new edition (odd positive priority)
	  }
	else if ( priority >= 0 )
	  {
		if ( priority == 0 )
			this.upcoming = true;
		this.priority = priority*10;
		this.newitem  = true;
		this.highlight = false;
		this.new_edition = (priority%2 == 1);
	  }
	else if ( priority == -99 )
	  {
		this.priority = 0;
		this.newitem  = false;
		this.highlight = false;
		this.new_edition = false;
	  }
	else
	  {
		this.priority = -priority*10;
		this.newitem  = false;
		this.highlight = false;
		this.new_edition = false;
	  }
	this.type		= type;			// Type, i.e. book or software
	this.filename	= filename;		// Filename
	this.title		= title;		// Title
	this.subtitle	= subtitle;		// Subtitle
	this.code	= '';				// Amazon ISBN code, or a URL
	this.kcode	= '';				// Amazon Kindle ISBN code
	this.pcode	= '';				// Amazon PDF ISBN code
	if ( typeof(code) == 'object' )
	  {
		if ( code[0] ) this.code = code[0];
		if ( code[1] ) this.kcode = code[1];
		if ( code[2] ) this.pcode = code[2];
	  }
	else
	  {
		this.code	= code;			// Amazon ISBN code, or a URL
	  }
	this.description = description;	// Description
	this.pages		= pages;		// If book, number of pages; 1 means download only; 2 means CD only
	this.related	= related;		// List of related ISBNs
	this.randhi		= 0;			// High end of prioritized range
	this.isBorder	= true;
}

//	cItem method: generate HTML for description of item; if myTitleOnly is true, generate title only.
cItem.prototype.DescriptionHTML = function ( myTitleOnly )
{
	var sHTML = '';
	if ( arguments.length < 1 )
		myTitleOnly = false;
	var myDescription = this.description;
	if ( myDescription )
	  {
		if ( (this.priority >= 0) && (!myTitleOnly) )
			sHTML += "<strong><i>" + this.ShippingStatus() + "</i></strong>: ";
		sHTML += "<strong><a href='";
		if ( (this.code).charAt(0) == '_' )
		  {	// if the code starts with a '_', it is a RegNow code
			sHTML += "http://www.regnow.com/softsell/nph-softsell.cgi?item=";
			sHTML += (this.code).substr(1);
			sHTML += "&amp;affiliate=15469";
		  }
		else if ( (this.code).indexOf(".") != -1 )
		  {	// if the code contains a dot, it is a URL
			sHTML += this.code;
		  }
		else
		  {	// otherwise the code is an Amazon.com product code
			sHTML += "http://www.amazon.com/exec/obidos/ASIN/";
			sHTML += this.code;
			sHTML += "/browsernews-20";
		  }
		sHTML += "'>" + this.title;
		if ( (this.subtitle != '') && (!myTitleOnly) )
			sHTML += ": " + this.subtitle;
		sHTML += "</a></strong>";
		if ( myTitleOnly )
			return( sHTML );
		sHTML += "<strong> - " + '&#8220;</strong>' + myDescription + "." + '<strong>&#8221;</strong>';
		if ( this.pages )
		  {
			var type = this.type;
			if ( this.pages == 1 )
				sHTML += ' Download only.';
			else if ( this.pages == 2 )
				sHTML += ' CD only.';
			else if ( type == Book )
				sHTML += ' ' + this.pages + ' pages.';
		  }
		if ( this.kcode != '' )
		  {
			sHTML += " <a href='";
			sHTML += "http://www.amazon.com/exec/obidos/ASIN/";
			sHTML += this.kcode;
			sHTML += "/browsernews-20";
			sHTML += "' class='kindle'>For Kindle too</a>.";
		  }
		if ( this.pcode != '' )
		  {
			sHTML += " <a href='";
			sHTML += "http://www.amazon.com/exec/obidos/ASIN/";
			sHTML += this.pcode;
			sHTML += "/browsernews-20";
			sHTML += "' class='pdf'>As PDF too</a>.";
		  }
		if ( this.related != '' )
		  {	// List related items
			var aRelated = (this.related).split(' ');
			var isFirst = true;
			var i, myNextItem;
			for ( i = 0; i < aRelated.length; ++i )
			  {
				if ( aRelated[i] == '' )
					continue;
				myNextItem = myItemFindISBN( aRelated[i] );
				if ( myNextItem < 0 )
					continue;
				if ( isFirst )
					sHTML += ' <strong><i>See also</i></strong>: ';
				else
					sHTML += ' &#8226; ';
				isFirst = false;
				sHTML += Item[myNextItem].DescriptionHTML ( true );
			  }
		  }
	  }
	return( sHTML );
}

//	cItem method: return HTML for link for specified item
cItem.prototype.LinkHTML = function ( alignleft, vspace )
{
	var sHTML = "<a href='";
	if ( (this.code).charAt(0) == '_' )
	  {	// if the code starts with a '_', it is a RegNow code
		sHTML += "http://www.regnow.com/softsell/nph-softsell.cgi?item=";
		sHTML += (this.code).substr(1);
		sHTML += "&amp;affiliate=15469";
	  }
	else if ( (this.code).indexOf(".") != -1 )
	  {	// if the code contains a dot, it is a URL
		sHTML += this.code;
	  }
	else
	  {	// otherwise the code is an Amazon.com product code
		sHTML += "http://www.amazon.com/exec/obidos/ASIN/";
		sHTML += this.code;
		sHTML += "/browsernews-20";
	  }
	sHTML += "' title='" + this.ShippingStatus() + ": ";
	sHTML += this.title;
	sHTML += "'>";
	sHTML += "<img src='";
	if ( (this.filename == 'png') || (this.filename == 'jpg') )
	  {	// If the filename is just png or jpg, it is really adv/(book|sw|mag)_CODE.(png|jpg)
		if ( this.type == Book )
			sHTML += 'adv/book_' + this.code + '.' + this.filename;
		else if ( this.type == Software )
			sHTML += 'adv/sw_' + this.code + '.' + this.filename;
		else if ( this.type == Hardware )
			sHTML += 'adv/hw_' + this.code + '.' + this.filename;
		else if ( this.type == typeMagazine )
			sHTML += 'adv/mag_' + this.code + '.' + this.filename;
		else
			alert( 'Type undefined' );
	  }
	else
	  {	// otherwise the filename is as specified
		sHTML += this.filename;
	  }
	sHTML += "' class='bookad' ";
	if ( vspace )
		sHTML += "vspace='2' ";
	if ( alignleft )
		sHTML += "align='left' ";
	sHTML += "alt='" + this.ShippingStatus() + ": ";
	sHTML += this.title;
	sHTML += "' ";
	if ( this.isBorder == false )
		sHTML += 'style="border:none;" ';
	sHTML += " /></a>";
	return( sHTML );
}

//	cItem method: return status of item ('Now shipping', 'Key resource', etc.)
cItem.prototype.ShippingStatus = function ()
{
	var status = '';
	var type = this.type;
	if ( (type == Book) && (this.new_edition) )
		status += 'New edition, ';
	if ( (this.priority == 0) && (this.newitem == true) )
	  {
		if ( this.highlight )
			status += 'Now shipping';
		else
			status += 'Coming soon';
	  }
	else if ( type == Hardware )
		status += 'Hot product';
	else if ( this.newitem == false )
		status += 'Key resource';
	else if ( type == Book )
		status += 'Hot off the press';
	else if ( type == Software )
		status += 'Hot software';
	else if ( type == Hardware )
		status += 'Hot product';
	return( status );
}


//	Set info for one item
function AddItem ( priority, type, filename, title, subtitle, code, description, pages, related )
{
	if ( arguments.length < 7 )
		alert( 'Error, there should be 7-9 arguments for ' + title );
	if ( arguments.length < 9 )
		related = '';
	var i = Item.length;
	Item[i] = new cItem( priority, type, filename, title, subtitle, code, description, pages, related );
	nPrevItem = i;
}

function AddItemProperty ( name, value )
{
	Item[nPrevItem][name] = value;
}



// Define cItemList class
function cItemList( id )
{
	this.list = new Array();		// Array of ISBNs
	if ( arguments.length > 0 )
		this.id = id;				// id where HTML should be inserted
	else
		this.id = null;
}


//  Return id for a cItemList
cItemList.prototype.getID = function ( id )
{
	if ( this.id != null )
		return( this.id );
	else if ( arguments.length > 0 )
		return( id );
	else
		return( null );
}

//	Insert HTML for ISBNs in a cItemList for an id (default id='ins_ListISBNs')
cItemList.prototype.ListISBNs = function ( id )
{
	if ( arguments.length == 0 )
		id = this.getID( 'ins_ListISBNs' );
	var oInsert = getElement( id );
	if ( oInsert )
	  {
		var sHTML = '';
		for ( var i = 0; i < this.list.length; ++i )
		  {
			sHTML += myItemISBN( this.list[i] );
		  }
		oInsert.innerHTML = sHTML;
	  }
}

//	Generate HTML for random ISBN in a cItemList for an id (default id='ins_RandomISBN')
cItemList.prototype.RandomISBN = function ( id )
{
	if ( arguments.length == 0 )
		id = this.getID( 'ins_RandomISBN' );
	var oInsert = getElement( id );
	if ( oInsert )
	  {
		var nRandom = Math.floor( (this.list.length)*Math.random() );
		var sHTML = myItemISBN( this.list[nRandom] );
		oInsert.innerHTML = sHTML;
	  }
}

//	Set a cItemList to list of ISBNs
cItemList.prototype.SetISBNs = function ( sISBN )
{
	for ( var i = 0; i < arguments.length; ++i )
	  {
		this.list[i] = new Object();
		this.list[i] = arguments[i];
	  }
}

//	Generate HTML for randomly-selected item, where id = 'ins_ItemAd' appears
function myItemAd ()
{
	var oItemAd = getElement( 'ins_ItemAd' );
	if ( oItemAd == null )
		return;
	var sHTML = "<p class='hot'>";
	var oItem = Item[myPickHotItem()];
	sHTML += oItem.LinkHTML( true, false );
	sHTML += oItem.DescriptionHTML();
	sHTML += "</p>";
	sHTML += "<p class='hot' style='clear:left;'>";
	oItem = Item[myPickKeyItem()];
	sHTML += oItem.LinkHTML( true, false );
	sHTML += oItem.DescriptionHTML();
	sHTML += "</p>";
	oItemAd.innerHTML = sHTML;
}

//	Find item given the ISBN (or code)
function myItemFindISBN ( myISBN )
{
	for ( var i = 0; i < Item.length; ++i )
	  {
		if ( Item[i].code == myISBN )
			return(i);
	  }
	if ( String(window.location).indexOf('file:') == 0 )
		alert( 'myItemFindISBN() error: not found, ' + myISBN );
	return( -1 );
}

//	Generate HTML given the ISBN (or code).  If given several codes, randomly picks one.
function myItemISBN ( myISBN )
{
	var nRandom = 0;
	var myItem;
	if ( arguments.length > 1 )
	  {
		nRandom = Math.floor( (arguments.length)*Math.random() );
		myItem = myItemFindISBN( arguments[nRandom] );
	  }
	else
	  {
		myItem = myItemFindISBN( myISBN );
	  }
	if ( myItem < 0 )
		return( '' );
	var oItem = Item[myItem];
	var sHTML = "<p class='hot' style='clear:left;'>";
	sHTML += oItem.LinkHTML( true, true );
	sHTML += oItem.DescriptionHTML( );
	sHTML += "</p>";
	return( sHTML );
}

//	Pick randomly selected key item (where priority is 1*10)
function myPickKeyItem ()
{
	var i;
	var nKeyItems = 0;
	for ( i = 0; i < Item.length; ++i )
	  {	
		if ( Item[i].priority == 10 )
			nKeyItems += 1;
	  }
	var nRandom = Math.floor( nKeyItems*Math.random() );
	nKeyItems = 0;
	for ( i = 0; i < Item.length; ++i )
	  {	
		if ( Item[i].priority == 10 )
		  {
			if ( nKeyItems == nRandom )
				break;
			nKeyItems += 1;
		  }
	  }
	if ( i == Item.length )	i--;	// Protect i from overflow
	return( i );
}

//	Pick randomly selected hot item (where priority > 1*10), applying each item's priority
function myPickHotItem ()
{
	var i;
	var nSumOfPriorities = 0;
	for ( i = 0; i < Item.length; ++i )
	  {	// Sum the priorities of all the hot items
		if ( Item[i].priority > 10 )
			nSumOfPriorities += Item[i].priority;
	  }
	var nNextLo = 0;
	for ( i = 0; i < Item.length; ++i )
	  {	// Set the random high points for each item
		if ( Item[i].priority <= 10 ) continue;	// Skip non-hot items
		Item[i].randhi = nNextLo + Math.floor( Item[i].priority );
		nNextLo = 1 + Item[i].randhi;
	  }
	var nRandom = Math.floor( nNextLo*Math.random() );
	for ( i = 0; i < Item.length; ++i )
	  {	// Find first item's high point that exceeds nRandom; this is item picked
		if ( Item[i].priority <= 10 ) continue;	// Skip non-hot items
		if ( Item[i].randhi >= nRandom )
			break;
	  }
	if ( i == Item.length )	i--;	// Protect i from overflow
	return( i );
}

//	Pick randomly selected item, applying each item's priority
function myPickItem ()
{
	var i;
	var nSumOfPriorities = 0;
	for ( i = 0; i < Item.length; ++i )
	  {	// Sum the priorities of all the items
		nSumOfPriorities += Item[i].priority;
	  }
	var nNextLo = 0;
	for ( i = 0; i < Item.length; ++i )
	  {	// Set the random high points for each item
		if ( Item[i].priority == 0 ) continue;	// Skip zero priority (N/A) items
		Item[i].randhi = nNextLo + Math.floor( Item[i].priority );
		nNextLo = 1 + Item[i].randhi;
	  }
	var nRandom = Math.floor( nNextLo*Math.random() );
	for ( i = 0; i < Item.length; ++i )
	  {	// Find first item's high point that exceeds nRandom; this is item picked
		if ( Item[i].priority == 0 ) continue;	// Skip zero priority (N/A) items
		if ( Item[i].randhi >= nRandom )
			break;
	  }
	if ( i == Item.length )	i--;	// Protect i from overflow
	return( i );
}

//	Generate HTML for all recent books and CD-books
function myBookAds ()
{
	var oInsert = getElement( 'ins_BookAds' );
	if ( oInsert == null )
		return;
	var i, oItem;
	var sHTML = "<p>";
	for ( i = 0; i < Item.length; ++i )
	  {	// Skip items that are not new
		oItem = Item[i];
		if ( (oItem.highlight == false) && ((oItem.priority == 0) || (oItem.newitem == false)) ) continue;
		if ( oItem.type == Book )
			sHTML += oItem.LinkHTML( false, true );
	  }
	sHTML += "</p>";
	oInsert.innerHTML = sHTML;
}

//	Generate HTML for all software
function mySoftwareAds ()
{
	var oInsert = getElement( 'ins_SoftwareAds' );
	if ( oInsert == null )
		return;
	var i, oItem;
	var sHTML = "<p>";
	for ( i = 0; i < Item.length; ++i )
	  {	// Skip items that are not new
		oItem = Item[i];
		if ( (!oItem.highlight) && ((oItem.priority == 0) || (oItem.newitem == false)) ) continue;
		if ( oItem.type == Software )
			sHTML += oItem.LinkHTML( false, true );
	  }
	sHTML += "</p>";
	oInsert.innerHTML = sHTML;
}

//	Generate HTML for all ads
function myTestAds ()
{
	var oInsert = getElement( 'ins_TestAds' );
	if ( oInsert == null )
		return;
	var i, oItem;
	var sHTML = '';
	var sERROR = '';
	for ( i = 0; i < Item.length; ++i )
	  {
		oItem = Item[i];
		sHTML += "<p class='block'>";
		sHTML += oItem.LinkHTML( true, true );
		sHTML += oItem.DescriptionHTML();
		sHTML += "</p>";
		if ( oItem.related != '' )
		  {	// List related items
			var aRelated = (oItem.related).split(' ');
			var j, myNextItem;
			for ( j = 0; j < aRelated.length; ++j )
			  {
				if ( aRelated[j] == '' )
					continue;
				myNextItem = myItemFindISBN( aRelated[j] );
				if ( myNextItem < 0 )
				  {
					sERROR = '' + aRelated[j] + ' ';
					continue;
				  }
			  }
		  }
	  }
	if ( sERROR != '' )
		sHTML = '<p class="error">Reference(s) to missing books: ' + sERROR + '.</p>\n' + sHTML;
	oInsert.innerHTML = sHTML;
}

//	Generate HTML for all upcoming books
function myUpcomingBookAds ()
{
	var oInsert = getElement( 'ins_UpcomingBookAds' );
	if ( oInsert == null )
		return;
	var i, oItem;
	var sHTML = "<p>";
	for ( i = 0; i < Item.length; ++i )
	  {	// Skip items that are not new
		oItem = Item[i];
		if ( oItem.upcoming && (oItem.type == Book) )
			sHTML += oItem.LinkHTML( false, true );
	  }
	sHTML += "</p>";
	oInsert.innerHTML = sHTML;
}

