var t_name_dir = "http://" + window.location.hostname + '/sentryengine/code/ajax/';
function refresh_servers(game_select)
{
 jQuery.ajax({
   url: t_name_dir + 'ajax.php',
   data:{
       mode: 'servers',
       id: jQuery(game_select).val()},
    type: 'GET',
    success: function(data,code)
    {
        jQuery('#servers').html(data);
    }

 });

 jQuery.ajax({
   url: t_name_dir + 'valuta_name.php',
   data:{
       id: jQuery(game_select).val()},
   type: 'GET',
   beforeSend: function(o)
    {
        jQuery('#server_loading').show();
    },
    success: function(data,code)
    {
        jQuery('#server_loading').hide();
        jQuery('#game_money').text(data);
    }

 });

}

function validateComment()
{
    var mas = ["name","icq","comment"];
    for(var i=0;i<mas.length;i++)
    if(jQuery.trim(jQuery('#'+mas[i]).val())=='')
        {
            jQuery.prompt('Поле "<font color=red>'+jQuery('#'+mas[i]+'S').html()+'</font>" не заполнено!',{top:'40%'});
            jQuery('#'+mas[i]).focus();
            return false;
        }
    jQuery('#commentForm').ajaxSubmit({
       url: t_name_dir +'ajax_comments.php',
       type: 'POST',
       dataType: 'json',
       beforeSubmit: function(mas,nab,op)
        {
            jQuery('#commentLoading').show();
            jQuery('#commentButton').attr('disabled','disabled');
        },
       success: function(data,success,ob)
       {
           jQuery.prompt(data.message,{top:'40%'});
           jQuery('#commentLoading').hide();
           jQuery('#commentButton').removeAttr('disabled');
           if(data.status==1)
           {
            jQuery('#comment_table').slideUp();
            jQuery("#commentForm").clearForm();
           }

           refresh_comment_captcha();

       }

    });
   return false;
}

function refresh_comment_captcha()
{
    jQuery('#captcha').attr('src','manager/includes/veriword.php?'+Math.floor(Math.random()*10000))
}

      jQuery.fn.clearForm = function() {
        return this.each(function() {
          jQuery(':input', this).each(function() {

            var type = this.type, tag = this.tagName.toLowerCase();

            if (type == 'text' || type == 'password' || tag == 'textarea')

              this.value = '';

            else if (type == 'checkbox' || type == 'radio')

              this.checked = false;

            else if (tag == 'select')

              this.selectedIndex = -1;

          });

        });

      };

function adv_search()
{

    if(jQuery('#adv_search').css("display")=='none')
    {
       jQuery('#adv_search').slideDown("slow");
       jQuery('#adv_status').val(1);
    }
    else
    {
       jQuery('#adv_search').slideUp("fast");
       jQuery('#adv_status').val(0);
    }
   return false;
}

function refresh_shops()
{
 jQuery.ajax({
   url: t_name_dir + 'graph_ajax.php',
   data:{
   		mode: 'shops',
   		game_id: jQuery('#games').val(),
        id: jQuery('#servers').val()},
   type: 'GET',
   beforeSend: function(o)
    {
        jQuery('#div_shops_id').html("<img src=\"assets/templates/modxaggc/images/loading.gif\" >");
    },
    success: function(data,code)
    {
        jQuery('#div_shops_id').html(data);
    }

 });
}

function refresh_servers_and_shops(game_select)
{
 jQuery.ajax({
   url: t_name_dir + 'graph_ajax.php',
   data:{
       mode: 'servers',
       id: jQuery(game_select).val()},
    type: 'GET',
    success: function(data,code)
    {
        jQuery('#servers').html(data);
        jQuery.ajax({
		   url: t_name_dir + 'graph_ajax.php',
		   data:{
		   		mode: 'shops',
		   		game_id: jQuery('#games').val(),
		        id: jQuery('#servers').val()},
		   type: 'GET',
		   beforeSend: function(o)
		    {
		    	jQuery('#div_shops_id').html("<img src=\"assets/templates/modxaggc/images/loading.gif\" >");
		    },
		   success: function(data,code)
		    {
		        jQuery('#div_shops_id').html(data);
		    }

		 });
    }

 });

 jQuery.ajax({
   url: t_name_dir + 'valuta_name.php',
   data:{
       id: jQuery(game_select).val()},
   type: 'GET',
   beforeSend: function(o)
    {
        jQuery('#server_loading').show();
    },
    success: function(data,code)
    {
        jQuery('#server_loading').hide();
        jQuery('#game_money').text(data);
    }

 });
}

