﻿/**********************************************
Dette script er udviklet af Tangora Partneren:

PinfoVejle - www.prinfovejle.dk

Scriptet må IKKE anvendes på andre websites uden
samtykke fra PrinfoVejle. Andre Tangora Partnere 
skal også indhente tilladdelse til anvendelse af 
scriptet.
************************************************/

var priceArr;
priceArr = new Array();

function newProduct(subproductID,size,color)
{
	statusok = false;
	if (produktArr[curProduct].length == 0)
	{
		produktArr[curProduct][0] = new Array();
		produktArr[curProduct][0][0] = size;
		produktArr[curProduct][0][1] = new Array();
		produktArr[curProduct][0][1][0] = color + "|" + subproductID;
		
		statusok = true;		
	}

	if (!statusok)
	{
		for (j = 0; j < produktArr[curProduct].length; j++)
		{
			if (produktArr[curProduct][j][0] == size)
			{
				produktArr[curProduct][j][1][produktArr[curProduct][j][1].length] = color + "|" + subproductID;
				statusok = true;
			}
		}
	}
	
	if (!statusok)
	{
		// størrelsen skal oprettes i arrayet.
		newpos = produktArr[curProduct].length;
		
		produktArr[curProduct][newpos] = new Array();
		produktArr[curProduct][newpos][0] = size;
		produktArr[curProduct][newpos][1] = new Array();
		produktArr[curProduct][newpos][1][0] = color + "|" + subproductID;		

	}	
}
function newPrice(subproductID, price)
{
	priceArr[subproductID] = price;
}


function N(subproductID,size,color,price)
{
	newProduct(subproductID,size,color);
	newPrice(subproductID,price);
}

function updateColorList(selBoks, prodID)
{
	if (selBoks[selBoks.selectedIndex].value == "")
	{
		document.getElementById('color' + prodID).options.length = 0;
		document.getElementById('color_container' + prodID).style.display = 'none';
		document.getElementById('color_container_sel' + prodID).style.display = 'none';		
	}
	else
	{
		document.getElementById('color' + prodID).options.length = 0;
		document.getElementById('color' + prodID).options[0] = new Option("(vælg)","");
		for (k = 0; k < produktArr[prodID][selBoks.selectedIndex-1][1].length; k++)
		{
			valueArr = produktArr[prodID][selBoks.selectedIndex-1][1][k].split("|");
			
			document.getElementById('color' + prodID).options[k+1] = new Option(valueArr[0],valueArr[1]);

		}
		document.getElementById('color_container' + prodID).style.display = 'block';
		document.getElementById('color_container_sel' + prodID).style.display = 'block';		
	}
	document.getElementById('priceview' + prodID).style.display = 'none';	
}

function updatePrice(selBoks, prodID)
{
	variantSel = selBoks[selBoks.selectedIndex].value;
	if (variantSel != "")
	{
		document.getElementById('priceview' + prodID).innerHTML = '<b>DKK ' + priceArr[variantSel] + '</b><br><br>';
		document.getElementById('priceview' + prodID).style.display = 'block';	
	}
}

function makeBoxes(ProductID)
{
	if (produktArr[ProductID].length == 0)
		document.write('<div style="display:none;">');
		
	document.write('<table border="0" cellpadding="0" cellspacing="0">');
	document.write('<tr>');
	document.write('<td class="section">St&oslash;rrelse:&nbsp;</td><td><select name="size' + ProductID + '_name" id="size' + ProductID + '" onchange="updateColorList(this, ' + ProductID + ');">');
	document.write('<option value="">(v&aelig;lg)</option>');
	for (j = 0; j < produktArr[ProductID].length; j++)
	{
		document.write('<option value="' + produktArr[ProductID][j][0] + '">' + produktArr[ProductID][j][0] + '</option>');
	}
	document.write('</select></td><td>&nbsp;</td><td class="section">');
	
	document.write('<div id="color_container' + ProductID + '" style="display:none;">Farve:&nbsp;</div></td><td><div id="color_container_sel' + ProductID + '" style="display:none;"><select name="color' + ProductID + '_name" id="color' + ProductID + '" onchange="updatePrice(this, '+ProductID + ');"></select></div>');
	document.write('</td></tr>');
	document.write('</table><br>');
	document.write('<div id="priceview' + ProductID + '" style="display:none;" class="section"></div>');
	
	if (produktArr[ProductID].length == 0)
		document.write('</div>');	
}

function AddVariantToBasket(ProductID)
{
	sizebox = document.getElementById('size' + ProductID);
	colorbox = document.getElementById('color' + ProductID);
	
	if (sizebox.options.length == 1)
	{
		AddToBasket(ProductID,1);
	}
	else
	{
		if (sizebox[sizebox.selectedIndex].value == "" || colorbox[colorbox.selectedIndex].value == "")
		{
			alert('Vælg venligst størrelse og farve.');	
		}
		else
		{
			AddToBasket(colorbox[colorbox.selectedIndex].value,1);
		}
	}
}
