//var host = 'http://localhost:8180/wap.herocraft.com';
var host = 'http://wap.herocraft.com';

function swap(data){
    //get new page content
    var new_content = $('<div></div>');
    $(new_content).css({'display':'none'});
    $(new_content).attr('id','replace');
    $(new_content).html(data);
    //install it after present content
    $('.right_side').after(new_content);
    //check if if have 1 game
    var one_game = $('#one-game');
    if (one_game.length != 0){
	//fly to games page
	var new_url = host + one_game.html();
	window.location = new_url;
    }
    else{
	//replace contents of the page by found games
	var right_sides = $('.right_side');
	$(right_sides[0]).replaceWith(right_sides[1]);
	$("#replace").remove();
    }
}

function search_for_games(button){
    var fm = button.form;
    fm.onsubmit = function(){
        return false;
    };
    var action = host + $(fm).attr('action');
    var input  = $('.search_field')[0];
    var name = $(input).attr('name');
    var value = $(input).attr('value');
    var url = action + '?' + name + '=' + value + '&async=t';
    $.ajax({
	       url: url,
	       success: swap
	   });
}

