function CreateVRCardCollection(id,containerId, documentId,productImage, price, imagePath, imageName, title, pdfPreview)
{
	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.PdfPreview = pdfPreview;
	obj.ViewType = "FULL";
	obj.CardType = "";
	obj.Array = new Array();
	obj.UI = new Object();
	obj.UI.ShortDescription = "";

	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, fromName, toName){
		this.Array[this.Array.length] = new this.productLine(count, this.GetProductLineNr(), fromName, toName);
	};

	obj.AddFromBasketXSLT = function(count, fromName, toName, lineNo){
		this.Add(count, fromName, toName);
		this.Array[this.Array.length - 1].LineNo = lineNo;
	};
	
	obj.Render = function(cardtype) {
		this.CardType = cardtype;
		if (cardtype == 'CARD') {
			this.Add(1, "", "");
			
			var sHtml = new Array("");
			// sHtml.push(this.RenderBuyButton());
			document.getElementById(this.ContainerId).innerHTML = sHtml.join("");
			return "";
		}
		else { // if(cardtype == 'VRCARD') {
			this.RenderVRCARD();
		} 
	}
	
	obj.RenderVRCARD = function(){
		var sHtml = new Array("");
		if(this.ViewType=='BASKET' || this.ViewType=='STEP2') //if(this.ViewType=='BASKET')
			this.UpdateBasketFull();

		if(this.Array.length == 0){
			if(this.ViewType == 'FULL') {
				this.Add(1,"","");
			} else {
				//Hide basket element from basket full view
				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 clearflow">');
		for (var i=0; i<this.Array.length; i++){
			sHtml.push(this.RenderProductLine(this.Array[i]));
		}
		if(this.Array.length == 1) {
			switch (this.ViewType){
				case 'FULL':
					sHtml.push(this.RenderBuyButton());
					//sHtml.push(this.RenderAddMoreButton());
					//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.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.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.RenderProductLine = function(productLine){
		var sHtml = new Array("");
		sHtml.push('<div class="productline">');
		switch (this.ViewType){
			case 'FULL':
			case 'BASKET':
				//sHtml.push(this.RenderTxtCount(productLine));
				sHtml.push(this.RenderTxtToName(productLine));
				sHtml.push(this.RenderTxtFromName(productLine));
				//sHtml.push(this.RenderRemoveButton(productLine));
				break;
			case 'STEP2':
				sHtml.push('<div class="inputforms">');
				sHtml.push('<div class="productlines clearflow">');
				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">' + productLine.Count + ' stk., Til: ' + productLine.ToName + ', Fra: ' + productLine.FromName + '</span>');
				//sHtml.push(this.RenderDrpDwnSize(productLine));
				//sHtml.push(this.RenderDrpDwnSex(productLine));
				//sHtml.push(this.RenderDrpDwnColor(productLine));
				sHtml.push('</div>');
				sHtml.push(this.RenderSum(productLine));
				//sHtml.push(this.RenderRemoveButton(productLine));
				sHtml.push('</div></div>');
				break;
				
		}
		sHtml.push('</div>');
		return sHtml.join("");
	};

	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.RenderRemoveButton = function(productLine){
		var sHtml = new Array("");
		sHtml.push('<div class="productlinebutton">');
		if(this.PdfPreview.length > 0)
			sHtml.push('<a href="' + this.PdfPreview + '" target="_blank"><img src="btn/btnPDFPreview.gif" class="pdfbutton" alt="Vis eksempel" onMouseOver="objCart.ButtonMouseOver(this,\'btn/btnPDFPreview_a.gif\')" onMouseOut="objCart.ButtonMouseOut(this,\'btn/btnPDFPreview.gif\')" border="0"/></a>');
		sHtml.push('<a href="#" onclick="' + this.Id + '.RemoveProductLine(\'' + productLine.LineNo + '\');"><img src="btn/btnSlett.png" class="removebutton" alt="Fjern" /></a>');
		sHtml.push('</div>');
		return sHtml.join("");
	};


	obj.RenderAddMoreButton = function(){
		return '<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>';
	};

	obj.RenderBuyButton = function(){
		return '<a href="#" onclick="' + this.Id + '.Buy(this);" class="buybuttonlink"><img src="btn/btnGiveThisMiddle.png" class="buybutton" alt="Legg i handlevogn"></a>';
	};

	obj.RenderTxtCount = function(productLine){
		var sHtml = new Array("");
		sHtml.push('<input type="text" ');
		sHtml.push('onKeyDown="if(objCart.isEnterClicked(event)){' + this.Id + '.DoTextBoxUpdate(\'' + productLine.LineNo + '\');return false;};" onBlur="' + this.Id + '.DoTextBoxUpdate(\'' + productLine.LineNo + '\');" ');
		sHtml.push(' class="textbox" id="' + productLine.CountId + '" value="' + productLine.Count + '"/> Stk');
		return sHtml.join("");		
	};

	obj.DoTextBoxUpdate = function(lineNo){
		var productLine = this.GetProductLine(lineNo);
		if(productLine) {
			var c = document.getElementById(productLine.CountId).value;
			if(objCart.IsNumeric(c)) {
				if(parseInt(c, 10) > 0){
					this.UpdateItem(productLine);
				} else if(confirm('Vil du virkelig slette dette produktet?')) {
					objCart.RemoveItem(this.DocumentId, productLine.LineNo); //, productLine.Count,  0, 0, 0, productLine.FromName, productLine.ToName, 0, 0, 0);
					this.RemoveProductLine(lineNo);
				}
				window.setTimeout("if(document.getElementById('" + productLine.ToNameId + "')){document.getElementById('" + productLine.ToNameId + "').focus();}",100);
			} else {
				alert('Fyll ut feltet korrekt!')
			}
		}
	};

	obj.RenderTxtFromName = function(productLine){
		var sHtml = new Array("");
		sHtml.push('Fra: <input type="text" ');
		if(this.ViewType=='BASKET')
			sHtml.push(' onKeyDown="if(objCart.isEnterClicked(event)){' + this.Id + '.DoNameUpdate(\'' + productLine.LineNo + '\');return false;};" onBlur="' + this.Id + '.DoNameUpdate(\'' + productLine.LineNo + '\');" ');
		sHtml.push(' class="textbox fromname" id="' + productLine.FromNameId + '" value="' + productLine.FromName + '"/>');
		return sHtml.join("");		
	};


	obj.DoNameUpdate = function(lineNo){
		var productLine = this.GetProductLine(lineNo);
		if(productLine)
			this.UpdateItem(productLine);
	};

	obj.RenderTxtToName = function(productLine){
		var sHtml = new Array("");
		sHtml.push('<span class="toNameLabel">Til:</span> <input type="text" ');
		if(this.ViewType=='BASKET')
			sHtml.push(' onKeyDown="if(objCart.isEnterClicked(event)){' + this.Id + '.DoNameUpdate(\'' + productLine.LineNo + '\');return false;};" onBlur="' + this.Id + '.DoNameUpdate(\'' + productLine.LineNo + '\');" ');
		sHtml.push(' class="textbox toname" id="' + productLine.ToNameId + '" value="' + productLine.ToName + '"/>');
		return sHtml.join("");		
	};


	obj.AddProductLine = function(){
		if(this.ViewType == 'BASKET'){
			document.location.href='default.aspx?did=' + this.DocumentId;
			return false;
		}else{
			this.UpdateAllValues();
			this.Add(1,"","");
			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;
		}
		if(document.getElementById(productLine.FromNameId))
			productLine.FromName = document.getElementById(productLine.FromNameId).value;
		if(document.getElementById(productLine.ToNameId))
			productLine.ToName = document.getElementById(productLine.ToNameId).value;
	};

	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=='BASKET' || this.ViewType=='STEP2')
			objCart.UpdateItem(this.DocumentId, productLine.LineNo, productLine.Count,  0, 0, 0, productLine.FromName, productLine.ToName, 0, 0, 0)
		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].Count,10) ==0) ShowError = true;
			if(this.Array[i].FromName.length == 0) ShowError = true;
			if(this.Array[i].ToName.length == 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,productLineNr, fromName, toName){
		this.LineNo = productLineNr;
		this.Count = count;
		this.CountId = "count" + productLineNr;
		this.ToName = toName;
		this.ToNameId = "tName" + productLineNr;
		this.FromName = fromName;
		this.FromNameId = "fName" + productLineNr;
	};


	obj.XmlProductLine = function(productLine){
		var sHtml = new Array("");
		sHtml.push('<productline');
		sHtml.push(' type="VRCARD"');
		sHtml.push(' count="' + productLine.Count + '"');
		sHtml.push(' productnr="' + this.DocumentId + '"');
		sHtml.push(' lineNo="' +  productLine.LineNo + '"');
		sHtml.push(' colorId="0"');
		sHtml.push(' sizeId="0"');
		sHtml.push(' sexId="0"');
		sHtml.push('>');
		sHtml.push('<fromName><![CDATA[' +  productLine.FromName + ']]></fromName>');
		sHtml.push('<toName><![CDATA[' +  productLine.ToName + ']]></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;
}

