$(document).ready(function () {
    setTimeout("init()", 100);
  });

function init()
{
    $("#issuetype_show").attr("sgonChange", "stdm_onchange");
    $("#discipline_show").attr("sgonChange", "disc_onchange");
    sgissuetype.reloadUrlAdd([{urlParam: 'disc_key', field: 'discipline' }]);

    // mld_ins_discipline zetten als deze leeg is maar mld_stdmelding wel gevuld.
    if (sgdiscipline.getValue() < 0)
        stdm_onchange();
}

function disc_onchange()
{
    // Melding leegmaken
    sgissuetype.setValue(-1, "", true, false, null, true);
    sgissuetype.CheckJustOne();
}

function stdm_onchange()
{
    var stdmelding_key = sgissuetype.getValue();
    if (stdmelding_key > 0)
    {
        $.getJSON("../mld/get_mld_info_ajax.asp",
                  { req_info: "mld_stdmelding",
                    mld_stdmelding_key: stdmelding_key,
                    caller_key: -1
                  },
                  process_stdm_info);
    }
}

function process_stdm_info(data, textStatus)
{
    // Zet de discipline indien niet ingevuld
    if ($("#discipline").val() <= 0)
    {
        var disc_naam = (data.ins_srtdiscipline_prefix != null ? data.ins_srtdiscipline_prefix + "-" : "")
                      + data.discipline_omschrijving;
        sgdiscipline.setValue( data.ins_discipline_key
                                         , disc_naam
                                         , false /*doonChange*/
                                         , true  /*checkExist*/
                                         );
    }
}

