jQuery(function(){
	numberInput.init();
});


var toolbox = {
	showFormError: function(id, message) {
		var msg = jQuery('#' + id);
		msg.slideUp(200, function() {
			msg.text(message).slideDown();
		});
	}
};


var numberInput = {
	init: function() {
		jQuery('input.number').keypress(function(e) {
			numberInput.keyPress(e);
		});
	},


	keyPress: function(e) {
		// Ctrl, tab, F5, delete,
		// left, right, home, end
		// backspace, numbers
		var allowed = e.ctrlKey || e.keyCode == 9 || e.keyCode == 116 || e.keyCode == 46 ||
				e.keyCode == 37 || e.keyCode == 39 || e.keyCode == 36 || e.keyCode == 35 ||
				e.which == 8 || e.which >= 48 && e.which <= 57;
		if(!allowed) e.preventDefault();
		return allowed;
	}
};


/*
 * c: tizedesek
 * d: tizedesjel
 * t: ezreselválasztó
 */
Number.prototype.formatMoney = function(c, d, t) {
	var n = this,
		c = isNaN(c = Math.abs(c)) ? 2 : c,
		d = d == undefined ? ',' : d,
		t = t == undefined ? '.' : t,
		s = n < 0 ? '-' : '',
		i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + '',
		j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');
};


String.prototype.validateEmail = function() {
	re = new RegExp("^[0-9a-z]+[0-9a-z._+\-]*@([0-9a-z]+)([.\-]([0-9a-z]+))+$", "gi");
	return re.test(this);
}
