/**
 * helper classes for accessing tables
 *
 * used by calculations (see bereken.js)
 * tables values are stored in tables.js
 */

// AanvragerInkomenNl table helper
var AanvragerInkomenNl = function() {
	
	var getValue = function( table, choice, name ) {
		if( typeof table != 'undefined' && typeof table[choice] != 'undefined' && typeof table[choice][name] != 'undefined' )
			return table[choice][name];
	}
	
	function AanvragerInkomenNl( choice, table ) {
		this.choice = choice;
		this.table = table || Tabellen.AanvragerInkomenNl;
	}

	AanvragerInkomenNl.prototype.wlf = function() { return getValue( this.table, this.choice, "WLF" ); }
	AanvragerInkomenNl.prototype.werk = function() { return getValue( this.table, this.choice, "Werk" ); }
	
	return AanvragerInkomenNl;
}();

// ToeslagpartnerInkomenNL table helper
var ToeslagpartnerInkomenNl = function() {
	
	var getValue = function( table, choice, name ) {
		if( typeof table != 'undefined' && typeof table[choice] != 'undefined' && typeof table[choice][name] != 'undefined' )
			return table[choice][name];
	}
	
	function ToeslagpartnerInkomenNl( choice, table ) {
		this.choice = choice;
		this.table = table || Tabellen.ToeslagpartnerInkomenNl;
	}

	ToeslagpartnerInkomenNl.prototype.wlf = function() { return getValue( this.table, this.choice, "WLF" ); }
	ToeslagpartnerInkomenNl.prototype.werk = function() { return getValue( this.table, this.choice, "Werk" ); }
	ToeslagpartnerInkomenNl.prototype.factor = function() { return getValue( this.table, this.choice, "Factor" ); }
	ToeslagpartnerInkomenNl.prototype.wlf2 = function() { return getValue( this.table, this.choice, "WLF2" ); }
	
	return ToeslagpartnerInkomenNl;
}();

// helper to access Jaar table
function Jaar(jaar, table ) { 
	this.jaar = jaar; 
	this.table = table || Tabellen.Jaar;
};
	
Jaar.prototype.getValue = function( name, defaultValue ) {
	return this.table && this.table[this.jaar] && this.table[this.jaar][name] ? this.table[this.jaar][name] : defaultValue;
};

Jaar.prototype.aanvraagdatum = function() { return this.getValue( "Aanvraagdatum", "" ); }
Jaar.prototype.ht = function() { return this.getValue( "HT", null ); }
Jaar.prototype.kt = function() { return this.getValue( "KT", null ); }
Jaar.prototype.kgb = function() { return this.getValue( "KGB", null ); }
Jaar.prototype.kot = function() { return this.getValue( "KOT", null ); }
Jaar.prototype.zt = function() { return this.getValue( "ZT", null ); }
Jaar.prototype.garage = function() { return this.getValue( "Garage", null ); }
Jaar.prototype.onderhuur = function() { return this.getValue( "Onderhuur", null ); }
Jaar.prototype.uitBetGrns = function() { return this.getValue( "UitbetGrns", 0 ); }
Jaar.prototype.halfjaar = function() { return this.getValue( "Halfjaar", "" ); }
Jaar.prototype.maxKT = function() { return this.getValue( "MaxKT", 0 ); }
Jaar.prototype.ondergrens = function() { return this.getValue( "Ondergrens", 0 ); }
Jaar.prototype.bovengrens = function() { return this.getValue( "Bovengrens", 0 ); }
Jaar.prototype.tslg = function() { return this.getValue( "Tslg", 0 ); }
Jaar.prototype.wtos = function() { return this.getValue( "WTOS", 0 ); }
Jaar.prototype.vh12plus = function() { return this.getValue( "VH12Plus", 0 ); }
Jaar.prototype.vh16plus = function() { return this.getValue( "VH16Plus", 0 ); }
Jaar.prototype.og = function() { return this.getValue( "OG", 0 ); }
Jaar.prototype.ohga = function() { return this.getValue( "OHGA", 0 ); }
Jaar.prototype.igta = function() { return this.getValue( "IGTA", 0 ); }
Jaar.prototype.igua = function() { return this.getValue( "IGUA", 0 ); }
Jaar.prototype.ohgb = function() { return this.getValue( "OHGB", 0 ); }
Jaar.prototype.igtb = function() { return this.getValue( "IGTB", 0 ); }
Jaar.prototype.igub = function() { return this.getValue( "IGUB", 0 ); }
Jaar.prototype.vsvb = function() { return this.getValue( "VSVB", 0 ); }
Jaar.prototype.maxUPDOKC = function() { return this.getValue( "MaxUPDOKC", 0 ); }
Jaar.prototype.maxUPDOGO = function() { return this.getValue( "MaxUPDOGO", 0 ); }
Jaar.prototype.maxUPBOKC = function() { return this.getValue( "MaxUPBOKC", 0 ); }
Jaar.prototype.maxUPBOGO = function() { return this.getValue( "MaxUPBOGO", 0 ); }
Jaar.prototype.maxUren = function() { return this.getValue( "MaxUren", null ); }
Jaar.prototype.wrkgvrBdr = function() { return this.getValue( "WrkgvrBdr", "" ); }
Jaar.prototype.middelen = function() { return this.getValue( "Middelen", "" ); }
Jaar.prototype.etp = function() { return this.getValue( "ETP", "" ); }
Jaar.prototype.om = function() { return this.getValue( "OM", "" ); }
Jaar.prototype.wlf= function() { return this.getValue( "WLF", "" ); }	
Jaar.prototype.repwlft= function() { return this.getValue( "RepWlfT", "" ); }	
Jaar.prototype.hdcp= function() { return this.getValue( "HDCP", "" ); }	
Jaar.prototype.sp = function() { return this.getValue( "SP", 0 ); }
Jaar.prototype.drempel = function() { return this.getValue( "Drempel", 0 ); }
Jaar.prototype.tda = function() { return this.getValue( "TDA", 0 ); }
Jaar.prototype.bda = function() { return this.getValue( "BDA", 0 ); }
Jaar.prototype.tdmt = function() { return this.getValue( "TDMT", 0 ); }
Jaar.prototype.bdmt = function() { return this.getValue( "BDMT", 0 ); }
Jaar.prototype.mxInk1 = function() { return this.getValue( "MxInk1", 0 ); }
Jaar.prototype.mxInk2 = function() { return this.getValue( "MxInk2", 0 ); }
	// Halfjaar table access helper
function Halfjaar( halfjaar ) {
	this.table = Tabellen.Halfjaar[halfjaar];
}

Halfjaar.prototype.kwKrtGrns = function() {
	return this.table && this.table.KwKrtGrns ? this.table.KwKrtGrns : 0;
}

Halfjaar.prototype.aftopA = function() {
	return this.table && this.table.AftopA ? this.table.AftopA : 0;
}

Halfjaar.prototype.aftopB = function() {
	return this.table && this.table.AftopB ? this.table.AftopB : 0;
}

Halfjaar.prototype.gk = function() {
	return this.table && this.table.GK ? this.table.GK : 0;
}

Halfjaar.prototype.mxSK = function() {
	return this.table && this.table.MxSK ? this.table.MxSK : 0;
}

Halfjaar.prototype.ohKort = function() {
	return this.table && this.table.OHKort ? this.table.OHKort : 0;
}

Halfjaar.prototype.maxHuur = function() {
	return this.table && this.table.MaxHuur ? this.table.MaxHuur : 0;
}

Halfjaar.prototype.htb = function() {
	return this.table && this.table.HTB ? this.table.HTB : "";
}

Halfjaar.prototype.minNrmHr = function() {
	return this.table && this.table.MinNrmHr ? this.table.MinNrmHr : 0;
}

Halfjaar.prototype.vrKndInk = function() {
	return this.table && this.table.VrKndInk ? this.table.VrKndInk : 0;
}// helper to access kott table

var Kott = function() {

	function findRow( table, inkomen ) {
		for( var i = 0, sz = table.length; i < sz; ++i ) 
			if( table[i].inkomen.van <= inkomen && table[i].inkomen.tm >= inkomen )
				return table[i];

		return null;
	}
	
	function Kott(jaar) {
		this.jaar = jaar;
		this.table = Tabellen.KOTT[this.jaar];
	}

	Kott.prototype.kotPercentageRang1 = function( algemeenInkomen ) {
		if( this.table )
		{
			var row = findRow( this.table, algemeenInkomen );
			return row ? row.kinderopvangtoeslag.eersteKind : 0;
		} else
			return 0;
	}

	Kott.prototype.kotPercentageRang2 = function( algemeenInkomen ) {
		if( this.table )
		{
			var row = findRow( this.table, algemeenInkomen );
			return row ? row.kinderopvangtoeslag.tweedeEvKind : 0;
		} else
			return 0;
	}

	Kott.prototype.etPercentageRang1 = function( algemeenInkomen ) {
		if( this.table )
		{
			var row = findRow( this.table, algemeenInkomen );
			return row ? row.extraToeslag.eersteKind : 0;
		} else
			return 0;
	}

	Kott.prototype.etPercentageRang2 = function( algemeenInkomen ) {
		if( this.table )
		{
			var row = findRow( this.table, algemeenInkomen );
			return row ? row.extraToeslag.tweedeEvKind : 0;
		} else
			return 0;
	}
	
	return Kott;
}();
// WLF table access helper
function Wlf( jaar, table ) {
	this.jaar = jaar;
	this.table = table || Tabellen.WLF;
}

Wlf.prototype.wlf = function( land ) {
// 	return this.table && this.table[this.jaar] && this.table[this.jaar][land] ? this.table[this.jaar][land] : 0;
	return this.table && this.table[land] && this.table[land][this.jaar] ? this.table[land][this.jaar] : 0;
}
