﻿FLR.submitVacancy = function(){

    /* Private */
        
    /* Properties */
    
    var cmp = {};
    
    
    
    
    
    
    /* Methods */
    
    var init = function(){
    
        // Submit vacancy
         $('#submitVacancyNav .temp').click(function() {
         
            // Show correct content
            $('.temporary').show();
            $('.permanent').hide();
            
            // Correct tab colouring
            $(this).css({ backgroundPosition: '-246px -32px' });
            $('#submitVacancyNav .perm').css({ backgroundPosition: '0 -32px' });
            
            return false;
         
         });
         
        $('#submitVacancyNav .perm').click(function() {
            
            // Show correct content
            $('.permanent').show();
            $('.temporary').hide();
            
            // Correct tab colouring        
            $(this).css({ backgroundPosition: '0 0' });
            $('#submitVacancyNav .temp').css({ backgroundPosition: '-246px 0' });
            
            return false;
         
         });
        
        initForm();
        
    };
    
    
    var initForm = function() {
    
        // Submit registration password form
        var submitSubmitVacancy = function() {
        
            cmp.submitVacancyForm.validate({
                       
                success: function(d) {

                    cmp.submitVacancyForm.submit({
                   
                        url: '/handlers/general.aspx/submitVacancy',
                        data: {
                            uploadedSpec : $('#uploadedSpec').val().replace(/\\/g,'\\\\')
                        }, 
                        success: function(d) {

                           $('#submitVacancyForm').html('<p>Vacancy successfully submitted! <p> One of our consultants will contact you shortly to discuss this role. <p><a href="/submitvacancy.aspx">Submit Another</a></p>');
                            
                        },
                        failure: function(d) {
                        
                           cmp.submitVacancyForm.error(d.errors);
                        }
                   }); 
                   
                },
                failure: function(d) {
                
                    cmp.submitVacancyForm.error(d.errors);
                    
                }
            });
           

        
        };
        
        cmp.submitVacancyForm = new TVI.Form({
            
            ID: 'submitVacancyForm',
            errorsEl: '.errors',
            buttons: [{

                selector: '.submit',
                enter: true,
                handler: submitSubmitVacancy
                
            }],
            load: {
                meta: true,
                success: function() {
                    cmp.submitVacancyForm.el.find('#submitVacancyForm-salary select option').eq(0).html('Select salary range');
                }
            }

        });
      
    };
   
    /* Public */
    
    TVI.apply(cmp, {
    
        /* Properties */
    
        /* Methods */
    
    });
    
    
    TVI.ready(init);
    
    return cmp;

}();
