function risicoTest()
{
	var oWin = window.open('/risicotest.aspx', 'risicotest', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=958,height=735');
	if (oWin) {
		if (oWin.focus) oWin.focus();
		return false;
	}
}

function ShowElement(id)
{
	var element= document.getElementById(id);
	if(element != null && element.className.indexOf('hiddentemp') != -1)
	{
		element.className = element.className.replace(/hiddentemp/g, '');
	}
}

function HideElement(id)
{
	var element= document.getElementById(id);
	if(element != null && element.className.indexOf('hiddentemp') == -1)
	{
		element.className = element.className + ' hiddentemp';
	}
}

function Quantity_OnKeyUp(sender,id)
{
    if(Number(sender.value) >= 1)
    {
	    Marlon.Vdv.Web.AsyncCalls.UpdateQuantity(id,Number(sender.value),UpdateQuantityCallBack,id);
	 }
}

function Quantity_OnBlur(sender,id)
{
    if(!Number(sender.value))
    {
	    sender.value = 1;
	    Marlon.Vdv.Web.AsyncCalls.UpdateQuantity(id,Number(sender.value),UpdateQuantityCallBack,id);
	}
}

function IncreaseQuantity(qfield,id)
{
	Marlon.Vdv.Web.AsyncCalls.IncreaseQuantity(id,IncreaseQuantityCallBack,id);
	RenderIncreasedQuantity(qfield);
}

function DecreaseQuantity(qfield,id)
{
	Marlon.Vdv.Web.AsyncCalls.DecreaseQuantity(id,DecreaseQuantityCallBack,id);
	RenderDecreasedQuantity(qfield);
}

function UpdateQuantityCallBack(response)
{
	if(response.error != null)
	{
		alert(response.error);
	}
	else
	{
		var productID = response.context;
		RenderTotals(productID,response.value);
	}
}

function IncreaseQuantityCallBack(response)
{
	if(response.error != null)
	{
		alert(response.error);
	}
	else
	{
		var productID = response.context;
		RenderTotals(productID,response.value);
	}
}

function DecreaseQuantityCallBack(response)
{
	if(response.error != null)
	{
		alert(response.error);
	}
	else
	{
		var productID = response.context;
		RenderTotals(productID,response.value);
	}
}

function RenderTotals(productID,items)
{
	var total = 0;
	for(var i = 0; i < items.length; i++)
	{
		if(items[i].Product.Id == productID)
		{
			var subtotalcontainer = document.getElementById("subtotal_" + productID);
			if(subtotalcontainer != null)
			{
				if(subtotalcontainer.hasChildNodes())
				{
					subtotalcontainer.removeChild(subtotalcontainer.childNodes[0]);
				}

				subtotalcontainer.appendChild(document.createTextNode(PrepareDecimal(items[i].Subtotal)));
				
				//Highlight("subtotalcell_" + productID);
			}
		}
		
		total += items[i].Subtotal;
	}
	
	var totalcontainer = document.getElementById("totalamount");
	if(totalcontainer != null)
	{
		totalcontainer.removeChild(totalcontainer.childNodes[0]);
		totalcontainer.appendChild(document.createTextNode(PrepareDecimal(total)));
		
		//Highlight("totalcell");
	}
}

function PrepareDecimal(input)
{
	//first, lets round
	input = Math.round(input*100);
	input = input/100;

	input = (input + '').replace('.',',');
	if(input.indexOf(",") == -1)
	{
		input = input + ',00';
	}
	else if(input.indexOf(",") < input.length-1)
	{
		input = input + '0';
	}
	
	return input;
}

function RenderIncreasedQuantity(qfield)
{
	var quantityfield = document.getElementById(qfield);
	if(quantityfield != null)
	{
		quantityfield.value = Number(quantityfield.value) + 1;
	}
}

function RenderDecreasedQuantity(qfield)
{
	var quantityfield = document.getElementById(qfield);
	if(quantityfield != null)
	{
		var display = Number(quantityfield.value) - 1;
		
		if(Number(display) < 1)
		{
			display = '1';
		}
		
		quantityfield.value = display;
	}
}

var fadeInterval = 300;

var startFadeAt = 7;

var fadeSteps = new Array();
	fadeSteps[1] = "ff";
	fadeSteps[2] = "ee";
	fadeSteps[3] = "dd";
	fadeSteps[4] = "cc";
	fadeSteps[5] = "bb";
	fadeSteps[6] = "aa";
	fadeSteps[7] = "99";

function Highlight(targetId)
{
    DoFade(startFadeAt, targetId);
}

function DoFade(colorId, targetId)
{
    if(colorId >= 1)
    {
		document.getElementById(targetId).style.color = "#ffff" + fadeSteps[colorId];
		
        // If it's the last color, set it to transparent
        if (colorId==1)
        {
            document.getElementById(targetId).style.color = "#ffffff";
		}
        colorId--;
		
        // Wait a little bit and fade another shade
        setTimeout("DoFade("+colorId+",'"+targetId+"')", fadeInterval);
	}
}

/*
JSTarget function by Roger Johansson, www.456bereastreet.com
*/
var JSTarget = {
	init: function(att,val) {
		if (document.getElementById && document.createElement && document.appendChild)
		{
			var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att;
			var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val;
			var arrLinks = document.getElementsByTagName('a');
			var oLink;
			var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
			for (var i = 0; i < arrLinks.length; i++)
			{
				oLink = arrLinks[i];
				if ((strAtt == 'class' && oRegExp.test(oLink.className)) || oRegExp.test(oLink.getAttribute(strAtt)))
				{
					if(val == 'external')
					{
						oLink.onclick = JSTarget.openWin;
					}
					else
					{
						oLink.onclick = JSTarget.openPopup;
					}
				}
			}
		}
	},
	openWin: function(e) {
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
		else {
		    var oWin = window.open(this.getAttribute('href'), '_blank');
			if (oWin) {
				if (oWin.focus) oWin.focus();
				return false;
			}
			oWin = null;
			return true;
		}
	},
	openPopup: function(e) {
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
		else {
		    var oWin = window.open(this.getAttribute('href') + '?popup', 'memberinfo', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=550,height=400');
			if (oWin) {
				if (oWin.focus) oWin.focus();
				return false;
			}
			oWin = null;
			return true;
		}
	},
	/*
	addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
	*/
	addEvent: function(obj, type, fn)
	{
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent)
		{
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn]( window.event );}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
JSTarget.addEvent(window, 'load', function(){JSTarget.init("rel","external");});
JSTarget.addEvent(window, 'load', function(){JSTarget.init("rel","popup");});