﻿
var currenciesLoader;
var currenciesContent;

function loadCurrencies() { loadCurrencies_server(); }
function loadCurrencies_server(changeCurrency, priceType) {
    var urlCurrencies = "GetControl.aspx";
    var newCurrency = '';
    var newPriceType = '';
    if (typeof (changeCurrency) != 'undefined')
        newCurrency = changeCurrency;
    if (typeof (priceType) != 'undefined')
        newPriceType = priceType;
    if (newCurrency.length > 0)
        urlCurrencies = urlCurrencies + "?changeCurrency=" + newCurrency;
    if (newPriceType.length > 0) {
        if (newCurrency.length > 0)
            urlCurrencies = urlCurrencies + "&changePriceType=" + newPriceType;
        else
            urlCurrencies = urlCurrencies + "?changePriceType=" + newPriceType;
    }

    advAJAX.post({
        url: urlCurrencies,
        parameters: { 'control': 'Currencies' },
        onSuccess: function (obj) {
            loadSuccess(currenciesContent, currenciesLoader, obj);
            if (newCurrency.length > 0) {
                if (typeof (loadProducts) != 'undefined')
                    loadProducts();
                if (typeof (loadBasket) != 'undefined')
                    loadBasket();
                if (typeof (changedCurrency) != 'undefined')
                    changedCurrency();
            }
            if (newPriceType.length > 0) {
                if (typeof (loadProducts) != 'undefined') {
                    loadProducts();
                }
                if (typeof (changedCurrency) != 'undefined')
                    changedCurrency();
            }
        },
        onError: function (obj) { alert('error'); },
        onInitialization: function () {
            loadStart(currenciesContent, currenciesLoader);
        }

    });
}

function loadElements() {
    currenciesContent = document.getElementById('currenciesContent');
    currenciesLoader = document.getElementById('currenciesLoader');
}

addLoadEvent(loadElements);
addLoadEvent(loadCurrencies);
