﻿function appendOptionToSelect(select, text, value) {
	if (text == undefined || value == undefined) {
		return select;
	}

	return select
		.append(
			$('<option></option>')
				.attr('value', value)
				.text(text));
}

Number.prototype.fraction = function (decimal) {
	if (!decimal) {
		decimal = this;
	}

	if (String(decimal).indexOf('.') == -1) {
		return decimal;
	}

	var whole = String(decimal).split('.')[0];
	decimal = parseFloat("." + String(decimal).split('.')[1]);
	var num = "1";
	for (var z = 0; z < String(decimal).length - 2; z++) {
		num += "0";
	}
	decimal = decimal * num;
	num = parseInt(num);
	for (var z = 2; z < decimal + 1; z++) {
		if (decimal % z == 0 && num % z == 0) {
			decimal = decimal / z;
			num = num / z;
			z = 2;
		}
	}
	return ((whole == 0) ? "" : whole + " ") + decimal + "/" + num;
}
