$(document).ready(function(){
    
    // prettyPhoto
    
    $("a[rel^='prettyPhoto']").prettyPhoto({theme: 'facebook'});
    
    // Подвал - в подвал
    
    if ($('body').outerHeight()<$(window).height()) {
        $('#filler').attr('height', $(window).height()+$('#filler').parent().height()-$('body').outerHeight());
    }
    
    // Валидация форм
    
    $('form.validate').validate();
        
    // Быстрые диалоги
    
    $('.load').click(function(){
        $('<div></div>').load($(this).attr('href')+'ajax-1/', function(){
            $('form.validate').validate();
        }).dialog({
            title:$(this).attr('title').length ? $(this).attr('title') : $(this).html(),
            buttons:{
                'Закрыть':function(){
                    $(this).dialog('destroy');
                }
            },
            modal:true,
            width:640,
            height:480,
            resizable:false,
            draggable:false
        });
        return false;
    });
    
    $('.dialog').click(function(){
        $('<div></div>').load($(this).attr('href')+'ajax-1/', function(){
            $('form.validate').validate();
        }).dialog({
            title:$(this).attr('title').length ? $(this).attr('title') : $(this).html(),
            buttons:{
                'Отмена':function(){
                    $(this).dialog('destroy');
                },
                'Ok':function(){
                    $(this).find('form').submit();
                }
            },
            modal:true,
            width:500,
            resizable:false,
            draggable:false
        });
        return false;
    });
        
});

$.validator.addMethod('phone', function(ph, element) {
    if (this.optional(element)) {
        return true;
    }
    var stripped = ph.replace(/[\s()+-]|ext\.?/gi, '');
    // 6 is the minimum number of numbers required
    return ((/\d{6,}/i).test(stripped));
}, 'Пожалуйста, введите корректный номер телефона.');

