


/*
======================================================================
 LIQUID NAILS: Product Catalog JavaScript.
 This is used on the Product Information page.
 Requires: prototype.js
======================================================================
*/

var Product = Class.create();
Product.prototype = {

id : null,
number : null,
name : null,

// Constructor.
//
initialize : function( my_id, my_number, my_name ) {

	this.id = my_id;
	this.number = my_number;
	this.name = my_name;

}, // End initialize().

getId : function() {
	return this.id;
},

getNumber : function() {
	return this.number;
},

getName : function() {
	return this.name;
}

} // End class Product.


var Brand = Class.create();
Brand.prototype = {

id : null,
name : null,
products : null,

// Constructor.
//
initialize : function( my_id, my_name, my_products ) {

	this.id = my_id;
	this.name = my_name;
	this.products = my_products;

}, // End initialize().

getId : function() {
	return this.id;
},

getName : function() {
	return this.name;
},

getProducts : function() {
	return this.products;
}

} // End class Brand.


var ProductCatalog = Class.create();
ProductCatalog.prototype = {

sortBy : 'number',
showCategories : false,
brands : null,

// Constructor.
//
initialize : function( my_brands ) {

	this.brands = my_brands;

	// Sort the brands by name.
	this.brands.sort( this.util_brandSortFunc );

}, // End initialize().

// Sets whether the product categories should display or not.
//
setSortBy : function( str ) {

	this.sortBy = str;

}, // End setShowCategories().

// Sets whether the product categories should display or not.
//
setShowCategories : function( b ) {

	this.showCategories = b;

}, // End setShowCategories().

// Returns an array of drop down list options representing the product catalog.
//
getSelectOptions : function( b ) {

	var retArr = new Array();

	// For each brand...
	this.brands.each(
		function( brand ) {

			// Add the brand list item.
			if ( this.showCategories ) {
				retArr[ retArr.length ] = new Option( brand.getName(), '' );
			} // End if.

			// Create a new group.
			var groupArr = new Array();

			// For each product in the brand...
			brand.getProducts().each(
				function( product ) {

					var label = "";

					// If grouping by categories, indent and bullet the product list items.
					if ( this.showCategories ) {
						label = "\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u2022 ";
					} // End if.

					// Create a label for the product.
					if ( this.sortBy == 'number' ) {
						label += product.getNumber() + " - " + product.getName();
					} else {
						label += product.getName() + ' (' + product.getNumber() + ')';
					} // End if.

					// Save the list item.
					groupArr[ groupArr.length ] = new Option( label, product.getId() );

				}.bind( this ) // End function.
			);

			// Sort group array if needed.
			if ( this.showCategories ) {
				groupArr.sort( this.util_optionSortFunc );
			} // End if.

			// Append the group array to the return array.
			retArr = retArr.concat( groupArr );

		}.bind( this ) // End function.
	)

	// If not grouping by categories... 
	if ( !this.showCategories ) {
		retArr.sort( this.util_optionSortFunc ); // Sort the entire array.
		retArr = this.util_optionRemoveDuplicates( retArr );
	} // End if.

	return retArr;

}, // End getSelectOptions().

util_brandSortFunc : function( a, b ) {

	var a_name = a.getName();
	var b_name = b.getName();

	if ( a_name < b_name ) return -1;
	if ( a_name > b_name ) return 1;
	return 0;

}, // End util_brandSortFunc().

util_optionSortFunc : function( a, b ) {

	if ( a.text < b.text ) return -1;
	if ( a.text > b.text ) return 1;
	return 0;

}, // End util_optionSortFunc().

// Removes all duplicate products from the options list.
// The specified array must already be sorted.
//
util_optionRemoveDuplicates : function( arr ) {

	for ( var i = arr.length - 1; i > 0; i-- ) {
		if ( arr[ i ].text == arr[ i - 1 ].text ) arr.splice( i, 1 );
	} // End for.

	return arr;
}

} // End class ProductCatalog.


var productCatalog = new ProductCatalog(
new Array(
  new Brand( 1, 'Caulks, Sealants & Weatherproofing', new Array(
    new Product( 1, 'AC-138', 'All Purpose Adhesive Caulk -  Bright White' ),
    new Product( 3, 'DR-807', 'Asphalt Repair ' ),
    new Product( 4, 'CS-144', 'Clear Seal All Purpose Sealant ' ),
    new Product( 6, 'CR-805', 'Concrete Repair' ),
    new Product( 7, 'LRS-280', 'Energy Saving Multi-Purpose Caulk ' ),
    new Product( 11, 'LC-135', 'Painter\'s Caulk' ),
    new Product( 12, 'RR-808', 'Roof Repair' ),
    new Product( 13, 'LS-205', 'Silicone Premium Universal Sealant (Clear)' ),
    new Product( 68, 'LS-205', 'Silicone Premium Universal Sealant (White)' ),
    new Product( 15, 'TC-10', 'Tub & Tile Acrylic Latex Caulk' ),
    new Product( 17, 'LC-130', 'Window & Door Supercaulk Clear' ),
    new Product( 51, 'LC-130', 'Window & Door Supercaulk Colored' ),
    new Product( 52, 'LC-130', 'Window & Door Supercaulk Gray' ),
    new Product( 53, 'LC-130', 'Window & Door Supercaulk White' ),
    new Product( 18, 'GC-17', 'Window Glazing' )
  )),
  new Brand( 3, 'Construction Adhesives', new Array(
    new Product( 32, 'LN-975', 'Clear Adhesive' ),
    new Product( 24, 'CAP-95', 'Contact Cement, Latex Gel' ),
    new Product( 25, 'CB-10/CBP-10', 'Cove Base & Stair Tread Adhesive (low-VOC)' ),
    new Product( 81, 'DWP-24', 'Drywall Adhesive' ),
    new Product( 66, 'FRP-300', 'Fiberglass Reinforced Plastic Panel Adhesive' ),
    new Product( 26, 'FRP-310', 'Fiberglass Reinforced Plastic Panel Adhesive (low-VOC)' ),
    new Product( 36, 'LN-901/LNP-901', 'Heavy Duty Construction Adhesive' ),
    new Product( 35, 'LN-903/LNP-903', 'Heavy Duty Construction Adhesive (low-VOC)' ),
    new Product( 82, 'LN-704/LNP-704', 'Interior Projects Adhesive (low-VOC)' ),
    new Product( 42, 'LN-601/LNP-601', 'Projects Construction Adhesive' ),
    new Product( 60, 'LN-701/LNP-701', 'Projects Construction Adhesive (low-VOC)' ),
    new Product( 37, 'LN-905', 'Landscape Block, Stone & Timber Adhesive (low-VOC)' ),
    new Product( 38, 'LN-933', 'Marble & Granite and Solid Surface Materials Adhesive (low-VOC)' ),
    new Product( 39, 'LN-930', 'Mirror Adhesive' ),
    new Product( 83, 'LN-730', 'Mirror Adhesive (low-VOC)' ),
    new Product( 65, 'LN-606', 'Paneling & Molding' ),
    new Product( 40, 'LN-910', 'Paneling & Molding Adhesive' ),
    new Product( 61, 'LN-710', 'Paneling & Molding Adhesive (low-VOC)' ),
    new Product( 54, 'LN-950', 'Polyurethane Construction Adhesive (low-VOC)' ),
    new Product( 28, 'LN-603/LNP-603', 'Projects & Construction Adhesive, Trowelable' ),
    new Product( 34, 'LN-604', 'Projects & Foamboard Adhesive' ),
    new Product( 45, 'LN-602/LNP-602', 'Subfloor & Deck Construction Adhesive' ),
    new Product( 44, 'LN-902/LNP-902', 'Subfloor & Deck Construction Adhesive (low-VOC)' ),
    new Product( 46, 'LN-915', 'Tub Surround & Shower Walls Adhesive' ),
    new Product( 62, 'LN-715', 'Tub Surround & Shower Walls Adhesive (low-VOC)' ),
    new Product( 55, 'LN-990', 'Ultra Quik Grip' ),
    new Product( 56, 'LN-940', 'Wood Projects Construction Adhesive' ),
    new Product( 57, 'LN-740', 'Wood Projects Construction Adhesive (low-VOC)' )
  )),
  new Brand( 4, 'Household Adhesives', new Array(
    new Product( 74, 'LN-207', 'Clear Small Projects Silicone Adhesive' ),
    new Product( 78, 'LN-201', 'Home Projects Repair Adhesive' ),
    new Product( 76, 'LN-203', 'Metal Projects Repair Adhesive' ),
    new Product( 85, 'PG-00', 'Perfect Glue' ),
    new Product( 77, 'LN-202', 'Small Ceramic Projects Repair Adhesive' ),
    new Product( 47, 'LN-600', 'Small Projects & Repairs Adhesive' ),
    new Product( 79, 'LN-700', 'Small Projects Repair Adhesive' ),
    new Product( 75, 'LN-206', 'Wood Projects Repair Adhesive' )
  ))
));
