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

    File:           login.asp
    Description:    We weten echt niet wie de gebruiker is.
                    Toon maar een inlogscherm
    Parameters:
    Context:
    Note:

    Uiteindelijk: redirect terug naar de 'aanroepende' pagina die is meegegeven.
*/
ANONYMOUS_Allowed = 1;
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/login.inc" -->
<!--#include file="../shared/useragent.inc" -->
<%
if (Request.QueryString.Count > 0)
{   // relaxed omdat mensen nog wel eens een bookmark naar de inlogpagina inclusief
    // HMAC leggen en we daar niet al te moeilijk over willen doen.
    var is_ok = protectQS.verify( { relaxed: true } ); // Voorkom Un-validated Redirects and Forwards
    if (!is_ok)
    {   // De hmac is fout. Dan strippen we alles van de url af zodat het toch weer veilig is.
        Response.Redirect(rooturl + "/");
    }
}

var ret_page = getQParam("ret_page", rooturl + "/");
var querystring = getQParam("querystring", "");

FCLTHeader.Requires({plugins: ["jQuery"], js:["jQuery-ui.js"]});

checkUserAgent(); // heeft device capability bits gezet
if (device.test(device.isMobile))
    FCLTHeader.Requires({css:["../pda/default.css"]});
%>
<html id="loginhtml">
<head>
<%
    FCLTHeader.Generate()
%>
 <script type="text/javascript">
    function login_callback(json)
    {
        if (json.success && json.otp_prompt)
        {
            $("tr.trname,tr.trpass,tr.trremember").hide(); // Ingevulde usernaam/ wachtwoord laten we bewust staan
            $("tr.trotp").show();            // en submitten we een tweede keer maar dan met otpcode
            $("tr.trotp").find("label").html(json.otp_prompt);
        }
        else if (json.success)
        {
            window.location.href = "<%=safe.jsstring(ret_page + (querystring?"?" + querystring:""))%>";
        }
    }

    function do_submit()
    {
        $.post($("form[name=ifl_f]")[0].action, $("[name=ifl_f]").serialize(), FcltCallbackAndThen(login_callback), "json");
    }

    function passwrd2mobile()
    {
      if ($("#visname").val() == "") return false;

      $("#mobile").val(1);  // submit mee
      $.post('../Shared/sendPasswrd.asp?login='+escape($("#visname").val()));
      $("#vispswd").removeAttr("readonly");
      $("#mobbutton").attr("disabled", "disabled");
    }
    function passwrd2mail()
    {
        FcltMgr.openModalDetail("pass2mail.asp", L("lcl_password_to_email"));
    }
    function token2mail()
    {
        FcltMgr.openModalDetail("../pda/token2mail.asp", L("lcl_token2email"));
    }
    function selfregister()
    {
        FcltMgr.openModalDetail("../prs/self_register.asp", L("lcl_self_register"));
    }
 </script>
</head>

<body id="loginbody">

<div id="myportalteaser">
    <%=L("lcl_logon_teaser")%>
</div>
<div id="dmodal">
<form name="ifl_f" action="login_save.asp" method="post" onsubmit='do_submit();return false;'>
  <input type="hidden" id="mobile" name="mobile" value="0">
  <div id="logindiv">
  <table id="logintable">

    <tr class='trname'><td class="label"><label><%=L("lcl_vis_log_name")%></label>
        <div id="mobkey"><%
         if (S("mobile_password") == 1
             || (S("mobile_password_pda") == 1 && device.test(device.isMobile))) {
      	    %><img class="details" id="mobbutton" title="<%=L("lcl_password_to_mobile")%>" alt="SMS" src="../Pictures/key.png" onClick="passwrd2mobile();"><%
         }
      %></div></td>
    </tr>
    <tr class='trname'>
      <td><input class="required" type="text" maxlength="100" id="visname" name="vis_name"></td>
    </tr>

    <tr class='trpass'>
      <td class="label"><label><%=L("lcl_vis_log_psw")%></label></td>
    </tr>
    <tr class='trpass'>
      <td><input type="Password" <%=(S("mobile_password") == 1?" readonly ":"")%> maxlength="50" id="vispswd" name="vis_pswd"></td>
    </tr>

    <tr class='trotp' style='display:none'>
      <td class="label"><label><%=L("lcl_vis_log_psw")%></label></td>
    </tr>
    <tr class='trotp' style='display:none'>
       <td><input type="text" maxlength="6" id="otpcode" name="otpcode"></td>
    </tr>

<%  if (S("login_remember_days") > 0)
        RWCHECKBOXTR("remember", "fldremember", L("lcl_login_remember"), 0, {boxfirst: true, trclass: "trremember"});
    %><tr>
    <td><%
    buttons = [ { title: L("lcl_logon"), action: "do_submit()" } ];
    if (S("fac_emailtoken_auth_expire") > 0 && device.test(device.isMobile))
      buttons.push ({ title: L("lcl_token2email"), action: "token2mail()" });
    else if (S("email_password") > 0) {
      buttons.push ({ title: L("lcl_password_to_email"), action: "passwrd2mail()" });
    }
    if (S("self_register") == 1) {
      buttons.push ({ title: L("lcl_self_register"), action: "selfregister()" });
    }
    CreateButtons(buttons, { entersubmit: true, vertical: buttons.length>2});
    %></td>
    </tr>
  </table>
</div>
<% IFACE.FORM_END(); %>
</form>
</div>

<div id="loginfooter"><%=L("lcl_facilitor_footer")%></div>
</body>
</html>
