function fmtEarn(value)
{
   result = Math.floor(value)+".";
   var cents = 100*(value-Math.floor(value));
   result += Math.floor(cents/10);
   result += Math.floor(cents%10);
   return result;
}

function fmtPrice(value)
{
   result = "$ "+Math.floor(value)+".";
   var cents = 100*(value-Math.floor(value));
   result += Math.floor(cents/10);
   result += Math.floor(cents%10);
   return result;
}

function calcqtr(value)
{
	quarter = value*.125;
	if (quarter <= 50)
		{	quarter = 50 }
	else 
		{	quarter = Math.round(quarter*100)/100 };
	return quarter;
}

function calcmnth(value)
{
	q = value*.125;
	m = q / 3;
	if (q <= 50)
		{	m = Math.round((50/3)*100)/100 }
	else
		{	m = Math.round(m*100)/100	};
	return m;
}

function calcwk(value)
{
	q = value*.125;
	w = q / 13
	if (q <= 50)
		{	w = Math.round((50/13)*100)/100 }
	else
		{	w = Math.round(w*100)/100 };
	return w;
}

function checkearnings(earnings)
{
	re2 = /^\d+$/
	re = /^\d+[.]\d{0,2}$/
	if (re.test(earnings.value) || re2.test(earnings.value))
		{	data = "GOOD" }
	else 
		{ data = "BAD" }
}

function checkwks()
{
	re = /^\d{1,2}$/
	if (re.test(document.PTDues.weeks.value))
		{	if ((document.PTDues.weeks.value < 1) || (document.PTDues.weeks.value > 13))
			{	data = "BAD";
				document.PTDues.PTEarnings.value = fmtEarn(document.PTDues.PTEarnings.value)
				alert("Please input a valid number of weeks that you worked.");
				document.PTDues.weeks.focus();
				document.PTDues.weeks.select()
			}
		}
	else	
		{	data = "BAD";
			alert("Please input a valid number of weeks that you worked.");
			document.PTDues.weeks.focus();
			document.PTDues.weeks.select()
		}
}

function calcfull()
{
	checkearnings(document.FullDues.Earnings);
	if (data == "GOOD")
		{	document.FullDues.FullQuarter.value = fmtPrice(calcqtr(document.FullDues.Earnings.value));
			document.FullDues.FullMonth.value = fmtPrice(calcmnth(document.FullDues.Earnings.value));
			document.FullDues.FullWeek.value = fmtPrice(calcwk(document.FullDues.Earnings.value));
			document.FullDues.Earnings.value = fmtEarn(document.FullDues.Earnings.value);
		}
	else
		{	alert("Incorrect format for your Earnings. (####.##)");
			document.FullDues.Earnings.focus();
			document.FullDues.Earnings.select()
		}
}

function calcpt()
{
	checkearnings(document.PTDues.PTEarnings);
	if (data == "GOOD")
		{ checkwks() }
	else
		{	alert("Incorrect format for your Earnings. (####.##)");
			document.PTDues.PTEarnings.focus();
			document.PTDues.PTEarnings.select()
		};
	if (data == "GOOD")
		{	document.PTDues.PTQuarter.value = fmtPrice(calcqtr(document.PTDues.PTEarnings.value/document.PTDues.weeks.value));
			document.PTDues.PTEarnings.value = fmtEarn(document.PTDues.PTEarnings.value)
		}
}