/* ---------------------------
' (C) Copyright 2008
' Niro Solutions Pty Limited
' ABN 89 106 967 140
' ---------------------------
' Revision: 2.0.0
' Author: Zhongbo Sun
' Modtime: 05/11/09/08

' --------------------------- */


fieldArray = new Array("insurance","registration","ctp","maintenance","fuel","bustrain","taxi","holidays","cinema","hobbies","memberships",
"subscriptions","books","paytv","magazines","rates","water","gas","electricity","phone","internet","homebuildings",
"homecontents","repairs","cleaning","groceries","meatfish","fruitveg","restaurant","alcohol","tobacco","schoolfees",
"uniforms","lifeinsurance","doctors","medicine","healthinsurance","clothing","laundry","makeup");

function startInt(){
  for(i=0; i<fieldArray.length; i++){
    recalcAmount(fieldArray[i], "w");
  }
  calcInt = setInterval(calculateIt, 100);
}

function parseUndefinedInt(val){
  return (val=="") ? 0 : parseInt(val);
}

function calculateIt(){
  f = document.forms.calcForm;
  total_w=0;
  for(i=0; i<fieldArray.length; i++){
    total_w+=parseUndefinedInt(f[fieldArray[i]+'_w'].value);
  }
  f.total_w.value=total_w;
  f.total_m.value=Math.round(total_w*52/12);
  
}

function recalcAmount(field, type, field1){
    intOnly(field1)
  f = document.forms.calcForm;
  newType=(type=="w")?"m":"w";
  changedTo=parseUndefinedInt(f[field+'_'+type].value);
  newAm=Math.round((type=="w")?(changedTo*(52/12)):changedTo/(52/12));
  f[field+'_'+newType].value=(newAm!=0)?newAm:"";
  //if(newAm!=0) f[field+'_'+newType].value=newAm;
}

function intOnly(field) 
{ 
    if (field != undefined )
    {
        var m_strOut = new String(field.value); 
        m_strOut = m_strOut.replace(/[^0-9]/g, ''); 
        
        if (field.value != m_strOut)
            {field.value = m_strOut} 

    }
}
