var karrier={
    errors:[],
    init:function(){
        $('#karrierUrlap').bind('submit',function(){
            return karrier.check();
        });
        /*$('.cv input[name="legmagasabb_iskolai_vegzettseg"]').bind('click',function(){
            karrier.showWrappers($(this).val());
        });
        $('.cv input[name="legmagasabb_iskolai_vegzettseg"]').each(function(){
            $(this).attr('checked',false);
        });
        karrier.showWrappers('');*/
        $('.errorMsg').empty();
    },
    check:function(){
        karrier.errors=[];
        var tmp=false;
        $('#karrierUrlap input[name="erdeklodesi_terulet[]"]').each(function(){
            if($(this).attr('checked')){
                tmp=true;
            }
        });
        if(!tmp){karrier.errors.push('erdeklodesi_terulet');}
        
        if($('#karrierUrlap input[name="munkavegzes_helye"]').val().match(/^\s*$/)){
            karrier.errors.push('munkavegzes_helye');
        }
        if($('#karrierUrlap input[name="nev"]').val().match(/^\s*$/)){
            karrier.errors.push('nev');
        }
        if($('#karrierUrlap input[name="szuletesi_hely"]').val().match(/^\s*$/)){
            karrier.errors.push('szuletesi_hely');
        }
        if($('#karrierUrlap input[name="szuletesi_ido"]').val().match(/^\s*$/)){
            karrier.errors.push('szuletesi_ido');
        }
        if($('#karrierUrlap input[name="allampolgarsag"]').val().match(/^\s*$/)){
            karrier.errors.push('allampolgarsag');
        }
        if($('#karrierUrlap input[name="irszam"]').val().match(/^\s*$/)){
            karrier.errors.push('irszam');
        }
        if($('#karrierUrlap input[name="helyseg"]').val().match(/^\s*$/)){
            karrier.errors.push('helyseg');
        }
        if($('#karrierUrlap input[name="utca_hsz"]').val().match(/^\s*$/)){
            karrier.errors.push('utca_hsz');
        }
        if($('#karrierUrlap input[name="telefon"]').val().match(/^\s*$/)){
            karrier.errors.push('telefon');
        }
        if($('#karrierUrlap input[name="email"]').val().match(/^\s*$/)){
            karrier.errors.push('email');
        }
        if(!$('#karrierUrlap input[name="cv"]').val().match(/^(.*\.(doc|docx|pdf))?$/i)){
            karrier.errors.push('cv');
        }
        
        if(karrier.errors.length>0){
            karrier.displayErrors();
            return false;
        }
        return true;
    },
    displayErrors:function(){
        var msg=errorHeader+'<br />';
        for(var i=0;i<karrier.errors.length;i++){
            msg+='<br />'+errorMessages[karrier.errors[i]];
        }
        msg+='<br /><br />';
        $('.errorMsg').html(msg);
        $(document).scrollTop(500);
    },
    showWrappers:function(myVal){
        switch(myVal){
            case'felso':
                $('#kozepiskola_wrapper').hide();
                $('#egyetem_wrapper').show();
                break;
            case'kozep':
                $('#egyetem_wrapper').hide();
                $('#kozepiskola_wrapper').show();
                break;
            default:
                $('#egyetem_wrapper').hide();
                $('#kozepiskola_wrapper').hide();
                break;
        }
    }
};

karrier.init();

