/* Argument base:    string, indicates the type of
                     base system.
   Argument indexed: 1 or 0, indicates whether or not
                     to index.
   Result: a taxsystem structure, representing
   a base (pre-Budget) tax system of the appropriate kind.
*/
function makeBaseSystem( base, indexed )
{
    //alert( 'base=|'+base+'| indexed=|'+indexed+'| ' );
        if( "BASE1" == base ){ // include preannounced gains/losses
        if( indexed == 1 ){ // ignore indexation
                        //alert( 'makeIndexedDayBefore' );
            return makeIndexedDayBefore();
        } else {  // allow indexation
                        //alert( 'makeNonIndexedDayBefore' );
            return makeNonIndexedDayBefore();
        }
    } else {  // ignore preannounced gains/losses
        if( indexed == 1 ){
                        //alert( 'makeNonIndexedPreAnnounced' );
            return makeIndexedPreAnnounced();
        } else {
                        //alert( 'makeNonIndexedPreAnnounced' );
            return makeNonIndexedPreAnnounced();
        }
    }
}


/* Result: a taxsystem structure, representing
           the post-Budget tax system.

    +++++++++++i.e. April05 in 05prices plus Budget changes+++++++++++++

    !!! Actual version following Budget
*/
function makeNewSystem( )
{
  var sys = {
        personalAllowance:4895.0/52.0,
        ageAllowance1:7090.0/52.0,
        ageAllowance2:7220.0/52.0,
        MCA1:5905.0 * 0.1 /52.0,
        MCA2:5975.0 * 0.1 /52.0,
        ageAllowanceTaper:0.50,
        ageAllowanceThreshold:19500.0/52.0,
        savingsRate:0.20,
        itRates: new Array( 0.10, 0.22, 0.40 ),
        itBands: new Array( 2090/52.0, 32400/52.0, 99999999999 ),
        niInRates: new Array( 0.0, 0.11, 0.01 ),
        niOutRates: new Array( 0.0, 0.094, 0.01 ),
        niBands: new Array( 94.0, 630.0, 999999999999 ),
        niClass4: new Array( 0.0, 0.08, 0.01 ),
        niClass2:2.1,
        niLel: 82,
        beer:0.01,  /** just the extra per pint, bottle etc **/
        wine:0.03,
        spirits:0.00,
        petrol:0.00,
        fags:0.08
  }
  return sys;
}



/* Result: a taxsystem structure, representing
           a pre-Budget system indexed.

   ++++++++++++++i.e. Autumn04 in 05 prices - the 'indexed base'++++++++++++

  Statutory indexation is 3.1%. for it, 2.36% for indir
*/
function makeIndexedDayBefore()
{
   var sys = {
        personalAllowance:4895.0/52.0,
        ageAllowance1:7050.0/52.0,
        ageAllowance2:7170.0/52.0,
        MCA1:5905.0 * 0.1 /52.0,
        MCA2:5975.0 * 0.1 /52.0,
        ageAllowanceTaper:0.50,
        ageAllowanceThreshold:19500.0/52.0,
        savingsRate:0.20,
        itRates: new Array( 0.10, 0.22, 0.40 ),
        itBands: new Array( 2090/52.0, 32400/52.0, 99999999999 ),
        niInRates: new Array( 0.0, 0.11, 0.01 ),
        niOutRates: new Array( 0.0, 0.094, 0.01 ),
        niBands: new Array( 94.0, 630.0, 999999999999 ),
        niClass4: new Array( 0.0, 0.08, 0.01 ),
        niClass2:2.0,
        niLel: 82,
        beer:0.01,  /** just the extra per pint, bottle etc **/
        wine:0.03,
        spirits:0.15,
        petrol:0.01,
        fags:0.08
   }
   return sys;
}



/* Result: a taxsystem structure, representing
           a pre-Budget system non-indexed.

  ++++++++++++++++++ Autumn04 NOMINAL - the 'non-indexed base'++++++++++++++++

*/
function makeNonIndexedDayBefore(){
  var sys = {
        personalAllowance:4745.0/52.0,
        ageAllowance1:6830.0/52.0,
        ageAllowance2:6950.0/52.0,
        MCA1:5725.0 * 0.1 /52.0,
        MCA2:5795.0 * 0.1 /52.0,
        ageAllowanceTaper:0.50,
        ageAllowanceThreshold:18900.0/52.0,
        savingsRate:0.20,
        itRates: new Array( 0.10, 0.22, 0.40 ),
        itBands: new Array( 2020/52.0, 31400/52.0, 99999999999 ),
        niInRates: new Array( 0.0, 0.11, 0.01 ),
        niOutRates: new Array( 0.0, 0.094, 0.01 ),
        niBands: new Array( 91.0, 610.0, 999999999999 ),
        niClass4: new Array( 0.0, 0.08, 0.01 ),
        niClass2:2.0 ,
        niLel: 79,
        beer:0.0,  /** just the extra per pint, bottle etc **/
        wine:0.0,
        spirits:0.0,
        petrol:0.0,
        fags:0.0
        }
  return sys;
}




/* Result: a taxsystem structure, representing
           a pre-Budget system indexed
           that incorporates the pre-announced
           changes.


          ++++++++++++++++Autumn04 in 05 Prices with Pre-announced changes
          (pre-announced changes are over-indexation of age allowances and freezing of spirits duty)+++++++++++++++++++++++
*/
function makeIndexedPreAnnounced( )
{
  var sys = {
        personalAllowance:4895.0/52.0,
        ageAllowance1:7090.0/52.0,
        ageAllowance2:7220.0/52.0,
        MCA1:5905.0 * 0.1 /52.0,
        MCA2:5975.0 * 0.1 /52.0,
        ageAllowanceTaper:0.50,
        ageAllowanceThreshold:19500.0/52.0,
        savingsRate:0.20,
        itRates: new Array( 0.10, 0.22, 0.40 ),
        itBands: new Array( 2090/52.0, 32400/52.0, 99999999999 ),
        niInRates: new Array( 0.0, 0.11, 0.01 ),
        niOutRates: new Array( 0.0, 0.094, 0.01 ),
        niBands: new Array( 94.0, 630.0, 999999999999 ),
        niClass4: new Array( 0.0, 0.08, 0.01 ),
        niClass2:2.0,
        niLel: 82,
        beer:0.01,  /** just the extra per pint, bottle etc **/
        wine:0.03,
        spirits:0.00,
        petrol:0.01,
        fags:0.08
  }
  return sys;
}



/* Result: a taxsystem structure, representing
           a pre-Budget system non-indexed
           that incorporates the pre-announced
           changes.
           +++++++++++++++++Autumn04 NOMINAL with pre-announced
           changes++++++++++++
*/
function makeNonIndexedPreAnnounced( )
{
  var sys = {
        personalAllowance:4745.0/52.0,
        ageAllowance1:7090.0/52.0,
        ageAllowance2:7220.0/52.0,
        MCA1:5725.0 * 0.1 /52.0,
        MCA2:5795.0 * 0.1 /52.0,
        ageAllowanceTaper:0.50,
        ageAllowanceThreshold:18900.0/52.0,
        savingsRate:0.20,
        itRates: new Array( 0.10, 0.22, 0.40 ),
        itBands: new Array( 2020/52.0, 31400/52.0, 99999999999 ),
        niInRates: new Array( 0.0, 0.11, 0.01 ),
        niOutRates: new Array( 0.0, 0.094, 0.01 ),
        niBands: new Array( 91.0, 610.0, 999999999999 ),
        niClass4: new Array( 0.0, 0.08, 0.01 ),
        niClass2:2.0 ,
        niLel: 79,
        beer:0.0,  /** just the extra per pint, bottle etc **/
        wine:0.0,
        spirits:0.0,
        petrol:0.0,
        fags:0.0
  }
  return sys;
}