function IsNumeric(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	if(sText.length == 0)
		return false;
	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if(ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
			}
		}
	return IsNumber;
}
function formatNumber(dNum) {
	var sNum = dNum.toFixed(0);
	return sNum.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + ",");	
}
$(function() {
	$(".info").hover(
		function () {
			$(this).parent().parent().find(".hint").show();
		},
		function () {
			$(this).parent().parent().find(".hint").hide();
		}
	);
	$("input").change(function () {
		var trafficBase = $("#trafficBase").val();
		var convRate = $("#convRate").val();
		var newConvRate = $("#newConvRate").val();
		var avgSale = $("#avgSale").val();
		var seoCost = $("#seoCost").val();
		if(IsNumeric(trafficBase) && IsNumeric(convRate) && IsNumeric(newConvRate) && IsNumeric(avgSale) && IsNumeric(seoCost)) {
			var newClient = trafficBase * (newConvRate - convRate) / 100;
			var newRev = newClient * avgSale;
			var cost = seoCost / 12 / newClient;
			var yrRev = newRev * 12;
			var yrCost = cost * newClient * 12;
			$("#newClient").html(formatNumber(newClient * 12));
			// $("#newRev").html(newRev.toFixed(0));
			$("#cost").html(formatNumber(cost));
			$("#newRevYear").html(formatNumber(yrRev - yrCost - seoCost));
		}
	});
});