
/*************************************
* Columbia EDP Check Cost Calculator *
* By: John Maier                     *
*     Midamerica Internet            *
* Date: 01/30/2001                   *
*
* modified 7/21/2003 reb
* 12/17/2004
* 12/23/2004
*************************************/
var paydone;  
function calc() {

	// Constant charge for number of checks written
	var TenOrLess = 1.65;
	var NextFive  = 1.15;
	var SixteenMore = 0.95;

	// Flat monthly Fees based on frequency of checks written.
	var MoreThanOnceAMonth = 6.00;
	var OnceAMonth=12.00;
	
	//Flat fees for Tax Processing
	var taxwkly = 3.50;
	var taxbiwkly = 7.00;
	var taxsemimo = 7.50;
	var taxmonthly = 15.00;
	
	// Fees for Direct Deposit
	var ddmonthly = 5.00;
	var ddtransmo = .10;
	
	 // wbsm - weekly,biweekly,semi-mo
	var ddwbsm = 2.50;          
	var ddtranswbsm = .10;
	
	// Fees for w-2's
	var w2fee = 2.00 ;
	
	
	var PerCheckCost = 0.00;
	var ProcessingFee = 0.00;
	var ddfee= 0.00;
	var ddcharges=0.00;
	var PerPayrollCost = 0.00;
	var AnnualPayrollCost = 0.00;
	
	// Form elements
	var CheckCount = parseInt(document.getElementById("checkcount").value) ;
	var CheckCount1 = parseInt(document.getElementById("checkcount1").value) ;
//	if(paydone="inside") {
//	    var payindex = document.getElementById("PayFreq").selectedIndex ;
//	    var PayFreq = parseInt(document.getElementById("PayFreq").options[payindex].value) ;
//	 }
//	 else
//	if(paydone="outside") {    
//	    var payindex = document.getElementById("PayFreq1").selectedIndex ;
//	    var PayFreq = parseInt(document.getElementById("PayFreq1").options[payindex].value) ;
//	 }   

    switch(paydone)
    {
       case "inside":
 	    var payindex = document.getElementById("PayFreq").selectedIndex ;
	    var PayFreq = parseInt(document.getElementById("PayFreq").options[payindex].value) ;
	    break;
	    
	   case "outside":
	    var payindex = document.getElementById("PayFreq1").selectedIndex ;
	    var PayFreq = parseInt(document.getElementById("PayFreq1").options[payindex].value) ;
        break;
        
       default : alert("PayFreq not valid");
       
     }	    
      
     
	var EmpCount = parseInt(document.getElementById("EmpCount").value) ;
	var EmpCount1 = parseInt(document.getElementById("EmpCount1").value);
	var depcost = parseFloat(document.getElementById("DepositCost").value) ;
	var depcost1 = parseFloat(document.getElementById("DepositCost1").value) ;
	var emprate = parseFloat(document.getElementById("EmployeeRate").value) ;
	var prephrs = parseFloat(document.getElementById("PrepHrs").value) ;
	var prepmins = parseFloat(document.getElementById("PrepMins").value) ;
	var checkcost = parseFloat(document.getElementById("CheckMaterialCost").value) ;
	var taxdepqtrly = parseFloat(document.getElementById("TaxDepositsQuarterly").value) ;
	var fedtaxrepqtrly = parseFloat(document.getElementById("FederalTaxReportsQuarterly").value) ;
	var stunemprepqtrly = parseFloat(document.getElementById("StateUnemploymentReportsQuarterly").value) ;
	var fedtaxrepyrly = parseFloat(document.getElementById("FederalTaxReportsYearly").value) ;
	var w21099cost = parseFloat(document.getElementById("W2Costs").value) ;
	var prepw21099frm = parseFloat(document.getElementById("PrepareW2Form").value) ;
	var miscperpay = parseFloat(document.getElementById("MiscPerPay").value) ;
	var miscperqtr = (parseFloat(document.getElementById("MiscPerQuarter").value) * 4) / PayFreq ;
	var miscperyr = parseFloat(document.getElementById("MiscPerYear").value) / PayFreq ;
	var prepcost = parseFloat(document.getElementById("PrepCost").value) ;
	var prepcost1 = parseFloat(document.getElementById("PrepCost1").value) ;
	var dbchanges = parseFloat(document.getElementById("DatabaseChanges").value) ;
	
	var CurrentCostPerPeriod;
	var CurrentCostAnnually;
	var YourCostPerPeriod;
	var YourCostAnnually;
	
	   
	/***************************************************
	* Calculate what it costs for to write checks      *
	***************************************************/
	// Cost of employee cost
	if(paydone == "outside") {
		var PayrollCost = prepcost1 + depcost1 + dbchanges;
	} else {
		var PrepTimeCost = (emprate * prephrs) + (prepmins * (emprate/60));
		var PayrollCost = PrepTimeCost + checkcost + depcost;
	}
	
		
	/***************************************************
	* Calculate what it costs to do taxes              *
	***************************************************/
        var TaxDeposits = (taxdepqtrly * 4)/PayFreq;
	var FederalTaxReports = (fedtaxrepqtrly * 4)/PayFreq;
	var StateUnemploymentReports = (stunemprepqtrly * 4) / PayFreq;
	var QuarterlyExpense = TaxDeposits + FederalTaxReports + StateUnemploymentReports;
	var FederalTaxReportsYearly = fedtaxrepyrly / PayFreq;
	var W2Costs = w21099cost / PayFreq;
	var PrepareW2Form = prepw21099frm / PayFreq;

	var YearlyCosts = FederalTaxReportsYearly + W2Costs + PrepareW2Form;

	
	var MiscExpense = miscperpay + miscperqtr + miscperyr;

	var CustomerCost = Math.round((PayrollCost + QuarterlyExpense+ YearlyCosts + MiscExpense)*100)/100+"";
	var AnualCustomerCost = Math.round((CustomerCost * PayFreq)*100)/100+"";


	/***********************************************
	* Ensure that there is a decimal and two trailing
	* Numbers.
	***********************************************/
	var pos = CustomerCost.indexOf(".");
	if(pos > -1) {
		CustomerCost += "00";
		CustomerCost = CustomerCost.substr(0,pos+3);
	} else {
		CustomerCost += ".00";
	}

	pos = AnualCustomerCost.indexOf(".");
	if(pos > -1) {
		AnualCustomerCost += "00";
		AnualCustomerCost = AnualCustomerCost.substr(0,pos+3);

	} else {
		AnualCustomerCost += ".00";
	}

	 CurrentCostPerPeriod = CustomerCost;
	 CurrentCostAnnually = AnualCustomerCost;
	
	/*************************************
	* added 7/21/2003 reb                *
	*************************************/
	 var your_perperiod = CurrentCostPerPeriod;
	 var your_annually = CurrentCostAnnually;
	 
	 
	
	/*******************************************
	* Calculate what we will charge for Checks *
	*******************************************/
	if( PayFreq <= 12) {
		ProcessingFee = OnceAMonth;
		ddfee = ddmonthly;                                // Direct Deposit Fee Monthly
		ddcharges = ddfee + (CheckCount * ddtransmo);     // Direct Deposit Charge + transactions
	} else {
		ProcessingFee = MoreThanOnceAMonth;
		ddfee = ddwbsm*1; 
		if(paydone =="inside") {                             // Direct Deposit Fee - Weekly,Biweekly,Semi-mo
	    	ddcharges = ddfee + (CheckCount * ddtranswbsm);   // Direct Deposit Charge + transactions
        }
        else {
            ddcharges = ddfee + (CheckCount1 * ddtranswbsm);
        }
	}   
	
   
 
   
	switch(paydone)
	{
	      case 'inside' : 
	                 if(CheckCount < 11) {
	                	PerCheckCost = TenOrLess * CheckCount + ProcessingFee + ddcharges;
                     	}

                	if(CheckCount > 10 && CheckCount < 16) {
		               PerCheckCost = TenOrLess * 10 + NextFive * (CheckCount - 10) +ProcessingFee + ddcharges;
                 	}

                 	if(CheckCount > 15) {
                		PerCheckCost = (TenOrLess * 10) + (NextFive * 5) + (SixteenMore * (CheckCount - 15)) + ProcessingFee + ddcharges;
		
                 	}
                 	if(CheckCount == 0) {
                		PerCheckCost = 0;
                 	}     
                 	 break;
	      case 'outside' : 
	               if(CheckCount1 < 11) {
	                	PerCheckCost = TenOrLess * CheckCount1 + ProcessingFee + ddcharges;
                 	}

                  	if(CheckCount1 > 10 && CheckCount1 < 16) {
                		PerCheckCost = TenOrLess * 10 + NextFive * (CheckCount1 - 10) +ProcessingFee + ddcharges;
                
                 	}

	                if(CheckCount1 > 15) {
	                	PerCheckCost = (TenOrLess * 10) + (NextFive * 5) + (SixteenMore * (CheckCount1 - 15)) + ProcessingFee + ddcharges;
		
                	}
                	if(CheckCount1 == 0) {
                		PerCheckCost = 0;
                 	}
                 	; break ;
          default:
                         alert("Check Count Error!");
         }

   
     
	

 
 
	
	
	// Cost of Payroll for 1 Period - processing + checks + direct deposits
	 // PerCheckCost = Math.round((PerCheckCost)*100)/100+"";
	// PerCheckCost = Math.round((PerCheckCost)*100)/100+ ".00";

	
	/**************************************************
	  add tax processing to payroll - 12/17/2004
	**************************************************/  
	switch(PayFreq)
	{
	      case 52: 
	                      PerPayrollCost = PerCheckCost*1 + taxwkly*1;
	                      break;
	      case 26:
	                     PerPayrollCost = PerCheckCost*1 + taxbiwkly*1;
  	                     break;
	      case 24:
	                     PerPayrollCost = PerCheckCost + taxsemimo;
	                     break;
          case 12:
                         PerPayrollCost = PerCheckCost + taxmonthly;
                           break;
          default:
                         alert("Selected Payroll Frequency Calculation Error!");
         }
         
        // Cost of payroll for 1 period - processing + checks + direct deposits + tax processing                              	                     
        PerPayrollCost = Math.round((PerPayrollCost)*100)/100+"";
       
	var AnnualPerPayrollCost = Math.round((PayFreq * PerPayrollCost)*100)/100+"";
 
                                
        /**************************************************************
          add W-2's and 1099's year end processing
         **************************************************************/ 	
         //  annualW21099 = Math.round((EmpCount * w2fee)*100)/100+"";
           if(paydone == "inside"){
              annualW21099 = Math.round((EmpCount * w2fee)*100)/100;
           }
           else {
              annualW21099 = Math.round((EmpCount1 * w2fee)*100)/100;
           }
        /**********************************************************
          Total cost for Year
        *********************************************************/
        AnnualPayrollCost =  (AnnualPerPayrollCost*1) + (annualW21099*1);
       
        AnnualPayrollCost = Math.round((AnnualPayrollCost)*100)/100+"";     

	/***********************************************
	* Ensure that there is a decimal and two trailing
	* Numbers.
	***********************************************/
	/*var pos = PerCheckCost.indexOf(".");
	if(pos > -1) {
		PerCheckCost += "00"
		PerCheckCost = PerCheckCost.substr(0,pos+3);
	} else {
		PerCheckCost += ".00"
	} 
	*/
      

	/*pos = AnualPerCheckCost.indexOf(".");
	if(pos > -1) {
		AnualPerCheckCost += "00"
		AnualPerCheckCost = AnualPerCheckCost.substr(0,pos+3);

	} else {
		AnualPerCheckCost += ".00"
	} */
      // Added following three 12/23/2004
      //**************************************************************
      pos = PerPayrollCost.indexOf(".");
	if(pos > -1) {
		PerPayrollCost+= "00";
		PerPayrollCost = PerPayrollCost.substr(0,pos+3);
             
	} else {
		PerPayrollCost += ".00";
	}
      pos = AnnualPerPayrollCost.indexOf(".");
	if(pos > -1) {
		AnnualPerPayrollCost += "00";
		AnnualPerPayrollCost= AnnualPerPayrollCost.substr(0,pos+3);

	} else {
		AnnualPerPayrollCost += ".00";
	}
       pos = AnnualPayrollCost.indexOf(".");
	if(pos > -1) {
		AnnualPayrollCost += "00";
		AnnualPayrollCost = AnnualPayrollCost.substr(0,pos+3);

	} else {
		AnnualPayrollCost += ".00";
	}
	
	
      // *******************************************************
	
	// Display out data 
	
	YourCostPerPeriod = PerPayrollCost ;
	YourCostAnnually  = AnnualPayrollCost ;
	
	/*******************************
	* added 7/21/2003 reb          *
	*******************************/
	 edp_perPeriod = YourCostPerPeriod;
	 edp_annually = YourCostAnnually;
	

     document.getElementById("CurrentCostPerPeriod").value = your_perperiod ;
 	 document.getElementById("CurrentCostAnnually").value = your_annually;
	 document.getElementById("YourCostPerPeriod").value = edp_perPeriod;
	 document.getElementById("YourCostAnnually").value = edp_annually;
	
	return ;
	
}

