// General Calculator

function checkNumber(form)
{
 if(form.totalcost.value==''){
          form.totalcost.value="000000.00";
          alert ("Please enter an amount.")
          form.totalcost.focus();
          form.totalcost.select();
          }
   status=''
    var str = form.totalcost.value;
    for (var i = 0; i < str.length; i++)        
                {var ch = str.substring(i, i + 1)
        if ((ch < "0" || "9" < ch) && ch != '.') {
                        form.totalcost.value=form.totalcost.value;
                        alert (form.notes.value="Please enter only number values");
                        form.totalcost.focus();
                        form.totalcost.select();
                        } 
           }   
  quote(form)
 }
 
function checkFloat(i)
{
	var txttext=i;
	var regex=/[0-9]$/;
	return regex.test(txttext);	
}
 
function fmtPrice(value)
{
result="$"+Math.floor(value)+".";
var cents=100*(value-Math.floor(value))+0.5;
return result;
}
function quote(form)
{
    form.notes.value="Actual payment may vary based on credit approval";

// This is where you chnage the values

if (form.totalcost.value<=1999 && form.totalcost.value>=1)
     {
     form.pmt24.value=" ";
     form.pmt36.value=" ";
     form.pmt48.value=" ";
     form.pmt60.value=" ";
     form.notes.value=" Minimum amount to calculate is $2000. ";
     }
if (form.totalcost.value<=3999 && form.totalcost.value>=2000)
     {
      form.pmt24.value=fmtPrice(form.totalcost.value*.05064);
      form.pmt36.value=fmtPrice(form.totalcost.value*.03386);
      form.pmt48.value=fmtPrice(form.totalcost.value*.02659);
      form.pmt60.value="N/A";
       }
if (form.totalcost.value<=14999 && form.totalcost.value>=4000)
     {
      form.pmt24.value=fmtPrice(form.totalcost.value*.05064);
      form.pmt36.value=fmtPrice(form.totalcost.value*.03386);
      form.pmt48.value=fmtPrice(form.totalcost.value*.02659);
      form.pmt60.value=fmtPrice(form.totalcost.value*.02286);
      }
if (form.totalcost.value<=100000 && form.totalcost.value>=15000)
     {
      form.pmt24.value=fmtPrice(form.totalcost.value*.04969);
      form.pmt36.value=fmtPrice(form.totalcost.value*.03386);
      form.pmt48.value=fmtPrice(form.totalcost.value*.02659);
      form.pmt60.value=fmtPrice(form.totalcost.value*.02286);
      }
if (form.totalcost.value>100001)
     {
     form.pmt24.value=" ";
     form.pmt36.value=" " ;
     form.pmt48.value=" ";
     form.pmt60.value=" ";
     form.notes.value="For amounts over $100,000.00 please e-mail/call for quote";
    }

}
function reset(form)
{
form.totalcost.value="";
form.pmt24.value="";
form.pmt36.value="";
form.pmt48.value="";
form.pmt60.value="";
form.notes.value="";

}

// Hatchett Calculator

function checkNumber2(form)
{
 if(form.totalcost.value==''){
          form.totalcost.value="000000.00";
          alert ("Please enter an amount.")
          form.totalcost.focus();
          form.totalcost.select();
          }
   status=''
    var str = form.totalcost.value;
    for (var i = 0; i < str.length; i++)        
                {var ch = str.substring(i, i + 1)
        if ((ch < "0" || "9" < ch) && ch != '.') {
                        form.totalcost.value=form.totalcost.value;
                        alert (form.notes.value="Please enter only number values");
                        form.totalcost.focus();
                        form.totalcost.select();
                        } 
           }   
  quote2(form)
 }
 
function checkFloat(i)
{
	var txttext=i;
	var regex=/[0-9]$/;
	return regex.test(txttext);	
}
 
function fmtPrice(value)
{
result="$"+Math.floor(value)+".";
var cents=100*(value-Math.floor(value))+0.5;
return result;
}
function quote2(form)
{
    form.notes.value="Actual payment may vary based on credit approval";

// This is where you change the values

if (form.totalcost.value<=1999 && form.totalcost.value>=1)
     {
     form.pmt24.value=" ";
     form.pmt36.value=" ";
     form.pmt48.value=" ";
     form.pmt60.value=" ";
     form.notes.value=" Minimum amount to calculate is $2000. ";
     }
if (form.totalcost.value<=3999 && form.totalcost.value>=2000)
     {
      form.pmt24.value=fmtPrice(form.totalcost.value*.04708);
      form.pmt36.value=fmtPrice(form.totalcost.value*.03289);
      form.pmt48.value=fmtPrice(form.totalcost.value*.02608);
      form.pmt60.value="N/A";
       }
if (form.totalcost.value<=14999 && form.totalcost.value>=4000)
     {
      form.pmt24.value=fmtPrice(form.totalcost.value*.04708);
      form.pmt36.value=fmtPrice(form.totalcost.value*.03289);
      form.pmt48.value=fmtPrice(form.totalcost.value*.02608);
      form.pmt60.value=fmtPrice(form.totalcost.value*.02180);
      }
if (form.totalcost.value<=100000 && form.totalcost.value>=15000)
     {
      form.pmt24.value=fmtPrice(form.totalcost.value*.04708);
      form.pmt36.value=fmtPrice(form.totalcost.value*.03289);
      form.pmt48.value=fmtPrice(form.totalcost.value*.02608);
      form.pmt60.value=fmtPrice(form.totalcost.value*.02180);
      }
if (form.totalcost.value>100001)
     {
     form.pmt24.value=" ";
     form.pmt36.value=" " ;
     form.pmt48.value=" ";
     form.pmt60.value=" ";
     form.notes.value="For amounts over $100,000.00 please e-mail/call for quote";
    }

}
function reset(form)
{
form.totalcost.value="";
form.pmt24.value="";
form.pmt36.value="";
form.pmt48.value="";
form.pmt60.value="";
form.notes.value="";

}



// Fee Calculator

function calculateFee()
{
	f = document.getElementById("feeform");
	val1 = document.getElementById("invoicetotal").value;
	term = f.term.value;

	if(checkFloat(val1))
	{
		//fee calculation 
		if(term==90) {factor = 0.045;}
		if(term==180) {factor = 0.070;}
		if(term==365) {factor = 0.10;}
		fee = val1 * factor;
		fee = format_number(fee,2);
		
		
		document.getElementById("fee").value = fee;
	}
	else
	{
		alert("Please enter Digits only.");
		document.getElementById("invoicetotal").focus();
	}

 }
function fmtPrice(value)
{
result="$"+Math.floor(value)+".";
var cents=100*(value-Math.floor(value))+0.5;
return result;
}


// This is where you chnage the values





function reset(form)
{
form.totalcost.value="";
form.pmt24.value="";
form.pmt36.value="";
form.pmt48.value="";
form.pmt60.value="";
form.notes.value="";

}

function format_number(pnumber,decimals){
	if (isNaN(pnumber)) { return 0};
	if (pnumber=='') { return 0};
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	if(sec.length > 1){
		var dec = new String(sec[1]);
	   dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
	   dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
	   var dot = dec.indexOf('.');
	   if(dot == -1){
		   dec += '.';
		   dot = dec.indexOf('.');
	   }
	   while(dec.length <= dot + decimals) { dec += '0'; }
	   result = dec;
   } else{
	   var dot;
	   var dec = new String(whole);
	   dec += '.';
	   dot = dec.indexOf('.');       
	   while(dec.length <= dot + decimals) { dec += '0'; }
	   result = dec;
  }   
   return result;
}
