var gs_xml_doc, user = config.user
$(document).ready(function() {
    getNetworkPort();
    $('#portSave').click(function() {
        if ("admin" == user || "super_admin" == user) {
            $.RestartModel.mask(setNetworkPort, '4');
        } else {
            $.optionBootoast($.i18n.prop('i18n-propoe'), "danger")
        }
    });
})

function getNetworkPort() {
    $.ajax({
        url: config.baseUrl + "/Network/Port",
        type: "GET",
        async: true,
        timeout: 15000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        success: function(xmlDoc, textStatus, xhr) {
            gs_xml_doc = xmlDoc;
            $("#rtpport").val($(xmlDoc).find('Port').eq(0).find('RTP').eq(0).text());

        },
        error: function(xhr, textStatus, errorThrown) {}
    });
}

function setNetworkPort() {
    $(gs_xml_doc).find('Port').eq(0).find('RTP').eq(0).text($("#rtpport").val());
    var cyXml = gs_xml_doc;
    var cyURL = config.baseUrl + "/Network/Port";
    $.ajax({
        type: "PUT",
        url: cyURL,
        async: true,
        processData: false,
        data: cyXml,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("If-Modified-Since", "0");
        },
        complete: function(xhr) {
            SaveState(xhr);
        },
        error: function(xhr) {
            $.optionBootoast($.i18n.prop('i18n-savefail'), "danger")
        }
    });
}