$(function() {
//if closeaftersave defined - close form
if ($('#closeaftersave').val() == 'true') self.close();
    
//validate form first time to initialize validator
$('.validate').validate({ ignore: '.ignore' });
$('.validate input').keydown(function(e) { if (e.keyCode == 13) { formchanged = true; return false; } });
    
       
    $('#fieldtypeid').change(function() {
        if (this.value == 5) {
            $('#cvfield').show();
            $('#cvfield textarea').addClass('required');
        }
        else {
            $('#cvfield').hide();
            $('#cvfield textarea').removeClass('required');
        }
    });

    $('form').validate();
});


function afterSave() {    
    opener.loadFields(true);
}

function selectAll(radio, cb) {
    cb.removeAttr('checked');
    $('input.permission').each(function(i, e) { $(e).attr('checked', false); });
    radio.each(function(i, e) { $(e).attr('checked', true); });
    return false;
}

function selectUserFieldNameLanguage() {
    var url = 'fieldlanguage.ivp/load?required=true&table=UserField&field=NameXml&id=' + $('#id').val();
    openDialog(url, 'selectlanguage', { width: 900, height: 650 });
    return false;
}

function selectUserFieldUnitLanguage() {
    var url = 'fieldlanguage.ivp/load?table=UserField&field=UnitXml&id=' + $('#id').val();
    openDialog(url, 'selectlanguage', { width: 900, height: 650 });
    return false;
}

function selectUserFieldComboLanguage() {
    var url = 'fieldlanguage.ivp/load?textarea=true&required=true&checkarray=true&table=UserField&field=ComboboxValuesXml&id=' + $('#id').val();
    openDialog(url, 'selectlanguage', { width: 900, height: 650 });
    return false;
}

function selectUserFieldHintLanguage() {
    var url = 'fieldlanguage.ivp/load?table=UserField&field=HintXml&id=' + $('#id').val();
    openDialog(url, 'selectlanguage', { width: 900, height: 650 });
    return false;
}

function editField(id) {
    var url = id ? 'userfield.ivp/view/' + id : 'userfield.ivp/create/' + $('#id').val();
    openDialog(url, 'field', { width: 800, height: 490 });
    return false;
} 