function currencyFormat(num) {
	var sign;
	var cents;

	// Parse as string
	num = num.toString();

	// Remove everything except numbers, periods and dashes
	num = num.replace(/[^0-9.-]/g, '');
	if (num === '') {
		return '';
	}

	// Positive or negative number?
	if (num.substr(0, 1) == '-') {
		sign = '-';
	} else {
		sign = '';
	}

	// Remove dashes
	num = num.replace(/[\-]/g, '');

	// Convert to a float
	num = parseFloat(num);
	if (isNaN(num)) {
		return '0.00';
	}

	// Get two decimal places
	num = Math.floor(num*100 + 0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if (cents < 10) {
		cents = "0" + cents;
	}

	// Insert commas
	num = num.toString();
	for (var i=0; i<Math.floor((num.length - (1 + i))/3); i++) {
		num = num.substring(0, num.length - (4*i + 3))+","+num.substring(num.length - (4*i + 3));
	}

	// No negative zero
	if (sign == '-' && num == '0' && cents == '00') {
		sign = '';
	}

	// Concatenate and return
	return sign+num+'.'+cents;
}

function integerFormat(num, groupThousands) {

	// Parse as integer
	num = num.toString().replace(/[^0-9.-]/g, "");
	if (num === '') {
		return '';
	}

	// Positive or negative number?
	var sign = num == (num = Math.abs(num))? "" : "-";

	// Round off decimal places
	num = Math.round(num);
	num = num.toString();

	// Insert commas
	if (groupThousands != false) {
		for (var i=0; i<Math.floor((num.length - (1 + i))/3); i++) {
			num = num.substring(0, num.length - (4*i + 3))+","+num.substring(num.length - (4*i + 3));
		}
	}

	// Return
	return sign+num;
}

function toInteger(num) {
	return parseInt(num.toString().replace(/[^0-9.-]/g, "" ));
}

function toFloat(num) {
	num = num.toString().replace(/[^0-9.\-]/g, '');
	if (num.substr(0, 1) == '-') {
		num = '-'+num.replace(/[^0-9.]/g, '');
	} else {
		num = num.replace(/[^0-9.]/g, '');
	}
	num = parseFloat(num);
	return num;
}

function getRadioValue(radioObj) {
	if (!radioObj) {
		return false;
	}
	if (radioObj.length == undefined) {
		if (radioObj.checked) {
			return radioObj.value;
		} else {
			return false;
		}
	}
	for (var i=0; i<radioObj.length; i++)	{
		if (radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return false;
}

function checkboxlistEmpty(id) {
	var empty = true;
	$$('#'+id+' input[type=checkbox]').each(function (elem) {
		if (elem.checked == true) {
			empty = false;
		}
	});
	return empty;
}


function $RF(el, radioGroup) {
    if($(el).type && $(el).type.toLowerCase() == 'radio') {
        var radioGroup = $(el).name;
        var el = $(el).form;
    } else if ($(el).tagName.toLowerCase() != 'form') {
        return false;
    }

    var checked = $(el).getInputs('radio', radioGroup).find(
        function(re) {return re.checked;}
    );
    return (checked) ? $F(checked) : null;
}