$(document).ready(function() {
	onDocumentReady();
});

function onDocumentReady() {
	setNumericFields();
	$("[type=submit]").button();
	$("[type=button]").button();
	$(".button").button();
}

function setNumericFields() {
	$(".numeric").live("blur", function(){
		var value = $(this).val();
		var formatStr = $(this).attr("format");
		var allowNeg = $(this).attr("allow_negative");
							
		if(allowNeg) {
			if(allowNeg.toLowerCase().indexOf("no") > 0 ||
			   allowNeg.toLowerCase().indexOf("false") ||
			   allowNeg.toLowerCase().indexOf("0")) {
				$(this).val(value.replace(/-/gi, ""));
			}
		}
		
		if(formatStr) {
			formatStr = formatStr.replace(/_/gi, "#");
			$(this).parseNumber({format:formatStr});
			$(this).formatNumber({format:formatStr});
		}
		else {
			$(this).parseNumber();
			$(this).formatNumber();
		}
	});	
}

Array.prototype.find = function(v) {
	if (this.length == 0) return -1;
	
	for(i=0; i < this.length; i++) {
		if(this[i].value == v) {
			return i;	
		}
	}	
	
	return -1;
};
