$(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 selectCompanyFieldNameLanguage() {
    var url = 'fieldlanguage.ivp/load?required=true&table=CompanyField&field=NameXml&id=' + $('#id').val();
    openDialog(url, 'selectlanguage', { width: 900, height: 650 });
    return false;
}

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

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

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

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