$(document).ready(function(){
    $('input#name, input#school, input#group, input#email, input#phone').val('');
    });

$(function(){
    var name = $('input#name');
    var school = $('input#school');
    var group = $('input#group');
    var email = $('input#email');
    var phone = $('input#phone');
    var notify =  $('div#notify');
    var patt = /^[\w-]+(\.[\w-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i;
    var phonePatt = /^[2-9]\d{2}-\d{3}-\d{4}$/;
    var errors = true
    

    
    function checkName(){
        if(name.val()==0) {
            errors = true;
            notify.show();
            name.css({'backgroundColor':'#ffc600'});

        }else {
            notify.hide();
            name.css({'backgroundColor':''});
        }
    }
    
    function checkSchool(){
        if(school.val()==0) {
            errors = true;
            notify.show();
            school.css({'backgroundColor':'#ffc600'});
        }else {
            notify.hide();
            school.css({'backgroundColor':''});
        }
    }
    
    function checkGroup(){
        if(group.val()==0) {
            errors = true;
            notify.show();
            group.css({'backgroundColor':'#ffc600'});
        }else {
            notify.hide();
            group.css({'backgroundColor':''});
        }
    }
    
    function checkEmail(){
        if(!patt.test(email.val())) {
            errors = true;
            
            notify.show();
            email.css({'backgroundColor':'#ffc600'});
        }else {
            notify.hide();
            email.css({'backgroundColor':''});
        }
    }
    
    function checkPhone(){
        if(!phonePatt.test(phone.val())) {
            errors = true;
            
            notify.show();
            phone.css({'backgroundColor':'#ffc600'});
        }else {
            notify.hide();
            phone.css({'backgroundColor':''});
        }
    }
    
    function send(){
        if(!errors) {
            $('#form').submit();
        }
    }
    
    $('button#send').click(function(){
        errors = false;
        checkName();
        checkSchool();
        checkGroup();
        checkEmail();
        checkPhone();
        send();
    return !errors;
});
    
    $('input#name').change(checkName);
    $('input#school').change(checkSchool);
    $('input#group').change(checkGroup);
    $('input#email').change(checkEmail);
    $('input#phone').change(checkPhone);
});
