function credentials_load_modal () {
    $('#dialog-message').dialog('open');
}

$(function(){
    // jQuery UI Dialog
    $('#confirm-dialog').dialog({
        autoOpen: false,
        width: 400,
        modal: true,
        resizable: false,
        buttons: {
            "Ok": function() {
                $.post("http://www.playbox.gr/sendmail", $("#participate").serialize(),function(data){
                    //and after the ajax request ends we check the text returned
                    if(data === 'sent'){
                        $('#participate').submit();
                    } else {
                        $(this).dialog("close");
                    }
                });
            },
            "άκυρο": function() {
                $(this).dialog("close");
            }
        }
    });
    $('.submit_btn').click(function(e){
//        e.preventDefault();
        $('#confirm-dialog').dialog('open');
    });
});
    
$(function(){
    $( "#dialog-message" ).dialog({
        autoOpen: false,
        modal: true,
        buttons: {
            Ok: function() {
                $( this ).dialog( "close" );
            }
        }
    });
    $('#submit_part').click(function(e){
        e.preventDefault();
        $('#dialog-message').dialog('open');
    });
});

$(function () {
    $('#home_main_container').find($('.ui-state-error')).each(function() {
        if ($(this).html() != '') {
            $(this).css({
                display : 'block'
            })
        }
    });
});
//$(document).ready(function () {
//    $( "#confirm-dialog" ).dialog({
//        autoOpen: false,
//        resizable: false,
//        modal: true,
//        buttons: {
//            Ok: function() {
//                $('#participate').submit();
//                $( this ).dialog( "close" );
//            },
//            άκυρο: function() {
//                $( this ).dialog( "close" );
//            }
//        }
//    });
//    
//    $('#participate').submit(function(e){
//        e.preventDefault();
//        $( "#confirm-dialog" ).dialog('open');
//    });
//});


function confirm_load_modal () {
    $( "#confirm-dialog" ).dialog({
        resizable: false,
        modal: true,
        buttons: {
            Ok: function() {
                $('#participate'.submit())
            },
            άκυρο: function() {
                $( this ).dialog( "close" );
            }
        }
    });
    $( "#confirm-dialog" ).dialog('open');
}

$(function () {
    $('#sport_select').find('input').change(function () {
        var activeplay = $(this).val();
        if (activeplay == 'basket') {
            $('#change_to_big_podosfairo').attr('src',$('#change_to_big_podosfairo').attr('src').replace(/_active/, ''));
            $('#change_to_big_tennis').attr('src',$('#change_to_big_tennis').attr('src').replace(/_active/, ''));
            $('#change_to_big_volley').attr('src',$('#change_to_big_volley').attr('src').replace(/_active/, ''));
        } else if (activeplay == 'podosfairo') {
            $('#change_to_big_basket').attr('src',$('#change_to_big_basket').attr('src').replace(/_active/, ''));
            $('#change_to_big_tennis').attr('src',$('#change_to_big_tennis').attr('src').replace(/_active/, ''));
            $('#change_to_big_volley').attr('src',$('#change_to_big_volley').attr('src').replace(/_active/, ''));
        } else if (activeplay == 'tennis') {
            $('#change_to_big_podosfairo').attr('src',$('#change_to_big_podosfairo').attr('src').replace(/_active/, ''));
            $('#change_to_big_basket').attr('src',$('#change_to_big_basket').attr('src').replace(/_active/, ''));
            $('#change_to_big_volley').attr('src',$('#change_to_big_volley').attr('src').replace(/_active/, ''));
        } else {
            $('#change_to_big_podosfairo').attr('src',$('#change_to_big_podosfairo').attr('src').replace(/_active/, ''));
            $('#change_to_big_tennis').attr('src',$('#change_to_big_tennis').attr('src').replace(/_active/, ''));
            $('#change_to_big_basket').attr('src',$('#change_to_big_basket').attr('src').replace(/_active/, ''));
        }
        var tochange = $('#change_to_big_'+activeplay).attr('src');
        $('#change_to_big_'+activeplay).attr('src',tochange.replace('.png', '_active.png'));
    }); 
});

$(function(){
    // jQuery UI Dialog
    $( "#sport_error" ).dialog({
        autoOpen: false,
        height: 150,
        width: 300,
        modal: true
    });
    
    $( "#search_type_error" ).dialog({
        autoOpen: false,
        height: 150,
        width: 300,
        modal: true
    });
    
    $( "#game_type_error" ).dialog({
        autoOpen: false,
        height: 150,
        width: 300,
        modal: true
    });
    
    $( "#nop_error" ).dialog({
        autoOpen: false,
        height: 150,
        width: 300,
        modal: true
    });
    
    $( "#location_error" ).dialog({
        autoOpen: false,
        height: 150,
        width: 300,
        modal: true
    });
    
    $( "#date_error" ).dialog({
        autoOpen: false,
        height: 150,
        width: 300,
        modal: true
    });
    
    $( "#description_error" ).dialog({
        autoOpen: false,
        height: 150,
        width: 300,
        modal: true
    });
    
    $('#submit_create').click(function(e){
        var basket = $('#basket_value:checked').val();
        var podosfairo = $('#podosfairo_value:checked').val();
        var tennis = $('#tennis_value:checked').val();
        var volley = $('#volley_value:checked').val();
        var game_type1 = $('#game_type1_value').val();
        var game_type2 = $('#game_type2_value').val();
        var search_type_single = $('#single_select:checked').val();
        var search_type_team = $('#team_select:checked').val();
        var nop = $('#number_of_persons').val();
        var town = $('#towns').val();
        var area = $('#area').val();
        var date = $('#datepicker').val();
        var description = $('#description_value').val();
        if (!basket && !podosfairo && !tennis && !volley ) {
            e.preventDefault();
            return $('#sport_error').dialog('open');
        }
        
        if (game_type1 == '' || game_type2 == '') {
            e.preventDefault();
            return $('#game_type_error').dialog('open');
        }
    
        if (!search_type_single && !search_type_team) {
            e.preventDefault();
            return $('#search_type_error').dialog('open');
        }

        if (nop == '') {
            e.preventDefault();
            return $('#nop_error').dialog('open');
        }

        if (town == '0' || area == '0') {
            e.preventDefault();
            return $('#location_error').dialog('open');
        }

        if (date == '') {
            e.preventDefault();
            return $('#date_error').dialog('open');
        }

        if (description == '') {
            e.preventDefault();
            return $('#description_error').dialog('open');
        }
    }); 
});

function load_user_info_modal (username) {
    $( "#load_user_info_"+username ).dialog({
        modal: true,
        buttons: {
            Ok: function() {
                $( this ).dialog( "close" );
            }
        }
    });
}



