﻿function RegistrationInit(element) {

    var location = element.find('#registrationLocation').mcDropdown('#locationmenu', { allowParentSelect: true });

    var realLocation = element.find('.real-location');
    if (realLocation.length == 1 && realLocation.val() != '') {
        var val = realLocation.val().split(',')[0];
        element.find('#registrationLocation').mcDropdown().setValue(val);
    }

    var btnClear = element.find('.btn-clear');
    if (btnClear.length == 1) {
        btnClear.click(function() {
            ResetFields(element);
            return false;
        });
    }

    var btnSubmit = element.find('.btn-submit');
    if (btnSubmit.length == 1) {
        btnSubmit.click(function() {
            element.find('.real-location').val(element.find('#registrationLocation').mcDropdown().getValue());
        });
    }
}

function ResetFields(element) {
    element.find('.inp-first-name').val('');
    element.find('.inp-surname').val('');
    element.find('.inp-work-number').val('');
    element.find('.inp-home-number').val('');
    element.find('.inp-mobile-number').val('');
    element.find('.inp-address').val('');
    element.find('.inp-postcode').val('');
    element.find('.select-profession').val('20000001');
    element.find('.inp-job-title').val('');
    element.find('#registrationLocation').mcDropdown().setValue('');
    element.find('.real-location').val('');
    jQuery(element.find('.check-job-type input[type=radio]')[0]).attr('checked', true);
    element.find('.inp-location-within').val('');
    element.find('.inp-town-postcode').val('');
    element.find('.select-salary-per-annum').val('');
    element.find('.select-salary-per-day').val('');
    element.find('.select-company-type').val('');
    element.find('.select-industry').val('');
    element.find('.inp-upload').each(function() {
        var el = jQuery(this);
        el.wrap('<div class="file_input_container_' + el.attr('id') + '"></div>');
        element.find('.file_input_container_' + el.attr('id'))
            .html(element.find('.file_input_container_' + el.attr('id'))
            .html());
    });
    jQuery(element.find('.attach-cv .permit input[type=radio]')[0]).attr('checked', true);
    jQuery(element.find('.submit-box .email-me input[type=radio]')[0]).attr('checked', true);
    jQuery(element.find('.submit-box .contact-me input[type=radio]')[0]).attr('checked', true);
    element.find('.checkbox-agreed-to-terms input[type=checkbox]').attr('checked', false);
}

function NewWnd(url, w, h, mb) {
    if (w == null) w = 600;
    if (h == null) h = 400;
    if (mb == null) mb = 0;
    var w = window.open(url, '_blank', 'menubar=' + mb
		+ ',resizable=1,scrollbars=1,top=50,left=50,width=' + w + ',height=' + h, true);
    w.focus();
}

jQuery(document).ready(function() {
    jQuery.noConflict();
    var registrationContainer = jQuery('.registration');
    if (registrationContainer.length == 1) {
        RegistrationInit(registrationContainer);
    }
});
