﻿      var cnstmanagementFee = 0.028
	  var cnstSuper = 0.09 / 1.09



/*make sure the total hours show if the period is anything but hourly*/
function CheckTotalHours(){
    if(document.getElementById("txtBillingPeriod").value=="Hourly")
    {
        document.getElementById("txtHoursWorked").style.display = "none";
        
        
    }
    else{
        document.getElementById("txtHoursWorked").style.display = "block";
       

    }
}

function StripDolla(currency){
    return currency.substr(1);
}

function validateInputs(){


            var iHourlyRate = StripDolla(document.getElementById("txtHourlyRate").value);
   
            //has the user entered an hourly rate?
          if(iHourlyRate=="" || iHourlyRate=="0.00")
          {
            txtHourlyRate.value = "";
            txtBillableRate.value = "";
            txtManagementFee.value = "";
            txtHourlyRateBeforeDeductingSuper.value = "";
            txtSuper.value = "";
            txtHourlyRateBeforeTax.value = "";
            alert("Please enter an hourly rate greater than zero dollars.");
            return false;
            }
            
   
  
            var iHoursWorked = document.getElementById("txtHoursWorked").value; 
             //make sure the user enters a number of hours if not hourly rate
             
             
             if(isNaN(iHoursWorked))
             {
                alert("Please enter a numeric value for the total number of hours worked during the specified period.");
                return false;
             }
            if(document.getElementById("txtBillingPeriod").value!="Hourly" && iHoursWorked=="")
             {
                alert("Please enter the total number of hours worked during the specified period.");
                return false;
            } 
            
          
            return true;  
}

function setupPayslip(){
    document.getElementById("teaser").style.display = "none"
    //document.getElementById("payslip").style.display = "none"
    document.getElementById("salaryBreakdown").style.display = "none"
}

function loadBlankPaySlip()
{
    document.getElementById("payslip").style.display = "block";
     t1 = new Tween(document.getElementById('payslip').style,'left',Tween.elasticEaseOut,0,750,2,'px');
     t1.start();
}

function runPaySlip(){
    
    setupPayslip();
    
    if(validateInputs())
    {
   
    setTimeout("calculateSalary()",1100); 
    setTimeout("ShowTeaser()",3000);
     //setTimeout( "document.getElementById('teaser').style.display = 'block'",3000);
    }
    
    
}


function ShowTeaser(){

    document.getElementById("teaser").style.display = "block";
     t1 = new Tween(document.getElementById('teaser').style,'left',Tween.strongEaseOut,900,750,2,'px');
     t1.start();

    //opacityTween = new OpacityTween(document.getElementById('teaser'),Tween.bounceEaseOut, 100, 0, 3);
      //opacityTween.start();

    
}

function calculateSalary(){


 try{
        if(!validateInputs()){return;}
        
        var iHourlyRate = StripDolla(document.getElementById("txtHourlyRate").value); 
        var iHoursWorked = document.getElementById("txtHoursWorked").value;
       
        var iTotalBillableAmount;
        var iHoursWorkedInPeriod;       
        if(iHoursWorked!="")
        {
            iHoursWorkedInPeriod = iHoursWorked;
        }
        else
        {
            iHoursWorkedInPeriod = 1;
        }  
        
      
        
        iTotalBillableAmount = iHourlyRate * iHoursWorkedInPeriod;
       
        /*work out the management fee*/
        var iManagementFee = iTotalBillableAmount * cnstmanagementFee;
        
        /*work out the NET HOURLY RATE BEFORE DUDUCTING SUPER*/
        var iNHRBDS = iTotalBillableAmount - iManagementFee;
        
        /*work out the super*/
        var iSuper = iNHRBDS * cnstSuper ;
        
        /*work out the net hourly rate before tax*/ 
        var iNHRBT =  iNHRBDS - iSuper
        
          document.getElementById("salaryBreakdown").style.display = "block";
         document.getElementById("txtBillableRate").value = formatCurrency(iTotalBillableAmount);     
        document.getElementById("txtManagementFee").value  = formatCurrency(iManagementFee);
         document.getElementById("txtHourlyRateBeforeDeductingSuper").value = formatCurrency(iNHRBDS);
        document.getElementById("txtSuper").value = formatCurrency(iSuper);
        document.getElementById("txtHourlyRateBeforeTax").value = formatCurrency(iNHRBT);
     
  		  }
  		  catch(err)
          {
          txt="Ooooops...something went wrong.\n\n";
          txt+= "We'd really appreciate it if you called and let us know on 1300 908 804 and we'll help you out with your query over the phone. \n\n"
          txt+="Error description: " + err.description + "\n\n";
          
          alert(txt);
          }


	  }
	  
	  /*the following javascript comes from http://javascript.internet.com/forms/currency-format.html*/
	  function formatCurrency(num) {
            num = num.toString().replace(/\$|\,/g,'');
            if(isNaN(num))
            num = "0";
            sign = (num == (num = Math.abs(num)));
            num = Math.floor(num*100+0.50000000001);
            cents = num%100;
            num = Math.floor(num/100).toString();
            if(cents<10)
            cents = "0" + cents;
            for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
            num = num.substring(0,num.length-(4*i+3))+','+
            num.substring(num.length-(4*i+3));
            return (((sign)?'':'-') + '$' + num + '.' + cents);
}
