$(function () {
    $('#myzone').click(function () {
        if ($('#myzone')[0].checked) {
            $('#myzone_connect').removeAttr('disabled');
        }
        else {
            $('#myzone_connect').attr('disabled', 'disabled');
        }
    });
    
    $('#zoneSearchForm').submit(function () {
        var forename = $('#forename').val();
        var surname = $('#surname').val();
        
        var valid = false;
        
        if ((typeof(forename) == 'undefined' || forename == '') && (typeof(surname) == 'undefined' || surname == '')) {
            valid = true;
        }
        
        if ((typeof(forename) == 'undefined' || forename == '') && (typeof(surname) != 'undefined' && surname != '')) {
            valid = true;
        }
        
        if (typeof(forename) != 'undefined' && forename != '') {
            if (typeof(surname) != 'undefined' && surname != '') {
                valid = true;
                $('#surname_label').removeClass('required');
                $('#formReport').hide();
            }
            else {
                $('#surname_label').addClass('required');
                $('#formReport').show();
            }
        }
        return valid;
    });
});

function submit_search(form) {
    var forename = $('#forename').val();
    var surname = $('#surname').val();
    
    var valid = false;
    
    if (typeof(forename) != 'undefined' && forename != '') {
        if (typeof(surname) != 'undefined' && surname != '') {
            valid = true;
            $('#surname_label').removeClass('required');
            $('#formReport').hide();
        }
        else {
            $('#surname_label').addClass('required');
            $('#formReport').show();
        }
    }
    // else {
    //     valid = true;
    // }
    // 
    // if (valid) {
    //     form.submit();
    // }
    return valid;
}

function countryOnchange(value) {
    var country = value;
    if(country == ''){
        country = 'SK';
    }
    if (country != 'SK') {
        $.getJSON(Router('joblife/portal/load-cities-json'), {
            country_id: country
        }, function (json) {
            var citySelect = $('#city_id')[0];
            while (citySelect.childNodes.length > 0) {
                citySelect.removeChild(citySelect.childNodes[0])
            }
            citySelect.options[0] = new Option('---', '');
            for (var i=0; i<json.length; i++) {
                citySelect.options[i + 1] = new Option(json[i].city, json[i].city_id);
            }
        });
    } else {
        $('#city_id').html($('#sk_city').html());
    }
}

