function countArray(B) {
    var C = 0;
    for (var A in B) {
        C++;
    }
    return C
}

var oBuynow = function() {
    var licensesPrices 			= new Array();
    var bundlesPrices 			= new Array();
    var offersPrices 			= new Array();
    var bundledProductsPrices 	= new Array();
    var licenses 				= new Array();
    var currencies2Operators 	= new Array();
    var currency 				= "USD";
    var language 				= "en";
    var productVersion 			= "0";
    var productId 				= 0;
    var defaultOperatorId 		= 0;
    var currentOperatorId 		= 0;
    var secLicId 				= 0;

    var selected 				= new Array();
		selected.licenses 		= new Array();
		selected.bundles 		= new Array();
		selected.offers 		= new Array();

    var isCouponValid 			= false;
    var nameInput 				= new Array();
    var emailInput 				= new Array();
    var total 					= 0;
    var totalOffers 			= 0;
    var supprices 				= new Array();

    var publicObject = 
	{
        setProductId: function(_productId)
		{
            productId = _productId;
        },
        
		setLanguage: function(_language)
		{
            language = _language;
        },
		
        setLicensesPrices: function(_licensesPrices)
		{
            licensesPrices = _licensesPrices;
        },
		
        setBundlesPrices: function(_bundlesPrices)
		{
            bundlesPrices = _bundlesPrices;
        },
		
        setOffersPrices: function(_offersPrices)
		{
            offersPrices = _offersPrices;
        },
		
        setBundledProductsPrices: function(_bundledProductsPrices)
		{
            bundledProductsPrices = _bundledProductsPrices;
        },
		
        setLicenses: function(_licenses)
		{
            licenses = _licenses;
        },
		
        setProductVersion: function(_productVersion)
		{
            productVersion = _productVersion;
        },
		
        setLicenseQuantity: function(_licenseId, _quantity)
		{
            $("#lqn_" + _licenseId).val(_quantity);
            this.calculateTotal(_licenseId);
            oBuynow.calcSecLic('287');
		},
		
        setDefaultOperatorId: function(_defaultOperatorId)
		{
            defaultOperatorId = _defaultOperatorId;
            currentOperatorId = _defaultOperatorId;
        },
        
		setCurrentOperatorId: function(_defaultOperatorId)
		{
            currentOperatorId = _defaultOperatorId;
        },
		
        setCurrencies2Operators: function(_currencies2Operators)
		{
            currencies2Operators = _currencies2Operators
        },
		
        showOffersPrices: function()
		{
            for (var i in offersPrices)
			{
                if (total > 0)
				{
                    $("#off_" + i).removeAttr("disabled")
				}
				else
				{
					$("#off_" + i).attr("disabled", "disabled");
                    delete(selected.offers[i])
				}
                
				var text = "";
                
				if (offersPrices[i]["text"])
				{
					text = offersPrices[i]["text"]
				}
				else
				{
					offersPrices[i]["text"] = text = $("#af" + i).html()
                }
                
				if (text != undefined && text.indexOf("XXX") != -1)
				{
					if (offersPrices[i]["price_percent"] > 0)
					{
						if (total > 0)
						{
							percPrice = publicObject.getOfferPercPrice(total, i, offersPrices[i]['price_percent']);
                        	
							text = text.replace('XXX', currency + ' ' + percPrice);
						}
						else
						{
							text = text.replace("XXX", currency + " 0.00")
                        }
                    
					}
					else
					{
						text = text.replace("XXX", currency + " " + offersPrices[i][currency])
					}
				}
                
				$("#af" + i).html(text)
			}
        },
        getOfferPercPrice: function(total, i, pricePercent)
        {
        	percPrice = ((total / 100) * pricePercent).toFixed(2);
        	
        	if(i == 2 && percPrice < 9.95)
        	{
        		percPrice = 9.95;
        	}	
        	
        	if(i == 5 && percPrice < 19.95)
        	{
        		percPrice = 19.95;
        	}	
        	
        	return parseFloat(percPrice);
        },
        
        setCurrency: function(_currency)
        {
            $("#" + currency.toLowerCase()).removeClass(currency.toLowerCase() + "S");
            currency = _currency;
            $("#" + currency.toLowerCase()).addClass(currency.toLowerCase() + "S");
        
            if (currencies2Operators[currency])
            {
                currentOperatorId = parseInt(currencies2Operators[currency])
            }
            else
            {
                currentOperatorId = defaultOperatorId
            }
            
            switch (currentOperatorId)
            {
            	case 2:
            		$("#processButton").unbind("click");
            		$("#processButton").click(function()
            		{
            			publicObject.processElement5Order();
            			return false
            		});
            		break;
            	
            	case 3:
            		$("#processButton").unbind("click");
            		$("#processButton").click(function()
            		{
            			publicObject.processPlimusOrder();
            			return false
            		});
            		break
            }
            
            this.showPrices();
            this.showTotal();
            this.showOffersPrices();
            this.setCookie("currency", currency)
        },
        
        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>")
                        }
                    }
                }
            }
			
            for (var i in bundlesPrices)
			{
                $("#bun_price_" + i).html("<s>" + currency + " " + bundledProductsPrices[i][currency].replace(".", ".<sup>") + "</sup></s> " + currency + " " + bundlesPrices[i][currency]["price"].replace(".", ".<sup>") + "</sup>")
            }
        },
        
        showAllCurrencies: function()
        {
            $("#showAll").css("display", "none");
            $("#hidedCurs").css("display", "block")
        },
        
        closeNote: function()
        {
            $("#note").fadeOut("fast");
            this.setCookie("dontshownote", true)
        },
        
        placePurchaseOrder: function()
        {
        	var paymentMethodInput = $(document.createElement("input"));
        	paymentMethodInput.attr("type", "hidden").attr("name", "paymentMethod").val("po");
        	this.processOrder(paymentMethodInput)
        },
        
        changeUpgradeNowLink: function(select)
        {
        	var version = $(select).val();

            if (parseInt(productVersion) == parseInt(version))
            {
            	$("#upgrade_link").colorbox({
                    width: "50%",
                    inline: true,
                    href: "#upgrade_info_container p",
                    opacity: 0.8
                });
            }
            else
            {
            	$("#upgrade_link").unbind($.cbox_click)
                .removeClass("cboxelement");
            }
        },
        
        expandCollapse: function(elementId, link)
        {
            var elem = $("#" + elementId);
            if (elem.css("display") == "none")
            {
                elem.slideDown("fast");
                if (link != undefined)
                {
                    $(link).attr("class", $(link).attr("class").replace(" close", ""));
                }
            }
            else
            {
            	elem.slideUp("fast");
                if (link != undefined)
                {
                	$(link).attr("class", $(link).attr("class") + " close");
                }
            }
        },
        
        showTotal: function()
        {
            var subtotals 			= new Array();
            var users 				= 0;
            var licenseSelectedFlag = false;
            var isInfinity 			= false;
            total 					= 0;
            totalOffers 			= 0;
            
            for (var i in selected)
            {
                for (var j in selected[i])
                {
                    switch (i)
                    {
                    	case "licenses":
                    		licenseSelectedFlag = true;
                    		var price = parseFloat(licensesPrices[j][currency]["price"]).toFixed(2);
                    		
                    		if (selected[i][j] > 1 && licensesPrices[j]["packs"])
                    		{
                    			for (var k in licensesPrices[j]["packs"])
                    			{
                    				var minUsers = parseInt(licensesPrices[j]["packs"][k]["min_usernumber"]);
                    				var maxUsers = parseInt(licensesPrices[j]["packs"][k]["usernumber"]);
                    				
                    				if (selected[i][j] >= minUsers && (selected[i][j] <= maxUsers || maxUsers == 0))
                    				{
                    					price = parseFloat(licensesPrices[j]["packs"][k][currency]).toFixed(2);
                    					
                    					break;
                    				}
                    			}
                    		}
                    		subtotals[j] = selected[i][j] * price;
                    		supprices[j] = price;
                    		
                    		
                    		total 		+= subtotals[j];
                    		users 		+= selected[i][j] * parseInt(licenses[j]["usernumber"]);
                        
                    		if (parseInt(licenses[j]["usernumber"]) == 0)
                    		{
                    			isInfinity = true
                    		}
                    		break;
                    	
                    	case "bundles":
                    		total += selected[i][j] * parseFloat(bundlesPrices[j][currency]["price"]);
                    		break;
                    }
                }
            }
            
            if (total > 0)
            {
            	for (var i in selected.offers)
            	{
            		if (offersPrices[i]["price_percent"] > 0)
            		{
                       	percPrice = publicObject.getOfferPercPrice(total, i, offersPrices[i]['price_percent']);
                       	
                       	totalOffers += percPrice;
            		}
            		else
            		{
            			totalOffers += parseFloat(offersPrices[i][currency])
            		}
            	}
            }
            	
            for (var i in licensesPrices)
            {
            	if (subtotals[i])
            	{
            		if( i == 293 || i == 294 || i == 295 )
            		{
            			$("#subtotal_287").html(subtotals[i].toFixed(2).replace(".", ".<sup>") + "</sup>")
            		}	
            		else
            		{
            			$("#subtotal_" + i).html(subtotals[i].toFixed(2).replace(".", ".<sup>") + "</sup>")
            		}
            	}
            	else
            	{
            		$("#subtotal_" + i).html("0.<sup>00</sup>")
                }
            }
            $("#total_bottom").html(currency + " " + (total + totalOffers).toFixed(2).replace(".", ".<sup>") + "</sup>");
            $("#total_right").html(currency + " " + (total + totalOffers).toFixed(2).replace(".", ".<sup>") + "</sup>");
            $("#usernumber_right").html((isInfinity ? "&infin;": ( ( users.toString() ) * 2 ) ) )
        },
            
		/*
			PROCESS ELEMENT 5
		*/
       
		processElement5Order: function (additionalField)
		{
            this.calcSecLic( '287' );
        
            this.calculateTotal();	
            var element5link 	= "";
			var SecPrice 		= "";
			var offersData 		= new Array();
			
        	var packs 			= $("#lqn_287");
   			var win 			= $("#sec_win_lic");
    		var lin 			= $("#sec_lin_lic");
    		
    		var packsVal 		= parseInt( packs.val() );
    		var totalLic		= packsVal*2;
    		
    		var winVal 			= parseInt( win.val() );
    		var linVal 			= parseInt( lin.val() );
    		var totalLicWL  	= winVal + linVal;

			element5link 		+= "currencies=" + currency;
			
			if (language == "en")
			{
				element5link += "&languageid=1"
			}
			if (language == "fr")
			{
				element5link += "&languageid=6"
			}
			if (language == "de")
			{
				element5link += "&languageid=2"
			}

			var escapeOrig = window.escape;

			window.escape = function (str)
			{
				var ret = [];
				for (var i = 0; i < str.length; i++)
				{
					var n = str.charCodeAt(i);
					if (n <= 0xFF)
					{
						ret.push(n);
					}	
				}
				return escapeOrig(String.fromCharCode.apply(null, ret));
			}

			if (isCouponValid)
			{	
				element5link += "&COUPON1=" + escape($("#coupon_input").val());
			}	

			if (countArray(selected.licenses) == 0)
			{
				for (var i in licenses)
				{
					if (licenses[i]["default"] == "Y")
					{
						selected.licenses[licenses[i]["id"]] = 1;
						break
					}
				}
			}

			for (var i in selected)
			{
				for (var j in selected[i])
				{
					var contractId 		= "";
					
					element5link += "&PRODUCT[";
				
					if (i == "licenses")
					{
						if (licensesPrices[j][currentOperatorId]["contractIds"][currency])
						{
							contractId += licensesPrices[j][currentOperatorId]["contractIds"][currency]
						}
						else
						{
							contractId += licensesPrices[j][currentOperatorId]["contractIds"]["default"]
						}
					}
					else
					{
						if (i == "bundles")
						{
							if (bundlesPrices[j][currentOperatorId]["contractIds"][currency])
							{
								contractId += bundlesPrices[j][currentOperatorId]["contractIds"][currency]
							}
							else
							{
								contractId += bundlesPrices[j][currentOperatorId]["contractIds"]["default"]
							}
						}
						else
						{
							if (i == "offers")
							{
								if (offersPrices[j][currentOperatorId][currency])
								{
									contractId += offersPrices[j][currentOperatorId][currency]
								}
								else
								{
									contractId += offersPrices[j][currentOperatorId]["USD"]
								}
							}
						}
					}
					
					element5link += contractId + "]=" + (i == "offers" ? 1 : selected[i][j]);
					element5link += "&PRODUCTPRICE[" + contractId + "]=";

					if (i == "licenses")
					{
						element5link += supprices[j];
                        SecPrice = supprices[j]
					}
					else
					{
						if (i == "bundles")
						{
							element5link += (parseFloat(bundlesPrices[j][currency]["price"])).toFixed(2)
						}
						else
						{
							if (i == "offers")
							{
								if (offersPrices[j]["price_percent"] > 0)
								{
									percPrice = publicObject.getOfferPercPrice(total, j, offersPrices[j]["price_percent"]);
									
									element5link += offersData[contractId] = percPrice;
								}
								else
								{
									element5link += offersPrices[j][currency]
								}
							}
						}
					}
					
					element5link += currency + ",N;";
					
					if (i == "licenses")
					{
						var packsUsed = false;
						
						if (licensesPrices[j]["packs"])
						{
							for (var k in licensesPrices[j]["packs"])
							{
								var minUsers = parseInt(licensesPrices[j]["packs"][k]["min_usernumber"]);
								var maxUsers = parseInt(licensesPrices[j]["packs"][k]["usernumber"]);
								
								if (selected[i][j] >= minUsers && (selected[i][j] <= maxUsers || maxUsers == 0))
								{
									element5link += licensesPrices[j]["packs"][k]["element5passwords"][contractId][currency];
									packsUsed = true;
									break
								}
							}
						}
						
						if (!packsUsed)
						{
							element5link += licensesPrices[j]["element5passwords"][contractId][currency]
						}
						
					}
					else
					{
						if (i == "bundles")
						{
							element5link += bundlesPrices[j]["element5passwords"][contractId][currency]
						}
						else
						{
							if (i == "offers")
							{
								if (offersPrices[j]["price_percent"] > 0)
								{
									element5link += "offermd5" + contractId
								}
								else
								{
									element5link += offersPrices[j]["element5passwords"][currency]
								}
							}
						}
					}
				}	
			}	

			element5link += "&HADD[" + contractId + "][ADDITIONAL1]=win_" + winVal;
    		element5link += "&HADD[" + contractId + "][ADDITIONAL2]=lin_" + linVal;
    		
			var procButton = $("#processButton");
				procButton.val($("#please_wait").html());
				procButton.attr("disabled", "disabled");
			
			if (offersData.length)
			{
				var postData = "";
				for (var i in offersData)
				{
					postData += "&offers[" + i + "]=" + offersData[i] + currency
				}
				

				ajax.post("/jcontroller/index.php", postData + "&ajaxmethod=getMd5", function (response)
				{
					eval("var hashes = " + response + ";");
						
					for (var i in hashes)
					{
						element5link = element5link.replace("offermd5" + i, hashes[i])
					}
					publicObject.redirectToElement5(element5link)
				})
 			}
			else
			{
				this.redirectToElement5(element5link)
			}
		},	
		
        redirectToElement5: function($linkOParameters)
		{
            window.location = "https://secure.element5.com/esales/checkout.html?" + $linkOParameters
        },
		
        calculateTotal: function(_licenseId, _bundleId, _offerId)
        {
            if (_licenseId != undefined)
            {
                var checked 	= $("#lic_287").is(":checked");
                var quantity 	= $("#lqn_287").val();

                if (checked)
                {
             		for (var i in licenses) 
					{
						delete(selected.licenses[i]);
					}
					selected.licenses[_licenseId] = quantity
                }
                else
                {
                	delete(selected.licenses[_licenseId])
                }
            }
            
            if (_bundleId != undefined)
            {
                var checked 	= $("#bun_" + _bundleId).is(":checked");
                var quantity 	= $("#bqn_" + _bundleId).val();
                
                if (checked)
               {
                    if (!isNaN(quantity))
                    {
                        selected.bundles[_bundleId] = quantity
                    }
                }
                else
                {
                	delete(selected.bundles[_bundleId])
                }
            }
            
            if (_offerId != undefined)
            {
                if (_offerId == 4)
                {
                    var newCheckbox = $(document.createElement("input"));
                    
                    newCheckbox	.attr("id", "off_4")
                    			.attr("type", "checkbox")
                    			.attr("class", "inpCheckbox");
                    
                    newCheckbox.bind("click", function()
                    {
                    	publicObject.calculateTotal(null, null, 4)
                    });
                    
                    $("#off_5").parent().append(newCheckbox);
                    
                    if ($("#off_5").is(":checked"))
                    {
                        newCheckbox.attr("checked", "checked")
                    }
                    
                    $("#off_5").remove();
                    
                    delete(selected.offers[5])
                }
                else
                {
                	if (_offerId == 5)
                	{
                        var newCheckbox = $(document.createElement("input"));
                        
                        newCheckbox	.attr("id", "off_5")
                        			.attr("type", "checkbox")
                        			.attr("class", "inpCheckbox");
                        
                        newCheckbox.bind("click", function()
                        			{
                            			publicObject.calculateTotal(null, null, 5)
                        			});
                        
                        $("#off_4").parent().append(newCheckbox);
                        
                        if ($("#off_4").is(":checked"))
                        {
                            newCheckbox.attr("checked", "checked")
                        }
                        $("#off_4").remove();
                       	delete(selected.offers[4])
                	}
                }
                	
                var checked = $("#off_" + _offerId).is(":checked");
                	
                if (checked)
                {
                	selected.offers[_offerId] = true
                }
                else
                {
                	delete(selected.offers[_offerId])
                }
            }
           	this.showTotal();
           	this.showOffersPrices();
           	this.checkCoupon()
        },
        
        checkCoupon: function()
        {
            var coupon = $("#coupon_input").val();
            var status = $("#couponStatus");
            var licensesStr = "";
        
            for (var i in selected.licenses)
            {
                licensesStr += (licensesStr != "" ? ",": "") + i
            }
            
            status.html("");
            
            if (coupon.length > 0 && licensesStr.length > 0)
            {
                status.html('<img src="/images/buynow/spinner_white.gif" width="24" height="24" style="margin-left:5px;" />');
            
                ajax.post("/jcontroller/index.php", "ajaxmethod=validatecoupon&coupon=" + encodeURIComponent(coupon) + "&licenses=" + licensesStr, {
                    func: "oBuynow.checkCouponSucc"
                });
            }
        },
        
        checkCouponSucc: function(value)
        {
            var status = $("#couponStatus");
        
            if (parseInt(value) == 0)
            {
                status.html('<div class="notValid">' + $("#not_valid").html() + "</div>");
                isCouponValid = false
            }
            else
            {
                status.html('<div class="valid">OK!</div>');
                isCouponValid = true
            }
        },
        
        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;
        },
        
       
        calcSecLic: function( id )
        {
   			var packs 	= $("#lqn_287");
   			var win 	= $("#sec_win_lic");
    		var lin 	= $("#sec_lin_lic");
    		var packsNote   	= $("#packsNote");
    			packsNote.click(function(){
    				packsNote.hide('slow');
    				return false;
    			});
    		
    		var packsVal 		= parseInt( packs.val() );
    		var totalLic		= packsVal*2;
    		
    		var winVal 			= parseInt( win.val() );
    		var linVal 			= parseInt( lin.val() );
    		var totalLicWL  	= winVal + linVal;
    		var OldPacks   		= totalLicWL / 2;
     		
    		var newWinVal = 0;
    		var newLinVal = 0;
    		
    		switch(id) 
    		{
    			case '287':
    				packsNote.hide('fast');
    				if( totalLic > totalLicWL)
    				{
    					newWinVal = totalLic - linVal;
    					win.attr('value', newWinVal );
    				}

    				if( totalLic < totalLicWL)
    				{
    					newWinVal = totalLic - linVal;
    					
    					if( newWinVal < 0 )
    					{
    						newLinVal = linVal + newWinVal;
    						newWinVal = 0;
    						lin.attr('value', newLinVal );
    					}	
    					win.attr('value', newWinVal );
    				}
    				break;
    			
    			case 'win_lic':
    				if( linVal == 0 )
    				{
    					if( totalLicWL > totalLic)
    					{
    	   					newWinVal = totalLic;
    	   					win.attr( 'value', newWinVal );
    	   					if( (packsNote.css('display')) == 'none'){ packsNote.show('fast'); };
    					}
    					
    					if( totalLicWL < totalLic)
    					{
    						packsNote.hide('fast');
    						newLinVal = totalLic - winVal;
    						lin.attr( 'value', newLinVal );
    					}	
    				}
    				else
    				{
   						packsNote.hide('fast');
  	   					newLinVal = totalLic-winVal;
  	   					lin.attr( 'value', newLinVal );
    				}
    				break;
    			
    			case 'lin_lic':
    				if( winVal == 0 )
    				{
    					if( totalLicWL > totalLic)
    					{
    	   					newLinVal = totalLic;
    	   					lin.attr( 'value', newLinVal );
    	   					if( (packsNote.css('display')) == 'none'){ packsNote.show('fast'); }; 
    					}
    					
    					if( totalLicWL < totalLic)
    					{
    						packsNote.hide('fast');
    						newWinVal = totalLic - linVal;
    						win.attr( 'value', newWinVal );
    					}	
    				}
    				else
    				{
    					packsNote.hide('fast');
   	   					newWinVal = totalLic-linVal;
   	   					win.attr( 'value', newWinVal );
    				}
    				break;
    		}
    		
			for (var i in licenses) 
			{
				delete(selected.licenses[i]);
			}

    		winVal 	= parseInt( win.val() );
    		linVal	= parseInt( lin.val() );
			
			if(winVal > totalLic)
			{
				win.attr( 'value', totalLic );
				lin.attr( 'value', 0 );
				if( (packsNote.css('display')) == 'none'){ packsNote.show('fast'); };
			}

			if(linVal > totalLic)
			{
				win.attr( 'value', 0 );
				lin.attr( 'value', totalLic );
				if( (packsNote.css('display')) == 'none'){ packsNote.show('fast'); };
			}

    		winVal 	= parseInt( win.val() );
    		linVal	= parseInt( lin.val() );

			
    		
    			 if( winVal == 2 && linVal == 0)
    		{
    			publicObject.calculateTotal(295);	
    		}	
    		else if( winVal == 1 && linVal == 1)
        	{
    			publicObject.calculateTotal(294);	
        	}	
        	else if( winVal == 0 && linVal == 2)
        	{
        		publicObject.calculateTotal(293);	
        	}	
            else
            {
            	publicObject.calculateTotal(287);	 
            }	
    		
    		$("#wwwwin").empty().append(winVal + ' Windows');
    		$("#llllin").empty().append(linVal + ' Linux');
    		$("#wlpacks").empty().append(packsVal);
   		}	
    };
    $(document).ready(function() {
		$("#upgradeNow option:first-child").attr('selected', 'selected');$("#upgradeNow").change( function(){productVer 	= $(this).attr('rel');selectedVal = $(this).val();if (parseInt(productVer) == parseInt(selectedVal)){$("#upgrade_link").colorbox({width:"50%", inline:true, href:"#upgrade_info_container p"});}else{$("#upgrade_link").unbind($.cbox_click).removeData($.colorbox).removeClass("cboxelement");}});
		$("#processButton").val($("#process_my_order_now").html());
		$("#processButton").removeAttr("disabled");
        // license overlay prepare
        
		var licLinks = $(".license");
        $.each(licLinks, function() {
            this.href = this.href + '?ajax=true';
            $(this).colorbox({
                iframe: true,
                innerWidth: '80%',
                innerHeight: '70%',
                speed: 200,
                opacity: 0.8
            });
        });

        // license overlay prepare
        var licLinks = $(".hint");
        $.each(licLinks, function() {
            this.href = this.href + '?ajax=true';
            $(this).colorbox({
                iframe: true,
                innerWidth: '80%',
                innerHeight: '70%',
                speed: 200,
                opacity: 0.8
            });
        });
		// prodLinks overlay prepare
		var prodLinks = $("a.prodLink");
		$.each(prodLinks, function(){
			this.href = this.href + '?ajax=true';
			$(this).colorbox({
				iframe:true, 
				innerWidth:'80%', 
				innerHeight:'70%', 
				speed:200,
				opacity:0.8
			});
		});
        // contact form
        $(".contact").colorbox({
            iframe: true,
            innerWidth: '540px',
            innerHeight: '565px',
            speed: 200,
            opacity: 0.8
        });
        
        
        $("#splash a").colorbox({
			innerWidth:"600px", 
			innerHeight:"200px", 
			inline:true, 
			href:"#secDownloadBlock"
		});
        
        $(".highl tr").bind("mouseover", function() {
            $(this).children("td").css("background-color", "#494949")
            });
        $(".highl tr").bind("mouseout", function() {
            $(this).children("td").css("background-color", "#272727")
            });
            
        publicObject.showOffersPrices();
        
		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")
			}
        }
        
        var spinButtons = $("input.inpText").SpinButton({
            min: 0,
            reset: 1
        });
        
        var onChangeQuantity = function()
        {
        	var id 		= $(this).attr("id").substring(4);
            var type 	= $(this).attr("id").substring(0, 3);

			if( id == '287' || id == 'win_lic' || id == 'lin_lic' )
			{
				oBuynow.calcSecLic(id);
			}
            
            switch (type)
            {
            	case "lqn":
            		if (!$("#lic_" + id).is(":checked"))
            		{
            			$("#lic_" + id).attr("checked", "checked")
                    }
            		publicObject.calculateTotal(id, null, null);
            		break;
            	
            	case "bqn":
            		if (!$("#bun_" + id).is(":checked"))
            		{
            			$("#bun_" + id).attr("checked", "checked")
                    }
            		publicObject.calculateTotal(null, id, null);
            		break;
            }
        };
        
		$("#processButton").unbind("click");
		$("#processButton").click(function()
		{
			publicObject.processElement5Order();
            return false
        });

        spinButtons.bind("mousewheel", onChangeQuantity);
        spinButtons.bind("change", onChangeQuantity);
        spinButtons.mouseup(onChangeQuantity);

        setTimeout(function() {
            $("#mainForm").resetForm();
            for (var i in licensesPrices) {
                publicObject.calculateTotal(i)
                }
            for (var i in bundlesPrices) {
                publicObject.calculateTotal(null, i)
                }
            selected.licenses = new Array();
            for (var i in licenses) {
                if (licenses[i]["default"] == "Y") {
                    $("#lic_" + licenses[i]["id"]).attr("checked", "checked");
                    publicObject.calculateTotal(licenses[i]["id"]);
                    break
                }
            }
        }, 100);
        $(".e-button").bind("click", function() {
            var link = $(this);
            link.removeClass("e-button-p");
            link.addClass("e-button")
            });
        $(".e-button").bind("mousedown", function() {
            var link = $(this);
            link.removeClass("e-button");
            link.addClass("e-button-p")
            });
        $(".e-button").bind("mouseup", function() {
            var link = $(this);
            link.removeClass("e-button-p");
            link.addClass("e-button")
            });
        $(".e-button").bind("mouseout", function() {
            var link = $(this);
            link.removeClass("e-button-p");
            link.addClass("e-button")
            })
        });
    return publicObject
} ();