function countArray(B) {
    var C = 0;
    for (var A in B) {
        C++
    }
    return C
}
var oBuynow = function () {
    var licensesPrices = new Array();
    var licenses = new Array();
    var currencies2Operators = new Array();
	var languages = new Array();
	languages['en']=1;
	languages['de']=2;
	languages['fr']=6;
	languages['es']=4;
	languages['jp']=11;
	languages['it']=5;
		
    var currency = "USD";
    var language = "en";
    var defaultOperatorId = 0;
    var currentOperatorId = 0;
    var publicObject = {
        setLanguage: function (_language) {
            language = _language
        },
        setLicensesPrices: function (_licensesPrices) {
            licensesPrices = _licensesPrices
        },
        setLicenses: function (_licenses) {
            licenses = _licenses
        },
        setDefaultOperatorId: function (_defaultOperatorId) {
            defaultOperatorId = _defaultOperatorId;
            currentOperatorId = _defaultOperatorId
        },
        setCurrencies2Operators: function (_currencies2Operators) {
            currencies2Operators = _currencies2Operators
        },
        setCurrency: function (_currency) {
            currency = _currency;
            this.showPrices();
            this.setCookie("currency", currency)
        },
        creteElement5link: function () {
            var element5link = "https://secure.element5.com/esales/checkout.html?currencies=" + currency+"&languageid="+languages[language];
            for (var j in licensesPrices) {
                if (licensesPrices[j][currentOperatorId]["contractIds"][currency]) {
                    contractId = licensesPrices[j][currentOperatorId]["contractIds"][currency];
                }
                else {
                    contractId = licensesPrices[j][currentOperatorId]["contractIds"]["default"];
                }
                el5link = element5link + "&PRODUCT[" + contractId + "]=";

                if (licensesPrices[j]["packs"]) for (var i in licensesPrices[j]["packs"]) $("#buylink_" + i).attr('href', el5link + licensesPrices[j]["packs"][i]['min_usernumber'] + "&PRODUCTPRICE[" + contractId + "]=" + licensesPrices[j]["packs"][i][currency] + currency + ',N;' + licensesPrices[j]["packs"][i]['element5passwords'][contractId][currency] + '&js=-1');
                //					$("#buylink_"+i).attr('href',element5link+contractId+licensesPrices[j]["packs"][i]['min_usernumber']);					
                if (licensesPrices[j]['min_usernumber']) el5link += licensesPrices[j]['min_usernumber'];
                else el5link += "1";
                el5link += "&PRODUCTPRICE[" + contractId + "]=" + licensesPrices[j][currency]["price"] + currency;
                res = el5link + ',N;' + licensesPrices[j]['element5passwords'][contractId][currency] + '&js=-1';
                $("#buylink_" + j).attr('href', res);
            }
        },
		 showPrices: function () {
            for (var i in licenses) {
                if (licensesPrices != undefined && licensesPrices[i] != undefined && licensesPrices[i][currency] != undefined) {
                    $("#price_" + i).html(currency + " " + licensesPrices[i][currency]["price"].replace(".", ".<sup>") + "</sup>");
                    if (licensesPrices[i]["packs"]) {
                        for (var j in licensesPrices[i]["packs"]) {
                            $("#price_" + j).html(currency + " " + licensesPrices[i]["packs"][j][currency].replace(".", ".<sup>") + "</sup>")
                        }
                    }
                }
            }
        },
        setCookie: function (cookieName, value) {
            var exdate = new Date();
            exdate.setDate(365);
            document.cookie = cookieName + "=" + escape(value) + ";path=/;expires=" + exdate + ";domain=" + location.host
        },
        getCookie: function (cookieName) {
            if (document.cookie.length > 0) {
                start = document.cookie.indexOf(cookieName + "=");
                if (start != -1) {
                    start = start + cookieName.length + 1;
                    end = document.cookie.indexOf(";", start);
                    if (end == -1) {
                        end = document.cookie.length
                    }
                    return unescape(document.cookie.substring(start, end))
                }
            }
            return null
        }
    };
    $(document).ready(function () {
        $(".highl tr").bind("mouseover", function () {
            $(this).children("td").css("background-color", "#e1e1e1")
        });
        $(".highl tr").bind("mouseout", function () {
            $(this).children("td").css("background-color", "#fff")
        });
        var userCurrency = publicObject.getCookie("currency");
        if (userCurrency != null && userCurrency != "USD") {
            publicObject.setCurrency(userCurrency)
        } else {
            if (window.location.toString().indexOf("/fr/") != -1 || window.location.toString().indexOf("/de/") != -1) {
                publicObject.setCurrency("EUR")
            } else {
                publicObject.setCurrency("USD")
            }
        };
        if (currencies2Operators[currency]) {
            currentOperatorId = parseInt(currencies2Operators[currency])
        } else {
            currentOperatorId = defaultOperatorId
        }
    });
    return publicObject
}();
