function CreateProduct(id,containerId,documentId,title, price, imagePath, imageName, count, viewType, documentType){
	var obj = new Object;
	obj.Id = id;
	obj.ContainerId = containerId
	obj.Title = title;
	obj.DocumentId = documentId;
	obj.ImagePath = imagePath;
	obj.ImageName = imageName;
	obj.ProductImage = imagePath + "w60/" + imageName;
	obj.Price = price;
	obj.Count = count;
	obj.ViewType = viewType;
	obj.DocumentType = documentType;
	obj.LineNo = String(documentId);
	obj.UI = new Object();
	obj.UI.TextBoxId = "txt" + documentId;
	obj.UI.TextBox = function(){return document.getElementById("txt" + documentId);}
	obj.UI.HeaderId = "hd" + + documentId;
	obj.UI.Header = function(){return document.getElementById("hd" + documentId);}
	obj.UI.ShortDescription = "";
	obj.Xml = function(){
		var sHtml = new Array("");
		sHtml.push('<product');
		sHtml.push(' count="' + this.Count + '"');
		sHtml.push(' price="' + this.Price + '"');
		sHtml.push(' productnr="' + this.DocumentId + '"');
		sHtml.push(' lineNo="' +  this.LineNo + '"');
		sHtml.push('/>');
		return sHtml.join("");		
	}; 

	obj.Render = function(){
		var sHtml = new Array("");
		if(this.ViewType=='BASKET' || this.ViewType=='STEP2')
			this.UpdateBasketFull();
		if(this.Count == 0){
			if(this.DocumentType != "EXTRAGIFT") {
				document.getElementById(this.ContainerId).innerHTML = "";
				return false;
			}
		}
		//sHtml.push('<div class="header" id="' + obj.UI.HeaderId + '">');
		//sHtml.push(this.RenderHeader(this.Title, this.Price, this.Count, this.Count * this.Price));
		//sHtml.push('</div>');
		//sHtml.push('<span class="title">' + this.Title + '</span>');
		switch (this.ViewType){
			/* ah 20081215 - remove section (not in use anymore)
			case 'BASKET':
				sHtml.push('<div class="inputforms">');
				sHtml.push('<div class="productlines">');
				sHtml.push('<div class="productline">');
				sHtml.push('<img src="' + this.ProductImage + '" alt="' + this.Title + '">');
				sHtml.push(this.RenderTitle(this.Title));
				if (this.DocumentType == "EXTRAGIFT") {
					sHtml.push(this.RenderPriceField());
					sHtml.push(this.RenderAddButton());
				} else {
					sHtml.push(this.RenderTxtCount());			
				}
				sHtml.push(this.RenderSum());
				sHtml.push('</div>');
				sHtml.push('</div>');
				sHtml.push('</div>');
				break;
			*/
			case 'STEP2':
				sHtml.push('<div class="inputforms">');
				sHtml.push('<div class="productlines clearflow">');
				sHtml.push('<div class="productline">');
				if((this.ImageName != '0.')) {
					sHtml.push('<img src="' + this.ProductImage + '" alt="' + this.Title + '">');
				}
				sHtml.push(this.RenderTitle(this.Title));
				if (this.DocumentType == "EXTRAGIFT") {
					sHtml.push(this.RenderPriceField());
				} else {
					sHtml.push(this.RenderTxtCount());			
				}
				sHtml.push(this.RenderShortDescription());
				sHtml.push('</div>');
				sHtml.push(this.RenderSum());
				//sHtml.push(this.RenderRemoveButton());
				sHtml.push('</div>');
				sHtml.push('</div>');
				break;
			case 'FULL':
				sHtml.push('<div class="inputforms">');
				sHtml.push('<div class="productlines">');
				sHtml.push('<div class="productline">');
				sHtml.push('<img src="' + this.ProductImage + '" alt="' + this.Title + '">');
				sHtml.push(this.RenderTitle(this.Title));
				sHtml.push(this.RenderTxtCount());
				sHtml.push(this.RenderShortDescription());
				sHtml.push('</div>');
				//if(this.ViewType == 'FULL'){
					sHtml.push(this.RenderAddButton());
					sHtml.push(this.RenderShowButton());
				//}
				sHtml.push('</div>');
				sHtml.push('</div>');
				break;
		}
		//sHtml.push('<span class="item-values">' + this.Count + ' stk.');
		document.getElementById(this.ContainerId).innerHTML = sHtml.join("");
		return "";
	};

	obj.RenderTitle = function(title){
		var sHtml = new Array("");
		sHtml.push('<div class="title">' + title + '</div>');
		return sHtml.join("");
	}
		
	obj.RenderHeader = function(title){
		var sHtml = new Array("");
		var price = "";
		var totalprice = this.Price * this.Count;
		if(parseInt(this.Price,10) == this.Price){
			price = this.Price + ",-";
			totalprice = totalprice + ",-";
		}
		if(this.DocumentType == "EXTRAGIFT") {
			sHtml.push('<span class="title">' + title + '</span>');
			sHtml.push('<span class="item-price">');
			sHtml.push('Pris&nbsp;<span class="item-tot-price">' + totalprice + '</span>');
			sHtml.push('</span>');
		} else {
			sHtml.push('<span class="title">' + title + ', ' + price + '&nbsp;pr.stk.</span>');
			sHtml.push('<span class="item-price">');
			sHtml.push('<span class="item-count">' + this.Count + '</span>&nbsp;Stk&nbsp;&nbsp;');
			sHtml.push('Pris&nbsp;<span class="item-tot-price">' + totalprice + '</span>');
			sHtml.push('</span>');
		}
		return sHtml.join("");
	}

	obj.RenderShortDescription = function() {
		var sHtml = new Array("");
		if(this.UI.ShortDescription.length >0 ){
			sHtml.push('<span class="short-description">');
			sHtml.push('&nbsp;(' + this.UI.ShortDescription.replace('<br>', '').replace('</br>', '') + ')');
			sHtml.push('</span>');
		}	
		return sHtml.join("");
	};
	
	obj.RenderSum = function() {	
		var sHtml = new Array("");
		sHtml.push('<div class="product-sum">');
		var price = "";
		var totalprice = this.Sum();
		if(parseInt(this.Price,10) == this.Price){
			price = this.Price + ",-";
			totalprice = totalprice + ",-";
		}
		//sHtml.push('<span class="title">' + title + ', ' + price + '&nbsp;pr.stk.</span>');
		//sHtml.push('<span class="item-price">');
		//sHtml.push('<span class="item-count">' + this.ItemCount() + '</span>&nbsp;Stk&nbsp;&nbsp;');
		//sHtml.push('</span>');
		sHtml.push(this.RenderRemoveButton());
		sHtml.push('<span class="item-sum"><span class="item-price">Pris&nbsp;</span><span class="item-tot-price">' + totalprice + '</span></span>');
		sHtml.push('</div>');
		return sHtml.join("");
	}

	obj.RenderRemoveButton = function(){
		return '<a href="#" onclick="' + this.Id + '.Remove();"><img src="btn/btnSlett.png" class="removebutton" alt="Fjern" /></a>';
	};
	
	obj.CheckRequiredFieldsMissing = function() {
		return false;
	};
	
	obj.RenderAddButton = function(){
		return '<a href="#" onclick="' + this.Id + '.AddToBasket(this);"><img src="btn/btnAddToBasket.gif" class="buybutton" alt="Legg i handlevogn" onMouseOver="objCart.ButtonMouseOver(this,\'btn/btnAddToBasket_a.gif\')" onMouseOut="objCart.ButtonMouseOut(this,\'btn/btnAddToBasket.gif\')" border="0"/></a>';
	};

	obj.RenderShowButton = function(){
		return '<a href="default.aspx?did=' + this.DocumentId + '"><img src="btn/btnShowFull.gif" class="showbutton" alt="Vis produkt" onMouseOver="objCart.ButtonMouseOver(this,\'btn/btnShowFull_a.gif\')" onMouseOut="objCart.ButtonMouseOut(this,\'btn/btnShowFull.gif\')" border="0"/></a>';
	};


	obj.AddToBasket = function(linkObject){
		objCart.Buy(linkObject,this.DocumentId, obj.UI.TextBox().value);
		var count = 1;
		obj.UI.TextBox().value = "1";
		this.Count = count;
		obj.UI.Header().innerHTML = this.RenderHeader(this.Title, this.Price, this.Count, this.Count * this.Price)
	};

	obj.Remove = function(){
		objCart.RemoveItem(this.DocumentId , this.LineNo);
		this.Count = 0;
		this.Render();
	}

	obj.RenderTxtCount = function(){
		return '<input type="text" onKeyDown="if(objCart.isEnterClicked(event)){' + this.Id + '.DoTextBoxUpdate(this);return false;};" onBlur="' + this.Id + '.DoTextBoxUpdate(this);" class="textbox" id="' + this.UI.TextBoxId + '" value="' + this.Count + '"/> <span>stk &aacute; ' + this.Price + ',-</span>';
	};
	
	// Extragift
	obj.RenderPriceField = function(){
		return '<input type="text" onKeyDown="if(objCart.isEnterClicked(event)){' + this.Id + '.DoTextBoxUpdate(this);return false;};" onBlur="' + this.Id + '.DoTextBoxUpdate(this);" class="textbox" id="' + this.UI.TextBoxId + '" value="' + this.Count + '" /> <span>Valgfri sum</span>';
	};

	obj.RenderCount = function(){
		return '<span class="itemcount">' + this.Count + ' stk</span>';
	};


	obj.DoTextBoxUpdate = function(textbox){
		var count = textbox.value;
		if(!objCart.IsNumeric(count)){
			textbox.value = this.Count;
			return false;
		}
		if(this.ViewType == 'STEP2'){ //if(this.ViewType == 'BASKET'){
				this.Count = parseInt(count,10);
				if(this.Count>0) {
					var response;
					response = Cart.UpdateItem(objCart.DocumentId, String(this.DocumentId), this.LineNo,this.Count,0,0,0,"","",0,0,0);
					if(cart){
						if (response.error!=null){	
							alert(response.error);
							cart.innerHTML = response.error;
							return;
						}
						cart.innerHTML = response.value;
					}
					this.Render();		
					return false;
				} else if(confirm('Vil du virkelig slette dette produktet?')){
					this.Remove();
				}
		}else {
			this.Count = count;
			obj.UI.Header().innerHTML = this.RenderHeader(this.Title, this.Price, this.Count, this.Count * this.Price)
			return true;
		}
	};

	obj.Sum = function(){
		return this.Count * this.Price;
	};

	obj.ItemCount = function(){
		return this.Count;
	};
	return obj;
}

