function ccGetPrefix(currency)
{
  if (currency == 'usd') return '$ ';
  if (currency == 'gbp') return '&pound; ';
  return '';
}

function ccGetSuffix(currency)
{
  if (currency == 'eur') return ' &euro;';
  return ' ' + currency.toUpperCase()
}

function ccGetRate(currency)
{
  if (currency == 'usd') {
    return amd2usd;
  } else if (currency == 'eur') {
    return amd2eur;
  } else if (currency == 'rub') {
    return amd2rub;
  } else if (currency == 'gbp') {
    return amd2gbp;
  } else if (currency == 'cad') {
    return amd2cad;
  } else if (currency == 'chf') {
    return amd2chf;
  } else if (currency == 'amd') {
    return 1.0;
  } else {
    return null;
  }
}

function ccConvertPrices(currency)
{
  var price_coef = ccGetRate(currency);
  if (!price_coef) return;
  var round_up = currency == 'amd' ? 0.0 : 0.49999;
  var prefix = ccGetPrefix(currency);
  var suffix = prefix == '' ? ccGetSuffix(currency) : '';

  $("div.sell_price,div.product_sell_price,td.price,td.subtotal,span.price_range,#line-items-div td,table.order-review-table td,table.order-pane-table td,table.line-item-table td,span.cart_total_price,div.add_to_cart span.adjustment_price,span.sell_price").each(function(i, el) {
    if (!el.price_amd) {
      //el.price_amd = parseInt($(el).html().replace(/[^0-9\.]/g, ''));
	    el.price_amd = parseInt($(el).html().replace(/.*([^0-9]|^)([0-9]*) AMD/, "$2"));
	    el.repl_text = el.price_amd + ' AMD';
    }
    var price = el.price_amd * price_coef;
    if (price > 0) {
      price = Math.round(price*100.0 + round_up)/100.0;
      price = '' + price;
      x = price.indexOf('.');
      if (x != -1) {
          if (x + 3 > price.length) {
              price = price + '0';
          }
          if (currency != 'usd') {
              price = price.substring(0, x) + ',' + price.substring(x+1);
          }
      }
      price = prefix + price + suffix;
      //price = Array(el.repl_text.length + 1 - price.length).join(' ') + price;
      var tmp = $(el).html();
      $(el).html(el.repl_text);
      $(el).html(tmp.replace($(el).html(), price));
      el.repl_text = price;
    }
  });
}



