//The following are the scripts for calculating overtime pay; for verifying that only numbers
//are entered into number entry fields; for formatting the calculated results; and for
//initializing certain fields. They were developed by the author of the book Especially for
//Texas Employers for the 2011 online edition.
//Reset the relevant text fields on the page
function reset2Rates() {
wtavg.job1.value = "Job 1 hours?";
wtavg.pay1.value = "1st pay rate?";
wtavg.job2.value = "Job 2 hours?";
wtavg.pay2.value = "2nd pay rate?";
wtavg.straightpay1.value = "";
wtavg.straightpay2.value = "";
wtavg.totalpay1.value = "";
wtavg.totalhours.value = "";
wtavg.wtavg1.value = "";
wtavg.halfrr1.value = "";
wtavg.ot1.value = "";
wtavg.totalpay2.value = "";
wtavg.grosspay1.value = "";
wtavg.job1.select();
}
//**Calculate gross pay using the weighted-average method
function wtavgcalc() {
var hours1 = document.wtavg.job1.value * 1;
var payrate1 = document.wtavg.pay1.value *1;
var hours2 = document.wtavg.job2.value * 1;
var payrate2 = document.wtavg.pay2.value *1;
var stpay1 = Math.round((hours1 * payrate1) * 100) / 100;
var stpay2 = Math.round((hours2 * payrate2) * 100) / 100;
var stpay = stpay1 + stpay2;
var thours = hours1 + hours2;
var wtavg = Math.round((stpay / thours) * 100) / 100;
if (wtavg < 7.25) {
wtavg = 7.25;
alert("Since the total straight-time pay divided by the hours worked is below the minimum wage, the law deems the regular rate of pay to be $7.25 for the purpose of the overtime calculation.");}
var halfrr = Math.round((wtavg / 2) * 100) / 100;
var ot = Math.round((thours - 40) * 100) / 100;
var extraotpay = Math.round((halfrr * ot) * 100) / 100;
var grosspay = extraotpay + stpay;
var stpay1str = stpay1.toString();
if (stpay1str.charAt(stpay1str.length - 2) == ".") {
document.wtavg.straightpay1.value = "$" + stpay1 + "0";}
else if ((Math.round(stpay1) - stpay1) == 0) {
document.wtavg.straightpay1.value = "$" + stpay1 + ".00";}
else {
document.wtavg.straightpay1.value = "$" + stpay1;}
var stpay2str = stpay2.toString();
if (stpay2str.charAt(stpay2str.length - 2) == ".") {
document.wtavg.straightpay2.value = "$" + stpay2 + "0";}
else if ((Math.round(stpay2) - stpay2) == 0) {
document.wtavg.straightpay2.value = "$" + stpay2 + ".00";}
else {
document.wtavg.straightpay2.value = "$" + stpay2;}
var stpaystr = stpay.toString();
if (stpaystr.charAt(stpaystr.length - 2) == ".") {
document.wtavg.totalpay1.value = "$" + stpay + "0";}
else if ((Math.round(grosspay) - grosspay) == 0) {
document.wtavg.totalpay1.value = "$" + stpay + ".00";}
else {
document.wtavg.totalpay1.value = "$" + stpay;}
document.wtavg.totalhours.value = thours;
var wtavgstr = wtavg.toString();
if (wtavgstr.charAt(wtavgstr.length - 2) == ".") {
document.wtavg.wtavg1.value = "$" + wtavg + "0" + "/hour";}
else if ((Math.round(grosspay) - grosspay) == 0) {
document.wtavg.wtavg1.value = "$" + wtavg + ".00" + "/hour";}
else {
document.wtavg.wtavg1.value = "$" + wtavg + "/hour";}
var halfrrstr = halfrr.toString();
if (halfrrstr.charAt(halfrrstr.length - 2) == ".") {
document.wtavg.halfrr1.value = "$" + halfrr + "0";}
else if ((Math.round(halfrr) - halfrr) == 0) {
document.wtavg.halfrr1.value = "$" + halfrr + ".00";}
else {
document.wtavg.halfrr1.value = "$" + halfrr;}
document.wtavg.ot1.value = ot;
document.wtavg.totalpay2.value = document.wtavg.totalpay1.value;
var grosspaystr = grosspay.toString();
if (grosspaystr.charAt(grosspaystr.length - 2) == ".") {
document.wtavg.grosspay1.value = "$" + grosspay + "0";}
else if ((Math.round(grosspay) - grosspay) == 0) {
document.wtavg.grosspay1.value = "$" + grosspay + ".00";}
else {
document.wtavg.grosspay1.value = "$" + grosspay;}
}
//49
function filterEntry(field) {
var onlynumbers = field.value;
onlynumbers = onlynumbers.replace(/\$|\,/g,"");
field.value = onlynumbers;
}//
//91
//Calculate overtime under the fixed salary-fluctuating workweek method
function fixedsalarycalc() {
var salary = document.fxsalary.fxsalary1.value *1;
var hours = document.fxsalary.fxhours1.value * 1;
var regulrate = Math.round((salary / hours) * 100) / 100;
if (regulrate < 7.25) {
regulrate = 7.25;
alert("Since the salary divided by the hours worked is below the minimum wage, the law deems the regular rate of pay to be $7.25 for the purpose of the overtime calculation.");}
var halfrr = Math.round((regulrate / 2) * 100) / 100;
var ot = Math.round((hours - 40) * 100) / 100;
var extraotpay = Math.round((halfrr * ot) * 100) / 100;
var grosspay = Math.round((extraotpay + salary) * 100) / 100;
var regulratestr = regulrate.toString();
if (regulratestr.charAt(regulratestr.length - 2) == ".") {
document.fxsalary.fxregulrate1.value = "$" + regulrate + "0";}
else if ((Math.round(regulrate) - regulrate) == 0) {
document.fxsalary.fxregulrate1.value = "$" + regulrate + ".00";}
else {
document.fxsalary.fxregulrate1.value = "$" + regulrate;}
var grosspaystr = grosspay.toString();
if (grosspaystr.charAt(grosspaystr.length - 2) == ".") {
document.fxsalary.fxgrosspay1.value = "$" + grosspay + "0";}
else if ((Math.round(grosspay) - grosspay) == 0) {
document.fxsalary.fxgrosspay1.value = "$" + grosspay + ".00";}
else {
document.fxsalary.fxgrosspay1.value = "$" + grosspay;}
}
//Reset the relevant text fields on the fixed salary page
function resetfxsalary() {
fxsalary.fxsalary1.value = "Salary?";
fxsalary.fxhours1.value = "Total hours?";
fxsalary.fxregulrate1.value = "";
fxsalary.fxgrosspay1.value = "";
fxsalary.fxsalary1.select();
}