
var AOFCTLS_DEFAULTS = {
	basePath: '/great-taste/includes/js/form-controls'
};

var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", AOFCTLS_DEFAULTS.basePath + '/style/aofctls.css');

if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref);

function CurrencyField (cfg) {
	
	this.FormatCurrency = CurrencyField.FormatCurrency; 

	this.cfCtl = document.getElementById(cfg.controlname);
	
	this.cfCtl.onchange = function() { CurrencyField.FormatCurrency(this); };
	this.cfCtl.onfocus = function() { this.select(); };

	CurrencyField.FormatCurrency(this.cfCtl);
};

CurrencyField.FormatCurrency = function (ctl) {
	
	var num = ctl.value;
	
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		return;
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	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));
	ctl.value = (((sign)?'':'-') + num + '.' + cents);	
	
};

if (!this.Radio) {
	Radio = {};
}

Radio.GetValue = function (name) {
	
	var radios = document.getElementsByName(name);
	
	for (var i=0; i < radios.length; i++) {
		if (radios[i].checked) {
			return radios[i].value;
		}
	}

	return null;
};

