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("A megengedett legkisebb üzemeltetői-liszensz szám: 1!");
        document.getElementById("iOperators").value = 1;
    }

    if ((countStaff = document.getElementById("iStaffs").value) < 1) {
        countStaff = 1;
        alert("A megengedett legkisebb karbantartöi-liszensz szám: 1!");
        document.getElementById("iStaffs").value = 1;
    }

    if ((countClient = document.getElementById("iClients").value) < 5) {
        countClient = 5;
        alert("A megengedett legkisebb ügyfél-liszensz szám: 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=19&currencies=RON" + "&backlink=http%3A%2F%2Fwww.cmmsservice.com";
    //window.location=location;
    window.open(location, "_blank");
}

function formatForint(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);
}

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 strip_tags(str, allowed_tags) {
//  // http://kevin.vanzonneveld.net
//  // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
//  // +   improved by: Luke Godfrey
//  // +      input by: Pul
//  // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
//  // +   bugfixed by: Onno Marsman
//  // +      input by: Alex
//  // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
//  // +      input by: Marc Palau
//  // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
//  // +      input by: Brett Zamir (http://brettz9.blogspot.com)
//  // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
//  // +   bugfixed by: Eric Nagel
//  // +      input by: Bobby Drake
//  // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
//  // *     example 1: strip_tags('<p>Kevin</p> <br /><b>van</b> <i>Zonneveld</i>', '<i><b>');
//  // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
//  // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
//  // *     returns 2: '<p>Kevin van Zonneveld</p>'
//  // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");
//  // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
//  // *     example 4: strip_tags('1 < 5 5 > 1');
//  // *     returns 4: '1 < 5 5 > 1'

//  var key = '', allowed = false;
//  var matches = [];
//  var allowed_array = [];
//  var allowed_tag = '';
//  var i = 0;
//  var k = '';
//  var html = '';

//  var replacer = function(search, replace, str) {
//    return str.split(search).join(replace);
//  };

//  // Build allowes tags associative array
//  if (allowed_tags) {
//    allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);
//  }

//  str += '';

//  // Match tags
//  matches = str.match(/(<\/?[\S][^>]*>)/gi);

//  // Go through all HTML tags
//  for (key in matches) {
//    if (isNaN(key)) {
//      // IE7 Hack
//      continue;
//    }

//    // Save HTML tag
//    html = matches[key].toString();

//    // Is tag not in allowed list? Remove from str!
//    allowed = false;

//    // Go through all allowed tags
//    for (k in allowed_array) {
//      // Init
//      allowed_tag = allowed_array[k];
//      i = -1;

//      if (i != 0) { i = html.toLowerCase().indexOf('<' + allowed_tag + '>'); }
//      if (i != 0) { i = html.toLowerCase().indexOf('<' + allowed_tag + ' '); }
//      if (i != 0) { i = html.toLowerCase().indexOf('</' + allowed_tag); }

//      // Determine
//      if (i == 0) {
//        allowed = true;
//        break;
//      }
//    }

//    if (!allowed) {
//      str = replacer(html, "", str); // Custom replace. No regexing
//    }
//  }

//  return str;
//}

function exchangeRate(amount, currency, exchangeIn) {

    ajaxObject = function() {
        try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {
            try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {
                try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
                    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
                        try { return new XMLHttpRequest() } catch (e) {
                            throw new Error("Az ön browsere nem támogatja az XMLHttpRequest-et.");
                        } 
                    } 
                } 
            } 
        } 
    }

    var rate = 4.2;
    var xmlhttp;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ajaxObject(); // use ajaxObject to start XMLHttpRequest() for most browsers
    }
    if (xmlhttp == null)
        return (rate);

    googleQuery = "../App_Themes/exchange.php?amount=" + amount + "&currency=" + currency + "&exchangeIn=" + exchangeIn;
    xmlhttp.open("GET", googleQuery, false);
    //  xmlhttp.onreadystatechange = function() { // ***** Because of a bug in FireFox browser, this method doesn't work for .open with assync = false *****
    //    if (xmlhttp.readyState === 4) {  // Makes sure the document is ready to parse.
    //      if (xmlhttp.status === 200) {  // Makes sure it's found the file.
    //        askGoogle = xmlhttp.responseText;
    //        askGoogle = strip_tags(askGoogle);
    //        matches = askGoogle.match(/= ([0-9]|\.|,|\ )*/);
    //        rate = parseFloat(matches[0].substring(2));
    //      }
    //    }
    //  }
    xmlhttp.send(null);
    if (xmlhttp.status == 200) { /* the request has been returned */
        askGoogle = xmlhttp.responseText;
        // ***** First version. Receives the whole Google page from PHP. *****
        //    askGoogle = strip_tags(askGoogle);
        //    matches = askGoogle.match(/= ([0-9]|\.|,|\ )*/);
        //    rate = parseFloat(matches[0].substring(2));
        // ***** Second version. Receives only the exchange rate a string from PHP *****
        rate = parseFloat(askGoogle);
    }
    return (rate);
}

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;
    var rate = exchangeRate(1, "EUR", "RON");
    //  alert(rate);
    priceSumFt = priceSumEUR * rate;
    document.getElementById("sumprice").value = formatEUR(priceSumEUR) + " EUR  \(~" + formatForint(priceSumFt) + " RON*\)";
}
