//	book_ad.js - Javascript to generate ads
//
//	Copyright (C) 2003-2011 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#
	// CSS + HTML + xHTML
	AddItem( -1, Book, jpg, 'Build Your Own Website The Right Way Using HTML & CSS, 3<sup>rd</sup>Ed', '', ['0987090852','B005ESF8DM'], 'Learn to build websites using today&rsquo;s standards' );
	AddItem( 65, Book, jpg, 'Bulletproof Web Design, 3<sup>rd</sup>Ed', 'Improving flexibility and protecting against worst-case scenarios with HTML5 and CSS3', '0321808355', 'Outlines strategies for creating standards-based designs that provide flexibility, readability, and user control; updated for HTML5 and CSS3', 0 );
	AddItem( -1, Book, png, 'Cascading Style Sheets: The Definitive Guide, 3<sup>rd</sup>Ed', '', ['0596527330','B00457X7L8'], '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( -1, Book, jpg, 'Creating a Website, 3<sup>rd</sup>Ed', 'The Missing Manual', ['144930172X','B005011IRS'], 'This gives you tools, techniques, and advice about building a website' );
	AddItem( -1, 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, 2<sup>nd</sup>Ed', '', ['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, 2<sup>nd</sup>Ed', '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, 'CSS3', 'Visual QuickStart Guide', ['0321719638','B0045JKJ7Q'], 'This task-based, visual reference guide teaches beginning and intermediate users CSS 2.1 and 3.0' );
	AddItem( -1, Book, png, 'Dynamic HTML: The Definitive Reference, 3<sup>rd</sup>Ed', '', '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' );
	AddItem( -1, Book, png, 'Head First HTML with CSS &amp; XHTML', '', '059610197X', 'A starter book for those interested in web design' );
	AddItem(  8, Book, jpg, 'Head First HTML 5 Programming', 'Building Web Apps with JavaScript', '1449390544', 'This introduces the key HTML 5 features &#8212; including improved text elements, audio and video tags, geolocation, and the Canvas drawing surface &#8212; and uses concrete examples and exercises to apply and reinforce these concepts.' );
	AddItem(  8, Book, png, 'HTML5: The Missing Manual', '', ['1449302394','B005KOJ3MC'], 'Gets you started with your first HTML5-powered site and shows you how to use HTML5 with JavaScript, CSS, and other familiar tools' );
	AddItem( -1, Book, jpg, 'HTML5 Solutions', 'Essential Techniques for HTML5 Developers', ['1430233869','B005PZ5D6Q'], 'A collection of solutions to all of the most common HTML5 problems' );
	AddItem( 16, Book, jpg, 'Introducing HTML 5, 2<sup>nd</sup>Ed', '', ['0321784421','B005OR9MJY'], 'Learn the elements of HTML 5 which you can use today' );
	AddItem( 33, Book, jpg, 'Pro HTML5 Programming, 2<sup>nd</sup>Ed', '', ['143023864X','B006C9EL9E'], '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, 'Stunning CSS3', 'A Project-Based Guide to the Latest in CSS', ['0321722132','B004JXXL0A'], 'Shows how you can create eye-catching visual effects using CSS3; with practical examples' );
	AddItem( -1, Book, jpg, 'Stylin&rsquo; with CSS', 'A Designer&rsquo;s Guide', ['0321525566','B004USPOJK'], '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( -1, Book, jpg, 'Communicating Design, 2<sup>nd</sup>Ed', 'Developing Web Site Documentation for Design and Planning', ['0321712463','B0045U9W4G'], '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, png, 'Designing the Obvious, 2<sup>nd</sup>Ed', 'A Common Sense Approach to Web Application Design', ['0321749855','B004GEATG6'], 'This details the guiding principles of web-based application design' );
	AddItem( -1, Book, jpg, 'Designing with Web Standards, 3<sup>rd</sup>Ed', '', ['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, 3<sup>rd</sup>Ed', '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, 2<sup>nd</sup>Ed', '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','B00292BEVG'], 'Explains how to create markup and style, exploring multiple techniques for handling situations when building with web standards', 0, '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, 'Canvas Pocket Reference', '', ['1449396801','B004GTLFEQ'], 'A Guide to Using the HTML 5 Canvas Feature' );
	AddItem( -1, Book, png, 'Eloquent JavaScript', 'A Modern Introduction to Programming', ['1593272820','B004OEJNQ0'], 'A guide to JavaScript with a focus on good programming techniques' );
	AddItem( -1, Book, png, 'High Performance JavaScript', '', ['059680279X','B0043D2F62'], '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, 6<sup>th</sup>Ed', '', ['0596805527','B004XQX4K0'], 'Comprehensive coverage of ECMAScript 5 (the new JavaScript standard), the new APIs introduced in HTML5, and language extensions and subsets' );
	AddItem( -1, Book, png, 'JavaScript and DHTML Cookbook, 2<sup>nd</sup>Ed', '', ['0596514085', 'B0028N4WEM','B002AWX8L4'], 'An extensive collection of problems, solutions, and practical examples for JavaScript programmers, applying state-of-the-art standards and best practices' );
	AddItem(  4, Book, png, 'Supercharged JavaScript Graphics', '', ['1449393632','B005EI85IC'], 'Shows how to create rich web applications for PCs and small-screen devices using JavaScript, jQuery, DHTML, and HTML5&rsquo;s Canvas element' );
	// Perl
	AddItem(  0, Book, png, 'Intermediate Perl, 2<sup>nd</sup>Ed', 'Beyond The Basics of Learning Perl', ['1449393098','B0026OR38K'], 'An introduction to intermediate Perl, by the authors of the classic <i>Learning Perl</i>. Updated for Perl 5.14' );
	AddItem( -1, Book, png, 'Learning Perl, 6<sup>th</sup>Ed', 'Making Easy Things Easy and Hard Things Possible', ['1449303587','B005EI865O'], 'Teaches how to program in Perl. Updated for Perl 5.14' );
	AddItem(  0, Book, jpg, 'Programming Perl, 4<sup>th</sup>Ed', 'Unmatched Power for Text Processing and Scripting', '0596004923', 'The Perl bible. Updated for Perl 5.14' );
	// PHP
	// Search Engine Optimization
	AddItem( -1, Book, jpg, 'The Art of SEO', '', ['0596518862','B0043D2E7W'], '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, 2<sup>nd</sup>Ed', '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, 3<sup>rd</sup>Ed', '', ['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( -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( -1, Book, png, 'Google Analytics', '', ['0596158009','B0042FZWGQ'], '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( -1, Book, jpg, 'Talent Is Not Enough, 2<sup>nd</sup>Ed', 'Business Secrets For Designers', ['0321702026','B003Q6CX2S'], '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' );
	// Hardware
	AddItem(-99, Hardware, 'adv/pic_kindle4F.png', 'Amazon Kindle Fire', '', 'B0051VVOB2', 'this innovative tablet can put 6000 books in your hand', 0, 'B005890G8Y B0051QVESA' );
	AddItemProperty( 'isBorder', false );
	AddItem(-99, Hardware, 'adv/pic_kindle4T.png', 'Amazon Kindle Touch', '', 'B005890G8Y', 'this innovative touch eBook reader can put 3500+ books in your hand', 0, 'B0051VVOB2 B0051QVESA' );
	AddItemProperty( 'isBorder', false );
	AddItem(-99, Hardware, 'adv/pic_kindle4.png', 'Amazon Kindle 4', '', 'B0051QVESA', 'this innovative eBook reader can put 3500+ books in your hand', 0, 'B0051VVOB2 B005890G8Y' );
	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, '' );
	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-350', '', 'B003Z97FOW', 'one of Sony&rsquo;s renowned pocket eBook readers, available in several colors', 0, 'B003Z97GKK B0046SHTME' );
	AddItem(-99, Hardware, png, 'Sony PRS-650', '', 'B003Z97GKK', 'one of Sony&rsquo;s renowned touch eBook readers, available in several colors', 0, 'B003Z97FOW B0046SHTME' );
	AddItem(-99, Hardware, png, 'Sony PRS-950', '', 'B0046SHTME', 'one of Sony&rsquo;s renowned touch eBook readers', 0, 'B003Z97GKK B003Z97FOW' );
	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
	{								// Full title
		var ix = title.indexOf( ', ' );
		if ( ix <= 0 )
			this.fulltitle = title + ( (subtitle=='') ? '' : ': ' + subtitle );
		else
			this.fulltitle = title.substring(0,ix) + ( (subtitle=='') ? '' : ': ' + subtitle ) + title.substring(ix);
	}
	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 += "'>";
		if ( !myTitleOnly )
			sHTML += this.fulltitle;
		else
 			sHTML += this.title;
		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'><span class='kindle'>K</span>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 ( isAlignLeft, isVspace, isImage, isNew )
{
	if ( isImage === undefined )
		isImage = true;
	if ( isNew === undefined )
		isNew = true;
	var sTitle = this.fulltitle;
	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 += "'>";
	if ( isImage )
	  {
		sHTML += "<img src='";
		if ( (this.filename == 'png') || (this.filename == 'jpg') )
		  {	// If the filename is just png or jpg, it is really adv/(book|sw)_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
				alert( 'Type undefined' );
		  }
		else
		  {	// otherwise the filename is as specified
			sHTML += this.filename;
		  }
		sHTML += "' class='bookad' ";
		if ( isVspace )
			sHTML += "vspace='2' ";
		if ( isAlignLeft )
			sHTML += "align='left' ";
		sHTML += "alt='" + this.ShippingStatus() + ": ";
		sHTML += this.title;
		sHTML += "' ";
		if ( this.isBorder == false )
			sHTML += 'style="border:none;" ';
		sHTML += " />";
	  }
	else if ( isNew )
	  {
		sHTML += '<span class="new">' + sTitle + '</span>';
	  }
	else
	  {
		sHTML += sTitle;
	  }
	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;
	  }
}

//	Insert HTML for titles of ISBNs in a cItemList for an id (default id='ins_ListTitlesISBNs')
cItemList.prototype.ListTitlesISBNs = function ( id )
{
	if ( arguments.length == 0 )
		id = this.getID( 'ins_ListTitlesISBNs' );
	var o = getElement( id );
	if ( o )
	  {
		var isNew = false;
		var myItem;
		var sHTML = '';
		var sPrefix = '';
		for ( var i = 0; i < this.list.length; ++i )
		  {
			if ( this.list[i] == 'new' )
			  {
				isNew = true;
				continue;
			  }
			myItem = myItemFindISBN( this.list[i] );
			if ( myItem < 0 )
				continue;
			var oItem = Item[myItem];
			sHTML += sPrefix + oItem.LinkHTML( false, false, false, isNew );
			if ( oItem.kcode != '' )
			  {
				sHTML += " <a href='";
				sHTML += "http://www.amazon.com/exec/obidos/ASIN/";
				sHTML += oItem.kcode;
				sHTML += "/browsernews-20";
				sHTML += "'><span class='kindle'>K</span></a>";
			  }
			sPrefix = ' &#9830; ';
			isNew = false;
		  }
		o.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;
}


