﻿function AddItemToBasket(itemID)
{
	var num = document.getElementById("number_textbox");
	if (!num) num = document.getElementById("number_textbox_" + itemID);
	var size = document.getElementById("size_select");
	var numval = 1;

	if(num) numval = num.value;

	if(size) itemID = size.options[size.selectedIndex].value;

	AddToBasket(itemID,numval);

	return false;
}

function VarietyHandler(priceContainerID, destContainerID, destContainerRowID)
{
	this.Items = new Array();
	this.PriceContainer = document.getElementById(priceContainerID);
	var destContainer = document.getElementById(destContainerID);
	var destRow = document.getElementById(destContainerRowID);

	this.Add = function(intID,strName,intPrice,intSalePrice)
	{
		var o = new Object();
		o.id = intID;
		o.name = strName;
		o.intPrice = intPrice;
		o.intSalePrice = intSalePrice;
		this.Items.push(o);
	}

	this.SetPrice = function(i)
	{
		var price = this.Items[i].intPrice;

		if(parseFloat(this.Items[i].intSalePrice) > 0)
		{
			price += "<span class='sale_price'> - Tilbud: " + this.Items[i].intSalePrice + "</span>";
		}

		this.PriceContainer.innerHTML = price;		
	}

	this.OnChangeHandler = function()
	{
		var i = this.selectedIndex;
		vHandler.SetPrice(i);
	}

	this.Render = function()
	{
		if(this.Items.length > 0)
		{
			var select = document.createElement("select");
			select.id = "size_select";
			select.onchange = this.OnChangeHandler;

			for(var i = 0; i < this.Items.length; i++)
			{
				var option = document.createElement("option");
				option.value = this.Items[i].id;
				option.innerHTML = this.Items[i].name;
				select.appendChild(option);
			}

			this.SetPrice(0);
			destContainer.appendChild(select);
			destRow.style.display = "block";
		}
	}
}

function CopyValue(source, target)
{
	this.SourceElement = null;
	this.TargetElement = null;

	this.Init = function()
	{
		cv.SourceElement = document.getElementById(source);
		cv.TargetElement = document.getElementById(target);

		cv.SourceElement.onblur = cv.OnBlurHandler;
	}

	this.Copy = function()
	{
		this.TargetElement.value = this.SourceElement.value;

	}

	this.OnBlurHandler = function()
	{
		cv.Copy();
	}
}