function intval (mixed_var, base) 
{
	// Get the integer value of a variable using the optional base for the conversion  
    // 
    // version: 910.813
    // discuss at: http://phpjs.org/functions/intval    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Matteo
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4
    // *     example 3: intval(42, 8);    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9
    // *     example 5: intval('1e', 16);
    // *     returns 5: 30
	
    var tmp;

	var type = typeof(num);
	
	tmp = parseInt(mixed_var, base || 10);
    return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;
}

function chgNumber(num, amt, dir)
{
	var numI = intval(num);
	
	if(dir == 'up')
	{
		return (numI + amt);
	}
	
	if(dir == 'down')
	{
		newNum = numI - amt;
		
		return (newNum < 0) ? 0 : newNum;
	}
}

function numberFormat(nStr, prefix)
{
	var prefix = prefix || '';
	nStr += '';
	
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	
	var rgx = /(\d+)(\d{3})/;
	
	while (rgx.test(x1))
    	x1 = x1.replace(rgx, '$1' + ',' + '$2');
	
    return prefix + x1 + x2;
}

function updateTotal(quantity, price, symbol)
{
	var num = quantity * price;
	
	if(num < 0)
		num = 0;

	return numberFormat(num.toFixed(2), symbol)
}

var valueArr = [];

function updateGrandTotal(currencySymbol, arr, cartTotalWithoutItem)
{
	var grandTotal = 0;
	
	arr.each(function(item) {
//			alert($(item[0]).value);
//			alert(item[1]);
		grandTotal = grandTotal + ($(item[0]).value * item[1]);
	});
	
	var totalTotal = cartTotalWithoutItem + grandTotal;
	
	$('item-grand-total').update(numberFormat(grandTotal.toFixed(2), currencySymbol));
	$('item-combined-total').update(numberFormat(totalTotal.toFixed(2), currencySymbol));
}

var valueArrOld = [];

function updateGrandTotalOld(currencySymbol, arr, cartTotalWithoutItem)
{
	var grandTotal = 0;
	
	arr.each(function(item) 
	{
//		alert($(item[0]).value);
//		alert(item[1]);
			
		grandTotal = grandTotal + ($(item[0]).value * item[1]);
	});
	
	var totalTotal = cartTotalWithoutItem + grandTotal;
	
	$('old-item-grand-total').update(numberFormat(grandTotal.toFixed(2), currencySymbol));
	$('old-item-combined-total').update(numberFormat((totalTotal).toFixed(2), currencySymbol));
}