<%@language = "javascript" %>
<% /*
     $Revision$
     $Id$

     SUBMIT-form
*/ %>
<%
var JSON_Result = true;
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../API2/api2.inc" -->
<!-- #include file="../API2/model_regions.inc" -->
<!-- #include file="../Shared/json2.js" -->
<%
protectRequest.validateToken();
var regio_key = getQParamInt( "regio_key" );
var action = getQParam( "action", "" );

var formfields = [ {name: "name", frm: "reg_oms" }];
var params = { filter: { "id": regio_key }};
var jsondata = api2.form2JSONdata(model_regions, params, formfields);

switch (action)
{
    case "I":
        var regio_array = model_regions.REST_POST(params, jsondata);
        regio_key = regio_array.key;
        break;
    case "U":
        if (regio_key > 0)
            var regio_array = model_regions.REST_PUT(params, jsondata, params.filter.id);
        break;
    case "D":
        if (regio_key > 0)
            var regio_array = model_regions.REST_DELETE(params, params.filter.id);
        break;
    default :
        var regio_array = {warning: L("lcl_cnt_Del_Fails_Auth")};
}
var warning = regio_array.warning;


var result = { regio_key: regio_key,
               warning: warning,
               keepForm: !!warning,
               success: true };
Response.Write(JSON.stringify(result));
%>