///	<summary>Class Product<br>
///	Represents a product with basic information for display including thumbnail image.</summary>
function Product(id, productNumber, name, description, site, upc, yearIntroduced,
	yearDiscontinued, gender, price, suggestedAge, sortOrder, createdBy, 
	createDate, updatedBy, updateDate) {

	//	==================
	// Protected Variables
	//	==================
	this.id = id;
	this.productNumber = productNumber;
	this.name = name;
	this.description = description;
	this.site = site;
	this.upc = upc;
	this.yearIntroduced = yearIntroduced;
	this.yearDiscontinued = yearDiscontinued;
	this.gender = gender;
	this.price = price;
	this.suggestedAge = suggestedAge;
	this.sortOrder = sortOrder;
	this.createdBy = createdBy;
	this.createDate = createDate;
	this.updatedBy = updatedBy;
	this.updateDate = updateDate;
	
	this.link = "";
	
	//==============
	this.media = new Array();
	this.content = new Array();
	
	// ==============
	// Public Methods
	// ==============
	
	this.GetId = function() {
		return this.id;
	}

	this.GetSku = function() {
		return this.productNumber;
	}

	this.GetName = function() {
		return this.name;
	}
	/*
	this.GetImg = function() {
		return new FPImage("thumb_" + this.id, "http://fpdev/img/product_shots/" + this.productNumber + "_60_1.jpg", "img", 110, 110, this.Name, null, null);
	}
	*/
	this.GetAges = function() {
		return this.suggestedAge;
	}
	
	this.GetLink = function() {
		return this.link;
	}
	
	//=======================================
	///	<summary>Adds a <c>Media</c> object to the media arary.</summary>
	/// <param name="media"><c>Media</c> object.</param>
	/// modified 10/4/04 - some mac versions don't support array.push?
	this.AddMedia = function(media) {
		//this.media.push(media);
		this.media[this.media.length] = media;
	}
	
	///	<summary>Retrieves all <c>Media</c> matching the media_type_code passed in.</summary>
	/// <param name="typeCode"><c>string</c> media_type_code.</param>
	/// <returns><c>Array</c> of <c>Media</c></returns>
	this.GetMedia = function(typeCode) {
		var media = new Array();
		var i = 0;
		
				// Loop all <c>Product</c> media
		for (; i < this.media.length; i++) {
					// If media_type_code's match, add media to return array
			if (typeCode == this.media[i].GetTypeCode()) {
				media[media.length] = this.media[i];
			}
		}
		
		return media;
	}
	
	///	<summary>Adds a <c>Content</c> object to the content arary.</summary>
	/// <param name="media"><c>Content</c> object.</param>
	this.AddContent = function(content) {
		this.content[this.content.length] = content;
	}
	
	///	<summary>Retrieves all <c>Content</c> matching the content_type_code passed in.</summary>
	/// <param name="typeCode"><c>string</c> content_type_code.</param>
	/// <returns><c>Array</c> of <c>Content</c></returns>
	this.GetContent = function(typeCode) {
		var content = new Array();
		var i = 0;
		
				// Loop all <c>Product</c> media
		for (; i < this.media.length; i++) {
					// If media_type_code's match, add media to return array
			if (typeCode = this.media[i].GetTypeCode()) {
				content[content.length] = this.media[i];
			}
		}
		
		return content;
	}
}
///	<summary>Returns valid string for use in the status bar.</summary>
/// <param name="text"><c>string</c> text that needs to be cleaned.</param>
///	<remarks>Should probably be removed to a js util file and set Product.CleanStatus = CleanStatus(text);</remarks>
Product.CleanStatus = function(text) {
	var aryItems = Array('<br>', ' ', '\'', '&#147;');		// add to array any value/replacement pair that needs to be replaced in the status bar
	var status = text;
	
			// Proceed if text exists
	if (status != null) {
				// Loop all value/replacement pairs
		for (var i = 0; i < aryItems.length; i+=2){
					// While loop is used here b/c replace function only replaces one occurence
					// so we loop until there are no more
			while (status.indexOf(aryItems[i]) != -1){
				status = status.replace(aryItems[i], aryItems[i + 1]);
			}
		}
	} else {
		status = "";
	}
	
	return status;
}

///	<summary>To replace image size with desired one.</summary>
/// <param name="imgPath"><c>string</c> image path.</param>
/// <param name="size"><c>string</c> desired image size.</param>
Product.ReplaceImageSize = function (imgPath, size){
	var path = imgPath;
	var sizes = new Array('_a_', '_b_', '_c_', '_60_');		// All available image sizes on fp site
	var i = 0;
	
			// Loop all image sizes
	for(; i < sizes.length; i++){
				// If size match is found, replace
		if (path.indexOf(sizes[i]) != -1){
			path = path.replace(sizes[i], size);
			break;
		}
	}
	
	return path;
}
