function ValidationMarkFieldBad( elem )
{
if ( $(elem) )
{
if ( $(elem).hasClassName( 'highlight_on_error' ) )
new Effect.Morph( elem, {style: 'color: #FF9900', duration: 0.5 } );
else
new Effect.Morph( elem, {style: 'border-color: #FF9900', duration: 0.5 } )
}
}
function ValidationMarkFieldOk( elem )
{
if ( $(elem) )
{
if ( $(elem).hasClassName( 'highlight_on_error' ) )
$(elem).style.color='';
else
$(elem).style.borderColor = '';
}
}
function BIsTwoFactorEnabled()
{
var bEnabled = $J( document.body).hasClass( "two_factor_sale_enabled" );
return bEnabled;
}
RemoveListingDialog = {
m_bOKClicked: false,
m_bInitialized: false,
m_oListingOriginalRow: null,
m_ulListingId: false,
m_bAwaitingConfirmation: false,
m_fnDocumentKeyHandler: null,
m_modal: null,
Initialize: function() {
$('market_removelisting_dialog_accept').observe( 'click', this.OnAccept.bindAsEventListener(this) );
$('market_removelisting_dialog_cancelbtn').observe( 'click', this.OnCancel.bindAsEventListener(this) );
},
Show: function ( sElementPrefix, listingid, item, bAwaitingConfirmation ) {
if ( !this.m_bInitialized )
this.Initialize();
this.m_bOKClicked = false;
this.m_oListingOriginalRow = $(sElementPrefix + '_' + listingid);
this.m_ulListingId = listingid;
this.m_bAwaitingConfirmation = bAwaitingConfirmation;
if ( bAwaitingConfirmation )
{
$J('#market_removelisting_dialog_title').text( 'Снять лот' );
$J('#market_removelisting_dialog_confirmation_text').html( 'Этот лот ожидает вашего подтверждения. Он еще не выставлен на Торговую площадку.
Снять лот ?' );
$J('#market_removelisting_dialog_accept > span').text( 'Да, снять этот лот' );
}
else
{
$J('#market_removelisting_dialog_title').text( 'Снять лот' );
$J('#market_removelisting_dialog_confirmation_text').html( 'Вы хотите снять лот и вернуть предмет в инвентарь?' );
$J('#market_removelisting_dialog_accept > span').text( 'Да, снять лот' );
}
$('market_removelisting_dialog_error').hide();
$('market_removelisting_dialog_accept').show();
$('market_removelisting_dialog_accept').setOpacity('1');
$('market_removelisting_dialog_cancelbtn').show();
$('market_removelisting_dialog_cancelbtn').setOpacity('1');
$('market_removelisting_dialog_accept_throbber').hide();
var oItemName = Element.clone( $(sElementPrefix + '_' + listingid + '_name'), true );
$('market_removelisting_dialog_itemname').innerHTML = '';
$('market_removelisting_dialog_itemname').appendChild( oItemName );
this.m_fnDocumentKeyHandler = this.OnDocumentKeyPress.bindAsEventListener( this );
$(document).observe( 'keydown', this.m_fnDocumentKeyHandler );
var _this = this;
this.m_modal = new CModal( $J('#market_removelisting_dialog' ) );
this.m_modal.GetContent().find('.newmodal_close' ).click( function() { _this.Dismiss() } );
this.m_modal.Show();
$('market_removelisting_dialog').focus();
},
DisplayError: function( error ) {
$('market_removelisting_dialog_error').show();
$('market_removelisting_dialog_error').update( error );
$('market_removelisting_dialog_error').style.color = '#ffffff';
new Effect.Morph( $('market_removelisting_dialog_error'), { style: {color: '#ff0000'}, duration: 0.25 } );
},
Dismiss: function() {
$(document).stopObserving( 'keydown', this.m_fnDocumentKeyHandler );
if ( this.m_modal )
{
this.m_modal.Dismiss();
this.m_modal = null;
}
},
OnAccept: function( event ) {
event.stop();
if ( this.m_bOKClicked )
{
return;
}
this.m_bOKClicked = true;
$('market_removelisting_dialog_error').hide();
$('market_removelisting_dialog_accept_throbber').clonePosition( $('market_removelisting_dialog_accept') );
$('market_removelisting_dialog_accept').fade({ duration: 0.25 });
$('market_removelisting_dialog_cancelbtn').fade({ duration: 0.25 });
$('market_removelisting_dialog_accept_throbber').show();
$('market_removelisting_dialog_accept_throbber').fade({ duration: 0.25, from: 0, to: 1 });
var listingid = this.m_ulListingId;
new Ajax.Request( 'https://steamcommunity.com/market/removelisting/' + listingid, {
method: 'post',
parameters: {
sessionid: g_sessionID
},
onSuccess: function( transport ) { RemoveListingDialog.OnSuccess( transport ); },
onFailure: function( transport ) { RemoveListingDialog.OnFailure( transport ); }
} );
},
OnCancel: function( event ) {
this.Dismiss();
event.stop();
},
OnSuccessEffects: function() {
// Decrement listing counters
if ( this.m_bAwaitingConfirmation )
{
if ( $( 'my_market_listingstoconfirm_number' ) )
$( 'my_market_listingstoconfirm_number' ).update( parseInt( $( 'my_market_listingstoconfirm_number' ).innerHTML ) - 1 );
}
else
{
if ( $( 'my_market_activelistings_number' ) )
$( 'my_market_activelistings_number' ).update( parseInt( $( 'my_market_activelistings_number' ).innerHTML ) - 1 );
if ( $( 'my_market_selllistings_number' ) )
$( 'my_market_selllistings_number' ).update( parseInt( $( 'my_market_selllistings_number' ).innerHTML ) - 1 );
}
// Remove any listing rows
$$('.listing_' + this.m_ulListingId).each( function( oListingRow ) {
oListingRow.remove();
} );
var queue = Effect.Queues.get('global');
queue.each(function(effect) { effect.cancel(); });
$('market_removelisting_dialog_accept').hide();
$('market_removelisting_dialog_cancelbtn').hide();
$('market_removelisting_dialog_accept_throbber').hide();
this.Dismiss();
},
OnSuccess: function( transport ) {
if ( transport.responseJSON )
{
this.OnSuccessEffects();
}
else
{
this.OnFailureEffects();
this.DisplayError( 'Ошибка при удалении лота. Обновите страницу и повторите попытку.' );
}
},
OnFailureEffects: function() {
this.m_bOKClicked = false;
var queue = Effect.Queues.get('global');
queue.each(function(effect) { effect.cancel(); });
$('market_removelisting_dialog_accept').show();
$('market_removelisting_dialog_accept').setOpacity('0');
$('market_removelisting_dialog_accept').fade({ duration: 0.25, from: 0, to: 1 });
$('market_removelisting_dialog_cancelbtn').show();
$('market_removelisting_dialog_cancelbtn').setOpacity('0');
$('market_removelisting_dialog_cancelbtn').fade({ duration: 0.25, from: 0, to: 1 });
$('market_removelisting_dialog_accept_throbber').fade({ duration: 0.25 });
},
OnFailure: function( transport ) {
this.OnFailureEffects();
this.DisplayError( 'Ошибка при удалении лота. Обновите страницу и повторите попытку.' );
},
OnDocumentKeyPress: function( event ) {
if ( event.keyCode == Event.KEY_ESC )
{
this.Dismiss();
event.stop();
}
}
};
function RemoveMarketListing( sElementPrefix, listingid, appid, contextid, itemid )
{
RemoveListingDialog.Show( sElementPrefix, listingid, g_rgAssets[appid][contextid][itemid], false );
}
function CancelMarketListingConfirmation( sElementPrefix, listingid, appid, contextid, itemid )
{
RemoveListingDialog.Show( sElementPrefix, listingid, g_rgAssets[appid][contextid][itemid], true );
}
CancelMarketBuyOrderDialog = {
m_bInitialized: false,
m_llBuyOrderID: null,
Initialize: function() {
},
Show: function ( buy_orderid ) {
if ( !this.m_bInitialized )
this.Initialize();
this.m_llBuyOrderID = buy_orderid;
this.OnAccept();
},
DisplayError: function( error ) {
alert( error );
},
Dismiss: function() {
},
OnAccept: function() {
new Ajax.Request( 'https://steamcommunity.com/market/cancelbuyorder/', {
method: 'post',
parameters: {
sessionid: g_sessionID,
buy_orderid: this.m_llBuyOrderID
},
onSuccess: function( transport ) { CancelMarketBuyOrderDialog.OnSuccess( transport ); },
onFailure: function( transport ) { CancelMarketBuyOrderDialog.OnFailure( transport ); }
} );
},
OnCancel: function() {
this.Dismiss();
},
OnSuccessEffects: function() {
window.location.reload();
},
OnSuccess: function( transport ) {
if ( transport.responseJSON )
{
this.OnSuccessEffects();
}
else
{
// this.DisplayError( 'Ошибка при удалении лота. Обновите страницу и повторите попытку.' );
}
},
OnFailure: function( transport ) {
alert( 'failed to cancel buy order' );
}
};
function CancelMarketBuyOrder( buy_orderid )
{
CancelMarketBuyOrderDialog.Show( buy_orderid );
}
CreateBuyOrderDialog = {
m_bInitialized: false,
m_divContents: null,
m_unAppId: null,
m_strMarketHashName: null,
m_strMarketItemName: null,
m_timeBuyOrderPollingStart: null,
m_bPageNeedsRefresh: false,
m_nBestBuyPrice: null,
m_bActive: false,
Initialize: function( unAppId, strMarketHashName, strMarketItemName, divPopup ) {
this.m_bInitialized = true;
this.m_divContents = divPopup;
this.m_unAppId = unAppId;
this.m_strMarketHashName = strMarketHashName;
this.m_strMarketItemName = strMarketItemName;
},
Show: function( unAppId, strMarketHashName, strMarketItemName, divPopup ) {
if ( !this.m_bInitialized )
this.Initialize( unAppId, strMarketHashName, strMarketItemName, divPopup );
if ( !g_bLoggedIn )
{
showModal( 'NotLoggedInWarning', true );
return;
}
this.m_bActive = true;
// show the frame in the dialog
var modal = ShowDialog( 'Купить — %1$s'.replace( '%1$s', strMarketItemName ), this.m_divContents.show() );
modal.always( function() { CreateBuyOrderDialog.OnUserClosedDialog() } );
$J('#market_buyorder_dialog_error').hide();
// show the payment frame
$J('#market_buyorder_dialog_paymentinfo_frame_container').show();
$J('#market_buyorder_dialog_placing_order').hide();
$J('#market_buy_commodity_view_in_inventory').hide();
$J('#market_buy_commodity_input_price').prop( 'disabled', false);
$J('#market_buy_commodity_input_quantity').prop('disabled', false);
// set our callbacks
$J('#market_buy_commodity_input_price').keyup( function() { CreateBuyOrderDialog.UpdateTotal(); } );
$J('#market_buy_commodity_input_quantity').keyup( function() { CreateBuyOrderDialog.UpdateTotal(); } );
$J('#market_buyorder_dialog_purchase').click( function() { CreateBuyOrderDialog.StartPurchase(); } );
$J('#market_buyorder_dialog_addfunds').click( function() { CreateBuyOrderDialog.OnAddFunds(); } );
$J('#market_buy_commodity_input_price').blur( function() {
var sWalletCurrencyCode = GetCurrencyCode( g_rgWalletInfo['wallet_currency'] );
var currency = GetPriceValueAsInt( $J('#market_buy_commodity_input_price').val() );
$('market_buy_commodity_input_price').setValue( v_currencyformat( currency, sWalletCurrencyCode ) );
});
var sWalletCurrencyCode = GetCurrencyCode( g_rgWalletInfo['wallet_currency'] );
if ( window.g_rgWalletInfo )
{
$('market_buyorder_dialog_walletbalance_amount').update( v_currencyformat( g_rgWalletInfo['wallet_balance'], sWalletCurrencyCode ) );
}
else
{
$('market_buyorder_dialog_walletbalance_amount').update( 'no funds' );
}
// set our default price
$('market_buy_commodity_input_price').setValue( v_currencyformat( this.m_nBestBuyPrice, sWalletCurrencyCode ) );
this.UpdateTotal();
},
UpdateTotal: function() {
var currency = GetPriceValueAsInt( $J('#market_buy_commodity_input_price').val() );
var quantity = parseInt( $J('#market_buy_commodity_input_quantity').val() );
var price = Math.round( currency * quantity );
var div = $J('#market_buy_commodity_order_total');
if ( isNaN(price) || !window.g_rgWalletInfo )
div.html( '--' );
else
div.html( v_currencyformat( price, GetCurrencyCode( g_rgWalletInfo['wallet_currency'] ) ) );
if ( !window.g_rgWalletInfo || isNaN(price) || g_rgWalletInfo['wallet_balance'] < price )
{
// show add funds
console.log(g_rgWalletInfo['wallet_balance']);
$J('#market_buyorder_dialog_purchase').hide();
$J('#market_buyorder_dialog_addfunds').show();
$J('#market_buyorder_dialog_accept_ssa_container').hide();
}
else
{
// show buy button
$J('#market_buyorder_dialog_addfunds').hide();
$J('#market_buyorder_dialog_purchase').show();
$J('#market_buyorder_dialog_accept_ssa_container').show();
}
},
StartPurchase: function() {
if ( !$J('#market_buyorder_dialog_accept_ssa').prop('checked') )
{
this.DisplayError( 'Для завершения операции необходимо принять условия соглашения подписчика Steam.' );
return;
}
if ( g_bRequiresBillingInfo )
{
var rgBadFields = {
first_name : false,
last_name : false,
billing_address : false,
security_code : false,
billing_city : false,
billing_state_text : false,
billing_phone : false,
billing_postal_code : false,
billing_state_select_trigger : false
}
var errorString = '';
errorString = BillingAddress_VerifyAddressFields( rgBadFields, g_bHasBillingStates );
for ( var key in rgBadFields )
{
if ( rgBadFields[key] )
ValidationMarkFieldBad( key );
else
ValidationMarkFieldOk( key );
}
if ( errorString != '' )
{
this.DisplayError( errorString );
return;
}
}
new Effect.BlindUp( 'market_buyorder_dialog_paymentinfo_frame_container', { duration: 0.25 } );
new Effect.BlindDown( 'market_buyorder_dialog_placing_order', { duration: 0.25 } );
$J('#market_buy_commodity_input_price').prop( 'disabled', true);
$J('#market_buy_commodity_input_quantity').prop('disabled', true);
$J('#market_buyorder_dialog_error').hide();
$J('#market_buy_commodity_status').html( 'Размещение запроса на покупку…' );
var currency = GetPriceValueAsInt( $J('#market_buy_commodity_input_price').val() );
var quantity = parseInt( $J('#market_buy_commodity_input_quantity').val() );
var price_total = Math.round( currency * quantity );
var first_name = $J('#first_name') ? $J('#first_name').val() : '';
var last_name = $J('#last_name') ? $J('#last_name').val() : '';
var billing_address = $J('#billing_address') ? $J('#billing_address').val() : '';
var billing_address_two = $J('#billing_address_two') ? $J('#billing_address_two').val() : '';
var billing_country = $J('#billing_country') ? $J('#billing_country').val() : '';
var billing_city = $J('#billing_city') ? $J('#billing_city').val() : '';
var billing_state = g_bHasBillingStates ? ( $J('#billing_state_select') ? $J('#billing_state_select').val() : '' ) : '';
var billing_postal_code = $J('#billing_postal_code') ? $J('#billing_postal_code').val() : '';
var save_my_address = $J('#save_my_address') ? $J('#save_my_address').prop('checked') : false;
// we'll want to refresh the page behind us when done
this.m_bPageNeedsRefresh = true;
// ajax in the result
$J.ajax( {
url: 'https://steamcommunity.com/market/createbuyorder/',
type: 'POST',
data: {
sessionid: g_sessionID,
currency: g_rgWalletInfo['wallet_currency'],
appid: this.m_unAppId,
market_hash_name: this.m_strMarketHashName,
price_total: price_total,
quantity: quantity,
first_name: first_name,
last_name: last_name,
billing_address: billing_address,
billing_address_two: billing_address_two,
billing_country: billing_country,
billing_city: billing_city,
billing_state: billing_state,
billing_postal_code: billing_postal_code,
save_my_address: save_my_address ? '1' : '0'
},
crossDomain: true,
xhrFields: { withCredentials: true }
} ).done( function ( data ) {
CreateBuyOrderDialog.OnCreateBuyOrderComplete( { responseJSON: data } );
} ).fail( function( jqxhr ) {
// jquery doesn't parse json on fail
var data = $J.parseJSON( jqxhr.responseText );
CreateBuyOrderDialog.OnCreateBuyOrderComplete( { responseJSON: data } );
} );
},
OnCreateBuyOrderComplete: function( transport ) {
if ( transport.responseJSON && transport.responseJSON.success == 1 )
{
$J('#market_buyorder_dialog_purchase_throbber').show();
$J('#market_buy_commodity_status').html( 'Поиск подходящего предмета по заданной цене…' );
var buy_orderid = transport.responseJSON.buy_orderid;
// poll for buy order result
this.m_timeBuyOrderPollingStart = $J.now();
setTimeout( function() { CreateBuyOrderDialog.PollForBuyOrderCompletion( buy_orderid ); }, 1000 );
}
else if ( transport.responseJSON && transport.responseJSON.message )
{
this.DisplayError( transport.responseJSON.message );
}
else if ( transport.responseJSON && transport.responseJSON.success )
{
this.DisplayError( 'Извините! Серверы Steam не ответили на запрос о вашем заказе. Возможно, ваш заказ уже создан или выполнен. Если это не так, повторите попытку позже.' + ' (' + transport.responseJSON.success + ')' );
}
else
{
this.DisplayError( 'Извините! Серверы Steam не ответили на запрос о вашем заказе. Возможно, ваш заказ уже создан или выполнен. Если это не так, повторите попытку позже.' );
}
},
OnAddFunds: function() {
var currency = GetPriceValueAsInt( $J('#market_buy_commodity_input_price').val() );
var quantity = parseInt( $J('#market_buy_commodity_input_quantity').val() );
var price = Math.round( currency * quantity );
if ( !window.g_rgWalletInfo || isNaN(price) || g_rgWalletInfo['wallet_balance'] >= price )
{
window.location = 'https://store.steampowered.com/steamaccount/addfunds?marketlisting=1&returnurl=' + window.location;
}
else
{
if ( price > g_rgWalletInfo['wallet_max_balance'] && price > g_rgWalletInfo['wallet_balance'] )
{
this.DisplayError(
'Итоговая сумма превышает максимально возможный баланс кошелька Steam (%1$s).'
.replace( '%1$s', v_currencyformat( g_rgWalletInfo['wallet_max_balance'], GetCurrencyCode( g_rgWalletInfo['wallet_currency'] ) ) )
);
}
else
{
window.location = 'https://store.steampowered.com/steamaccount/addfunds?marketlisting=1&minneeded=' + (price - g_rgWalletInfo['wallet_balance']) + '&returnurl=' + window.location;
}
}
},
PollForBuyOrderCompletion: function( buy_orderid ) {
if ( $J.now() > (this.m_timeBuyOrderPollingStart+5000) )
{
this.BuyOrderPlaced();
}
else
{
// keep asking
$J.ajax( {
url: 'https://steamcommunity.com/market/getbuyorderstatus/',
type: 'GET',
data: {
sessionid: g_sessionID,
buy_orderid: buy_orderid
}
} ).done( function ( data ) {
CreateBuyOrderDialog.OnPollForBuyOrderCompletionSuccess( buy_orderid, { responseJSON: data } );
} ).fail( function( jqxhr ) {
CreateBuyOrderDialog.BuyOrderPlaced();
} );
}
},
OnPollForBuyOrderCompletionSuccess: function( buy_orderid, response ) {
if ( response.responseJSON.success != 1 )
{
// failed for some reason - just keep polling until we either timeout or get a status
setTimeout( function() { CreateBuyOrderDialog.PollForBuyOrderCompletion( buy_orderid ); }, 1000 );
}
else if ( response.responseJSON.purchased )
{
this.BuyOrderPlaced();
$J('#market_buy_commodity_status').html( 'Покупка завершена! Теперь предмет у вас в инвентаре, вы получите подтверждение по электронной почте.' );
if ( response.responseJSON.purchase_amount_text )
{
$J('#market_buy_commodity_purchase_detail').html( response.responseJSON.purchase_amount_text );
}
for( var i = 0; i < response.responseJSON.purchases.length; i++ )
{
if ( response.responseJSON.purchases[i].assetid && response.responseJSON.purchases[i].contextid )
{
$J('#market_buy_commodity_view_in_inventory').show();
$J('#market_buy_commodity_view_in_inventory').click( function() {
CreateBuyOrderDialog.ViewPurchasedItemInInventory( response.responseJSON.purchases[i].appid, response.responseJSON.purchases[i].contextid, response.responseJSON.purchases[i].assetid );
}
);
break;
}
}
}
else if ( response.responseJSON.active )
{
setTimeout( function() { CreateBuyOrderDialog.PollForBuyOrderCompletion( buy_orderid ); }, 1000 );
}
},
BuyOrderPlaced: function() {
// too long has passed, give up
$J('#market_buy_commodity_status').html( 'Готово! Ваш заказ размещен.
Вы получите автоматическое сообщение на электронную почту после завершения покупки. Вы можете отменить заказ внизу этой страницы или со страницы Торговой площадки.' );
$J('#market_buy_commodity_throbber').hide();
},
ViewPurchasedItemInInventory: function( appid, contextid, assetid ) {
window.location = 'https://steamcommunity.com/my/inventory/#' + appid + '_' + contextid + '_' + assetid;
},
DisplayError: function( error ) {
$J('#market_buyorder_dialog_purchase_throbber').hide();
$J('#market_buyorder_dialog_error').show();
$J('#market_buyorder_dialog_error_text').html( error );
$J('#market_buyorder_dialog_error_text').css( 'color', '#ffffff' );
// this doesn't work, need jquery-color plugin or a different solution
$J('#market_buyorder_dialog_error_text').animate( {'color':'#ff0000'}, 250 );
$J('#market_buyorder_dialog_placing_order').hide();
},
OnUserClosedDialog: function() {
if ( this.m_bPageNeedsRefresh )
{
this.m_bPageNeedsRefresh = false;
window.location.reload();
}
this.m_bActive = false;
}
};
function Market_ShowBuyOrderPopup( unAppId, sMarketHashName, strMarketItemName ) {
if ( typeof g_rgWalletInfo != 'undefined' && g_rgWalletInfo['wallet_currency'] == 0 )
{
ShowConfirmDialog(
'Невозможно разместить запрос',
'Вы сможете покупать вещи на Торговой площадке сообщества, только когда пополните баланс кошелька Steam или сделаете покупку в магазине Steam и предоставите платежный адрес.',
'Пополнить кошелёк',
'Отмена'
).done( function() {
location.href = 'https://store.steampowered.com/steamaccount/addfunds';
} );
}
else
{
CreateBuyOrderDialog.Show( unAppId, sMarketHashName, strMarketItemName, $J('#market_buy_commodity_popup') );
}
}
BuyItemDialog = {
m_bPurchaseClicked: false,
m_bPurchaseSuccess: false,
m_bInitialized: false,
m_oListingOriginalRow: null,
m_sElementPrefix: null,
m_ulListingId: false,
m_item: null,
m_fnDocumentKeyHandler: null,
m_nSubtotal: 0,
m_nFeeAmount: 0,
m_nTotal: 0,
m_sAddFundsReturnURL: null,
m_modal: null,
Initialize: function() {
$('market_buynow_dialog_purchase').observe( 'click', this.OnAccept.bindAsEventListener(this) );
$('market_buynow_dialog_addfunds').observe( 'click', this.OnAddFunds.bindAsEventListener(this) );
$('market_buynow_dialog_cancel').observe( 'click', this.OnCancel.bindAsEventListener(this) );
$('market_buynow_dialog_cancel_close').observe( 'click', this.OnCancel.bindAsEventListener(this) );
$('market_buynow_dialog_close').observe( 'click', this.OnCancel.bindAsEventListener(this) );
$('market_buynow_dialog').style.visibility = 'hidden';
$('market_buynow_dialog').show();
$('market_buynow_dialog').hide();
$('market_buynow_dialog').style.visibility = '';
this.m_bInitialized = true;
},
Show: function ( sElementPrefix, listingid, item ) {
if ( !this.m_bInitialized )
this.Initialize();
this.m_bPurchaseClicked = false;
this.m_bPurchaseSuccess = false;
$('market_buynow_dialog_error').hide();
$('market_buynow_dialog_title').update( 'Купить предмет' );
$('market_buynow_dialog_purchasecomplete_message').hide();
$('market_buynow_dialog_purchase').show();
$('market_buynow_dialog_purchase_throbber').hide();
$('market_buynow_dialog_paymentinfo_frame_container').show();
$('market_buynow_dialog_bottom_buttons').hide();
$('market_buynow_dialog_cancel').show();
$('market_buynow_dialog_cancel_close').hide();
var sCurrentURL = window.location.protocol + "//" + window.location.host + window.location.pathname;
this.m_sAddFundsReturnURL = encodeURIComponent( sCurrentURL + '#buy' + sElementPrefix + '|' + listingid + '|' + item['appid'] + '|' + item['contextid'] + '|' + item['id'] );
this.m_oListingOriginalRow = $(sElementPrefix + '_' + listingid);
var bNoWallet = g_rgWalletInfo['wallet_currency'] == 0;
var sWalletCurrencyCode = GetCurrencyCode( g_rgWalletInfo['wallet_currency'] );
var rgListing = g_rgListingInfo[listingid];
if ( rgListing['converted_fee_per_unit'] > 0 )
{
this.m_nSubtotal = rgListing['converted_price_per_unit'];
this.m_nFeeAmount = rgListing['converted_fee_per_unit'];
this.m_nTotal = rgListing['converted_price_per_unit'] + rgListing['converted_fee_per_unit'];
var nFeePublisher = rgListing['converted_publisher_fee_per_unit'];
var nFeeSteam = rgListing['converted_steam_fee_per_unit'];
if ( this.m_nFeeAmount != nFeePublisher + nFeeSteam || this.m_nTotal != this.m_nSubtotal + nFeePublisher + nFeeSteam )
{
alert( "An unexpected error occurred trying to show the purchase dialog. Error: " + listingid + " " + this.m_nTotal + " " + this.m_nSubtotal + " " + this.m_nFeeAmount + " " + nFeePublisher + " " + nFeeSteam );
return;
}
if ( BIsTwoFactorEnabled() )
{
this.m_nTotal -= nFeeSteam;
this.m_nFeeAmount -= nFeeSteam;
//nFeeSteam = 0;
}
$('market_buynow_dialog_totals_subtotal').update( v_currencyformat( this.m_nSubtotal, sWalletCurrencyCode ) );
$('market_buynow_dialog_totals_publisherfee').update( v_currencyformat( nFeePublisher, sWalletCurrencyCode ) );
$('market_buynow_dialog_totals_publisherfee_percent').update( ( rgListing['publisher_fee_percent'] * 100 ).toFixed(1) );
if ( typeof g_rgAppContextData[rgListing['publisher_fee_app']] != 'undefined' )
{
$J('#market_buynow_dialog_totals_publisherfee_gamename').text( g_rgAppContextData[rgListing['publisher_fee_app']].name );
}
else
{
// No app data for some reason
// Say "Game fee"
$J('#market_buynow_dialog_totals_publisherfee_gamename').text( 'Игру' );
}
$('market_buynow_dialog_totals_transactionfee').update( v_currencyformat( nFeeSteam, sWalletCurrencyCode ) );
$('market_buynow_dialog_totals_transactionfee_percent').update( ( g_rgWalletInfo['wallet_fee_percent'] * 100 ).toFixed(1) );
$('market_buynow_dialog_totals_total').update( v_currencyformat( this.m_nTotal, sWalletCurrencyCode ) );
$('market_buynow_dialog_totals').show();
}
else
{
this.m_nSubtotal = rgListing['converted_price_per_unit'];
this.m_nFeeAmount = 0;
this.m_nTotal = rgListing['converted_price_per_unit'];
$('market_buynow_dialog_totals').hide();
}
var elEuSSA = $('market_buynow_dialog_eu_ssa');
if ( this.m_nTotal > g_rgWalletInfo['wallet_balance'] || bNoWallet )
{
$('market_buynow_dialog_purchase').hide();
$('market_buynow_dialog_addfunds').show();
$('market_buynow_dialog_accept_ssa_container').hide();
if ( elEuSSA )
{
elEuSSA.hide();
}
}
else
{
$('market_buynow_dialog_purchase').show();
$('market_buynow_dialog_addfunds').hide();
$('market_buynow_dialog_accept_ssa_container').show();
if ( elEuSSA )
{
elEuSSA.show();
}
}
if ( bNoWallet )
{
$('market_buynow_dialog_walletbalance').hide();
}
else
{
$('market_buynow_dialog_walletbalance').show();
$('market_buynow_dialog_walletbalance_amount').update( v_currencyformat( g_rgWalletInfo['wallet_balance'], sWalletCurrencyCode ) );
}
this.m_sElementPrefix = sElementPrefix;
this.m_ulListingId = listingid;
this.m_item = item;
var oListingRow = Element.clone( this.m_oListingOriginalRow, true );
var oListingTable = Element.clone( this.m_oListingOriginalRow.up(1), false );
var oListingTableRowHeader = Element.clone( this.m_oListingOriginalRow.up().down(), true);
var oListingTableRows = Element.clone( this.m_oListingOriginalRow.up(), false );
oListingTableRows.appendChild( oListingTableRowHeader );
oListingRow.id = oListingRow.id + 'Copy';
var oItemImg = oListingRow.select('.market_listing_item_img').first();
if ( typeof oItemImg != 'undefined' )
oItemImg.id = oItemImg.id + 'Copy';
var oItemActionMenuButton = oListingRow.select('.market_actionmenu_button').first();
if ( typeof oItemActionMenuButton != 'undefined' )
{
oItemActionMenuButton.id = oItemActionMenuButton.id + 'Copy';
$(oItemActionMenuButton).observe( 'click', function() {
var rgAsset = g_rgListingInfo[listingid].asset;
HandleMarketActionMenu( oItemActionMenuButton, g_rgAssets[rgAsset.appid][rgAsset.contextid][rgAsset.id], listingid );
return false;
} );
}
var oItemName = oListingRow.select('.market_listing_item_name').first();
oItemName.update( this.m_item.name.escapeHTML() ); // Remove any quantity from the item name
oItemName.id = oItemName.id + 'Copy';
oListingTableRows.appendChild( oListingRow );
var oAvatarLink = oListingTableRows.select('a').each( function( item ) {
item.target = '_new';
});
oListingTableRows.id = oListingTable.id + 'Copy';
oListingTable.appendChild( oListingTableRows );
oListingTable.id = oListingTable.id + 'Copy';
$('market_buynow_dialog_item').innerHTML = '';
$('market_buynow_dialog_item').appendChild( oListingTable );
if ( typeof oItemImg != 'undefined' )
CreateItemHoverFromContainer( g_rgAssets, oItemImg.id, item.appid, item.contextid, item.id, item.amount );
CreateItemHoverFromContainer( g_rgAssets, oItemName.id, item.appid, item.contextid, item.id, item.amount );
$('hover').style.zIndex = 1001;
this.m_fnDocumentKeyHandler = this.OnDocumentKeyPress.bindAsEventListener( this );
$(document).observe( 'keydown', this.m_fnDocumentKeyHandler );
var _this = this;
this.m_modal = new CModal( $J('#market_buynow_dialog' ) );
this.m_modal.GetContent().find('.newmodal_close' ).click( function() { _this.Dismiss() } );
this.m_modal.Show();
$('market_buynow_dialog').focus();
},
DisplayError: function( error ) {
$('market_buynow_dialog_error').show();
$('market_buynow_dialog_error_text').update( error );
$('market_buynow_dialog_error_text').style.color = '#ffffff';
new Effect.Morph( $('market_buynow_dialog_error_text'), { style: {color: '#ff0000'}, duration: 0.25 } );
},
Dismiss: function() {
$(document).stopObserving( 'keydown', this.m_fnDocumentKeyHandler );
if ( this.m_modal )
{
this.m_modal.Dismiss();
this.m_modal = null;
}
},
OnAddFunds: function( event ) {
event.stop();
window.location = 'https://store.steampowered.com/steamaccount/addfunds?marketlisting=' + this.m_ulListingId + '&returnurl=' + this.m_sAddFundsReturnURL;
},
OnAccept: function( event ) {
event.stop();
// If already accepted, ignore
if ( this.m_bPurchaseSuccess || this.m_bPurchaseClicked )
{
return;
}
if ( !$('market_buynow_dialog_accept_ssa') || !$('market_buynow_dialog_accept_ssa').checked )
{
this.DisplayError( 'Для завершения операции необходимо принять условия соглашения подписчика Steam.' );
return;
}
if ( g_bRequiresBillingInfo )
{
var rgBadFields = {
first_name : false,
last_name : false,
billing_address : false,
security_code : false,
billing_city : false,
billing_state_text : false,
billing_phone : false,
billing_postal_code : false,
billing_state_select_trigger : false
}
var errorString = '';
errorString = BillingAddress_VerifyAddressFields( rgBadFields, g_bHasBillingStates, '_buynow' );
for ( var key in rgBadFields )
{
if ( rgBadFields[key] )
ValidationMarkFieldBad( key + '_buynow' );
else
ValidationMarkFieldOk( key + '_buynow' );
}
if ( errorString != '' )
{
this.DisplayError( errorString );
return;
}
}
this.m_bPurchaseClicked = true;
$('market_buynow_dialog_error').hide();
$('market_buynow_dialog_purchase_throbber').clonePosition( $('market_buynow_dialog_purchase') );
$('market_buynow_dialog_purchase').fade({ duration: 0.25 });
$('market_buynow_dialog_purchase_throbber').show();
$('market_buynow_dialog_purchase_throbber').fade({ duration: 0.25, from: 0, to: 1 });
var listingid = this.m_ulListingId;
var first_name = $J('#first_name_buynow') ? $J('#first_name_buynow').val() : '';
var last_name = $J('#last_name_buynow') ? $J('#last_name_buynow').val() : '';
var billing_address = $J('#billing_address_buynow') ? $J('#billing_address_buynow').val() : '';
var billing_address_two = $J('#billing_address_two_buynow') ? $J('#billing_address_two_buynow').val() : '';
var billing_country = $J('#billing_country_buynow') ? $J('#billing_country_buynow').val() : '';
var billing_city = $J('#billing_city_buynow') ? $J('#billing_city_buynow').val() : '';
var billing_state = g_bHasBillingStates ? ( $J('#billing_state_select_buynow') ? $J('#billing_state_select_buynow').val() : '' ) : '';
var billing_postal_code = $J('#billing_postal_code_buynow') ? $J('#billing_postal_code_buynow').val() : '';
var save_my_address = $J('#save_my_address_buynow') ? $J('#save_my_address_buynow').prop('checked'): false;
$J.ajax( {
url: 'https://steamcommunity.com/market/buylisting/' + listingid,
type: 'POST',
data: {
sessionid: g_sessionID,
currency: g_rgWalletInfo['wallet_currency'],
subtotal: this.m_nSubtotal,
fee: this.m_nFeeAmount,
total: this.m_nTotal,
quantity: 1,
first_name: first_name,
last_name: last_name,
billing_address: billing_address,
billing_address_two: billing_address_two,
billing_country: billing_country,
billing_city: billing_city,
billing_state: billing_state,
billing_postal_code: billing_postal_code,
save_my_address: save_my_address ? '1' : '0'
},
crossDomain: true,
xhrFields: { withCredentials: true }
} ).done( function ( data ) {
BuyItemDialog.OnSuccess( { responseJSON: data } );
} ).fail( function( jqxhr ) {
// jquery doesn't parse json on fail
var data = $J.parseJSON( jqxhr.responseText );
BuyItemDialog.OnFailure( { responseJSON: data } );
} );
},
OnCancel: function( event ) {
this.Dismiss();
event.stop();
},
OnSuccessEffects: function() {
$('market_buynow_dialog_cancel').hide();
$('market_buynow_dialog_cancel_close').show();
$('market_buynow_dialog_purchase_throbber').fade({ duration: 0.25 });
new Effect.BlindUp( 'market_buynow_dialog_paymentinfo_frame_container', { duration: 0.25 } );
new Effect.BlindDown( 'market_buynow_dialog_purchasecomplete_message', { duration: 0.25 } );
new Effect.BlindDown( 'market_buynow_dialog_bottom_buttons', { duration: 0.25 } );
// Replace the listing row with a message that says this was purchased
var oOriginalItemName = Element.clone( this.m_oListingOriginalRow.select('.market_listing_item_name').first(), true );
this.m_oListingOriginalRow.update('');
var elMessage = new Element( 'div', {'class': 'market_listing_purchase_message' } );
var sItemNameSpanId = this.m_sElementPrefix + '_purchased_' + this.m_ulListingId;
elMessage.update(
'Вы приобрели предмет <%1$s>%2$s>. <%3$s>Открыть инвентарь%4$s>'
.replace( '%1$s', 'span id="' + sItemNameSpanId + '"' )
.replace( '%2$s', 'span' )
.replace( '%3$s', 'a href="https://steamcommunity.com/my/inventory/"' )
.replace( '%4$s', 'a' ) );
this.m_oListingOriginalRow.appendChild( elMessage );
$(sItemNameSpanId).appendChild( oOriginalItemName );
},
OnSuccess: function( transport ) {
this.m_bPurchaseSuccess = true;
if ( transport.responseJSON )
{
var rgNewWalletInfo = transport.responseJSON.wallet_info;
if ( rgNewWalletInfo && rgNewWalletInfo.success )
{
g_rgWalletInfo = rgNewWalletInfo;
}
var sWalletCurrencyCode = GetCurrencyCode( g_rgWalletInfo['wallet_currency'] );
$('marketWalletBalanceAmount').update( v_currencyformat( g_rgWalletInfo['wallet_balance'], sWalletCurrencyCode ) );
this.OnSuccessEffects();
}
else
{
this.OnFailureEffects();
this.DisplayError( 'Ошибка при покупке предмета. Возможно, лот был удален. Обновите страницу и повторите попытку.' );
}
},
OnFailureEffects: function() {
var queue = Effect.Queues.get('global');
queue.each(function(effect) { effect.cancel(); });
$('market_buynow_dialog_purchase').show();
$('market_buynow_dialog_purchase').setOpacity('0');
$('market_buynow_dialog_purchase').fade({ duration: 0.25, from: 0, to: 1 });
$('market_buynow_dialog_purchase_throbber').fade({ duration: 0.25 });
},
OnFailure: function( transport ) {
this.m_bPurchaseClicked = false;
this.OnFailureEffects();
if ( transport.responseJSON && transport.responseJSON.message )
{
this.DisplayError( transport.responseJSON.message );
}
else
{
this.DisplayError( 'Ошибка при покупке предмета. Возможно, лот был удален. Обновите страницу и повторите попытку.' );
}
},
OnDocumentKeyPress: function( event ) {
if ( event.keyCode == Event.KEY_ESC )
{
this.Dismiss();
event.stop();
}
},
OnInputKeyPress: function( event ) {
if ( event.keyCode == Event.KEY_RETURN )
{
if ( this.m_bPurchaseSuccess )
{
this.OnConfirmationAccept( event );
}
else
{
this.OnAccept( event );
}
}
},
OnInputKeyUp: function( event ) {
}
};
function BuyMarketListing( sElementPrefix, listingid, appid, contextid, itemid )
{
if ( !g_bLoggedIn )
{
showModal( 'NotLoggedInWarning', true );
return;
}
if ( !g_rgAssets[appid] || !g_rgAssets[appid][contextid] || !g_rgAssets[appid][contextid][itemid] )
{
return;
}
BuyItemDialog.Show( sElementPrefix, listingid, g_rgAssets[appid][contextid][itemid] );
}
function ObjectIsEmpty( object )
{
for ( var property in object )
{
if ( object.hasOwnProperty( property ) )
{
return false;
}
}
return true;
}
function MergeWithAssetArray( newAssets )
{
if ( ObjectIsEmpty( newAssets ) )
{
return;
}
for( var appid in newAssets )
{
for ( var contextid in newAssets[appid] )
{
for ( var assetid in newAssets[appid][contextid] )
{
if ( typeof( g_rgAssets[appid] ) == 'undefined' )
{
g_rgAssets[appid] = [];
}
if ( typeof( g_rgAssets[appid][contextid] ) == 'undefined' )
{
g_rgAssets[appid][contextid] = [];
}
g_rgAssets[appid][contextid][assetid] = newAssets[appid][contextid][assetid];
}
}
}
}
function MergeWithListingInfoArray ( newListings )
{
if ( ObjectIsEmpty( newListings ) )
{
return;
}
for( var listingid in newListings )
{
g_rgListingInfo[listingid] = newListings[listingid];
}
}
function MergeWithAppDataArray( newAppData )
{
if ( ObjectIsEmpty( newAppData ) )
{
return;
}
for ( var appid in newAppData )
{
if ( typeof g_rgAppContextData[appid] == 'undefined' )
{
g_rgAppContextData[appid] = newAppData[appid];
}
}
}
var g_bBusyLoadingMore = false;
function LoadRecentListings( type, rows )
{
if ( g_bBusyLoadingMore )
{
return;
}
var elRows = $(rows);
elRows.update( g_htmlThrobber );
g_bBusyLoadingMore = true;
new Ajax.Request( 'https://steamcommunity.com/market/recent', {
method: 'get',
parameters: {
country: g_strCountryCode,
language: g_strLanguage,
currency: typeof( g_rgWalletInfo ) != 'undefined' ? g_rgWalletInfo['wallet_currency'] : 1 //time: g_rgRecents[type]['time'],
//listing: g_rgRecents[type]['listing']
},
onSuccess: function( transport ) {
if ( transport.responseJSON )
{
var response = transport.responseJSON;
if ( response.assets.length != 0 )
{
g_rgRecents[type]['time'] = response.last_time;
g_rgRecents[type]['listing'] = response.last_listing;
elRows.update( g_htmlSellListingsTableHeader + response.results_html );
MergeWithAssetArray( response.assets );
MergeWithListingInfoArray( response.listinginfo );
MergeWithAppDataArray( response.app_data );
eval( response.hovers );
}
}
},
onComplete: function() { g_bBusyLoadingMore = false; }
});
}
var g_bBusyLoadingRecentCompleted = false;
var g_bLoadedRecentCompleted = false;
function LoadRecentCompletedListings( )
{
if ( g_bBusyLoadingRecentCompleted )
{
return;
}
var elRows = $('soldListingRows');
elRows.update( g_htmlThrobber );
g_bBusyLoadingRecentCompleted = true;
new Ajax.Request( 'https://steamcommunity.com/market/recentcompleted', {
method: 'get',
parameters: { },
onSuccess: function( transport ) {
if ( transport.responseJSON )
{
var response = transport.responseJSON;
if ( response.assets.length != 0 )
{
g_rgRecents['sell_sold']['time'] = response.last_time;
g_rgRecents['sell_sold']['listing'] = response.last_listing;
elRows.update( g_htmlSoldListingTableHeader + response.results_html );
MergeWithAssetArray( response.assets );
MergeWithListingInfoArray( response.listinginfo );
MergeWithAppDataArray( response.app_data );
eval( response.hovers );
}
}
},
onComplete: function() { g_bLoadedRecentCompleted = true; g_bBusyLoadingRecentCompleted = false; }
});
}
var g_bBusyLoadingMyMarketListings = false;
var g_oMyListings = null;
function RefreshMyMarketListings( bScrollIntoView )
{
if ( g_bBusyLoadingMyMarketListings )
{
return;
}
g_bBusyLoadingMyMarketListings = true;
var elMyMarketListings = $('tabContentsMyListings');
new Ajax.Request( 'https://steamcommunity.com/market/mylistings', {
method: 'get',
parameters: {
count: g_nMySellListingsPageSize
},
onSuccess: function( transport ) {
if ( transport.responseJSON )
{
var response = transport.responseJSON;
elMyMarketListings.innerHTML = response.results_html;
$('my_market_activelistings_number').update( response.num_active_listings );
MergeWithAssetArray( response.assets );
eval( response.hovers );
if ( response.total_count > response.pagesize )
{
g_oMyListings = new CAjaxPagingControls(
{
query: '',
total_count: response.total_count,
pagesize: response.pagesize,
prefix: 'tabContentsMyActiveMarketListings',
class_prefix: 'market'
}, 'https://steamcommunity.com/market/mylistings/'
);
g_oMyListings.SetResponseHandler( function ( response )
{
MergeWithAssetArray( response.assets );
eval( response.hovers );
} );
g_nMySellListingsPageSize = response.pagesize;
$J( '#my_listing_pagesize_10' ).addClass( 'whiteLink' ).removeClass( 'disabled' );
$J( '#my_listing_pagesize_30' ).addClass( 'whiteLink' ).removeClass( 'disabled' );
$J( '#my_listing_pagesize_100' ).addClass( 'whiteLink' ).removeClass( 'disabled' );
$J( '#my_listing_pagesize_' + g_nMySellListingsPageSize ).removeClass( 'whiteLink' ).addClass( 'disabled' );
if ( bScrollIntoView )
{
var elTable = $J( '#tabContentsMyActiveMarketListingsTable' ).get(0);
if ( typeof elTable.scrollIntoView !== 'undefined' )
{
elTable.scrollIntoView();
}
}
}
}
},
onComplete: function() { g_bBusyLoadingMyMarketListings = false; }
});
}
var g_bBusyLoadingMarketHistory = false;
var g_oMyHistory = null;
function LoadMarketHistory()
{
if ( g_bBusyLoadingMarketHistory )
{
return;
}
g_bBusyLoadingMarketHistory = true;
var elMyHistoryContents = $('tabContentsMyMarketHistory');
new Ajax.Request( 'https://steamcommunity.com/market/myhistory', {
method: 'get',
parameters: {
},
onSuccess: function( transport ) {
if ( transport.responseJSON )
{
var response = transport.responseJSON;
elMyHistoryContents.innerHTML = response.results_html;
MergeWithAssetArray( response.assets );
eval( response.hovers );
g_oMyHistory = new CAjaxPagingControls(
{
query: '',
total_count: response.total_count,
pagesize: response.pagesize,
prefix: 'tabContentsMyMarketHistory',
class_prefix: 'market'
}, 'https://steamcommunity.com/market/myhistory/'
);
g_oMyHistory.SetResponseHandler( function( response ) {
MergeWithAssetArray( response.assets );
eval( response.hovers );
});
}
},
onComplete: function() { g_bBusyLoadingMarketHistory = false; }
});
}
function MarketCheckHash()
{
if ( window.location.hash.length > 4 && window.location.hash.substr(0,4) == "#buy" )
{
var rgListing = window.location.hash.substr(4).split('|');
BuyMarketListing( rgListing[0], rgListing[1], rgListing[2], rgListing[3], rgListing[4] );
}
else if ( window.location.hash.length > 5 && window.location.hash.substr(0,5) == "#sell" )
{
var strAsset = window.location.hash.substr(5);
ShowModalContent('https://steamcommunity.com/my/inventory/?modal=1&market=1&sellOnLoad=1#' + strAsset, 'Выберите предмет из вашего инвентаря', 'https://steamcommunity.com/my/inventory/?modal=1&market=1&sellOnLoad=1#' + strAsset, false);
}
else if ( window.location.hash == "#myhistory" )
{
var oTabMyMarketHistory = $('tabMyMarketHistory');
oTabMyMarketHistory.click();
}
}
function InstallMarketActionMenuButtons()
{
for ( var listing in g_rgListingInfo ) {
var asset = g_rgListingInfo[listing].asset;
if ( typeof g_rgAssets[asset.appid][asset.contextid][asset.id].market_actions != 'undefined' )
{
// add the context menu
var elActionMenuButton = $J('');
elActionMenuButton.attr( 'id', 'listing_' + listing + '_actionmenu_button' );
elActionMenuButton.addClass( 'market_actionmenu_button' );
elActionMenuButton.attr( 'href', 'javascript:void(0)' );
$J('#listing_' + listing + '_image').parent().append( elActionMenuButton );
$J(elActionMenuButton).click( $J.proxy( function( elButton, rgAsset ) {
HandleMarketActionMenu( elButton.attr( 'id' ), g_rgAssets[rgAsset.appid][rgAsset.contextid][rgAsset.id] );
}, null, elActionMenuButton, asset ) );
}
}
}
function HandleMarketActionMenu( elActionMenuButton, item )
{
HideMenuFast( elActionMenuButton, 'market_action_popup' );
var elItemActions = $J('#market_action_popup_itemactions');
elItemActions.empty();
for ( var action = 0; action < item.market_actions.length; action++ )
{
var rgAction = item.market_actions[action];
var elNewAction = $J( '' );
elNewAction.addClass( 'popup_menu_item' );
elNewAction.attr(
'href',
rgAction.link.replace( "%assetid%", item.id )
.replace( "%contextid%", item.contextid )
.replace( "%owner_steamid%", item.owner )
);
if ( rgAction.link.substr( 0, 6 ) != "steam:" )
{
elNewAction.attr( 'target', '_blank' );
elNewAction.attr( 'rel', 'noreferrer' );
}
elNewAction.text( rgAction.name );
elNewAction.click( function() {
HideMenu( elActionMenuButton, 'market_action_popup' );
} );
elItemActions.append( elNewAction );
}
ShowMenu( elActionMenuButton, 'market_action_popup', 'right' );
}
Event.observe( document, 'dom:loaded', function() {
var oTabMyListings = $('tabMyListings');
var oTabMyMarketHistory = $('tabMyMarketHistory');
var oTabContentsMyListings = $('tabContentsMyListings');
var oTabContentsMyMarketHistory = $('tabContentsMyMarketHistory');
if ( oTabMyListings && oTabMyMarketHistory )
{
oTabMyListings.observe( 'click', function( event ) {
event.stop();
HideHover();
oTabContentsMyListings.show();
oTabContentsMyMarketHistory.hide();
oTabMyListings.addClassName( 'market_tab_well_tab_active' );
oTabMyListings.removeClassName( 'market_tab_well_tab_inactive' );
oTabMyMarketHistory.addClassName( 'market_tab_well_tab_inactive' );
oTabMyMarketHistory.removeClassName( 'market_tab_well_tab_active' );
} );
oTabMyMarketHistory.observe( 'click', function( event ) {
event.stop();
HideHover();
oTabContentsMyListings.hide();
oTabContentsMyMarketHistory.show();
oTabMyListings.addClassName( 'market_tab_well_tab_inactive' );
oTabMyListings.removeClassName( 'market_tab_well_tab_active' );
oTabMyMarketHistory.addClassName( 'market_tab_well_tab_active' );
oTabMyMarketHistory.removeClassName( 'market_tab_well_tab_inactive' );
LoadMarketHistory();
} );
}
var oTabPopularItems = $('tabPopularItems');
var oTabRecentSellListings = $('tabRecentSellListings');
var oTabRecentSoldListings = $('tabRecentSoldListings');
var oTabContentsPopularItems = $('popularItemsTable');
var oTabContentsRecentSellListings = $('sellListingsTable');
var oTabContentsRecentSoldListings = $('soldListingTable');
if ( oTabPopularItems && oTabRecentSellListings && oTabRecentSoldListings )
{
oTabPopularItems.observe( 'click', function( event ) {
event.stop();
HideHover();
oTabContentsPopularItems.show();
oTabContentsRecentSellListings && oTabContentsRecentSellListings.hide();
oTabContentsRecentSoldListings.hide();
oTabPopularItems.addClassName( 'market_tab_well_tab_active' );
oTabPopularItems.removeClassName( 'market_tab_well_tab_inactive' );
oTabRecentSellListings.addClassName( 'market_tab_well_tab_inactive' );
oTabRecentSellListings.removeClassName( 'market_tab_well_tab_active' );
oTabRecentSoldListings.addClassName( 'market_tab_well_tab_inactive' );
oTabRecentSoldListings.removeClassName( 'market_tab_well_tab_active' );
} );
if ( oTabContentsRecentSellListings )
{
// only set up the on click if we have the listing data
oTabRecentSellListings.observe( 'click', function( event ) {
event.stop();
HideHover();
oTabContentsPopularItems.hide();
oTabContentsRecentSellListings && oTabContentsRecentSellListings.show();
oTabContentsRecentSoldListings.hide();
oTabPopularItems.addClassName( 'market_tab_well_tab_inactive' );
oTabPopularItems.removeClassName( 'market_tab_well_tab_active' );
oTabRecentSellListings.addClassName( 'market_tab_well_tab_active' );
oTabRecentSellListings.removeClassName( 'market_tab_well_tab_inactive' );
oTabRecentSoldListings.addClassName( 'market_tab_well_tab_inactive' );
oTabRecentSoldListings.removeClassName( 'market_tab_well_tab_active' );
LoadRecentListings( 'sell_new', 'sellListingRows' );
} );
}
oTabRecentSoldListings.observe( 'click', function( event ) {
event.stop();
HideHover();
oTabContentsPopularItems.hide();
oTabContentsRecentSellListings && oTabContentsRecentSellListings.hide();
oTabContentsRecentSoldListings.show();
oTabPopularItems.addClassName( 'market_tab_well_tab_inactive' );
oTabPopularItems.removeClassName( 'market_tab_well_tab_active' );
oTabRecentSellListings.addClassName( 'market_tab_well_tab_inactive' );
oTabRecentSellListings.removeClassName( 'market_tab_well_tab_active' );
oTabRecentSoldListings.addClassName( 'market_tab_well_tab_active' );
oTabRecentSoldListings.removeClassName( 'market_tab_well_tab_inactive' );
LoadRecentCompletedListings();
} );
}
} );
AdvancedSearchDialog = {
m_bInitialized: false,
m_fnDocumentKeyHandler: null,
m_modal: null,
Initialize: function() {
},
Show: function () {
if ( !this.m_bInitialized )
this.Initialize();
this.m_fnDocumentKeyHandler = this.OnDocumentKeyPress.bindAsEventListener( this );
$(document).observe( 'keydown', this.m_fnDocumentKeyHandler );
var _this = this;
this.m_modal = ShowDialog( "\u041f\u043e\u0438\u0441\u043a \u043d\u0430 \u0422\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u043f\u043b\u043e\u0449\u0430\u0434\u043a\u0435", $J('#market_advancedsearch_dialog' ).show() );
this.m_modal.SetRemoveContentOnDismissal( false );
this.m_modal.always( function() { _this.Dismiss(); } );
$('market_advancedsearch_dialog').focus();
},
Dismiss: function() {
$(document).stopObserving( 'keydown', this.m_fnDocumentKeyHandler );
if ( this.m_modal )
{
this.m_modal.Dismiss();
this.m_modal = null;
}
},
SelectApp: function( unApp ) {
this.SelectAppElement( $J('#app_option_' + unApp ) );
},
SelectAppElement: function( elSelected ) {
var elActiveAppNew = elSelected.clone();
$J('#market_advancedsearch_appselect_activeapp').empty();
elActiveAppNew.attr( "id", elActiveAppNew.attr("id") + "_selected" );
$J('#market_advancedsearch_appselect_activeapp').append( elActiveAppNew );
$J('#market_advanced_search_app').remove();
var elHiddenAppInput = $J('');
$J('#market_advanced_search').append( elHiddenAppInput );
},
OnCancel: function( event ) {
this.Dismiss();
event.stop();
},
OnDocumentKeyPress: function( event ) {
if ( event.keyCode == Event.KEY_ESC )
{
this.Dismiss();
event.stop();
}
}
};
function ShowAdvancedSearchOptions()
{
AdvancedSearchDialog.Show();
if ( typeof g_rgFilterData != 'undefined' )
{
$J('#advancedSearchBox').val( g_strQueryText );
var data = { facets: g_rgFilterData };
ProcessFilterData( data );
AdvancedSearchDialog.SelectApp( g_unFilterApp );
}
}
function ProcessFilterData( data )
{
var elFilters = $J('#market_advancedsearch_filters');
elFilters.empty();
elFilters.css( 'text-align', 'inherit' );
var cCategories = 0;
$J.each( data.facets, function( sCategory, oCategory ) {
cCategories++;
} );
if ( cCategories > 0 )
{
// Do all dropdowns first
var cDropdowns = 0;
$J.each( data.facets, function( sCategory, oCategory ) {
var cTags = 0;
$J.each( oCategory.tags, function( k, oTag ) {
cTags++;
} );
if ( cTags > 20 )
{
var elCategory = $J('