function checkout() {
    var 
  location = "https://secure.shareit.com/shareit/checkout.html?PRODUCT[300252073]=1",
  clientCount, userCount, countOperator, countStaff, countClient;

    if ((countOperator = document.getElementById("iOperators").value) < 1) {
        countOperator = 1;
        alert("Die minimale Anzahl der Betriebsanwender-Lizenzen ist 1!");
        document.getElementById("iOperators").value = 1;
    }

    if ((countStaff = document.getElementById("iStaffs").value) < 1) {
        countStaff = 1;
        alert("Die minimale Anzahl der Wartungsfachmann-Lizenzen ist 1!");
        document.getElementById("iStaffs").value = 1;
    }

    if ((countClient = document.getElementById("iClients").value) < 5) {
        countClient = 5;
        alert("Die minimale Anzahl von Kunden-Lizenzen beträgt 5!");
        document.getElementById("iClients").value = 5;
    }
    calcPrice();

    if (countOperator >= 2) {
        location = location + "&PRODUCT[300320941]=1";
    }
    if (countOperator >= 3) {
        operatorCount = countOperator - 2;
        if (operatorCount > 3)
            operatorCount = 3;
        location = location + "&PRODUCT[300320942]=" + operatorCount;
    }
    if (countOperator >= 6) {
        operatorCount = countOperator - 5;
        if (operatorCount > 5)
            operatorCount = 5;
        location = location + "&PRODUCT[300320943]=" + operatorCount;
    }
    if (countOperator >= 11) {
        operatorCount = countOperator - 10;
        if (operatorCount > 10)
            operatorCount = 10;
        location = location + "&PRODUCT[300320944]=" + operatorCount;
    }
    if (countOperator >= 21) {
        operatorCount = countOperator - 20;
        if (operatorCount > 30)
            operatorCount = 30;
        location = location + "&PRODUCT[300320945]=" + operatorCount;
    }
    if (countOperator >= 51) {
        operatorCount = countOperator - 50;
        if (operatorCount > 50)
            operatorCount = 50;
        location = location + "&PRODUCT[300320946]=" + operatorCount;
    }
    if (countOperator >= 101) {
        operatorCount = countOperator - 100;
        location = location + "&PRODUCT[300320947]=" + operatorCount;
    }

    if (countStaff >= 2) {
        location = location + "&PRODUCT[300320948]=1";
    }
    if (countStaff >= 3) {
        staffCount = countStaff - 2;
        if (staffCount > 3)
            staffCount = 3;
        location = location + "&PRODUCT[300320949]=" + staffCount;
    }
    if (countStaff >= 6) {
        staffCount = countStaff - 5;
        if (staffCount > 5)
            staffCount = 5;
        location = location + "&PRODUCT[300320950]=" + staffCount;
    }
    if (countStaff >= 11) {
        staffCount = countStaff - 10;
        if (staffCount > 10)
            staffCount = 10;
        location = location + "&PRODUCT[300320951]=" + staffCount;
    }
    if (countStaff >= 21) {
        staffCount = countStaff - 20;
        if (staffCount > 30)
            staffCount = 30;
        location = location + "&PRODUCT[300320952]=" + staffCount;
    }
    if (countStaff >= 51) {
        staffCount = countStaff - 50;
        if (staffCount > 50)
            staffCount = 50;
        location = location + "&PRODUCT[300320953]=" + staffCount;
    }
    if (countStaff >= 101) {
        staffCount = countStaff - 100;
        location = location + "&PRODUCT[300320954]=" + staffCount;
    }

    if (countClient >= 6) {
        clientCount = countClient - 5;
        if (clientCount > 5)
            clientCount = 5;
        location = location + "&PRODUCT[300320955]=" + clientCount;
    }
    if (countClient >= 11) {
        clientCount = countClient - 10;
        if (clientCount > 10)
            clientCount = 10;
        location = location + "&PRODUCT[300320956]=" + clientCount;
    }
    if (countClient >= 21) {
        clientCount = countClient - 20;
        if (clientCount > 30)
            clientCount = 30;
        location = location + "&PRODUCT[300320957]=" + clientCount;
    }
    if (countClient >= 51) {
        clientCount = countClient - 50;
        if (clientCount > 50)
            clientCount = 50;
        location = location + "&PRODUCT[300320958]=" + clientCount;
    }
    if (countClient >= 101) {
        clientCount = countClient - 100;
        location = location + "&PRODUCT[300320959]=" + clientCount;
    }

    location = location + "&languageid=2&currencies=EUR" + "&backlink=http%3A%2F%2Fwww.cmmsservice.com";
    //window.location=location;
    window.open(location, "_blank");
}

function formatEUR(num) {
    num = num.toString().replace(/\$|\,/g, '');

    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();

    if (cents < 10)
        cents = "0" + cents;

    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + '.' +
  num.substring(num.length - (4 * i + 3));
    return (((sign) ? '' : '-') + num + "," + cents);
}

function calcPrice() {
    var i = 0;
    var arrLicense = new Array();
    var arrOperator = new Array();
    var arrStaff = new Array();
    var arrClient = new Array();
    var arrUserMultip = new Array();
    var arrClientMultip = new Array();

    var countOperator = document.getElementById("iOperators").value;
    var countStaff = document.getElementById("iStaffs").value;
    var countClient = document.getElementById("iClients").value;

    var colMatrix = 6;

    arrLicense[0] = 2;
    arrLicense[1] = 3;
    arrLicense[2] = 6;
    arrLicense[3] = 11;
    arrLicense[4] = 21;
    arrLicense[5] = 51;
    arrLicense[6] = 101;

    arrUserMultip[0] = 100;
    arrUserMultip[1] = 65;
    arrUserMultip[2] = 45;
    arrUserMultip[3] = 30;
    arrUserMultip[4] = 17;
    arrUserMultip[5] = 8;
    arrUserMultip[6] = 2;

    arrClientMultip[0] = 0;
    arrClientMultip[1] = 0;
    arrClientMultip[2] = 100;
    arrClientMultip[3] = 65;
    arrClientMultip[4] = 30;
    arrClientMultip[5] = 15;
    arrClientMultip[6] = 2;

    arrOperator[0] = 50;
    arrStaff[0] = 25;
    for (i = 1; i <= 6; i++) {
        arrOperator[i] = arrOperator[0] * arrUserMultip[i] / 100;
        arrStaff[i] = arrStaff[0] * arrUserMultip[i] / 100;
    }

    arrClient[0] = 0;
    arrClient[1] = 0;
    arrClient[2] = 10;
    for (i = 3; i <= 6; i++) {
        arrClient[i] = arrClient[2] * arrClientMultip[i] / 100;
    }

    //Operator  
    var sumOperator = 99;
    for (i = 0; i < colMatrix; i++) {
        tempCount = countOperator;
        if (countOperator >= arrLicense[i + 1]) {
            tempCount = arrLicense[i + 1] - 1;
        }
        if (tempCount >= arrLicense[i]) {
            sumOperator += (tempCount - arrLicense[i] + 1) * arrOperator[i];
        }
    }
    if (countOperator >= arrLicense[colMatrix]) {
        sumOperator += (countOperator - arrLicense[colMatrix] + 1) * arrOperator[colMatrix];
    }

    //Staff
    var sumStaff = 0;
    for (i = 0; i < colMatrix; i++) {
        tempCount = countStaff;
        if (countStaff >= arrLicense[i + 1]) {
            tempCount = arrLicense[i + 1] - 1;
        }
        if (tempCount >= arrLicense[i]) {
            sumStaff += (tempCount - arrLicense[i] + 1) * arrStaff[i];
        }
    }
    if (countStaff >= arrLicense[colMatrix]) {
        sumStaff += (countStaff - arrLicense[colMatrix] + 1) * arrStaff[colMatrix];
    }

    //Client  
    var sumClient = 0;
    for (i = 0; i < colMatrix; i++) {
        tempCount = countClient;
        if (countClient >= arrLicense[i + 1]) {
            tempCount = arrLicense[i + 1] - 1;
        }
        if (tempCount >= arrLicense[i]) {
            sumClient += (tempCount - arrLicense[i] + 1) * arrClient[i];
        }
    }
    if (countClient >= arrLicense[colMatrix]) {
        sumClient += (countClient - arrLicense[colMatrix] + 1) * arrClient[colMatrix];
    }

    priceSumEUR = sumOperator + sumStaff + sumClient;
    document.getElementById("sumprice").value = formatEUR(priceSumEUR) + " EUR";
}

function order_hdac1() {
    window.open("https://secure.shareit.com/shareit/checkout.html?PRODUCT[300482574]=1", "_blank");
}

function order_hdac2() {
    window.open("https://secure.shareit.com/shareit/checkout.html?PRODUCT[300482578]=1", "_blank");
}
