function ad_common_ready()
{menu_item_init(["main","myads","partner","balance","office","about"]);}
function ad_index_ready()
{}
function ad_inner_ready()
{}
function ad_static_init()
{if($(".ofc_fname").length)
{insert_stat_graphic($(".ofc_fname").eq(0).text());$(".show_graphic").each(function(i){$(this).click(function(){var fname=$(".ofc_fname").eq(i).text();$("#ofc")[0].load(eval(fname+"()"));$(".show_graphic").removeClass("selected");$(this).addClass("selected");});if(!i)$(this).addClass("selected");});}}
function ad_myads_ready()
{}
function ad_myads_view_ready()
{ad_static_init();ad_geo_init();}
function ad_myads_edit_ready()
{var adtitle=$('.adurl');var adtext=$('.adtext');var addomain=$('.addomain');$('#val_title').keyup(function(){var str=$(this).val();var max=$(this).attr("maxlength");if(str.length<=max)
adtitle.text(split_long_words($(this).val(),15));});$('#val_text').keydown(function(){var str=$(this).val();var max=$(this).attr("maxlength");$(this).val(str.substring(0,max));if(str.length>max)
return false;else
return true;});$('#val_text').keyup(function(){var str=$(this).val();var max=$(this).attr("maxlength");if(str.length<=max)
adtext.text(split_long_words($(this).val(),15));else
$(this).val(str.substring(0,max));});$('#val_url').keyup(function(){var str=$(this).val();var max=$(this).attr("maxlength");if(str.length>max)return;adtitle.attr('href',str);addomain.attr('href',str);var sp=str.split(/\//g);for(var i=0;i<sp.length;++i)
if(sp[i].indexOf(":")==-1&&sp[i]!="")
{addomain.text(split_long_words(sp[i],15));break;}});ad_geo_init();ad_keywords_init();symbol_indicator_init('.indicator');}
function symbol_indicator_init(statement)
{$(statement).each(function(i){var el=$(this);var forel=$('#'+el.attr('forel'));var length=forel.val().length;var max=parseInt(forel.attr('maxlength'));build_symbol_indicator(el,length,max);forel.keydown(function(e){var length=$(this).val().length;var max=parseInt(forel.attr('maxlength'));build_symbol_indicator(el,length,max);});});}
function build_symbol_indicator(el,length,max,delim)
{if(!delim)
delim='/'
el.empty();var s1=$('<span></span>').addClass('si_length').text(length);var s2=$('<span></span>').addClass('si_max').text(max);var s3=$('<span></span>').addClass('si_delim').text(delim);el.append(s1).append(s3).append(s2);}
function ad_balance_ready()
{}
function ad_office_ready()
{ad_commercial_toggle();}
function ad_geo_init()
{$(".gblock .gsel").toggle(function(){$(this).text("-");$(this).parent().parent().find(".childs").show();return false;},function(){$(this).text("+");$(this).parent().parent().find(".childs").hide();return false;});$(".gblock .gparent").change(function(){$(this).parent().parent().find(".gchild").attr("checked",this.checked);});$(".gblock .gchild").change(function(){var parent=$(this).parent().parent().parent().parent();var checked=parent.find(".gchild:checked").length!=0;parent.find(".gparent").attr("checked",checked);});$("#aall").click(function(){$("#loctable input").attr("checked",true);return false;});$("#aclear").click(function(){$("#loctable input").attr("checked",false);return false;});$("#amoscow").click(function(){$("#loctable input").attr("checked",false);$("#c1").attr("checked",true);$("#c1_2").attr("checked",true);return false;});$("#arussia").click(function(){$("#loctable input").attr("checked",false);$("#c1").attr("checked",true).parent().find(".childs input").attr("checked",true);return false;});}
function insert_stat_graphic(fname)
{var so=new SWFObject("/swf/open-flash-chart.swf","ofc","100%","400","9","#FFFFFF");so.addVariable("get-data",fname);so.addParam("allowScriptAccess","always");so.addParam("wmode","transparent");so.write("stat_graphic");}
function open_flash_chart_data(a)
{return"{\"elements\":[]}";}
function create_datepicker(obj,format,locale)
{if(!locale)locale={};if(!format)format='Y-m-d';obj.DatePicker({flat:false,date:obj.val(),format:'Y-m-d',locale:locale,onBeforeShow:function(){obj.focus(false);obj.DatePickerSetDate(obj.val(),true);},onChange:function(formated,dates){obj.val(formated);obj.DatePickerHide();}});}
function shiftDate(date1,date2)
{$("#stat_date_from").DatePickerSetDate(date1,true);$("#stat_date_to").DatePickerSetDate(date2,true);$("#date_filter").submit();}
function view_change_status(a,status)
{$('.status_str').toggleClass('hidden');ajax_href(a,'','&exit=');$('#status_changed').show().toggleClass('success').toggleClass('notice').find('span').toggleClass('hidden');autohide('#status_changed',5000);return false;}
function ad_partner_ready()
{$('.selcolor').colorPicker();ad_static_init();}
var last_keyword='';function ad_keywords_init()
{$('.keyword_row.not_garant').attr('title',$.trim($('#not_garant_title').text()));var acurl="keyword_suggest.php?";var options={minChars:2,max:10,scroll:false,selectFirst:false};$(".new_keyword .keyword").autocomplete(acurl,options).result(function(event,item){$(".new_keyword .keyword").val(item[1]);ad_set_new_keyword_price(item[1]);});setInterval(function(){var keyword=$('.new_keyword .keyword').val().toLowerCase();if(keyword!==last_keyword)
{last_keyword=keyword
ad_set_new_keyword_price(keyword);}},500);}
function ad_clear_keywords()
{$('.keyword_row').each(function(){var el=$(this);if($('.keyword_row').length==1)
el.addClass('hidden').find('input').attr('disabled','disabled');else if(!el.hasClass('hidden'))
el.remove();});}
function ad_new_keyword(keyword)
{var rows_length=$('.keyword_row').not('.hidden').length;if(rows_length>=parseInt($('#keywords_max_count').text()))
{myalert('#too_many_keywords_str');return false;}
var new_row=$('.new_keyword').eq(0);if(keyword==undefined)
{ad_clear_new_keyword_price();var keyword=new_row.find('.keyword').val();}
keyword=$.trim(keyword);if(!keyword)
{new_row.find('.keyword').focus();return false;}
$('.ac_results').hide();new_row.find('.keyword').val('');var already_exists=false;$('.keyword_row input.keyword').each(function(){if($(this).val().toLowerCase()==keyword.toLowerCase())
already_exists=true;});if(already_exists)return false;$('#keyword_progress_bar').show();var price=new_row.find('.price').val();new_row.val(parseFloat($('#floor_price').text()));var tpl_row=$('.keyword_row:last').clone()
tpl_row.removeClass('hidden').find('input').removeAttr('disabled');tpl_row.find('input.keyword').val(keyword);tpl_row.find('span.keyword').text(keyword);tpl_row.find('.price').val(ad_valid_price(price));$.get(get_keyword_price_url(keyword),function(data){data=data.split("\n");tpl_row.find('.view').text(data[0]);tpl_row.find('.first_price').text(data[1]);tpl_row.find('.garant_price').text(data[2]);$('#keyword_progress_bar').hide();ad_check_price(tpl_row);$('.keyword_row:last').after(tpl_row);ad_renumber_rows();$('.new_keyword .keyword').focus();});return true;}
function get_keyword_price_url(keyword)
{return"keyword_price.php?id="+($('#ad_id').text())+"&q="+encodeURI(keyword);}
function ad_remove_keyword(btn_el)
{if($('.keyword_row').length==1)
{$(btn_el).parents('.keyword_row').addClass('hidden').find('input').attr('disabled','disabled');return;}
$(btn_el).parents('.keyword_row').remove();ad_renumber_rows();}
function ad_valid_price(price)
{if(typeof price!=="number")
price=parseFloat(price)||0;price=Math.round(price*100)/100;var floor_price=parseFloat($('#floor_price').text());var roof_price=parseFloat($('#roof_price').text());if(price<floor_price)
price=floor_price;else if(price>roof_price)
price=roof_price;return price;}
function ad_set_price(el,val,parent)
{val=(val===undefined)?$(el).text():val;parent=(parent===undefined)?'.keyword_row':parent;el=$(el);if(parent)
el=el.parents(parent);if(!el.hasClass('price'))
el=el.find('.price');el.val(ad_valid_price(val));ad_check_price(el);return false;}
function ad_check_price(el)
{var row=$(el);if(!$(el).hasClass('keyword_row'))
row=row.parents('.keyword_row');var garant_price=row.find('.garant_price').text();var price=ad_valid_price(row.find('.price').val());if(price<garant_price)
row.attr('title',$.trim($('#not_garant_title').text())).addClass('not_garant');else
row.removeAttr('title').removeClass('not_garant');}
function ad_smaller_price(el,other,price_step,parent)
{if(other==undefined)
other=true;if(price_step==undefined)
price_step=parseFloat($('#price_step').text());var inp=$(el);if(other)
inp=inp.next();var val=ad_valid_price(inp.val());val-=price_step;ad_set_price(inp.get(0),val,parent);return false;}
function ad_higher_price(el,other,price_step,parent)
{if(other==undefined)
other=true;if(price_step==undefined)
price_step=parseFloat($('#price_step').text());var inp=$(el);if(other)
inp=inp.prev();var val=ad_valid_price(inp.val());val+=price_step;ad_set_price(inp.get(0),val,parent);return false;}
var price_change_interval=null;var price_change_interval_time=100;function ad_start_smaller_price(el,parent)
{ad_stop_price();price_change_interval=setInterval(function(){ad_smaller_price(el,undefined,undefined,parent)},price_change_interval_time);return false;}
function ad_start_higher_price(el,parent)
{ad_stop_price();price_change_interval=setInterval(function(){ad_higher_price(el,undefined,undefined,parent)},price_change_interval_time);return false;}
function ad_stop_price()
{clearInterval(price_change_interval);return false;}
function ad_keyword_enter(e)
{var btn=e.keyCode||e.which||e.charCode;if(btn==13)
{if(e.ctrlKey)
ad_new_keyword();return false;}
return true;}
function ad_price_keypress(e)
{var btn=e.keyCode||e.which||e.charCode;var el;if(e.target)el=e.target;else if(e.srcElement)el=e.srcElement;if(e.ctrlKey)
{if(btn==40)
$(el).parents('.keyword_row').next().find('input.price').focus();else if(btn==38)
$(el).parents('.keyword_row').prev().find('input.price').focus();}else
{var parent=$(el).attr('id')=='set_price2all'?'.set_enother':undefined;if(btn==40)
ad_smaller_price(el,false,0.1,parent);else if(btn==38)
ad_higher_price(el,false,0.1,parent);}}
function ad_set_first_price2all()
{$('.keyword_row .first_price').each(function(){var price=$(this).text();ad_set_price(this,price);});$('#new_prices_set_success').show();autohide('#new_prices_set_success');return false;}
function ad_set_garant_price2all()
{$('.keyword_row .garant_price').each(function(){var price=$(this).text();ad_set_price(this,price);});$('#new_prices_set_success').show();autohide('#new_prices_set_success');return false;}
function ad_cancel_enter(e)
{var btn=e.keyCode||e.which||e.charCode;if(btn==13)
{ad_set_price2all();return false;}
return true;}
function ad_set_price2all()
{var price=$('#set_price2all').val();$('.keyword_row .price').each(function(){ad_set_price(this,price);});$('#new_prices_set_success').show();autohide('#new_prices_set_success');return false;}
function ad_renumber_rows()
{$('.keyword_row').not('.hidden').find('.number').each(function(i){$(this).text(i+1);});}
function ad_clear_new_keyword_price()
{$('.new_keyword .stat_val').text('0');return false;}
function ad_set_new_keyword_price(keyword)
{keyword+='';if(!$.trim(keyword))
return ad_clear_new_keyword_price();$.get(get_keyword_price_url(keyword),function(data){var new_row=$('.new_keyword');data=data.split("\n");new_row.find('.view').text(data[0]);new_row.find('.first_price').text(data[1]);new_row.find('.garant_price').text(data[2]);});}
function ad_toggle_mass_keyword_add()
{$('.mass_new_keyword, .new_keyword').toggle();$('#keyword_text').val('').focus();return false;}
function ad_add_mass_keyword_add()
{var keywords=$('#keyword_text').val();var res=[],arr=[];keywords=keywords.split('\n');for(i in keywords)
{arr=keywords[i].split(',');for(j in arr)
res.push(arr[j]);}
var max_count=parseInt($('#keywords_max_count').text());var count=$('.keyword_row').not('.hidden').length;var i=0;do
{if(res[i]!=undefined&&ad_new_keyword(res[i]))
++count;i+=1;}while(i<res.length&&count<max_count);if(count==max_count)
myalert('#too_many_keywords_str');ad_toggle_mass_keyword_add();return false;}
function ad_commercial_toggle()
{var value=$('#val_commercial').val();$('.commercial').removeClass('hidden').not('#commercial_'+value).addClass('hidden');}
function ad_company_inn_req_toggle(checked)
{var els=$('._company_inn .required');checked?els.addClass('hidden'):els.removeClass('hidden');}
function ad_toggle_agreement()
{$('#agreement').toggleClass('hidden');return false;}
function ad_remove_site(el)
{$(el).parents('tr:first').remove();}
function ad_show_comment(el)
{$(el).parents('tr:first').next().toggleClass('hidden');}
function ad_homemenu_toggle(el,sel)
{$('.indexinfo').addClass('hidden').filter(sel).removeClass('hidden');$('.homemenu .item').removeClass('sel');$(el).addClass('sel');return false;}
var submitted=false;function ad_add_domain(form)
{if(!submitted)
{submitted=true;$(form).submit(function(){var adress=$.trim($(this).find('[name=adress]').val());var exit=!(adress==''||adress=='http://');if(inputtip_submit_res&&!exit)
$(this).find('[name=adress]').focus();return inputtip_submit_res&&exit&&send_form(form,'#only_domains','',function(){setup_inputtip();submitted=true;});});}}
function ad_image_change(unset)
{var length=0;if(unset)
{$('#val_image').val('');}
if($('#val_image').val().length)
{length=parseInt($('#text_length_image').text());$('#delimage_btn').removeClass('hidden');}else
{length=parseInt($('#text_length').text());$('#delimage_btn').addClass('hidden');}
$('#val_text').attr('maxlength',length).keydown();}
function ad_partner_change_type(el)
{var block=$('#val_adtype').parents('.block:first');if(el.value=='muzlinks')
{block.addClass('hidden');var count=$('#val_count');if(count.val()==count.attr('default'))
count.find('option').eq(2).attr('selected','selected');}
else
block.removeClass('hidden');}
function ad_send_out(form)
{var amount=parseFloat($.trim($('#wmz_out_amount').val()).replace(',','.'))||0;var min_amount=parseFloat($('#min_out_amount').text());if(amount<min_amount)
{myalert('#too_small_amount',function(){$('#wmz_out_amount').focus();});return false;}
$('#wmz_out_amount').val(amount);send_form(form,undefined,undefined,function(data){var name='ask_sent';if(data)
name='not_ask_sent';$('#balance_out .result').addClass('hidden').filter('#'+name).removeClass('hidden');});return false;}