var sazby = new Array();
var progr = new Array();
var degr = new Array();

var Sazba1 = null;
var SazbaProg1 = null;
var SazbaDegr1 = null;
var Sazba2 = null;
var SazbaProg2 = null;
var SazbaDegr2 = null;
var Sazba3 = null;
var SazbaDegr3 = null;

var ZivotniMinimum = new Array();
ZivotniMinimum['domacnost'] = new Array();
ZivotniMinimum['osoby'] = new Array();

var Doba = 20;
var Doba2 = 20;

// uz se nepouziva
var KoefProgr = 0.00462886511281619;

var IE = null; //IE5+
var NS = null; // Mozilla 0.9.1+
var OPERA = null; // Opera 7
var IE55 = null;
var IE5 = null;
var IE6 = null;

var ua = navigator.appName.toLowerCase();

if (ua.indexOf('explorer') > -1 && document.getElementById && document.childNodes && !document.addEventListener) { IE = true; }
if (ua.indexOf('netscape') > -1 && document.getElementById && document.childNodes && !document.all) { NS = true; }
if (ua.indexOf('opera') > -1 && document.getElementById && document.childNodes) { OPERA = true; }

if (!IE && !NS && !OPERA && document.addEventListener) { OPERA = true; }

ua = navigator.userAgent.toLowerCase();

if (IE && ua.indexOf('5.5') > -1) { IE55 = true; }
if (IE && ua.indexOf('5.0') > -1) { IE5 = true; }
if (IE && ua.indexOf('6.0') > -1) { IE6 = true; }
if (IE && ua.indexOf('7.0') > -1) { IE7 = true; }

function TestProhlizec() {

    if (!IE && !NS && !OPERA) {
        self.location = "javascript: alert('Chyba v dokumentu " + self.location + " .Prohlizec nepodporuje metody standardu W3C DOM a neni mozno dokument spravne zobrazit.')";
    }

}

function TestMetoda(name) {
    eval("what = " + name);
    if (!what) { self.location = "javascript: alert('Chyba v dokumentu " + self.location + " .Prohlizec nepodporuje metodu " + name + " a neni mozno dokument spravne zobrazit.')"; }
}

function GetSazba(Koef) {
    if (Koef == 0.7)
        return Sazba1;

    if (Koef == 0.85)
        return Sazba2;

    if (Koef == 1)
        return Sazba3;

    return 0;
}

function GetSazbaProg(Koef) {
    if (Koef == 0.7)
        return SazbaProg1;

    if (Koef == 0.85)
        return SazbaProg2;

    return 0;
}

function GetSazbaDegr(Koef) {
    switch (Koef) {
        case 0.7: return SazbaDegr1;
        case 0.85: return SazbaDegr2;
        case 1: return SazbaDegr3;
    }

    return 0;
}

function MaxObjemAnuita(Splatka, Doba, Urok) {
    var i = Urok / 12;
    var v = 1 / (1 + i);
    var n = Doba * 12;
    return Splatka * (1 - Math.pow(v, n)) / i;
}

function MaxObjemUrok(SplatkaU, Urok) {
    var i = Urok / 12;
    return SplatkaU / i;
}

function MaxObjemKlasika(Splatka, Doba, Urok) {
    var i = Urok / 12;
    var n = Doba * 12;

    return Splatka / (1 / n + i);
}

function ConvertStringToInteger(Value) {
    Output = '';
    for (var i = 0; i < Value.length; i++)
        if (Value.charAt(i) != ' ')
        Output += Value.charAt(i);

    if (isNaN(parseInt(Output)))
        return 0;

    return parseInt(Output);
}

function CurrencyFormat(Value) {
    ThousandsSep = ' ';
    CurrencySymbol = 'Kč';

    if (Value == 0)
        return '0 ' + CurrencySymbol;

    TempValue = Math.round(Value);

    Output = '';
    while (TempValue > 0) {
        Remainder = TempValue % 1000;
        TempValue = (TempValue - Remainder) / 1000;

        if (TempValue > 0) {
            if (Remainder < 10)
                Output = '00' + Remainder + ThousandsSep + Output;
            else if (Remainder < 100)
                Output = '0' + Remainder + ThousandsSep + Output;
            else
                Output = Remainder + ThousandsSep + Output;
        }
        else
            Output = Remainder + ThousandsSep + Output;
    }

    return Output + CurrencySymbol;
}

function ConvertAndGet(Obj) {
    value = ConvertStringToInteger(Obj.value);
    Obj.value = CurrencyFormat(value);

    return value;
}

function ConvertAndGetByID(ID) {
    return ConvertAndGet(document.getElementById(ID));
}

function ConvertAndGetAbsolute(Obj) {
    value = Math.max(0, ConvertStringToInteger(Obj.value));
    Obj.value = CurrencyFormat(value);

    return value;
}

function ConvertAndGetAbsoluteByID(ID) {
    return ConvertAndGetAbsolute(document.getElementById(ID));
}

// Excel[CZ] funkce: PLATBA
// Excel[EN] funkce: PMT
function ExcelPMT(Rate, NPer, PV) {
    FV = (arguments.length > 3)
            ? arguments[3] : 0;

    Type = (arguments.length > 3)
            ? arguments[4] : 0;

    TotalRate = Math.pow(1 + Rate, NPer);
    return (-FV - PV * TotalRate) / ((1 + Rate * Type) * (TotalRate - 1) / Rate);
}

// Excel[CZ] funkce: PLATBA.UROK
// Excel[EN] funkce: IPMT
function ExcelIPMT(Rate, ForPer, NPer, PV) {
    if (ForPer < 1)
        return null;

    if (ForPer > NPer)
        return null;

    var Balance = -PV;
    for (Counter = 1; Counter < ForPer; Counter++)
        Balance -= ExcelPPMT(Rate, ForPer - Counter, NPer, PV);

    return Rate * Balance;
}

// Excel[CZ] funkce: PLATBA.ZAKLAD
// Excel[EN] funkce: PPMT
function ExcelPPMT(Rate, ForPer, NPer, PV) {
    return ExcelPMT(Rate, NPer, PV) - ExcelIPMT(Rate, ForPer, NPer, PV);
}

function Dan(ZakladDane) {
    if (ZakladDane < 9100)
        return ZakladDane * 0.15;

    if (ZakladDane < 18200)
        return 1365 + (ZakladDane - 9100) * 0.2;

    if (ZakladDane < 27600)
        return 3185 + (ZakladDane - 18200) * 0.25;

    return 5535 + (ZakladDane - 27600) * 0.32;
}

function CistaMzda(HrubaMzda, Odpocitatelne) {
    ZdravSocPoj = 0.125 * HrubaMzda;
    ZakladDane = HrubaMzda - Odpocitatelne - ZdravSocPoj;

    return ZakladDane - Dan(ZakladDane) + Odpocitatelne;
}

function CistaMzdaUrokOdpocet(HrubaMzda, Odpocitatelne, UrokOdpocet) {
    ZdravSocPoj = 0.125 * HrubaMzda;
    ZakladDane = HrubaMzda - Odpocitatelne - ZdravSocPoj - UrokOdpocet;

    return ZakladDane - Dan(ZakladDane) + Odpocitatelne + UrokOdpocet;
}

/***************************************************************************/
/********************************* GETTERY *********************************/
/***************************************************************************/

function _GetTypUveru() {
    switch (document.getElementById('TypUveru').value) {
        case '1': return 1;
        case '2': return 5;
        case '3': return 6;
        case '4': return 7;
        case '5': return 8;
    }
}

function _GetVyseUveru() {
    switch (document.getElementById('VyseUveru').value) {
        case '70': return 1;
        case '85': return 2;
        case '100': return 3;
    }

    return 0;
}

function _GetTypSplaceni() {
    switch (document.getElementById('TypSplaceni').value) {
        case '1': return 1;
        case '2': return 2;
        case '3': return 3;
    }
}

function _GetDobaUveru() {
    return parseInt(document.getElementById('DobaUveru').value);
}

function _GetDelkaFixaceUrokoveSazby() {
    return parseInt(document.getElementById('DelkaFixaceUrokoveSazby').value);
}

function _GetPoplatky() {
    return document.getElementById('HypotekaBezPoplatku0').checked;
}

function _GetSeStatniFinancniPodporou() {
    return document.getElementById('SeStatniFinancniPodporou0').checked;
}

function _GetObjektHypotecnihoUveru() {
    return (document.getElementById('ObjektHypotecnihoUveru1').checked) ? 1 : 2;
}

function _GetMaxPozadovanaVyseUveru() {
    if ((element = document.getElementById('MaxPozadovanaVyseUveru')) == null)
        return 0;

    return ConvertStringToInteger(element.value);
}

function _GetAnuita() {
    return (_GetTypSplaceni() == 1);
}

function _GetMesicniSplatka() {
    var elementName = (_GetAnuita()) ? 'MesicniSplatka' : 'MesicniSplatkaNeAnuita';
    return ConvertStringToInteger(document.getElementById(elementName).value);
}

function _GetMinimalniVyseSplatkyNeAnuita_Uroky() {
    return ExcelIPMT(GetPredpokladanaUrokovaSazba() / 100 / 12, 1, _GetDobaUveru() * 12, -_GetMaxPozadovanaVyseUveru());
}

function _GetMinimalniVyseSplatkyNeAnuita_Anuita() {
    return ExcelPMT(GetPredpokladanaUrokovaSazba() / 100 / 12, _GetDobaUveru() * 12, -_GetMaxPozadovanaVyseUveru());
}

function _GetMesicniSplatkaNeAnuitaOd() {
    return (_GetTypSplaceni() == 2) ? _GetMinimalniVyseSplatkyNeAnuita_Uroky() : _GetMinimalniVyseSplatkyNeAnuita_Anuita();
}

function _GetMesicniSplatkaNeAnuitaDo() {
    return ((_GetTypSplaceni() == 2) ? 1 : 2) * _GetMinimalniVyseSplatkyNeAnuita_Anuita();
}

/***************************************************************************/
/******************************* KOEFICIENTY *******************************/
/***************************************************************************/

function GetUrokovaSazba() {
    var Sazby = GetUrokovaSazba_SazbyZDatabaze();
    if (Sazby[GetTypUveru() - 1] == null)
        return null;

    switch (_GetDelkaFixaceUrokoveSazby()) {
        case 1: return Sazby[GetTypUveru() - 1][0];
        case 3: return Sazby[GetTypUveru() - 1][1];
        case 5: return Sazby[GetTypUveru() - 1][2];
        case 10: return Sazby[GetTypUveru() - 1][3];
        case 15: return Sazby[GetTypUveru() - 1][4];
    }

    return null;
}

function GetUrokovaSazbaPrirazka() {
    if (GetTypUveru() == 7)
        return 0;

    if (GetTypUveru() == 8)
        return 0;

    if (!_GetPoplatky())
        return 0;

    Prirazky = new Array(
            new Array(3.62, 2.76, 2.22, 1.86, 1.61, 1.45, 1.33, 1.23, 1.16, 1.09, 1.03, 0.98, 0.95, 0.91, 0.88, 0.85, 0.82, 0.80, 0.78, 0.76, 0.74, 0.73, 0.72, 0.70, 0.69, 0.68, 0.66, 0.65, 0.65, 0.63, 0.63, 0.62, 0.62, 0.47, 0.28),
            new Array(3.30, 2.52, 2.03, 1.70, 1.47, 1.32, 1.21, 1.12, 1.06, 1.00, 0.94, 0.89, 0.86, 0.82, 0.79, 0.76, 0.73, 0.71, 0.69, 0.67, 0.65, 0.64, 0.63, 0.61, 0.60, 0.59, 0.57, 0.56, 0.56, 0.54, 0.54, 0.53, 0.53, 0.40, 0.24),
            new Array(3.10, 2.36, 1.90, 1.59, 1.38, 1.24, 1.14, 1.05, 0.99, 0.93, 0.88, 0.84, 0.81, 0.78, 0.75, 0.72, 0.69, 0.67, 0.65, 0.63, 0.61, 0.60, 0.59, 0.57, 0.56, 0.55, 0.53, 0.52, 0.52, 0.50, 0.50, 0.49, 0.49, 0.37, 0.22),
            new Array(2.92, 2.23, 1.79, 1.50, 1.30, 1.17, 1.07, 0.99, 0.93, 0.87, 0.82, 0.78, 0.76, 0.73, 0.71, 0.69, 0.67, 0.65, 0.63, 0.61, 0.59, 0.58, 0.57, 0.55, 0.54, 0.53, 0.51, 0.50, 0.50, 0.48, 0.48, 0.47, 0.47, 0.36, 0.21),
            new Array(2.77, 2.11, 1.70, 1.42, 1.23, 1.11, 1.02, 0.94, 0.89, 0.84, 0.79, 0.75, 0.73, 0.70, 0.68, 0.66, 0.64, 0.62, 0.60, 0.58, 0.56, 0.55, 0.54, 0.53, 0.52, 0.51, 0.50, 0.49, 0.49, 0.47, 0.47, 0.46, 0.46, 0.35, 0.21),
            new Array(2.65, 2.02, 1.62, 1.36, 1.18, 1.06, 0.97, 0.90, 0.85, 0.80, 0.76, 0.72, 0.70, 0.67, 0.65, 0.63, 0.61, 0.60, 0.59, 0.57, 0.56, 0.55, 0.54, 0.53, 0.52, 0.51, 0.50, 0.49, 0.49, 0.47, 0.47, 0.46, 0.46, 0.35, 0.21),
            new Array(2.57, 1.96, 1.58, 1.32, 1.14, 1.03, 0.94, 0.87, 0.82, 0.77, 0.73, 0.69, 0.67, 0.64, 0.62, 0.60, 0.58, 0.57, 0.56, 0.55, 0.54, 0.53, 0.52, 0.51, 0.50, 0.49, 0.48, 0.47, 0.47, 0.46, 0.46, 0.45, 0.45, 0.34, 0.20),
            new Array(2.48, 1.89, 1.52, 1.27, 1.10, 0.99, 0.91, 0.84, 0.79, 0.74, 0.70, 0.67, 0.65, 0.62, 0.60, 0.58, 0.56, 0.55, 0.54, 0.53, 0.52, 0.51, 0.50, 0.49, 0.48, 0.47, 0.46, 0.45, 0.45, 0.44, 0.44, 0.43, 0.43, 0.33, 0.20),
            new Array(2.40, 1.83, 1.47, 1.23, 1.06, 0.95, 0.87, 0.80, 0.75, 0.70, 0.66, 0.63, 0.61, 0.58, 0.56, 0.54, 0.52, 0.51, 0.50, 0.49, 0.48, 0.47, 0.46, 0.45, 0.44, 0.43, 0.42, 0.41, 0.41, 0.40, 0.40, 0.39, 0.39, 0.30, 0.18),
            new Array(2.34, 1.78, 1.43, 1.20, 1.04, 0.94, 0.86, 0.80, 0.75, 0.70, 0.66, 0.63, 0.61, 0.58, 0.56, 0.54, 0.52, 0.51, 0.50, 0.49, 0.48, 0.47, 0.46, 0.45, 0.44, 0.43, 0.42, 0.41, 0.41, 0.40, 0.40, 0.39, 0.39, 0.30, 0.18),
            new Array(2.28, 1.74, 1.40, 1.17, 1.01, 0.91, 0.83, 0.77, 0.73, 0.69, 0.65, 0.62, 0.60, 0.57, 0.55, 0.53, 0.51, 0.50, 0.49, 0.48, 0.47, 0.46, 0.45, 0.44, 0.43, 0.42, 0.41, 0.40, 0.40, 0.39, 0.39, 0.38, 0.38, 0.29, 0.17),
            new Array(2.22, 1.69, 1.36, 1.14, 0.99, 0.89, 0.82, 0.76, 0.72, 0.68, 0.64, 0.61, 0.59, 0.57, 0.55, 0.53, 0.51, 0.50, 0.49, 0.48, 0.47, 0.46, 0.45, 0.44, 0.43, 0.42, 0.41, 0.40, 0.40, 0.39, 0.39, 0.38, 0.38, 0.29, 0.17),
            new Array(2.17, 1.65, 1.33, 1.11, 0.96, 0.86, 0.79, 0.73, 0.69, 0.65, 0.61, 0.58, 0.56, 0.54, 0.52, 0.50, 0.48, 0.47, 0.46, 0.45, 0.44, 0.43, 0.42, 0.41, 0.40, 0.39, 0.38, 0.37, 0.37, 0.36, 0.36, 0.35, 0.35, 0.27, 0.16),
            new Array(2.10, 1.60, 1.29, 1.08, 0.93, 0.84, 0.77, 0.71, 0.67, 0.63, 0.60, 0.57, 0.55, 0.53, 0.51, 0.49, 0.47, 0.46, 0.45, 0.44, 0.43, 0.42, 0.41, 0.40, 0.39, 0.38, 0.37, 0.36, 0.36, 0.35, 0.35, 0.34, 0.34, 0.26, 0.15),
            new Array(2.06, 1.57, 1.26, 1.06, 0.92, 0.83, 0.76, 0.70, 0.66, 0.62, 0.59, 0.56, 0.54, 0.52, 0.50, 0.48, 0.46, 0.45, 0.44, 0.43, 0.42, 0.41, 0.40, 0.39, 0.38, 0.37, 0.36, 0.35, 0.35, 0.34, 0.34, 0.33, 0.33, 0.25, 0.15),
            new Array(2.01, 1.53, 1.23, 1.03, 0.89, 0.80, 0.73, 0.68, 0.64, 0.60, 0.57, 0.54, 0.52, 0.50, 0.48, 0.46, 0.44, 0.43, 0.42, 0.41, 0.40, 0.39, 0.38, 0.37, 0.36, 0.35, 0.34, 0.33, 0.33, 0.32, 0.32, 0.31, 0.31, 0.24, 0.14),
            new Array(1.95, 1.49, 1.20, 1.01, 0.87, 0.78, 0.72, 0.67, 0.63, 0.59, 0.56, 0.53, 0.51, 0.49, 0.47, 0.45, 0.43, 0.42, 0.41, 0.40, 0.39, 0.38, 0.37, 0.36, 0.35, 0.34, 0.33, 0.33, 0.33, 0.32, 0.32, 0.31, 0.31, 0.24, 0.14),
            new Array(1.90, 1.45, 1.17, 0.98, 0.85, 0.77, 0.71, 0.66, 0.62, 0.58, 0.55, 0.52, 0.50, 0.48, 0.46, 0.44, 0.42, 0.41, 0.40, 0.39, 0.38, 0.37, 0.36, 0.35, 0.35, 0.34, 0.33, 0.33, 0.33, 0.32, 0.32, 0.31, 0.31, 0.24, 0.14),
            new Array(1.87, 1.43, 1.15, 0.96, 0.83, 0.75, 0.69, 0.64, 0.60, 0.56, 0.53, 0.50, 0.48, 0.46, 0.44, 0.43, 0.41, 0.40, 0.39, 0.38, 0.37, 0.37, 0.36, 0.35, 0.35, 0.34, 0.33, 0.33, 0.33, 0.32, 0.32, 0.31, 0.31, 0.24, 0.14),
            new Array(1.83, 1.40, 1.13, 0.95, 0.82, 0.74, 0.68, 0.63, 0.59, 0.55, 0.52, 0.49, 0.48, 0.46, 0.44, 0.43, 0.41, 0.40, 0.39, 0.38, 0.37, 0.37, 0.36, 0.35, 0.35, 0.34, 0.33, 0.33, 0.33, 0.32, 0.32, 0.31, 0.31, 0.24, 0.14),
            new Array(1.79, 1.36, 1.09, 0.91, 0.79, 0.71, 0.65, 0.60, 0.57, 0.54, 0.51, 0.49, 0.48, 0.46, 0.44, 0.43, 0.41, 0.40, 0.39, 0.38, 0.37, 0.37, 0.36, 0.35, 0.35, 0.34, 0.33, 0.33, 0.33, 0.32, 0.32, 0.31, 0.31, 0.24, 0.14),
            new Array(1.76, 1.34, 1.08, 0.90, 0.78, 0.70, 0.64, 0.59, 0.56, 0.53, 0.50, 0.48, 0.47, 0.45, 0.44, 0.43, 0.41, 0.40, 0.39, 0.38, 0.37, 0.37, 0.36, 0.35, 0.35, 0.34, 0.33, 0.33, 0.33, 0.32, 0.32, 0.31, 0.31, 0.24, 0.14),
            new Array(1.73, 1.32, 1.06, 0.89, 0.77, 0.69, 0.63, 0.58, 0.55, 0.52, 0.49, 0.47, 0.46, 0.44, 0.43, 0.42, 0.41, 0.40, 0.39, 0.38, 0.37, 0.37, 0.36, 0.35, 0.35, 0.34, 0.33, 0.33, 0.33, 0.32, 0.32, 0.31, 0.31, 0.24, 0.14),
            new Array(1.71, 1.30, 1.05, 0.88, 0.76, 0.68, 0.62, 0.57, 0.54, 0.51, 0.48, 0.46, 0.45, 0.43, 0.42, 0.41, 0.40, 0.39, 0.38, 0.37, 0.36, 0.36, 0.36, 0.35, 0.35, 0.34, 0.33, 0.33, 0.33, 0.32, 0.32, 0.31, 0.31, 0.24, 0.14),
            new Array(1.69, 1.29, 1.04, 0.87, 0.75, 0.68, 0.62, 0.57, 0.54, 0.51, 0.48, 0.46, 0.45, 0.43, 0.42, 0.41, 0.40, 0.39, 0.38, 0.37, 0.36, 0.36, 0.36, 0.35, 0.35, 0.34, 0.33, 0.33, 0.33, 0.32, 0.32, 0.31, 0.31, 0.24, 0.14),
            new Array(1.68, 1.28, 1.03, 0.86, 0.74, 0.67, 0.61, 0.56, 0.53, 0.50, 0.47, 0.45, 0.44, 0.42, 0.41, 0.40, 0.39, 0.38, 0.37, 0.36, 0.35, 0.35, 0.35, 0.34, 0.34, 0.34, 0.33, 0.33, 0.33, 0.32, 0.32, 0.31, 0.31, 0.24, 0.14)
        );

    TargetField = Prirazky[_GetDobaUveru() - 5];
    Objem = _GetMaxPozadovanaVyseUveru();

    if (Objem < 300000)
        return 0;

    if (Objem < 3500000)
        return TargetField[Math.floor(Objem / 100000) - 3];

    if (Objem < 5000000)
        return TargetField[32];

    if (Objem < 10000000)
        return TargetField[33];

    return TargetField[34];
}

function GetOdchylkaProgres() {
    if (_GetTypSplaceni() != 2)
        return 0;

    SazbyOdchylkyProgres = GetUrokovaSazba_ProgZDatabaze();
    if (SazbyOdchylkyProgres[GetTypUveru() - 1] == null)
        return null;

    switch (_GetDelkaFixaceUrokoveSazby()) {
        case 1: return SazbyOdchylkyProgres[GetTypUveru() - 1][0];
        case 3: return SazbyOdchylkyProgres[GetTypUveru() - 1][1];
        case 5: return SazbyOdchylkyProgres[GetTypUveru() - 1][2];
        case 10: return SazbyOdchylkyProgres[GetTypUveru() - 1][3];
        case 15: return SazbyOdchylkyProgres[GetTypUveru() - 1][4];
    }

    return null;
}

function GetOdchylkaDegres() {
    if (_GetTypSplaceni() != 3)
        return 0;

    SazbyOdchylkyProgres = GetUrokovaSazba_DegrZDatabaze();
    if (SazbyOdchylkyProgres[GetTypUveru() - 1] == null)
        return null;

    switch (_GetDelkaFixaceUrokoveSazby()) {
        case 1: return SazbyOdchylkyProgres[GetTypUveru() - 1][0];
        case 3: return SazbyOdchylkyProgres[GetTypUveru() - 1][1];
        case 5: return SazbyOdchylkyProgres[GetTypUveru() - 1][2];
        case 10: return SazbyOdchylkyProgres[GetTypUveru() - 1][3];
        case 15: return SazbyOdchylkyProgres[GetTypUveru() - 1][4];
    }

    return null;
}

function GetKoefPRG() {
    switch (_GetDelkaFixaceUrokoveSazby()) {
        //case  5: return 0.00490823873508064;     
        //case 10: return 0.00519311783017143;     
        //case 15: return 0.00529028481501097;     
    }

    return 0;
}

function GetMinimumProDomacnost(PocetOsob) {
    if (PocetOsob == 0)
        return ZivotniMinimum['domacnost']['0'];

    if (PocetOsob == 1)
        return ZivotniMinimum['domacnost']['1'];

    if (PocetOsob == 2)
        return ZivotniMinimum['domacnost']['2'];

    if (PocetOsob < 5)
        return ZivotniMinimum['domacnost']['4'];

    return ZivotniMinimum['domacnost']['5'];
}

function GetMinimumProLidi(Do6, Od6, Od10, Od15, Dosp) {
    return ZivotniMinimum['osoby']['Do6'] * Do6 + ZivotniMinimum['osoby']['Od6'] * Od6 + ZivotniMinimum['osoby']['Od10'] * Od10 + ZivotniMinimum['osoby']['Od15'] * Od15 + ZivotniMinimum['osoby']['Dosp'] * Dosp;
}

function GetKas() {
    TypUveruValue = GetTypUveru();

    if ((TypUveruValue == 3) || (TypUveruValue == 7)) {
        return 1.5;
    }

    if (TypUveruValue == 2) {
        return 1.3;
    }

    return 1.25;
}

function GetSFPMax() {
    return (_GetObjektHypotecnihoUveru() == 1) ? 800000 : 1500000;
}

/***************************************************************************/
/*************************** POMOCNE VYPOCTY *******************************/
/***************************************************************************/

function GetTypUveru() {
    TU = _GetTypUveru();
    if (TU > 1)
        return TU;

    return _GetVyseUveru();
}

function ProcentoZastaveneNemovitosti() {
    if (GetTypUveru() == 8)
        return 0.5;

    if (GetTypUveru() == 2)
        return 0.85;

    if (GetTypUveru() == 3)
        return 1.00;

    return 0.70;
}

function GetPredpokladanaUrokovaSazba() {
    UrSaz = GetUrokovaSazba();
    Prirazka = GetUrokovaSazbaPrirazka();
    OdchylkaProgres = GetOdchylkaProgres();
    OdchylkaDegres = GetOdchylkaDegres();

    return Math.round((UrSaz + Prirazka + OdchylkaProgres + OdchylkaDegres) * 100) / 100;
}

/***************************************************************************/
/********************************* UPDATERY ********************************/
/***************************************************************************/

function UpdateTypUveru() {
    UpdatePoplatky();
    UpdateVyseUveru();
}

function UpdateVyseUveru() {
    while (document.getElementById('VyseUveru').options[0] != null)
        document.getElementById('VyseUveru').options[0] = null;

    if (_GetTypUveru() == 8) {
        document.getElementById('VyseUveru').options[0] = new Option('50 %', '50');
    }
    else {
        document.getElementById('VyseUveru').options[0] = new Option('70 %', '70');
    }

    if (_GetTypUveru() == 1) {
        document.getElementById('VyseUveru').options[1] = new Option('85 %', '85');
        document.getElementById('VyseUveru').options[2] = new Option('100 %', '100');
    }

    UpdateVyseUveruCallback();
}

function UpdateVyseUveruCallback() {
    UpdateTypSplaceni();
}

function UpdateTypSplaceni() {
    var actualTypSplaceni = _GetTypSplaceni();

    while (document.getElementById('TypSplaceni').options[0] != null)
        document.getElementById('TypSplaceni').options[0] = null;

    var counter = 0;

    document.getElementById('TypSplaceni').options[counter] = new Option('Anuitní', '1');
    if (actualTypSplaceni == 1)
        document.getElementById('TypSplaceni').options[counter].selected = true;
    counter++;
    /*
    if ( ( _GetVyseUveru() != 3 ) && ( ( _GetTypUveru() == 1 ) || ( _GetTypUveru() == 2 ) || ( _GetTypUveru() == 8 ) ) )
    {
    document.getElementById ( 'TypSplaceni' ).options[counter] = new Option ( 'Progresivní', '2' );
    if ( actualTypSplaceni == 2 )
    document.getElementById ( 'TypSplaceni' ).options[counter].selected = true;
    counter++;
    }

        if ( ( _GetTypUveru() != 5 ) && ( _GetTypUveru() != 6 ) )
    {
    document.getElementById ( 'TypSplaceni' ) . options[counter] = new Option ( 'Degresivní', '3' );
    if ( actualTypSplaceni == 3 )
    document.getElementById ( 'TypSplaceni' ).options[counter].selected = true;
    counter++
    }
    */
    UpdateTypSplaceniCallback();
}

function UpdateTypSplaceniCallback() {
    //document.getElementById ( 'MesicniSplatkaAnuitaDIV' ).style.display = ( _GetAnuita() ) ? 'block' : 'none';
    //document.getElementById ( 'MesicniSplatkaNeAnuitaDIV' ).style.display = ( ! _GetAnuita() ) ? 'block' : 'none';

    UpdateDobaUveru();
    UpdateMaxVyseUveru();
}

function UpdateDobaUveru() {
    var DobaUveru = document.getElementById('DobaUveru');

    if (_GetTypSplaceni() == 2) {
        Min = 20;
        Max = 20;
    }
    else {
        Min = (GetTypUveru() == 7) ? 3 : 5;
        Max = (GetTypUveru() == 7) ? 20 : 30;
    }

    ActualDobaUveru = DobaUveru.value;
    while (DobaUveru.options[0] != null)
        DobaUveru.options[0] = null;

    for (i = Min; i <= Max; i++) {
        Label = (i < 5) ? 'roky' : 'let';

        DobaUveru.options[i - Min] = new Option(i + ' ' + Label, '' + i + '');

        if (i == ActualDobaUveru)
            DobaUveru.options[i - Min].selected = true;
    }

    UpdateDobaUveruCallback();
}

function UpdateDobaUveruCallback() {
    UpdateDelkaFixaceUrokoveSazby();
}

function UpdatePoplatky() {
    var HypotekaBezPoplatku0 = document.getElementById('HypotekaBezPoplatku0');
    var HypotekaBezPoplatku1 = document.getElementById('HypotekaBezPoplatku1');

    if ((GetTypUveru() == 7) || (GetTypUveru() == 8)) {
        HypotekaBezPoplatku0.disabled = true;
        HypotekaBezPoplatku1.checked = true;
    }
    else
        HypotekaBezPoplatku0.disabled = false;

    UpdatePoplatkyCallback();
}

function UpdatePoplatkyCallback() {
    UpdateDelkaFixaceUrokoveSazby();
    UpdateSpravaUveru();
}

function UpdatePredpokladanaHodnota() {
    ConvertAndGetAbsoluteByID('PredpokladanaHodnota');
    UpdateMaxVyseUveru();
}

function UpdateVyseInvestice() {
    ConvertAndGetAbsoluteByID('VyseInvestice');
    UpdatePotrebnaVyseVlastnichProstredku();
}

function UpdateMaxVyseUveru() {
    var MaxVyseUveru = document.getElementById('MaxVyseUveru');
    var PredpokladanaHodnota = document.getElementById('PredpokladanaHodnota');

    MaxVyseUveru.value = CurrencyFormat(ConvertStringToInteger(PredpokladanaHodnota.value) * ProcentoZastaveneNemovitosti());

    UpdatePotrebnaVyseVlastnichProstredku();
}

function UpdatePotrebnaVyseVlastnichProstredku() {
    MaxVyseUveruValue = ConvertStringToInteger(document.getElementById('MaxVyseUveru').value);
    VyseInvesticeValue = ConvertStringToInteger(document.getElementById('VyseInvestice').value);

    document.getElementById('PotrebnaVyseVlastnichProstredku').value = CurrencyFormat(Math.max(0, VyseInvesticeValue - MaxVyseUveruValue));
    UpdateSkutecnaVyseVlastnichProstredku();
}

function UpdateSkutecnaVyseVlastnichProstredku() {
    value = ConvertAndGetAbsoluteByID('SkutecnaVyseVlastnichProstredku');

    if (ConvertStringToInteger(document.getElementById('PotrebnaVyseVlastnichProstredku').value) > value) {
        alert('Musíte mít naspořenou alespoň potřebnou výši vlastních prostředků. Bude doplněna minimální hodnota.');
        document.getElementById('SkutecnaVyseVlastnichProstredku').value = document.getElementById('PotrebnaVyseVlastnichProstredku').value;
    }

    UpdateMaxPozadovanaVyseUveru();
}

function UpdateMaxPozadovanaVyseUveru() {
    var MaxVyseUv = ConvertStringToInteger(document.getElementById('MaxVyseUveru').value);
    var Warning2 = document.getElementById('MaxPozadovanaVyseUveru200000Warning');
    var Warning3 = document.getElementById('MaxPozadovanaVyseUveru300000Warning');
    var MaxPozadovanaVyseUveru = document.getElementById('MaxPozadovanaVyseUveru');

    if (MaxVyseUv == 0)
        value = CurrencyFormat(0);
    else {
        Zamer = ConvertStringToInteger(document.getElementById('VyseInvestice').value);
        Nasporeno = ConvertStringToInteger(document.getElementById('SkutecnaVyseVlastnichProstredku').value);
        Minimum = Math.min(Zamer - Nasporeno, MaxVyseUv);

        if (GetTypUveru() != 7) {
            if (Minimum < 300000) {
                MaxPozadovanaVyseUveru.style.display = 'none';
                Warning3.style.display = 'block';
                Warning2.style.display = 'none';

                value = '';
            }
            else {
                MaxPozadovanaVyseUveru.style.display = 'block';
                Warning3.style.display = 'none';
                Warning2.style.display = 'none';

                value = CurrencyFormat(Minimum);
            }
        }

        else {
            if (Minimum < 200000) {
                MaxPozadovanaVyseUveru.style.display = 'none';
                Warning3.style.display = 'none';
                Warning2.style.display = 'block';

                value = '';
            }
            else {
                MaxPozadovanaVyseUveru.style.display = 'block';
                Warning3.style.display = 'none';
                Warning2.style.display = 'none';

                value = CurrencyFormat(Minimum);
            }
        }
    }

    MaxPozadovanaVyseUveru.value = value;
    UpdatePredpokladanaUrokovaSazba();
}

function UpdateDelkaFixaceUrokoveSazby() {
    var DelkaFixaceUrokoveSazby = document.getElementById('DelkaFixaceUrokoveSazby');

    ActualDelkaFixace = DelkaFixaceUrokoveSazby.value;

    while (DelkaFixaceUrokoveSazby.options[0] != null)
        DelkaFixaceUrokoveSazby.options[0] = null;

    counter = 0;

    if (_GetAnuita() && !_GetPoplatky() && (GetTypUveru() != 4)) {
        DelkaFixaceUrokoveSazby.options[counter] = new Option('1 rok', '1');
        if (ActualDelkaFixace == 1)
            DelkaFixaceUrokoveSazby.options[counter].selected = true;

        counter++;
    }

    if (_GetAnuita() && (GetTypUveru() != 4)) {
        DelkaFixaceUrokoveSazby.options[counter] = new Option('3 roky', '3');
        if (ActualDelkaFixace == 3)
            DelkaFixaceUrokoveSazby.options[counter].selected = true;

        counter++;
    }

    if (_GetDobaUveru() >= 5) {
        DelkaFixaceUrokoveSazby.options[counter] = new Option('5 let', '5');
        if (ActualDelkaFixace == 5)
            DelkaFixaceUrokoveSazby.options[counter].selected = true;

        counter++;
    }

    UpdateDelkaFixaceUrokoveSazbyCallback();
}

function UpdateDelkaFixaceUrokoveSazbyCallback() {
    UpdatePredpokladanaUrokovaSazba();
}

function UpdatePredpokladanaUrokovaSazba() {
    document.getElementById('PredpokladanaUrokovaSazba').value = GetPredpokladanaUrokovaSazba() + ' %';
    UpdateMesicniSplatka();
    UpdateVolbaVyseSplatkyLabel();
}

function UpdateMesicniSplatka() {
    MaxVyseUveruValue = ConvertStringToInteger(document.getElementById('MaxVyseUveru').value);

    if (MaxVyseUveruValue == 0)
        result = 0;
    else {
        Objem = _GetMaxPozadovanaVyseUveru();
        Sazba = GetPredpokladanaUrokovaSazba() / 100;
        Doba = _GetDobaUveru();

        if (GetTypUveru() == 4)
            result = Objem * GetKoefPRG();  // TODO

        else if ((GetTypUveru() == 5) || (GetTypUveru() == 6))
            result = Objem * Sazba / 12;    // TODO

        else
            result = ExcelPMT(Sazba / 12, Doba * 12, -Objem);
    }

    document.getElementById('MesicniSplatka').value = CurrencyFormat(result);
    UpdateStatniFinancniPodpora();
}

function UpdateVolbaVyseSplatkyLabel() {
    document.getElementById('MesicniSplatkaNeAnuitaOd').innerHTML = CurrencyFormat(_GetMesicniSplatkaNeAnuitaOd());
    document.getElementById('MesicniSplatkaNeAnuitaDo').innerHTML = CurrencyFormat(_GetMesicniSplatkaNeAnuitaDo());
}

function UpdateMesicniSplatkaNeAnuita() {
    var MesicniSplatkaNeAnuita = document.getElementById('MesicniSplatkaNeAnuita');
    var MesicniSplatkaNeAnuitaValue = ConvertAndGet(MesicniSplatkaNeAnuita);

    if (MesicniSplatkaNeAnuitaValue < _GetMesicniSplatkaNeAnuitaOd()) {
        alert('Zvolená měsíční částka je menší než požadované minimum. Bude doplněna nejnižší možná hodnota.');
        MesicniSplatkaNeAnuita.value = CurrencyFormat(_GetMesicniSplatkaNeAnuitaOd());
    }
    else if (MesicniSplatkaNeAnuitaValue > _GetMesicniSplatkaNeAnuitaDo()) {
        alert('Zvolená měsíční částka je vyšší než možné maximum. Bude doplněna nejvyšší možná hodnota.');
        MesicniSplatkaNeAnuita.value = CurrencyFormat(_GetMesicniSplatkaNeAnuitaDo());
    }

    UpdateMesicniSplatkaNeAnuitaCallback();
}

function UpdateMesicniSplatkaNeAnuitaCallback() {
    UpdateMesicniSplatkaVcetneFinancniPodpory();
}

function UpdateStatniFinancniPodpora() {
    // if ( ! _GetSeStatniFinancniPodporou() )
    SFP = 0;

    /*
    else
    {
    SFPObjem    = GetSFPMax();
    SFPActual   = 1;    // %
    SFPDobaMAX  = 10;

            SFPAnuitaPred   = ExcelPMT ( GetPredpokladanaUrokovaSazba() / 12 / 100, Math.min ( _GetDobaUveru(), SFPDobaMAX ) * 12, - Math.min ( SFPObjem, _GetMaxPozadovanaVyseUveru() ) );
    SFPAnuitaPo     = ExcelPMT ( ( GetPredpokladanaUrokovaSazba() - SFPActual ) / 12 / 100, Math.min ( _GetDobaUveru(), SFPDobaMAX ) * 12, - Math.min ( SFPObjem, _GetMaxPozadovanaVyseUveru() ) );

            SFP = SFPAnuitaPred - SFPAnuitaPo;
    }
    */

    document.getElementById('StatniFinancniPodpora').value = CurrencyFormat(SFP);
    UpdateMesicniSplatkaVcetneFinancniPodpory();
}

function UpdateMesicniSplatkaVcetneFinancniPodpory() {
    var StatniFinancniPodpora = document.getElementById('StatniFinancniPodpora');
    var MaxVyseUveru = document.getElementById('MaxVyseUveru');
    document.getElementById('MesicniSplatkaVcetneFinancniPodpory').value = CurrencyFormat((ConvertStringToInteger(MaxVyseUveru.value) == 0) ? 0 : _GetMesicniSplatka() - ConvertStringToInteger(StatniFinancniPodpora.value));

    UpdateMesicniUsporaNaDanich();
    UpdateSpravaUveru();
}

function UpdateHrubyPrijemCallback() {
    ConvertAndGetAbsoluteByID('HrubyPrijem');
    UpdateMesicniUsporaNaDanich();
}

function UpdateMesicniUsporaNaDanich() {
    var value = null;
    if (ConvertStringToInteger(document.getElementById('MaxVyseUveru').value) == 0)
        value = 0;
    else {
        HrubyPrijemValue = ConvertStringToInteger(document.getElementById('HrubyPrijem').value);

        if (HrubyPrijemValue == 0)
            value = 0;
        else if ((GetTypUveru() == 7))
            value = 0;
        else {
            UrokOdpocet = Math.min(25000, _GetMaxPozadovanaVyseUveru() * GetPredpokladanaUrokovaSazba() / 12 / 100 - ConvertStringToInteger(document.getElementById('StatniFinancniPodpora').value));
            CistaMzda2 = CistaMzdaUrokOdpocet(HrubyPrijemValue, 3170, UrokOdpocet);
            value = CistaMzda2 - CistaMzda(HrubyPrijemValue, 3170);
            //value = value * 0.92;
        }
    }
    document.getElementById('MesicniUsporaNaDanich').value = CurrencyFormat(value);
}

function UpdateSpravaUveru() {
    if (_GetPoplatky())
        value = 0;
    else if (_GetSeStatniFinancniPodporou())
        value = 220;
    else
        value = 150;

    document.getElementById('SpravaUveru').value = CurrencyFormat(value);
    UpdateMesicniVydajeCelkem();
}

function UpdateSplatkyJinychUveruCallback() {
    ConvertAndGetAbsoluteByID('SplatkyJinychUveru');
    UpdateMesicniVydajeCelkem();
}

function UpdatePojistneZaNemovitostCallback() {
    ConvertAndGetAbsoluteByID('PojistneZaNemovitost');
    UpdateMesicniVydajeCelkem();
}

function UpdateJinePojistkyCallback() {
    ConvertAndGetAbsoluteByID('JinePojistky');
    UpdateMesicniVydajeCelkem();
}

function UpdateZivotniMinimum() {
    PocetDo6 = parseInt(document.getElementById('PocetClenuDo6Let').value);
    PocetOd6 = parseInt(document.getElementById('PocetClenuOd6Let').value);
    PocetOd10 = parseInt(document.getElementById('PocetClenuOd10Let').value);
    PocetOd15 = parseInt(document.getElementById('PocetClenuOd15Let').value);
    PocetDosp = parseInt(document.getElementById('PocetClenuDospeli').value);

    Dom = GetMinimumProDomacnost(PocetDo6 + PocetOd6 + PocetOd10 + PocetOd15 + PocetDosp);
    Lidi = GetMinimumProLidi(PocetDo6, PocetOd6, PocetOd10, PocetOd15, PocetDosp);

    document.getElementById('ZivotniMinimum').value = CurrencyFormat(Dom + Lidi);

    UpdateMesicniVydajeCelkem();
}

function UpdateMesicniVydajeCelkem() {
    document.getElementById('MesicniVydajeCelkem').value = CurrencyFormat(
            ConvertStringToInteger(document.getElementById('ZivotniMinimum').value)
            + ConvertStringToInteger(document.getElementById('SpravaUveru').value)
            + ConvertStringToInteger(document.getElementById('SplatkyJinychUveru').value)
            + ConvertStringToInteger(document.getElementById('PojistneZaNemovitost').value)
            + ConvertStringToInteger(document.getElementById('JinePojistky').value));

    UpdateMaximalniVyseUveruPriDanichAPrijmech();
}

function UpdateMesicniPrijmyCelkem() {
    Prijem1 = ConvertAndGetAbsoluteByID('PrijmyZadatel1');
    Prijem2 = ConvertAndGetAbsoluteByID('PrijmyZadatel2');
    Prijem3 = ConvertAndGetAbsoluteByID('PrijmyZadatel3');
    Prijem4 = ConvertAndGetAbsoluteByID('PrijmyZadatel4');

    document.getElementById('MesicniPrijmyCelkem').value = CurrencyFormat(Prijem1 + Prijem2 + Prijem3 + Prijem4);
    UpdateMaximalniVyseUveruPriDanichAPrijmech();
}

function UpdateMaximalniVyseUveruPriDanichAPrijmech() {
    PrijmyCelkem = ConvertStringToInteger(document.getElementById('MesicniPrijmyCelkem').value);
    VydajeCelkem = ConvertStringToInteger(document.getElementById('MesicniVydajeCelkem').value);

    value = (PrijmyCelkem <= 0)
            ? 0 : MaxObjemAnuita((PrijmyCelkem - VydajeCelkem) / GetKas(), _GetDobaUveru(), GetPredpokladanaUrokovaSazba() / 100);

    value = Math.round(value / 1000) * 1000;

    document.getElementById('MaximalniVyseUveruPriDanichAPrijmech').value = CurrencyFormat(value);

    value = (ConvertStringToInteger(document.getElementById('MaxVyseUveru').value) == 0)
            ? 0 : VydajeCelkem + _GetMesicniSplatka() * GetKas() - ConvertStringToInteger(document.getElementById('StatniFinancniPodpora').value);

    //value = value + 6000;

    document.getElementById('PotrebnyCistyPrijem').value = CurrencyFormat(value);
}

//////TODO
////function LoadArrays() {
////    //    Velká / Úrokové sazby / HUF70
////    sazby[0] = new Array(5.69, 5.49, 5.49, 5.69, 5.69);
////    //    Velká / Úrokové sazby / HUF85
////    sazby[1] = new Array(5.69, 5.49, 5.49, 5.69, 5.69);
////    //    Velká / Úrokové sazby / HUF100
////    sazby[2] = new Array(6.49, 6.29, 6.29, 6.49, 6.49);
////    //    Velká / Úrokové sazby / Americka hypoteka
////    sazby[6] = new Array(8.74, 7.94, 7.94);
////    //    Velká / Úrokové sazby / HUF  bez prijmu
////    sazby[7] = new Array(7.64, 7.44, 7.44, 7.64, 7.64);

////    //    Malá / Sazba / Produkt 1
////    Sazba1 = 0.0549;
////    //    Malá / Sazba / Produkt 2
////    Sazba2 = 0.0549;
////    //    Malá / Sazba / Produkt 3
////    Sazba3 = 0.0629;

////    //    zivotni minimum pro vsechy osoby v domacnosti dohromady podle poctu osob
////    ZivotniMinimum['domacnost']['0'] = 0;
////    ZivotniMinimum['domacnost']['1'] = 2653;
////    ZivotniMinimum['domacnost']['2'] = 4055;
////    ZivotniMinimum['domacnost']['4'] = 6574;
////    ZivotniMinimum['domacnost']['5'] = 7385;

////    //    zivotni minimum pro jednotlive osoby v domacnosti podle veku
////    ZivotniMinimum['osoby']['Do6'] = 1600;
////    ZivotniMinimum['osoby']['Od6'] = 1960;
////    ZivotniMinimum['osoby']['Od10'] = 1960;
////    ZivotniMinimum['osoby']['Od15'] = 2250;
////    ZivotniMinimum['osoby']['Dosp'] = 3126;

////    try {
////        document.getElementById('castkaDo6').textContent = ZivotniMinimum['osoby']['Do6'];
////        document.getElementById('castkaOd6').textContent = ZivotniMinimum['osoby']['Od6'];
////        document.getElementById('castkaOd10').textContent = ZivotniMinimum['osoby']['Od10'];
////        document.getElementById('castkaOd15').textContent = ZivotniMinimum['osoby']['Od15'];
////        document.getElementById('castkaDosp').textContent = ZivotniMinimum['osoby']['Dosp'];
////    }
////    catch (e) {
////    }
////}

function GetUrokovaSazba_SazbyZDatabaze() {
    return sazby;
}

function GetUrokovaSazba_ProgZDatabaze() {
    return progr;
}

function GetUrokovaSazba_DegrZDatabaze() {
    return degr;
}

function GetKoef(C, M) {
    if (C - M < 200000)
        return 0;

    Koef = 1 - M / C;

    if (Koef <= 0.7)
        return 0.7;

    if (Koef <= 0.85)
        return 0.85;

    return 1;
}

function GetKas(Koef) {
    if (Koef <= 0.7)
        return 1.25;

    if (Koef <= 0.85)
        return 1.3;

    return 1.5;
}

function UpdateSpl() {
    C = Math.max(0, ConvertStringToInteger(document.getElementById('Cena').value));
    M = Math.max(0, ConvertStringToInteger(document.getElementById('Mam').value));

    document.getElementById('CenaValue').value = C;
    document.getElementById('MamValue').value = M;

    document.getElementById('Cena').value = CurrencyFormat(C);
    document.getElementById('Mam').value = CurrencyFormat(M);

    Koef = GetKoef(C, M);
    if (Koef == 0)
        alert('Minimální výše hypotečního úvěru je 200.000,- Kč. Zvyšte cenu nemovitosti, nebo snižte naspořenou částku.');

    document.getElementById('VyseUveruPoskytnuteho').value = (Koef > 0)
                            ? 'do ' + Math.round(Koef * 100) + '%'
                            : '';

    document.getElementById('VyseHypotecnihoUveru').value = (Koef > 0)
                            ? CurrencyFormat(C - M)
                            : '';

    document.getElementById('MesicniAnuitSplatka').value = (Koef > 0)
                            ? CurrencyFormat(ExcelPMT(GetSazba(Koef) / 12, Doba * 12, M - C))
                            : '';

    if (Koef < 1) {
        document.getElementById('MesicniProgrSplatkaContainer').disabled = false;

        var Splatka = ExcelIPMT(GetSazbaProg(Koef) / 12, 1, Doba * 12, M - C);
        document.getElementById('MesicniProgrSplatka').value = (Koef > 0)
                                ? CurrencyFormat(Splatka)
                                : '';
    }
    else {
        document.getElementById('MesicniProgrSplatkaContainer').disabled = true;
        document.getElementById('MesicniProgrSplatka').value = '';

        var Splatka = ExcelPMT(GetSazba(Koef) / 12, Doba * 12, M - C);
    }

    document.getElementById('MesicniDegrSplatka').value = (Koef > 0)
                            ? CurrencyFormat(ExcelPMT(GetSazbaDegr(Koef) / 12, Doba * 12, M - C) * 2)
                            : '';

    document.getElementById('MinCistyPrijem').value = (Koef > 0)
                            ? CurrencyFormat(ExcelPMT(GetSazba(Koef) / 12, Doba * 12, M - C) * GetKas(Koef) + 9810 + 300)
                            : '';
}

function UpdateMax() {
    VyseSplatky = ConvertAndGetAbsoluteByID('Splatka2');

    // vypocet
    maxobjem_70 = MaxObjemAnuita(VyseSplatky, Doba2, GetSazba(0.7));
    maxobjem_progr_70 = MaxObjemUrok(VyseSplatky, GetSazbaProg(0.7));
    maxobjem_degr_70 = MaxObjemAnuita(VyseSplatky / 2, Doba2, GetSazbaDegr(0.7));

    maxobjem_85 = MaxObjemAnuita(VyseSplatky, Doba2, GetSazba(0.85));
    maxobjem_progr_85 = MaxObjemUrok(VyseSplatky, GetSazbaProg(0.85));
    maxobjem_degr_85 = MaxObjemAnuita(VyseSplatky / 2, Doba2, GetSazbaDegr(0.85));

    maxobjem_100 = MaxObjemAnuita(VyseSplatky, Doba2, GetSazba(1));
    maxobjem_degr_100 = MaxObjemAnuita(VyseSplatky / 2, Doba2, GetSazbaDegr(1));

    // odkazy na inputy v HTML kodu
    var vyseuveru_70 = document.getElementById('vyseuveru_70');
    var maxcena_70 = document.getElementById('maxcena_70');
    var nasporeno_70 = document.getElementById('nasporeno_70');

    var vyseuveru_progr_70 = document.getElementById('vyseuveru_progr_70');
    var maxcena_progr_70 = document.getElementById('maxcena_progr_70');
    var nasporeno_progr_70 = document.getElementById('nasporeno_progr_70');

    var vyseuveru_degr_70 = document.getElementById('vyseuveru_degr_70');
    var maxcena_degr_70 = document.getElementById('maxcena_degr_70');
    var nasporeno_degr_70 = document.getElementById('nasporeno_degr_70');

    var vyseuveru_85 = document.getElementById('vyseuveru_85');
    var maxcena_85 = document.getElementById('maxcena_85');
    var nasporeno_85 = document.getElementById('nasporeno_85');

    var vyseuveru_progr_85 = document.getElementById('vyseuveru_progr_85');
    var maxcena_progr_85 = document.getElementById('maxcena_progr_85');
    var nasporeno_progr_85 = document.getElementById('nasporeno_progr_85');

    var vyseuveru_degr_85 = document.getElementById('vyseuveru_degr_85');
    var maxcena_degr_85 = document.getElementById('maxcena_degr_85');
    var nasporeno_degr_85 = document.getElementById('nasporeno_degr_85');

    var vyseuveru_100 = document.getElementById('vyseuveru_100');
    var maxcena_100 = document.getElementById('maxcena_100');
    var nasporeno_100 = document.getElementById('nasporeno_100');

    var vyseuveru_degr_100 = document.getElementById('vyseuveru_degr_100');
    var maxcena_degr_100 = document.getElementById('maxcena_degr_100');
    var nasporeno_degr_100 = document.getElementById('nasporeno_degr_100');

    // do 70% hodnoty nemovitosti
    if (maxobjem_70 < 300000) {
        vyseuveru_70.value = 'Minimální výše úvěru je 300.000,-';
        maxcena_70.value = '- - -';
        nasporeno_70.value = '- - -';
    }
    else {
        vyseuveru_70.value = CurrencyFormat(Math.round(maxobjem_70));
        maxcena_70.value = CurrencyFormat(Math.round(maxobjem_70 / 0.7));
        nasporeno_70.value = CurrencyFormat(Math.round(maxobjem_70 / 0.7) - Math.round(maxobjem_70));
    }

    if (maxobjem_progr_70 < 300000) {
        vyseuveru_progr_70.value = 'Minimální výše úvěru je 300.000,-';
        maxcena_progr_70.value = '- - -';
        nasporeno_progr_70.value = '- - -';
    }
    else {
        vyseuveru_progr_70.value = CurrencyFormat(Math.round(maxobjem_progr_70));
        maxcena_progr_70.value = CurrencyFormat(Math.round(maxobjem_progr_70 / 0.7));
        nasporeno_progr_70.value = CurrencyFormat(Math.round(maxobjem_progr_70 / 0.7) - Math.round(maxobjem_progr_70));
    }

    if (maxobjem_degr_70 < 300000) {
        vyseuveru_degr_70.value = 'Minimální výše úvěru je 300.000,-';
        maxcena_degr_70.value = '- - -';
        nasporeno_degr_70.value = '- - -';
    }
    else {
        vyseuveru_degr_70.value = CurrencyFormat(Math.round(maxobjem_degr_70));
        maxcena_degr_70.value = CurrencyFormat(Math.round(maxobjem_degr_70 / 0.7));
        nasporeno_degr_70.value = CurrencyFormat(Math.round(maxobjem_degr_70 / 0.7) - Math.round(maxobjem_degr_70));
    }

    // do 85% hodnoty nemovitosti
    if (maxobjem_85 < 300000) {
        vyseuveru_85.value = 'Minimální výše úvěru je 300.000,-';
        maxcena_85.value = '- - -';
        nasporeno_85.value = '- - -';
    }
    else {
        vyseuveru_85.value = CurrencyFormat(Math.round(maxobjem_85));
        maxcena_85.value = CurrencyFormat(Math.round(maxobjem_85 / 0.85));
        nasporeno_85.value = CurrencyFormat(Math.round(maxobjem_85 / 0.85) - Math.round(maxobjem_85));
    }

    if (maxobjem_progr_85 < 300000) {
        vyseuveru_progr_85.value = 'Minimální výše úvěru je 300.000,-';
        maxcena_progr_85.value = '- - -';
        nasporeno_progr_85.value = '- - -';
    }
    else {
        vyseuveru_progr_85.value = CurrencyFormat(Math.round(maxobjem_progr_85));
        maxcena_progr_85.value = CurrencyFormat(Math.round(maxobjem_progr_85 / 0.85));
        nasporeno_progr_85.value = CurrencyFormat(Math.round(maxobjem_progr_85 / 0.85) - Math.round(maxobjem_progr_85));
    }

    if (maxobjem_degr_85 < 300000) {
        vyseuveru_degr_85.value = 'Minimální výše úvěru je 300.000,-';
        maxcena_degr_85.value = '- - -';
        nasporeno_degr_85.value = '- - -';
    }
    else {
        vyseuveru_degr_85.value = CurrencyFormat(Math.round(maxobjem_degr_85));
        maxcena_degr_85.value = CurrencyFormat(Math.round(maxobjem_degr_85 / 0.85));
        nasporeno_degr_85.value = CurrencyFormat(Math.round(maxobjem_degr_85 / 0.85) - Math.round(maxobjem_degr_85));
    }

    // do 100% hodnoty nemovitosti
    if (maxobjem_100 < 300000) {
        vyseuveru_100.value = 'Minimální výše úvěru je 300.000,-';
        maxcena_100.value = '- - -';
        nasporeno_100.value = '- - -';
    }
    else {
        vyseuveru_100.value = CurrencyFormat(Math.round(maxobjem_100));
        maxcena_100.value = CurrencyFormat(Math.round(maxobjem_100));
        nasporeno_100.value = CurrencyFormat(0);
    }

    if (maxobjem_degr_100 < 300000) {
        vyseuveru_degr_100.value = 'Minimální výše úvěru je 300.000,-';
        maxcena_degr_100.value = '- - -';
        nasporeno_degr_100.value = '- - -';
    }
    else {
        vyseuveru_degr_100.value = CurrencyFormat(Math.round(maxobjem_degr_100));
        maxcena_degr_100.value = CurrencyFormat(Math.round(maxobjem_degr_100));
        nasporeno_degr_100.value = CurrencyFormat(0);
    }
}

function InitCalc() {
    if (window.addEventListener) {
        window.addEventListener("load", LoadArrays, false);
    }
    else if (window.attachEvent) {
        window.attachEvent("onload", LoadArrays);
    }
    else {
        window.onload = LoadArrays;
    }
}

function InitCompl() {
    if (window.addEventListener) {
        window.addEventListener("load", LoadArrays, false);
        window.addEventListener("load", LoadStyles, false);
    }
    else if (window.attachEvent) {
        window.attachEvent("onload", LoadArrays);
        window.attachEvent("onload", LoadStyles);
    }
    else {
        window.onload = LoadArrays;
        window.onload = LoadStyles;
    }
}

function LoadStyles() {
    document.getElementById('splatky').style.display = 'block';
    document.getElementById('maximum').style.display = 'none';
    document.getElementById('vypocet').style.display = 'none';
    document.getElementById('splatkyLink').style.display = 'none';
    document.getElementById('maximumLink').style.display = 'block';
    document.getElementById('vypocetLink').style.display = 'block';
}

function SelectCalc(type) {
    var style1 = document.getElementById('splatky').style;
    var style2 = document.getElementById('maximum').style;
    var style3 = document.getElementById('vypocet').style;
    var style4 = document.getElementById('splatkyLink').style;
    var style5 = document.getElementById('maximumLink').style;
    var style6 = document.getElementById('vypocetLink').style;

    if (type == 'splatky') {
        style1.display = 'block';
        style2.display = 'none';
        style3.display = 'none';
        style4.display = 'none';
        style5.display = 'block';
        style6.display = 'block';
    } else if (type == 'maximum') {
        style1.display = 'none';
        style2.display = 'block';
        style3.display = 'none';
        style4.display = 'block';
        style5.display = 'none';
        style6.display = 'block';
    } else if (type == 'vypocet') {
        style1.display = 'none';
        style2.display = 'none';
        style3.display = 'block';
        style4.display = 'block';
        style5.display = 'block';
        style6.display = 'none';
    }

    return false;
}