function CreateTShirtCollection(id, containerId, documentId, productImage, price, imagePath, imageName, title)
{
	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.ViewType = "FULL";
	obj.Array = new Array();
	obj.Size = new Array();
	obj.Color = new Array();
	obj.Sex = new Array(); 
	obj.UI = new Object();
	obj.UI.ShortDescription = "";
	obj.UI.ProductSize = function(productLine) {return document.getElementById(productLine.SizeId);}
	obj.UI.ProductSex = function(productLine) {return document.getElementById(productLine.SexId);}
	obj.UI.ProductColor = function(productLine) {return document.getElementById(productLine.ColorId);}
	obj.GetProductLineNr = function()
	{
		var uniqTag = this.S4() + this.S4() + this.S4() + this.S4();
		return uniqTag;
	};

	obj.S4 = function()
	{
		return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
	};

	obj.Add = function(count, size, sex, color)
	{
		this.Array[this.Array.length] = new this.productLine(count, size, sex, color, this.GetProductLineNr());
	};

	obj.AddFromBasketXSLT = function(count, size, sex, color, lineNo)
	{
		this.Add(count, size, sex, color);
		this.Array[this.Array.length - 1].LineNo = lineNo;
	};

	obj.AddSize = function(text, value)
	{
		this.Size[this.Size.length] = new this.optionClass(text,value);
	};

	obj.AddColor = function(text, value)
	{
		this.Color[this.Color.length] = new this.optionClass(text,value);
	};

	obj.AddSex = function(text, value)
	{
		this.Sex[this.Sex.length] = new this.optionClass(text,value);
	};

	obj.Render = function()
	{
		var sHtml = new Array("");
		if(this.ViewType=='STEP2') //if(this.ViewType=='BASKET')
			this.UpdateBasketFull();

		if(this.Array.length == 0)
		{
			if(this.ViewType == 'FULL' || this.ViewType == 'PRODUCTCOLLECTION')
			{
				this.Add(1,0,0,0);
			}
			else
			{
				document.getElementById(this.ContainerId).innerHTML = "";
				return false;
			}
		}

		//sHtml.push(this.RenderHeader(this.Title));
		//sHtml.push('<div class="inputforms">');
		//if(this.UI.ShortDescription.length >0 ){
		//	sHtml.push('<div class="short-description">');
		//	sHtml.push(this.UI.ShortDescription);
		//	sHtml.push('</div>');
		//}
		//sHtml.push('<div class="productlines">');
		for (var i=0; i<this.Array.length;i++)
		{
			sHtml.push(this.RenderProductLine(this.Array[i]));
		}
		switch (this.ViewType)
		{
			case 'FULL':
				sHtml.push(this.RenderBuyButton());
				//sHtml.push(this.RenderShowButton());
				break;
			case 'BASKET':
				//sHtml.push(this.RenderAddMoreButton());
				break;
		}
		//sHtml.push('</div>');
		//sHtml.push('</div>');
		document.getElementById(this.ContainerId).innerHTML = sHtml.join("");
		return "";
	};

	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.RenderTitle = function(title){
		var sHtml = new Array("");
		sHtml.push('<div class="title">' + title + '</div>');
		return sHtml.join("");
	}
	
	obj.RenderShortDescription = function(){
		var sHtml = new Array("");
		if(this.UI.ShortDescription.length >0 ){
			sHtml.push('<div class="short-description">');
			sHtml.push(this.UI.ShortDescription);
			sHtml.push('</div>');
		}
		return sHtml.join("");
	}

	obj.RenderHeader = function(title)
	{
		var sHtml = new Array("");
		sHtml.push('<div class="header">');
		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('Pris&nbsp;<span class="item-tot-price">' + totalprice + '</span>');
		sHtml.push('</span>');
		sHtml.push('</div>');
		return sHtml.join("");
	}
	
	obj.RenderProductLine = function(productLine)
	{
		var sHtml = new Array("");
		sHtml.push('<div class="productline">');

		switch (this.ViewType)
		{
			case 'FULL':
			case 'BASKET':
				sHtml.push(this.RenderDrpDwnSize(productLine));
				sHtml.push(this.RenderDrpDwnSex(productLine));
				sHtml.push(this.RenderDrpDwnColor(productLine));
				//sHtml.push(this.RenderAddMoreButton());
				break;
			case 'STEP2':
				sHtml.push('<div class="inputforms">');
				sHtml.push('<div class="productlines">');
				sHtml.push('<div class="productline">');
				//sHtml.push(this.RenderHeader(this.Title));
				sHtml.push('<img src="' + this.ProductImage + '" alt="' + this.Title + '">');
				sHtml.push(this.RenderTitle(this.Title));
				sHtml.push(this.RenderShortDescription());
				//sHtml.push('<img src="' + this.ProductImage + '" alt="">');
				sHtml.push(this.RenderTxtCount(productLine));
				sHtml.push('<span class="item-values">. St&oslash;rrelse: ' + this.GetOptionText(this.Size,productLine.Size) + ', farge: ' + this.GetOptionText(this.Color,productLine.Color) + ', kj&oslash;nn: ' + this.GetOptionText(this.Sex,productLine.Sex) + '</span>');
				//sHtml.push(this.RenderDrpDwnSize(productLine));
				//sHtml.push(this.RenderDrpDwnSex(productLine));
				//sHtml.push(this.RenderDrpDwnColor(productLine));
				//sHtml.push(this.RenderRemoveButton(productLine));
				sHtml.push('</div>'); 
				sHtml.push(this.RenderSum(productLine));
				sHtml.push('</div></div>');
				break;
			case 'HERE_WAS_STEP2':
				sHtml.push('<span class="item-values">' + productLine.Count + ' Stk., st&oslash;rrelse: ' + this.GetOptionText(this.Size,productLine.Size) + ', farge: ' + this.GetOptionText(this.Color,productLine.Color) + ', kj&oslash;nn: ' + this.GetOptionText(this.Sex,productLine.Sex) + '</span>');
				break;
		}

		sHtml.push('</div>');
		return sHtml.join("");
	};

	obj.RenderSum = function(productLine) {	
		var sHtml = new Array("");
		sHtml.push('<div class="product-sum">');
		var price = "";
		var totalprice = this.Price * productLine.Count; //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(productLine));
		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(productLine)
	{
		var sHtml = new Array("");
		sHtml.push('<a href="#" onclick="' + this.Id + '.RemoveProductLine(\'' + productLine.LineNo + '\');"><img src="btn/btnSlett.png" class="removebutton" alt="Fjern" /></a>');
		return sHtml.join("");
	};

	obj.RenderAddMoreButton = function()
	{
		var sHtml = new Array("");
		sHtml.push('<a href="#" onclick="' + this.Id + '.AddProductLine();"><img src="btn/btnAddMore.gif" class="addmorebutton" alt="Legg til flere" onMouseOver="objCart.ButtonMouseOver(this,\'btn/btnAddMore_a.gif\')" onMouseOut="objCart.ButtonMouseOut(this,\'btn/btnAddMore.gif\')" border="0"/></a>');
		return sHtml.join("");
	};

	obj.RenderBuyButton = function()
	{
		var sHtml = new Array("");
		sHtml.push('<a href="#" onclick="' + this.Id + '.Buy(this);" class="buybuttonlink"><img src="btn/btnGiveThisMiddle.png" class="buybutton" alt="Legg i handlevogn" /></a>');
		return sHtml.join("");
	};


	obj.RenderDrpDwnSize = function(productLine)
	{
		var sHtml = new Array("");
		var onChange = "";
		if(this.ViewType == "BASKET")
			onChange = ' onchange="' + this.Id + '.OnChange(this,\'' + productLine.LineNo + '\')"';
		sHtml.push('<select id="' + productLine.SizeId + '"' + onChange + ' class="first">');
		sHtml.push(this.RenderDrpDwnOptions(this.Size,productLine.Size))
		sHtml.push('</select>');
		return sHtml.join("");		
	};


	obj.RenderDrpDwnSex = function(productLine)
	{
		var sHtml = new Array("");
		var onChange = "";
		if(this.ViewType == "BASKET")
			onChange = ' onchange="' + this.Id + '.OnChange(this,\'' + productLine.LineNo + '\')"';
		sHtml.push('<select id="' + productLine.SexId + '"' + onChange + '>');
		sHtml.push(this.RenderDrpDwnOptions(this.Sex,productLine.Sex))
		sHtml.push('</select>');
		return sHtml.join("");		
	};


	obj.RenderDrpDwnColor = function(productLine)
	{
		var sHtml = new Array("");
		var onChange ="";
		if(this.ViewType == "BASKET")
			onChange = ' onchange="' + this.Id + '.OnChange(this,\'' + productLine.LineNo + '\')"';
		sHtml.push('<select id="' + productLine.ColorId + '"' + onChange + '>');
		sHtml.push(this.RenderDrpDwnOptions(this.Color,productLine.Color))
		sHtml.push('</select>');
		return sHtml.join("");		
	};


	obj.RenderDrpDwnOptions = function(objArr, value)
	{
		var sHtml = new Array("");
		for (var i=0; i<objArr.length;i++)
		{
			sHtml.push('<option value="' +objArr[i].Value + '"');
			if(objArr[i].Value == value)
			{
				sHtml.push(' selected ');
			}
			sHtml.push('>' + objArr[i].Text + '</option>');
		}			
		return sHtml.join("");		

	}
	
	obj.GetOptionText = function(objArr, value)
	{
		for (var i=0; i<objArr.length;i++)
		{
			if(objArr[i].Value == value)
				return objArr[i].Text;
		}			
		return value;
	}	

	obj.RenderTxtCount = function(productLine)
	{
		var sHtml = new Array("");
		//sHtml.push('<input type="text" onKeyDown="if(objCart.isEnterClicked(event)){' + this.Id + '.DoTextBoxUpdate(\'' + productLine.LineNo + '\');return false;};" onBlur="' + this.Id + '.DoTextBoxUpdate(\'' + productLine.LineNo + '\');" class="textbox" id="' + productLine.CountId + '" value="' + productLine.Count + '"/> stk');
		sHtml.push('<input type="text" onKeyDown="if(objCart.isEnterClicked(event)){' + this.Id + '.DoTextBoxUpdate(\'' + productLine.LineNo + '\');return false;};" onBlur="' + this.Id + '.DoTextBoxUpdate(\'' + productLine.LineNo + '\');" class="textbox" id="' + productLine.CountId + '" value="' + productLine.Count + '"/> <span>stk &aacute; ' + this.Price + ',-</span>');
		return sHtml.join("");		
	};

	obj.optionClass = function(text, value)
	{
		this.Text = text;
		this.Value = value;
	};
	


	obj.DoTextBoxUpdate = function(lineNo)
	{
		var productLine = this.GetProductLine(lineNo);
		if(productLine) {
			var selCount = document.getElementById(productLine.CountId).value;
			if(objCart.IsNumeric(selCount)) {
				var c = parseInt(selCount, 10);
				if(c<1) {
					if(confirm('Vil du virkelig slette dette produktet?'))
						this.RemoveProductLine(lineNo);
				} else {
					//this.UpdateItem(productLine);
					objCart.UpdateItem(this.DocumentId, productLine.LineNo, c,  productLine.Color, productLine.Sex, productLine.Size,"","", this.GetOptionText(this.Color,productLine.Color), this.GetOptionText(this.Sex,productLine.Sex), this.GetOptionText(this.Size,productLine.Size))
					productLine.Count = c;
					this.Render();
				}
			} else {
			}
		}
	};
	

	obj.AddProductLine = function()
	{
		if(this.ViewType == 'BASKET')
		{
			document.location.href='default.aspx?did=' + this.DocumentId;
			return false;
		}
		else
		{
			this.UpdateAllValues();
			this.Add(1,0,0,0);
			this.Render();
		}
	};

	obj.UpdateAllValues = function()
	{

		var productLine = "";
		for (var i=0; i<this.Array.length;i++)
		{
			this.UpdateProductLineValues(this.Array[i])
		}
	};

	obj.UpdateProductLineValues = function(productLine)
	{
		if((document.getElementById(productLine.CountId) != null) && objCart.IsNumeric(document.getElementById(productLine.CountId).value)) {
			productLine.Count = parseInt(document.getElementById(productLine.CountId).value,10);
		} else {
			productLine.Count = 1;
		}
		switch(this.ViewType) {
			case 'STEP2':
				break;
			default:
				if(objCart.IsNumeric(document.getElementById(productLine.SizeId).value))
					productLine.Size = parseInt(document.getElementById(productLine.SizeId).value,10);
				if(objCart.IsNumeric(document.getElementById(productLine.SexId).value))
					productLine.Sex = parseInt(document.getElementById(productLine.SexId).value,10);
				if(objCart.IsNumeric(document.getElementById(productLine.ColorId).value))
					productLine.Color = parseInt(document.getElementById(productLine.ColorId).value,10);
				break;
		}
	};



	obj.Buy = function(objLink)
	{
		if(this.CheckRequiredFieldsMissing()==true) return false;
		objCart.ShowAjaxText(objLink);
		response = Cart.BuyMany(this.Xml(), objCart.DocumentId);
		if (response.error!=null) 
		{	
			alert(response.error);
			cart.innerHTML = response.error;
			return;
		}
		cart.innerHTML = response.value;
		setTimeout(this.Id + '.RenderAfterBuy()', 2000);

	};

	obj.RenderAfterBuy = function()
	{
		this.Array = new Array;
		this.Render();
	}

	obj.UpdateItem = function(productLine)
	{
		if(this.CheckRequiredFieldsMissing()==true) return false;
		this.UpdateProductLineValues(productLine);
		if(this.ViewType == 'STEP2') //if(this.ViewType == 'BASKET')
			objCart.UpdateItem(this.DocumentId, productLine.LineNo,productLine.Count,  productLine.Color, productLine.Sex, productLine.Size,"","", productLine.Color, productLine.Sex, productLine.Size)
		this.Render();
	};


	obj.OnChange = function(selectBox, lineNo)
	{
		if(selectBox.value > 0)
		{
			var productLine = this.GetProductLine(lineNo);
			if(productLine)
				this.UpdateItem(productLine);
			return true;
		}
		else
			this.Render();
		
	};


	
	obj.CheckRequiredFieldsMissing = function()
	{
		var ShowError = false;
		this.UpdateAllValues();
		for (var i=0; i<this.Array.length && ShowError == false;i++)
		{
			if(parseInt(this.Array[i].Color,10) == 0) ShowError = true;
			if(parseInt(this.Array[i].Size,10) == 0) ShowError = true;
			if(parseInt(this.Array[i].Sex,10) == 0) ShowError = true;
			if(parseInt(this.Array[i].Count,10) == 0) ShowError = true;
		}
		if(ShowError==true)
		{
			alert(document.getElementById('errRequiredFields' + this.DocumentId).innerHTML);
		}
		return ShowError;
	
	}
	




	obj.RemoveProductLine = function(nr)
	{
		var objArr = new Array();
		for (var i=0; i<this.Array.length;i++)
		{
			if(this.Array[i].LineNo != nr)			{
				objArr[objArr.length] = this.Array[i];
			}else{
				objCart.RemoveItem(this.DocumentId , this.Array[i].LineNo);
			}
		}
		this.Array = objArr;
		this.Render();
	};



	obj.Xml = function()
	{
		var sHtml = new Array("");
		sHtml.push('<productlines>');
		for (var i=0; i<this.Array.length;i++)
		{
			sHtml.push(this.XmlProductLine(this.Array[i]))
		}
		sHtml.push('</productlines>');
		return sHtml.join("");		
	};

	obj.productLine = function(count, size, sex, color, productLineNr)
	{
		this.Count = count;
		this.Size = parseInt(size,10);
		this.Sex = parseInt(sex,10);
		this.Color = parseInt(color,10);
		this.LineNo = productLineNr;
		this.CountId = "count" + productLineNr;
		this.SexId = "sex" + productLineNr;
		this.SizeId = "size" + productLineNr;
		this.ColorId = "color" + productLineNr;
	};


	obj.XmlProductLine = function(productLine)
	{
		var sHtml = new Array("");
		sHtml.push('<productline');
		sHtml.push(' type="TSHIRTS"');
		sHtml.push(' count="' + productLine.Count + '"');
		sHtml.push(' color="' + obj.UI.ProductColor(productLine).options[obj.UI.ProductColor(productLine).selectedIndex].text + '"');
		sHtml.push(' colorId="' + productLine.Color + '"');
		sHtml.push(' size="' + obj.UI.ProductSize(productLine).options[obj.UI.ProductSize(productLine).selectedIndex].text + '"');
		sHtml.push(' sizeId="' + productLine.Size + '"');
		sHtml.push(' sex="' + obj.UI.ProductSex(productLine).options[obj.UI.ProductSex(productLine).selectedIndex].text + '"');
		sHtml.push(' sexId="' + productLine.Sex + '"');
		sHtml.push(' productnr="' + this.DocumentId + '"');
		sHtml.push(' lineNo="' +  productLine.LineNo + '"');
		sHtml.push('>');
		sHtml.push('<fromName><![CDATA[]]></fromName>');
		sHtml.push('<toName><![CDATA[]]></toName>');
		sHtml.push('</productline>');
		return sHtml.join("");		
	};

	obj.GetProductLine = function(lineNo)
	{
		for (var i=0; i<this.Array.length;i++)
		{
			if(this.Array[i].LineNo == lineNo)
			{
				return this.Array[i];
			}
		}
		return false;
	};

	obj.Sum = function()
	{
		var sum = 0;
		for (var i=0; i<this.Array.length;i++)
		{
			sum += this.Array[i].Count *  this.Price;
		}
		return sum;
	};
	
	obj.ItemCount = function()
	{
		var count = 0;
		for (var i=0; i<this.Array.length;i++)
		{
			count += this.Array[i].Count;
		}
		return count;
	};


	return obj;
}

