function setTabStatus(id, status) {
	e = document.getElementById(id);
	
	if (!e) return;
	    
	if (status)
		e.className = "tabtop_sel"
	else
		e.className = "tabtop"
}

function toMoney(val, decimals)
{
	if (typeof(decimals) != 'number')
		decimals = 2;
	rfac = Math.pow(10, decimals);
	val = Math.round(val * rfac) / rfac;
    val = String(val);
    
    dotindex = val.indexOf('.');
    
    if (dotindex < 0)
    {
        val += ".";
		zeroes_to_add = decimals;
    }
    else
    {
        zeroes_to_add = dotindex + decimals + 1 - val.length;
    }
        
	for (i = 0; i < zeroes_to_add; ++i)
		val += String("0");

	return money_prefix + val.replace(/\./, money_decimal_indicator) + money_postfix;
}

function selectTariff(tariff) {
	setTabStatus("tab0", tariff == 0)
	setTabStatus("tab1", tariff == 1)
	setTabStatus("tab2", tariff == 2)

	e = document.getElementById("pReductionText");
	if (e)
	    e.innerHTML = reduction_text[isbusiness][tariff];
	   
    for (carclass = 0; carclass < number_of_carclasses; ++carclass)
    {
        for (timezone = 0; timezone < number_of_timezones; ++timezone)
        {
            e = document.getElementById("tdTime." + carclass + "." + timezone);
            if (e) 
            {
                if (time_rate_display_factor == 1.0)
                    e.innerHTML = '<span >' + toMoney(hourrate[isbusiness][tariff][carclass][timezone]) + '</span>';
                else
                    e.innerHTML = '<span title="' + toMoney(hourrate[isbusiness][tariff][carclass][timezone]) + ' ' + per_hour_text + '">' + toMoney(hourrate[isbusiness][tariff][carclass][timezone] * time_rate_display_factor) + '</span>';
            }
        }
		
		if (jokerrate) {
			e = document.getElementById("tdJokerTime." + carclass);
			if (e)
				e.innerHTML = '<span title="' + toMoney(jokerrate[isbusiness][tariff][carclass] / 24) + ' ' + per_hour_text + '">' + toMoney(jokerrate[isbusiness][tariff][carclass]) + '</span>';
		}
		
        e = document.getElementById("tdKilometers." + carclass);
        if (e) 
            e.innerHTML = toMoney(kmprice[isbusiness][tariff][carclass]);
            
        e = document.getElementById("tdFuel." + carclass);
        if (e) 
            e.innerHTML = toMoney(fuelprice[isbusiness][carclass], 3);
    }
}


function subscribe() {
	var uri = 'http://customer.greenwheels.com/public/registration_customer.aspx?';
	uri += 'org=' + String(organisation);
	uri += '&lang=' + language;
	uri += '&company=' + (isbusiness ? 'true' : 'false');
	uri += '&utm_campaign=inschrijven';
	uri += '&utm_medium=green_button';
	if (language == 'nl')
		uri += '&utm_source=public_GWnl_' + (isbusiness ? 'b' : 'p') + '_tarieven';
	else
		uri += '&utm_source=GWde_' + (isbusiness ? 'b' : 'p') + '_tarif';
	window.location = uri;
}

function init() 
{
	selectTariff(default_tariff);

    for (i = 0; i < number_of_tariffs; ++i)
    {
        e = document.getElementById("lnk" + i);
        e.href="javascript:{selectTariff(" + i + ")}";
        tabtxt = tariff_name[isbusiness][i];
        mouseovertxt = tariff_name_mouseover[isbusiness][i];
        
        if (mouseovertxt != null)
            e.innerHTML = '<span title="' + mouseovertxt + '" >' + tabtxt + '</span>';
        else
            e.innerHTML = tabtxt;
	}
	
	e = document.getElementById("aJokerTitle");
	if (e) {
		e.href = joker_url;
	}
	
	e = document.getElementById("fuel_date_long");
	if (e)
		e.innerHTML = fuel_date_long;
	
	e = document.getElementById("fuel_date_short");
	if (e)
		e.innerHTML = fuel_date_short;
}
