function wissel(obj,fname)
{
	obj.src = 'images/menu/' + fname;
};

function changeCatPriceList(objItem)
{
	if (objItem.selectedIndex > -1 )
	{
		var c = objItem.options[objItem.selectedIndex].value;
	    window.document.location = '?p=3&c=' + c;
    };
};

function changeBasket(objItem,oId,bRid)
{
   window.document.location = '?p=4&a=changebasket&cnt=' + objItem.value + '&id=' + oId + '&rid=' + bRid;
};

function sameAddress(objItem)
{
	if (objItem.checked == true )
	{
		document.getElementById('del_address').value = document.getElementById('address').value;
		document.getElementById('del_zipcode').value = document.getElementById('zipcode').value;
		document.getElementById('del_city').value = document.getElementById('city').value;
		document.getElementById('del_country').value = document.getElementById('country').value;
	};
};

function addPoint(nStr)
{
	var x,x1,x2;
	
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x[1];
	if (isNaN(x2))
	{
		return x1 + '.00';
	}
	else if (x2.length==1)
	{
		return x1 + '.' + x2 + '0';
	} else
	{
		return x1 + '.' + Math.round(x2);
	};
	return '00.00';
}

function addPrice(objItem,catId)
{
	var cTotal;  // set total for this category to new ammount
	cTotal = document.getElementById(catId);
	cTotal.value = objItem.value;

	
	var cItems;  // get all input items
	cItems = document.getElementsByTagName('INPUT');
	
	var i;
	var naam;
	var cMeerprijzen,cTotaalPrijs;
	cMeerprijzen = 0;
	for (i=0;i<cItems.length;i++)
	{
		naam = cItems[i].name;
		if ( naam.indexOf('cat_price') == 0 ) // check if the item is a category_price
		{
			cMeerprijzen = parseFloat(cMeerprijzen) + parseFloat(cItems[i].value);
		};
	}
	//cMeerprijzen=addPoint(cMeerprijzen.toFixed(2));
	document.getElementById('meerMinderPrijzen').innerHTML = '<b>&euro; ' + num2money(cMeerprijzen) + '</b>';
	cTotaalPrijs =  parseFloat(parseFloat(document.getElementById('system_price').value) + parseFloat(cMeerprijzen));
	cTotaalPrijs = addPoint(cTotaalPrijs.toFixed(2));
	document.getElementById('totaalPrijs').innerHTML = '&euro; ' + num2money(cTotaalPrijs) + '';
	document.getElementById('sprijsdetail').innerHTML = '&euro; ' + num2money(cTotaalPrijs) + '';
};

function num2money(n_value) {

// validate input
if (isNaN(Number(n_value)))
return 'ERROR';

// save the sign
var b_negative = Boolean(n_value < 0);
n_value = Math.abs(n_value);

// round to 1/100 precision, add ending zeroes if needed
var s_result = String(Math.round(n_value*1e2)%1e2 + '00').substring(0,2);

// separate all orders
var b_first = true;
var s_subresult;
while (n_value > 1) {
s_subresult = (n_value >= 1e3 ? '00' : '') + Math.floor(n_value%1e3);
s_result = s_subresult.slice(-3) + (b_first ? '.' : ',') + s_result;
b_first = false;
n_value = n_value/1e3;
}
// add at least one integer digit
if (b_first)
s_result = '0.' + s_result;

// apply formatting and return
return b_negative
? '- ' + s_result + ''
: '' + s_result;
}

