
searchTerms = function() {
    var qs = location.search.split( '&' );
	if ( qs != null ) {
	    if ( qs.length > 0 ) {
	        qs.shift();
	    }
	}
	var search = qs.join( '&' );
	if ( search == null ) search = '';
	if ( search != '' ) search = '&' + search;
	return search;
}
loginLink_html = function() {    
	return '<a href=' + siteSettings.srLoginPath + '?openDocument' + searchTerms() + '">Login</a>';		
}
loginLink_Elem = function() {
    
	var a = document.createElement( 'A' );
	a.border = 0;
	a.href =siteSettings.srLoginPath + '?openDocument' + searchTerms();
	a.appendChild( document.createTextNode( 'Login' ) );
	
	return a;		
}
makeUnitPrice = function( price ) {
	return price == null ? '' : '$' + CommaFormatted( Number( price ).toFixed(2) );
}
sanitise = function( cleanThis ) {
	return cleanThis.replace(/\s+/g,'_').replace(/-/g,'_');
};
adviseNoResults = function() {
	if ( resDisplay != null ) {
		var row = resDisplay.createRow();
		if ( row != null ) {
			var td = row.insertCell( -1 );
			td.colSpan = 15; 
			td.className = 'noResults';
			
			var span = document.createElement( 'span' );
			td.appendChild( span );
			span.appendChild( document.createTextNode( 'Sorry, no results were found for your search. Please try to refine your search. If you still cannot find what you are looking for please contact the Customer Services Team or fill out the online enquiry form or email us. Contact details can be found on our Contact page or at the bottom of this page. For further assistance try the Search Help link below.' ) ); 
			span.appendChild( document.createElement( 'br' ) ); 
			
			var a = document.createElement( 'a' );
			a.border = 0;
			//a.href = 'javascript:void(0)';
			a.onmouseover= moverFunc;
			a.onmouseout= moutFunc;
			a.style.color = 'blue';
			if ( a.addEventListener ) {
				a.addEventListener( "click", helpSearch, true );
			} else {
				a.attachEvent( "onclick", helpSearch );
			}	
			a.appendChild( document.createTextNode( 'Search Help' ) );
			
			span.appendChild( a );
		}
	}
};
/*
*	RULES
*
*/
Rules = {
	SHIPMENT_MAX_THRESHOLD: 4838400000,		//number of milliseconds in 8 weeks (assumes no dst changeover)
	LEAD_MAX_THRESHOLD: 42,					//days
	LEAD_BUFFER: 2,							//weeks
	DISPLAY_ODD_ROWS: 'FFFFFF',
	DISPLAY_EVEN_ROWS: 'EBF3F5',
	leadTimeRule: function( days ) {
		if ( days == null ) return;
		
		var weeks = Number( days ) == 0 ? 1 : Math.ceil( Number( days ) / 7 );
		 
		return String( weeks ) + ' - ' + String( weeks + 2 ) + ' weeks'
	} 
};
/*
*	DISPLAY HELP
*
*/
PanelManager = function () {
	this.panel = null;
	this.content = {
		ProductLineCode: null,
		DescLong: null,
		alt: null,
		Brand: null,
		BrandCode: null,
		extendDescLong: null,
		lead: null,
		shipments: null,
		UOM: null,
		unit: null,
		Available: null,
		hazMat: null
	}
	this.context = null;
	this.tt1 = null;
	this.tt2 = null;
	this.showDetail = function( sID ) {
		if ( sID == null ) return;	       
	    if ( this.panel == null ) return;	    
	    if ( prodSet == null ) return;
	    	 
    	    
	    if ( this.content.ProductLineCode == null ) return;
		if ( this.content.DescLong == null ) return;
		if ( this.content.alt == null ) return;
		if ( this.content.Brand == null ) return;
		if ( this.content.BrandCode == null ) return;
		if ( this.content.extendDescLong == null ) return;
		if ( this.content.lead == null ) return;
		if ( this.content.shipments == null ) return;
		if ( this.content.UOM == null ) return;
		if ( this.content.unit == null ) return;
		if ( this.content.Available == null ) return;
		if ( this.content.hazMat == null ) return;
	    
	    var product = eval( 'prodSet.byName.prod_' + sID );
	    if ( product == null ) return;
	    
	    var data = product.data;
	    if ( data == null ) return;
	    
	    this.context = data;
	    
	    this.panel.setHeader( 'Product Details' + ( data.ProductLineCode != null ? ' - ' + data.ProductLineCode : '' ) );
	    this.content.ProductLineCode.innerHTML = ( data.ProductLineCode != null ? data.ProductLineCode : '' );
		this.content.DescLong.innerHTML = ( data.DescLong != null ? data.DescLong : '' );
		this.content.alt.innerHTML = ( data.alt != null ? data.alt : '' );
		this.content.Brand.innerHTML = ( data.Brand != null ? data.Brand : '' );
		this.content.BrandCode.innerHTML = ( data.BrandCode != null ? data.BrandCode : '' );
		this.content.extendDescLong.innerHTML = ( data.extendDescLong != null ? data.extendDescLong : '' );
		this.content.Available.innerHTML = loginLink_html();
		this.content.UOM.innerHTML = ( data.UOM != null ? data.UOM : '' );
		this.content.unit.innerHTML = loginLink_html();
		this.content.hazMat.innerHTML = ( data.hazMat != null ? ( data.hazMat ? '<span style="font-weight:bold; color: red;">YES</span>' : 'No' ) : 'No' );
		
		this.content.lead.innerHTML = loginLink_html();
		this.content.shipments.innerHTML = loginLink_html();
	    
    	this.panel.show();     
	};	
		
	this.init = function() {
		var details = {
	        panel: null,
	        name: "details",
	        header: "Product Details",
	        visible: false,
	        modal: true,
			src: document.getElementById( 'detailPanel' )
		}
		makePanel( details );
		this.panel = details.panel;
		details.src.style.display = '';
				
		this.content.ProductLineCode = document.getElementById( 'detail_catNo' );
		this.content.DescLong = document.getElementById( 'detail_desc' ); 
		this.content.alt = document.getElementById( 'detail_alt' ); 
		this.content.Brand = document.getElementById( 'detail_brand' ); 
		this.content.BrandCode = document.getElementById( 'detail_brandCode' ); 
		this.content.extendDescLong = document.getElementById( 'detail_extendDesc' );  
		this.content.lead = document.getElementById( 'detail_lead' );  
		this.content.shipments = document.getElementById( 'detail_shipments' ); 
		this.content.Available = document.getElementById( 'detail_avail' );
		this.content.UOM = document.getElementById( 'detail_uom' );
		this.content.unit = document.getElementById( 'detail_unit' );
		this.content.hazMat = document.getElementById( 'detail_hazmat' );
	};
}
panelMan = null;
initPanelMan = function() {
	panelMan = new PanelManager();
	panelMan.init();
	
}
ResultsNavigator = function() {
	this.navMap = {
		start: 0,
		end: 0,
		total: 0
	};
	
	this.start = {
		a: null,
		tt: null
	};
	this.goStart = function() {
		doSearch(1);
	};
	
	this.previous = {
		a: null,
		tt: null
	};
	this.goPrevious = function() {
		if ( this.navMap != null ) {
			if ( this.navMap.start > 1 ) {
				var newStart = ( 2 * this.navMap.start ) - this.navMap.end - 1; 
				doSearch( newStart > 1 ? newStart : 1 );
			}
		}
	};
	
	this.next = {
		a: null,
		tt: null
	};
	this.goNext = function() {
		if ( this.navMap != null ) {
			if ( this.navMap.end < this.navMap.total ) doSearch( this.navMap.end + 1 );
		}
	};
	
	this.end = {
		a: null,
		tt: null
	};
	this.goEnd = function() {
		if ( this.navMap != null ) {
			var newStart = this.navMap.total - ( this.navMap.end - ( this.navMap.start - 1 ) ) + 1; 
			doSearch( newStart > 1 ? newStart : 1 );
		}
	};
		
	this.init = function() {
				
		if ( this.start.a == null ) this.start.a = document.getElementById( 'resultsNavStart' );
		this.start.a.navMap = this.navMap;
		if ( this.start.tt == null ) this.start.tt = new YAHOO.widget.Tooltip("tt_" + this.start.a.id, { 
								context: this.start.a.id, text:"Go to Start", preventoverlap: false, zIndex: 100 });
										
		if ( this.previous.a == null ) this.previous.a = document.getElementById( 'resultsNavPrevious' );
		this.previous.a.navMap = this.navMap;
		if ( this.previous.tt == null ) this.previous.tt = new YAHOO.widget.Tooltip("tt_" + this.previous.a.id, { 
								context: this.previous.a.id, text:"Go to Previous", preventoverlap: false, zIndex: 100 });
								
		if ( this.next.a == null ) this.next.a = document.getElementById( 'resultsNavNext' );
		this.next.a.navMap = this.navMap;
		if ( this.next.tt == null ) this.next.tt = new YAHOO.widget.Tooltip("tt_" + this.next.a.id, { 
								context: this.next.a.id, text:"Go to Next", preventoverlap: false, zIndex: 100 });
								
		if ( this.end.a == null ) this.end.a = document.getElementById( 'resultsNavEnd' );
		this.end.a.navMap = this.navMap;
		if ( this.end.tt == null ) this.end.tt = new YAHOO.widget.Tooltip("tt_" + this.end.a.id, { 
								context: this.end.a.id, text:"Go to End", preventoverlap: false, zIndex: 100 });
								
								
		if ( this.start.a.addEventListener ) {
			this.start.a.addEventListener( 'click', this.goStart, false );
			this.previous.a.addEventListener( 'click', this.goPrevious, false );
			this.next.a.addEventListener( 'click', this.goNext, false );
			this.end.a.addEventListener( 'click', this.goEnd, false );
		} else {
			this.start.a.attachEvent( 'onclick', goStart );
			this.previous.a.attachEvent( 'onclick', goPrevious );
			this.next.a.attachEvent( 'onclick', goNext );
			this.end.a.attachEvent( 'onclick', goEnd );
		}	
	};
}
//flamin IE!
goStart = function() {
	if ( resultsNav != null ) resultsNav.goStart();
}
goPrevious = function() {
	if ( resultsNav != null ) resultsNav.goPrevious();
}
goNext = function() {
	if ( resultsNav != null ) resultsNav.goNext();
}
goEnd = function() {
	if ( resultsNav != null ) resultsNav.goEnd();
}
resultsNav = null;
initResultsNav = function() {
	resultsNav = new ResultsNavigator();
	resultsNav.init();
}
reCap = function() {
	if ( resultsNav.navMap != null ) {
		doSearch( resultsNav.navMap.start );
	} else {
		doSearch(1);
	}
};
ResultsSpan = function( spanID ) {
	this.val = 0;
	this.spanID = spanID;
	this.span = null;
	
	this.inc = function() {
		++this.val;
		this.update();
	};
	
	this.dec = function() {
		--this.val;
		this.update();
	};
	
	this.set = function( val ) {
		this.val = val;
		this.update();
	}
	
	this.update = function() {
		if( ( this.span != null ) && ( this.val != null )) this.span.innerHTML = this.val;		
	};
	
	this.init = function() {
		this.span = document.getElementById( this.spanID );
		this.update();
	};
}
ResultsDisplay = function() {
	this.SortModes = {
		BY_BRAND: 1,
		BY_PRICE: 2,
		BY_Available: 3
	};
	this.sortMode = null;
	this.setMode = function ( mode ) { this.sortMode = mode; };
	this.getMode = function() { return this.sortMode; };
	
	this.resultsTable = null;
	this.getResTable = function() { return this.resultsTable };
	
	this.productRows = null;	
	this.colouriseRows = function( ) {
		if( this.productRows != null ) {
			if ( this.productRows.length != null ) {
				var ctr = 0;
				for ( var i = 0; i < this.productRows.length; ++i ) {
					var product = this.productRows[i];					
					if ( product != null ) {
						if ( product.visible() ) product.assignRowBackground( ( ++ctr % 2 != 0 ? Rules.DISPLAY_ODD_ROWS : Rules.DISPLAY_EVEN_ROWS ) );
					}
				}
			}
		}
	}
	
	this.createRow = function( at ) {
		return ( this.resultsTable != null ? this.resultsTable.insertRow( at != null ? at : -1 ) : null ); 
	};
	
	this.resultsStart = null;	
	this.resultsEnd = null;	
	this.resultsTotal = null;
	
	
	this.init = function() {
		this.resultsTable = document.getElementById( 'resTable' );
		
		this.resultsStart = new ResultsSpan( 'resultsStart' );
		this.resultsStart.init();
		
		this.resultsEnd = new ResultsSpan( 'resultsEnd' );
		this.resultsEnd.init();
		
		this.resultsTotal = new ResultsSpan( 'resultsTotal' );
		this.resultsTotal.init();
				
	};
}
resDisplay = null;
initResultsDisplay = function() {
	if ( resDisplay == null ) resDisplay = new ResultsDisplay();
	resDisplay.init();  
}
/*
*	BrandS
*
*/
BrandDisplay = function( ) {
	this.option = null;
	this.brand = null;
	this.rows = {
		titleRow: null,
		titleSpan: null,
		spacerRow: null,
		showSpacer: false
	};		//only used if resDisplay.getMode() ==  resDisplay.SortModes.BY_Brand
	
		
	this.updateBrandTitle = function() {
		if ( this.option == null ) return;
		if ( this.brand == null ) return;
				
				
		var numToShow = 
			( this.brand.products != null ? ( this.brand.products.length != null ? this.brand.products.length : 0 ) : 0 )
			-
			( this.brand.removedProducts != null ? ( this.brand.removedProducts.length != null ? this.brand.removedProducts.length : 0 ) : 0 );
				
		var label = this.brand.title + ' (' + numToShow;
						
		if ( this.brand.count != null ) {
			if ( !isNaN( this.brand.count)  ) {
				this.option.text = this.brand.title + ' (' + this.brand.count + ')';
				label += ' of ' + this.brand.count;		
			} else {
				this.option.text = label + ')';
			}
		} else {
			this.option.text = label + ')';
		}
		label += ')';
		if ( this.rows.titleSpan != null ) {
			this.rows.titleSpan.innerHTML = label;
			if ( numToShow != 0 ) {
				//hide the spacer if it exists
				this.rows.showSpacer = false;
				if ( this.rows.spacerRow != null ) {
					this.rows.spacerRow.style.display = 'none';
				}
			} else {
				//ensure that the spacer is in place
				this.rows.showSpacer = true;
				if ( this.rows.spacerRow == null ) {				
					var row = resTable.insertRow( this.rows.titleRow.rowIndex + 1  );
					row.className = 'resultsSpacer';
					
					var td = row.insertCell( -1 );
					td.colSpan = 15;
					
					this.rows.spacerRow = row;
				}
				//show spacer if this Brand is visible
				if ( this.visible() ) this.rows.spacerRow.style.display = ''; 
			}
		} 
	}
		
	this.visible = function() {
		return( this.rows.titleRow != null ? this.rows.titleRow.style.display == '' : false );
	};
	
	this.hide = function() {
		if ( this.rows.titleRow != null ) {
			this.rows.titleRow.style.display = 'none';				
		}	
		if ( this.rows.spacerRow != null ) {
			this.rows.spacerRow.style.display = 'none';				
		}	
	};
	
	this.show = function() {
		if ( this.rows.titleRow != null ) {
			this.rows.titleRow.style.display = '';				
		}	
		if ( this.rows.spacerRow != null ) {
			if ( this.rows.showSpacer ) this.rows.spacerRow.style.display = '';				
		}	
	};
		
	this.init = function( select, brand ){
		if ( select == null ) return;
		if ( brand == null ) return;
		if ( brand.title == null ) return;
		
		this.brand = brand;
		brand.display = this;
		
		this.option = document.createElement( 'option' );		
		this.updateBrandTitle();
		this.option.text = brand.title;
		this.option.value = brand.key;
		this.option.brandDisplay = this;
		try { select.add( this.option, null ); } catch (e) { select.add( this.option ); }
		
		if ( this.rows.titleRow == null ) {
			if ( resDisplay.getMode() == resDisplay.SortModes.BY_BRAND ) {
				if ( resDisplay == null ) return;
				
				var row = resDisplay.createRow();				
				row.className = 'brandRow';
					
				var td = row.insertCell( -1 );
				td.className = 'dragCol';
				
				td = row.insertCell( -1 );
				td.className = 'resCol0';
				
				td = row.insertCell( -1 );
				td.colSpan = 13;
				
				var span = document.createElement( 'span' );
				span.innerHTML = brand.title;
				td.appendChild( span );
				
				this.rows.titleRow = row;
				this.rows.titleSpan = span;
			}
		}
	};
	
}
BrandSetDisplay = function( ) {
	this.filterBox = null;
	this.options = {
		byName: { },
		byIndex: new Array()
	};		
	
	this.updateBrandTitle = function( brand ) {
		if ( brand == null ) return;
		var option = eval( 'this.options.byName.brand_' + brand.key + ';' ); 			
		if ( option == null ) return;		
		option.updateBrandTitle();		
	}
	
	this.addBrand = function( brand ) {
		if ( brand != null ) {
			if ( brand.title != null ) {				
				if ( this.filterBox != null ) {
					
					if ( eval( 'this.options.byName.brand_' + brand.key ) != null ) return;
				
					var option = new BrandDisplay();
					option.init( this.filterBox, brand );
					option.updateBrandTitle();
					option.hide();
					
					eval( 'this.options.byName.brand_' + brand.key + ' = option;' )
					this.options.byIndex.push( option );
				}		
			}
		}
	};
	
	this.onFilterChange = function () {
		doSearch();		
	};
	
	this.resort = function() {
		if ( this.filterBox == null ) return;
		try {			
			Array.prototype.sort.call(
					this.filterBox.options,
					function(a,b){
						return a.text < b.text ? -1 : a.text > b.text ? 1 : 0;
					}
			);
		} catch (e) {
			try {							
				var optionsToSort = new Array();
				var optionsValues = new Array();	
					
				for ( var i = 0; i < this.filterBox.options.length; ++i ) {
					var option = this.filterBox.options[i];
					if ( option != null ) {
						if( option.value != null ) {
							if( option.value != '' ) {
								optionsToSort.push( { index: i, opt: option } );
								optionsValues.push( option.text );
							}
						}
					}
				}
								
				for ( var i = optionsToSort.length; i > 0 ; --i ) {
					var option = optionsToSort[i-1];
					if ( option != null ) {
						var removed = this.filterBox.remove( option.index );
					}
				}
				
				optionsValues.sort();
				for ( var i = 0; i < optionsValues.length; ++i ) {					
					for ( var j = 0; j < optionsToSort.length; ++j ) {
						var option = optionsToSort[j].opt;					
						if ( option != null ) {
							if ( option.text == optionsValues[i] ) {
								try{ this.filterBox.add( option, null ); } catch (ie) { this.filterBox.add( option ); }
								break;
							}
						}					
					}
				}
				
			} catch (ee) {
				alert( 'BrandSetDisplay.resort(): ' + ee + '\nhandling: ' + e );
			} 			
		}
	}
	
	this.init = function(){		
		this.filterBox = document.getElementById( 'resultBrands' );
		this.filterBox.brandSetDisplay = this;
		this.filterBox.onchange = function() {
			if ( this.brandSetDisplay != null ) {
				this.brandSetDisplay.onFilterChange();
			}
		};
	};
	
}
Brand = function( BrandData ) {
	this.title = BrandData.Brand;
	this.key = BrandData.ProdGrp;
	this.count = BrandData.Count;
	this.hidden = false;
	this.display = false;		//instance of BrandDisplay
	
	this.products = new Array();
	this.addProduct = function( prod ) {	
		if ( prod != null ) {
			this.products.push( prod );
			this.display.show();
		}
	};
	this.removedProducts = new Array();
	this.removeProduct = function( prod ) {	
		if ( prod != null ) {
			this.removedProducts.push( prod );
		}
	}
	this.restoreRemoved = function() {
		if ( ! this.hidden ) {		
			for ( var i = 0; i < this.removedProducts.length; ++i ) {
				if ( this.removedProducts[i] != null ) this.removedProducts[i].show();
			}			
		}
		this.removedProducts.length = 0;
	};
	
	this.hideProducts = function() {
		for ( var i = 0; i < this.products.length; ++i ) {
			if ( this.products[i] != null ) this.products[i].hide();
		}
		if ( this.display != null ) this.display.hide();
		this.hidden = true;
	};
	
	this.showProducts = function() {
		for ( var i = 0; i < this.products.length; ++i ) {
			if ( this.products[i] != null ) this.products[i].show();
		}
		if ( this.display != null ) this.display.show();
		this.hidden = false;
	};
}
BrandSet = function() {
	this.byName = { }
	this.byIndex = new Array();
	this.display = null;
	
	this.addBrand = function( brandData ) {
		try{
			if ( brandData == null ) return;
			if ( brandData.Brand == null ) return;
					
			if ( eval( 'this.byName.brand_' + brandData.ProdGrp ) != null ) return;
			
			var brand = new Brand( brandData ); 
			eval( 'this.byName.brand_' + brand.key + ' = brand;' );
			this.byIndex.push( brand );
			
			if ( this.display == null ) {
				this.display = new BrandSetDisplay();
				this.display.init();
			}
			this.display.addBrand( brand );
		} catch (e) {
			alert( 'BrandSet.addBrand(): ' + e );
		}		
	};	
	
	this.addProduct = function( prod ) {
		try{
			if ( prod == null ) return;
			if ( prod.brand == null ) return;
					
			var brand = eval( 'this.byName.brand_' + prod.brand()+ ';');
			if ( brand != null ) {
				brand.addProduct( prod );
				if ( this.display != null ) this.display.updateBrandTitle( brand );
			}
			
		} catch (e) {
			alert( 'BrandSet.addProduct(): ' + e );
		}	
	}
	
	
	this.removeProduct = function( prod ) {	
		if ( prod != null ) {
			var brand = eval( 'this.byName.brand_' + prod.brand() + ';');
			if ( brand != null ) {
				brand.removeProduct( prod );
				if ( this.display != null ) this.display.updateBrandTitle( brand );
			}
		}
	}
	
	this.restoreRemoved = function() {
		for ( var i = 0; i < this.byIndex.length; ++i ) {
			var brand = this.byIndex[i];
			if ( brand != null ) {
				brand.restoreRemoved( );
				if ( this.display != null ) this.display.updateBrandTitle( brand );
			}
		}
	};
	
	this.resort = function() {
		if ( this.display != null ) this.display.resort();
	}
	
}
/*
*	PRODUCTS
*
*/
ProductData = function( ) {
	try {
		
		this.copyItem = function( copyFrom, itemName ) {
			//expansion room here for type safety & range validation
			if ( itemName != '' ) eval( 'this.' + itemName + ' = ( copyFrom != null ? ( copyFrom.' + itemName + ' != null ? copyFrom.' + itemName + ' : null ) : null );' );
		};
		
				
		this.init = function( prod ) {
			this.copyItem( prod, 'ProductLineHostID' );
			this.copyItem( prod, 'ProductLineCode' );
			this.copyItem( prod, 'Brand' );
			this.copyItem( prod, 'PreSuppCode' );
			this.BrandCode = this.PreSuppCode;
			this.copyItem( prod, 'ProdGrp' );
			this.copyItem( prod, 'DescLong' );
			this.copyItem( prod, 'alt' );
			this.copyItem( prod, 'UOM' );
			
			this.copyItem( prod, 'Available' );
			if ( this.Available != null ) {
				if ( isNaN( this.Available ) ) {
					this.Available = 0;
				} else {
					if ( Number( this.Available ) > 0 ) {											
					} else {
						this.Available = 0;
					}
				}
			} else {
				this.Available = 0;
			}
			
			this.copyItem( prod, 'liveproduct' );
			if ( this.liveproduct != null ) {
				if( this.liveproduct.toString().toLowerCase() == 'true' ) {
					this.liveproduct = true;
				} else {
					this.liveproduct = false;
				} 
			} else {
				this.liveproduct = false;
			}
			
			this.copyItem( prod, 'DisplayPOA' );
			this.copyItem( prod, 'ValList' );
			this.copyItem( prod, 'PreLTime1' );
			this.copyItem( prod, 'HSNO' );
			this.hazMat = false;
			if ( this.HSNO != null ) {
				eval( 'this.hazMat = ' + String( this.HSNO ).toLowerCase() ); 	
			}
			this.copyItem( prod, 'numInCart' );	
			
			this.copyItem( prod, 'shipments' );	
			
		}
			
	} catch ( e ) {
	}
}
//------------
ProductDisplay = function( ) {
	this.row = null;			//TR entry	
	
	//Details popup "dialog"				
	this.detailsPanel = null;	//DIV?
	this.createDetailsPanel = function() {
	};
	//Drag handle column	
	this.dragHandle = {
		td: null		
	};	
	this.createDragHandle = function() {
		if ( this.row == null ) return;
		
		if ( this.dragHandle.td == null ) this.dragHandle.td = this.row.insertCell( - 1 );
		this.dragHandle.td.className = 'dragCol';
	};
	
	//flags column
	this.flags = {
		td1: null,
		hazMat: {
			flag: false,
			display: null,
			tt: null
		},
		td2: null,
		liveProd: {
			flag: false,
			display: null,
			tt: null
		}		
	};
	this.createFlags = function( flagData ) {
		if ( this.row == null ) return;
		
		if ( this.flags.td1 == null ) this.flags.td1 = this.row.insertCell( - 1 );
		this.flags.td1.className = 'resCol0';
		
		if ( flagData != null ) {
			this.flags.hazMat.flag = ( flagData.hazMat != null ? flagData.hazMat : false );
		
			if ( this.flags.hazMat.flag ) {
				if ( this.flags.hazMat.display == null ) {
					if ( flagData.ProductLineHostID != null ) {
						var img = document.createElement( 'img' );
						img.src = '/icons/vwicn091.gif';
						img.id = 'haz_' + flagData.ProductLineHostID;
						img.border = '0';
						this.flags.td1.appendChild( img );
						this.flags.hazMat.display = img;
						this.flags.hazMat.tt = new YAHOO.widget.Tooltip("tt_" + img.id, { 
									context: img.id, 	
									text:"Hazardous Goods", 
									preventoverlap: false, 
									zIndex: 100 }
						);
					}	
				}
			}
		}	
		
		if ( this.flags.td2 == null ) this.flags.td2 = this.row.insertCell( - 1 );
		this.flags.td2.className = 'resCol13';
		
		if ( flagData != null ) {
			this.flags.liveProd.flag = ( flagData.liveproduct != null ? flagData.liveproduct : false );
		
			if ( this.flags.liveProd.flag ) {
				if ( this.flags.liveProd.display == null ) {
					if ( flagData.ProductLineHostID != null ) {
						var img = document.createElement( 'img' );
						img.src = '/icons/vwicn148.gif';
						img.id = 'live_' + flagData.ProductLineHostID;
						img.border = '0';
						this.flags.td2.appendChild( img );
						this.flags.liveProd.display = img;
						this.flags.liveProd.tt = new YAHOO.widget.Tooltip("tt_" + img.id, { 
									context: img.id, 	
									text:"Customers have bought this product before", 
									preventoverlap: false, 
									zIndex: 100 }
						);
					}	
				}
			}
		}		
	};
	
	//Catalogue # & DescLongription column
	this.catDescLong = {
		td1: null,
		td2: null,
		prodCode: {
			code: '',
			display: null,
			panel: null
		},
		DescLongription: null
	};
	this.createCatDescLong = function( catDescLongData ) {
		try {
			if ( this.row == null ) return;
			
			if ( this.catDescLong.td1 == null ) this.catDescLong.td1 = this.row.insertCell( - 1 );
			this.catDescLong.td1.className = 'resCol1';
			
			if ( catDescLongData != null ) {
				this.catDescLong.prodCode.code = ( catDescLongData.ProductLineCode != null ? catDescLongData.ProductLineCode : '' );
				
				if ( this.catDescLong.prodCode.display == null ) {
					var a = document.createElement( 'a' );
					a.href = 'javascript:void(0)';
					//a.innerHTML = catDescLongData.ProductLineCode;		
						a.appendChild( document.createTextNode( catDescLongData.ProductLineCode ) )
					//a.setAttribute( 'onclick', "panelMan.showDetail( '" + catDescLongData.ProductLineCode + "' );" );
					eval( "a.onclick = function() { panelMan.showDetail( '" + catDescLongData.ProductLineHostID + "' ); }" );
					this.catDescLong.prodCode.display = a;
					this.catDescLong.td1.appendChild( a );
				}	
			}
			
			if ( this.catDescLong.td2 == null ) this.catDescLong.td2 = this.row.insertCell( - 1 );
			this.catDescLong.td2.className = 'resCol11';
			
			if ( catDescLongData != null ) {
				if ( this.catDescLong.DescLongription == null ) {
					if ( catDescLongData.DescLong != null ) {
						if ( catDescLongData.DescLong != '' ) {
							this.catDescLong.DescLongription = catDescLongData.DescLong;
							var a = catDescLongData.DescLong.split( '\\n' );
							for ( var i = 0; i < a.length; ++i ) {
								var text = document.createTextNode( a[i] );								
								this.catDescLong.td2.appendChild( text );	
								if ( i < ( a.length - 1 ) ) {
									var br = document.createElement( 'br' );								
									this.catDescLong.td2.appendChild( br );
								}						
							}
													
						}
					}
				}
			}
			
		} catch (e) {
			alert( 'ProductDisplay.createCatDescLong(): ' + e );
		}
	};
	
	//UOM column
	this.UOM = {
		td: null
	};			
	this.createUOM = function( UOMData ) {
		try {
			if ( this.row == null ) return;
			if ( this.UOM.td == null ) this.UOM.td = this.row.insertCell( - 1 );
			this.UOM.td.className = 'resCol2';
			
			
			if ( UOMData != null ) {								
				if ( UOMData.UOM != null ) {
					if ( UOMData.UOM != '' ) {
						this.UOM.td.appendChild( document.createTextNode( UOMData.UOM ) );						
					}
				}
			}
		} catch (e) {
			alert( 'ProductDisplay.createUOM(): ' + e );
		}
	};
		
	//Availableability Column
	this.Availableability = {
		td: null
	};
	this.createAvailableability = function( AvailableData ) {
		try {
			if ( this.row == null ) return;
			
			if ( this.Availableability.td == null ) this.Availableability.td = this.row.insertCell( - 1 );
			this.Availableability.td.colSpan = 9;
			
			
			this.Availableability.td.appendChild( loginLink_Elem() );
			this.Availableability.td.appendChild( document.createTextNode( ' to view pricing and availability' ) );
			
		} catch (e) {
			alert( 'ProductDisplay.createAvailableability(): ' + e );
		}
	};
	
	
	//actions column
	this.actions = {
		remove: {
			td: null,
			img: null,
			tt: null
		}
	};
	this.createActions1 = function( actionData ) {
		try {
			if ( this.row == null ) return;
			
			if ( this.actions.remove.td == null ) {
				this.actions.remove.td = this.row.insertCell( - 1 );
				this.actions.remove.td.className = 'resCol9';
							
				if ( this.actions.remove.img == null ) {
					var a = document.createElement( 'a' );
					a.href = 'javascript:void(0)';
					//a.setAttribute( 'onclick', "prodSet.removeProduct( '" + actionData.ProductLineCode + "' );" );
					eval( "a.onclick = function() { prodSet.removeProduct( '" + actionData.ProductLineHostID + "' ); } " ); 
					this.actions.remove.td.appendChild( a );
					
					var img = document.createElement( 'img' );								
					//img.src = '/icons/vwicn081.gif';
					img.src = '/__CC257456003226C9.nsf/0/3FE6A16F0921DD19CC257459002D6BC2/rtImage/0.84?OpenElement';
					img.id = 'remove_' + actionData.ProductLineHostID;
					img.border = '0';
					a.appendChild( img );
					this.actions.remove.img = img;
					
					this.actions.remove.tt = new YAHOO.widget.Tooltip("tt_" + img.id, { 
								context: img.id, 	
								text:"Remove from Search Results", 
								preventoverlap: false, 
								zIndex: 100 });
				}
			}						
			
		} catch (e) {
			alert( 'ProductDisplay.createActions1(): ' + e );
		}
	};
	this.createProductRow = function( prodData ) {
		//input = instance of ProductData
		if ( ( this.row == null ) && ( resDisplay != null ) ) {
			var at = -1;
			if ( resDisplay.getMode() == resDisplay.SortModes.BY_BRAND ) {
				var bs = prodSet.brandSet;	
				if ( bs != null ) {
					var brand = eval( 'bs.byName.brand_' + prodData.ProdGrp );
					if ( brand != null ) {	
						if ( brand.products.length > 0 ) {
							var prevProd = brand.products[ brand.products.length - 1 ];
							if ( prevProd != null ) {
								if( prevProd.display != null ) {
									if ( prevProd.display.row != null ) {
										at = prevProd.display.row.rowIndex + 1;
									}
								}
							}
						} else {
							if ( brand.display != null ) {
								if ( brand.display.rows.spacerRow != null ) {
									at = brand.display.rows.spacerRow.rowIndex + 1;								
								} else {
									if ( brand.display.rows.titleRow != null ) {
										at = brand.display.rows.titleRow.rowIndex + 1;								
									}
								}
							}	
						}
					}					
				}
			}
			this.row = resDisplay.createRow(at);
		}
		
		if ( this.row != null ) {
			
			//this.createDragHandle();
			this.createDetailsPanel();
			
			this.createActions1( prodData );
			this.createFlags( prodData );
			this.createCatDescLong( prodData );	
			
			this.createUOM( prodData );
			this.createAvailableability( prodData );
			this.show();			
		}
	};
		
	this.assignRowBackground = function( background ) {
		if ( this.row != null ) {
			this.row.style.backgroundColor = background;
		}
	} 
		
	this.visible = function() {
		return( this.row != null ? this.row.style.display == '' : false );
	};
	
	this.hide = function() {
		if ( this.row != null ) {
			this.row.style.display = 'none';				
		}	
	};
	
	this.show = function() {
		if ( this.row != null ) {
			this.row.style.display = '';				
		}	
	};
}
//------------
Product = function( ) {
	try {
		this.data = null;		
		this.display = null;	
		this.removed = false;	
		
		this.ProductLineHostID = function() { return this.data.ProductLineHostID };
		this.brand = function() { return this.data.ProdGrp };
		
	
		this.assignRowBackground = function( background ) {
			if ( this.display != null ) {
				this.display.assignRowBackground( background );				
			}
		} 
		
		this.hide = function() {
			if ( this.display != null ) {
				this.display.hide();				
			}	
		};
		
		this.show = function() {
			if ( ! this.removed ) {
				if ( this.display != null ) {
					this.display.show();					
				}
			}	
		};
		
		this.remove = function() {
			if ( ! this.removed ) {
	    		if( resDisplay.resultsEnd != null ) resDisplay.resultsEnd.dec();
	    		if( resDisplay.resultsTotal != null ) resDisplay.resultsTotal.dec();
			}
			this.removed = true;
			this.hide();
		}
		
		this.restore = function() {
			if ( this.removed ) {			
	    		if( resDisplay.resultsEnd != null ) resDisplay.resultsEnd.inc(); 
	    		if( resDisplay.resultsTotal != null ) resDisplay.resultsTotal.inc(); 
			}
			this.removed = false;		
		}
		
		this.visible = function() {
			return( this.display != null ? ( this.removed ? false : this.display.visible() ) : false );
		};
		
		
		this.init = function( prod ) {
			try {
				this.data = new ProductData();
				this.data.init( prod );
			
				this.display = new ProductDisplay();		
				this.display.createProductRow( this.data );
			} catch (e) {
				alert( 'Product.init(): ' + e );			
			}				
		}
	} catch ( e ) {
		alert( 'Product(): ' + e );
	}
}
//------------
ProductSet = function() {	
	try {
		this.brandSet = null;
		this.byName = { };
		this.byIndex = new Array();
				
		
		this.addProduct = function( prod ) {
			try {
				if ( prod == null ) return;
				if ( prod.ProductLineHostID == null ) return;
				if ( prod.Brand == null ) return;
				
				if ( this.brandSet == null ) this.brandSet = new BrandSet();
				this.brandSet.addBrand( prod );
				
				var product = new Product( );
				product.init( prod );		
						
				if ( eval( 'this.byName.prod_' + product.ProductLineHostID() ) != null ) return;
				
				eval( 'this.byName.prod_' + product.ProductLineHostID() + ' = product;' );
				this.byIndex.push( product );
				
				this.brandSet.addProduct( product );
				
				if ( resDisplay.productRows == null ) resDisplay.productRows = this.byIndex;
				 	
			} catch ( e ) {
				alert( 'ProductSet.addProduct(): ' + e );
			}	
		};
		
		this.removeProduct = function( productID ) {
			var product = eval( 'this.byName.prod_' + productID );
			 
			if ( product == null ) return;
			product.remove();
			if ( this.brandSet != null ) this.brandSet.removeProduct( product );
    		resDisplay.colouriseRows(); 
		};
		
		this.restoreRemoved = function() {
			for ( var i = 0; i < this.byIndex.length; ++i ) {
				if ( this.byIndex[i] != null ) this.byIndex[i].restore();
			}
			if ( this.brandSet != null ) this.brandSet.restoreRemoved( );	
    		resDisplay.colouriseRows();		
		};
		
		this.removePresent = function() {
			for ( var i = 0; i < this.byIndex.length; ++i ) {
				if ( this.byIndex[i] != null ) {
					if ( this.byIndex[i].data != null ) {
						if ( this.byIndex[i].data.numInCart != null ) {
							if ( this.byIndex[i].data.numInCart > 0 ) this.removeProduct( this.byIndex[i].data.ProductLineHostID );
						}
					}
				}
			}
		};
		
		this.addBrand = function( brand ) {
			if ( this.brandSet == null ) this.brandSet = new BrandSet();
			this.brandSet.addBrand( brand );
		};
		
		this.resortBrands = function() {
			if ( this.brandSet != null ) this.brandSet.resort();
		};
			
		this.hideProducts = function() {
			for ( var i = 0; i < this.byIndex.length; ++i ) {
				if ( this.byIndex[i] != null ) this.byIndex[i].hide();
			}
		};
		
		this.showProducts = function() {
			for ( var i = 0; i < this.byIndex.length; ++i ) {
				if ( this.byIndex[i] != null ) this.byIndex[i].show();
			}
		};
	} catch ( e ) {
		alert( 'ProductSet(): ' + e );
	}
}
var prodSet = null;	//master product set
initProdSet = function() {
	if ( prodSet == null ) prodSet = new ProductSet();
}
