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

    File:               PostcodeVertaalGLN.asp
    Description:        Voor de leverancier: vertaal de postcode(s) of postcode range VAN - T/M in een GLN van de leverancier (zodat de opdracht daar landt).
    Context:            Voor de leverancier met Mareon Premium. Registratie gebeurt in "eigen" tabel (key 12), in de records fac_usrdata.

*/
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->


<%
  FCLTHeader.Requires({plugins:["jQuery"]})



  // De leverancier die Postcode(gebieden) mag vertalen naar GLN, is beheerder, en heeft WEB_EXTREL
  // Daarop gaan we controleren...

  __Log("START authparams: ");
  var authparams = user.checkAutorisation("WEB_EXTREL");
  
%>


<html>
  <head>
    <%
    FCLTHeader.Generate();
    %>
    <title>Vertaaltabel Postcodes-GLN</title>
    <style type="text/css">
      html, body { height: 100%; margin: 0; padding: 0;}
    </style>


    <script>

      
      function doReset()
      {
         document.getElementById("postcode").value = "";
         document.getElementById("gln_lev").value = "";
         
      }
      
      function show_list_vertaling()
      {
        $('#list_vertaling_postcode').load('../fac/fac_report.asp?rapcode=fac_vertaling_postcodegln&mode=list');
      }
      
      function escapeXML(p_str)
      {
        p_result = p_str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
        return p_result;
      }
      
      function doSubmit(p_action)
      {
          
          var l_url = "<%=HTTP.urlzelf()%>";
          var l_apiname = "ACTION_REF_KEY";
          var post2url = l_url + "/?API=" + l_apiname;
          
          var l_postcode = document.getElementById("postcode").value;
          var l_gln_lev = document.getElementById("gln_lev").value;
          var l_refkey;
          var l_refkey_array = [];
         
          
          if (p_action == "FAC_USRDATA_POSTCODEGLN"){
             l_refkey_array.push(-1); // dummy, dont care, doet nog niets
          }
          
          for (var i = 0; i < l_refkey_array.length; i++)
          {
            l_refkey = l_refkey_array[i];
            var body = "<xml><action><action_code>" + p_action + "</action_code><ref_key>" + l_refkey + "</ref_key><extra_omschr>" + escapeXML(l_postcode) + '|' + escapeXML(l_gln_lev) + "</extra_omschr></action></xml>"
            
            $.post(post2url, body, fnCallback, "text");
          }
      }

      function fnCallback(l_xml_response)
      { 
        //console.log(l_xml_response);
        
        if (l_xml_response.indexOf("false") != -1)
        {
          var l_error_indicator_start = "<omschrijving>";
          var l_error_pos_1 = l_xml_response.indexOf(l_error_indicator_start);
          var l_error_indicator_end = "</omschrijving>";
          var l_error_pos_2 = l_xml_response.indexOf(l_error_indicator_end);
          var l_error_omschr = l_xml_response.substring(l_error_pos_1 + 14, l_error_pos_2);
          
          l_error_indicator_start = "mar_update_action_ref_key:";
          l_error_pos_1 = l_xml_response.indexOf(l_error_indicator_start);
          l_error_indicator_end = "[Action";
          l_error_pos_2 = l_xml_response.indexOf(l_error_indicator_end);
          l_error_omschr = l_xml_response.substring(l_error_pos_1 + 26, l_error_pos_2);
          FcltMgr.alert(l_error_omschr);
        }
        else
        {
          show_list_vertaling();
        }
      }

      function init(){
        show_list_vertaling();
      }

    </script>
  </head>

  <body onload="init()">
        <div id="list_vertaling_postcode" style="width:100%"></div>
        <form method="post">
            <table style="width:100%;border:5px double black">
              <tr>
                <td>
                  <span><%=L("lcl_alg_loc_postcode")%>: <input id="postcode" type="number" class="fld" style="width:200px" value=""></span>
                  <br/>
                </td>
                <td
                  <span><%=L("lcl_prs_companies_leverancier_nr")%>: <input id="gln_lev" type="text" class="fld wildcard" style="width:200px" value=""></span>
                  <br/>
                </td>
              </tr>
              <tr>
                <td align="right" colspan="2">
                  <input type="button" onclick="doSubmit('FAC_USRDATA_POSTCODEGLN')" value='<%=L("lcl_change")%>'>
                  <input type="button" onclick="doReset()" value='<%=L("lcl_reset")%>'>
                </td>
              </tr>
            </table>
        </form>        
    </body>
</html>

<% ASPPAGE_END(); %>
