function ShowToggle(div){ 
    if($('.overlay').css('display') == 'block'){  
        $('#'+div).fadeOut(200, function(){
            $('.overlay').fadeOut(500);   
        });
        //hide
    } else {
        //show
        $('.overlay').fadeIn(500, function(){
            $('#'+div).fadeIn(200);
        });
    }
              
}

function Register(){
    
    if($('#RegisterResultDiv').css('display') != 'none'){
        $('#RegisterResultDiv').css({'display' : 'none'});
    }
    $('#RegisterLoading').css({'display' : 'block'});
    
    $.post('register.php?register=1',
            $('#RegisterForm').serialize(),
            function(data){
                var res = eval('('+data+')');                        
                $('#RegisterResultDiv').html(res.msg);     
                $('#RegisterLoading').css({'display' : 'none'});  
                $('#RegisterResultDiv').fadeIn('normal');
                if(res.status == 1){
                    document.location.href = res.loginAdress;
                } 
            }
    );
}

function RecoverPassword(){                          
    
    if($('#ForgottenResultDiv').css('display') != 'none'){
        $('#ForgottenResultDiv').css({'display' : 'none'});    
    }
    
    $('#ForgottenLoading').css({'display' : 'block'});
    
    $.post('forgotten_password.php?recover=1',
            $('#ForgottenForm').serialize(),
            function(data){
                var res = eval('('+data+')');

                $('#ForgottenResultDiv').html(res.msg);  
                $('#ForgottenLoading').css({'display' : 'none'});
                $('#ForgottenResultDiv').fadeIn('normal');

            }
    );
    
}
function SendFeedback(){                          
    
    if($('#FeedbackResultDiv').css('display') != 'none'){
        $('#FeedbackResultDiv').css({'display' : 'none'});    
    }
    
    $('#FeedbackLoading').css({'display' : 'block'});
    
    $.post('feedback.php?send=1',
            $('#FeedbackForm').serialize(),
            function(data){
                var res = eval('('+data+')');

                $('#FeedbackResultDiv').html(res.msg);  
                $('#FeedbackLoading').css({'display' : 'none'});
                $('#FeedbackResultDiv').fadeIn('normal');

            }
    );
    
}
function ShowRanking(page){
        $.get('ranking.php?page='+page,
                $('#RankingForm').serialize(true),
                function(data){
                    $('#RankingResult').html(data);
                }
        );   
}
function showTour(id){
    $('[id^="game_tour_header_"]').css({'display' : 'none'});
    $('[id^="game_tour_step_"]').css({'display' : 'none'});
    
    $('#game_tour_header_'+id).fadeIn('normal');
    $('#game_tour_step_'+id).fadeIn('normal');      
}

function ShowTourRegister(){
    $('#GameTour').fadeOut(200, function(){
            $('.overlay').fadeOut(500, function(){
                ShowToggle('RegisterDiv');
            });   
    });                        
}

function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

function reload_image(){
    var now = rand(10000);
    $('.auth_code').attr({ src: "img_auth.php?what="+now, alt: "Bot Captcha" });
}

$(function(){
    $('.blink').blink(250);
});

$(function(){       
    $('#LoginForm > :input[name="password"]').keypress(function(e) {
        if(e.keyCode == 13) {
              $('#LoginForm').submit();
        }
    });
});
