<%@ page language="java" errorPage="/common/error.jsp" %>

<%@ page import="org.apache.struts.Globals"  %>
<%@ page import="vkc.db.serializer.VKCSysParameterSerializer"%>
<%@ page import="vkc.db.serializer.VKCLanguageSerializer"%>
<%@ page import="vkc.db.entities.VKCLanguage"%>

<%@ taglib uri="struts-bean"  prefix="bean"  %>
<%@ taglib uri="struts-html"  prefix="html"  %>
<%@ taglib uri="struts-logic" prefix="logic" %>
<%@ taglib uri="vkc-taglib"   prefix="vkc"   %>

<% 
	String ctxPath = request.getContextPath();
	
	if (request.getLocale() == null) {
	    VKCLanguage lang = VKCLanguageSerializer.getDefaultLanguage();
		session.setAttribute(Globals.LOCALE_KEY, lang.getLocale());
	}
%>

<html:html locale="true">
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="cache"        content="no-cache">
    <meta http-equiv="expires"      content="0">

    <vkc:cssinclude />

    <script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'   />"></script>
    <title>VKC Login</title>

    <script type="text/javascript">	
	if (<%=VKCSysParameterSerializer.retrieveIntValue("LOGIN", "StandaloneModus", 1)%> != 0) {
	    if (top != self) {
	        top.location = self.location;
	    }
	}
	
    function checkBrowserCompatibility() {
        var browserName = navigator.appName;
        var browserVersion = navigator.appVersion;                    
        
        if (navigator.appName == "Netscape" || navigator.appName == "Microsoft Internet Explorer") { 
            if (navigator.appName == "Netscape" && navigator.appVersion.charAt(0) > 4) {
                // ok
                return;
            }

            if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.charAt(0) >= 4) {
                // ok
                return;
            }
            
            // browser mismatch
            alert('<vkc:message javascript="true" filter="false" key="login.browser_version_hint_popup1"/>' + '\n' + '<vkc:message javascript="true" filter="false" key="login.browser_version_hint_popup2"/>' + '\n\n' + '<vkc:message javascript="true" filter="false" key="login.browser_version_hint_popup3"/>');             
            return;           
        } else {
            // unkown browser type, let it go
            return
        }
    }

    function init() {
        document.forms[0].username.focus();
        checkBrowserCompatibility();
    }

    function changeLdapServer() {
        var form = document.forms[0];
        
        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.change.ldapserver=true";
        } else {
          form.action = form.action + "&action.change.ldapserver=true";
        }
        
        form.submit();
    }
    
    </script>

</head>
<body onload="init();" id="default" marginwidth="0" marginheight="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <html:form action="/login" method="post">
  <bean:define id="form" name="loginForm" scope="request" type="vkc.view.form.LoginForm"/>
  <logic:present parameter="linkType">
  <html:hidden property="linkType"/>
  </logic:present>
  <logic:present parameter="objectId">
  <html:hidden property="objectId"/>
  </logic:present>
  <logic:present parameter="loginType">
  <html:hidden property="loginType"/>
  </logic:present>

  <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="100" width="20" border="0"/></td></tr>

  <vkc:hline lineHeight="1" lineClass="hline" colspan="1" bottomSpace="0" topSpace="0" />

  <tr><td align="center" class="loginMiddle"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="20" border="0"/></td></tr>

  <noscript>
    <tr><td align="center" class="loginMiddle"><font color="red"><vkc:message key="login.browser_enable_js_hint"/></font></td></tr>
  </noscript>
  <logic:equal name="form" property="compatibleBrowser" value="false">
    <tr><td align="center" class="loginMiddle"><vkc:message key="login.browser_version_hint"/></td></tr>  
    <tr><td align="center" class="loginMiddle"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="20" border="0"/></td></tr>
  </logic:equal>
  
  <tr><td align="center" class="loginMiddle"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="20" border="0"/></td></tr>
  <tr>
    <td align="center" class="loginMiddle">
      <table cellspacing="0" cellpadding="0" border="0">
        <tr>
          <td align="center"><vkc:img page="/templates/${template.name}/gfx/vkc-logo-large.gif" alt="VKC" border="0"/></td>
          <td width="20"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="20" border="0"/></td>
          <td width="1" class="hline"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="1" border="0"/></td>
          <td width="25"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="25" border="0"/></td>

          <td align="center" valign="middle">
            <table align="left" cellspacing="1" cellpadding="0" border="0">
              <tr>
                <td align="center">
                  <table cellspacing="0" cellpadding="0" border="0">
                    <tr>
                      <td align="center">
                        <table cellspacing="0" cellpadding="0" border="0">
						  <logic:present name="<%=Globals.ERROR_KEY%>">
						  <tr><td align="left" colspan="2"><vkc:errors /></td></tr>
                          <tr><td height="1" colspan="2"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5" border="0"/></td></tr>
						  </logic:present>

                          <tr>
                            <td><b><vkc:message key="vkc.username"/>:&nbsp;&nbsp;</b></td>
                            <td><html:text property="username" style="width:300px;" size="35" maxlength="20" tabindex="1"/></td>                              
                          </tr>

                          <tr><td height="1" colspan="2"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5" border="0"/></td></tr>

                          <tr>
                            <td><b><vkc:message key="vkc.password"/>:&nbsp;&nbsp;</b></td>
                            <td><html:password property="password" style="width:300px;" size="35" tabindex="2"/></td>
                          </tr>

                          <vkc:ldapEnabled>
                          <logic:notEmpty name="form" property="ldapServers">
                          <tr><td height="1" colspan="2"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5" border="0"/></td></tr>                          

                          <tr>
                            <td><b><vkc:message key="vkc.ldap.useldap"/>:&nbsp;&nbsp;</b></td>
                            <td><html:checkbox name="form" property="useLdap" onclick="javascript:changeLdapServer()" /></td>
                          </tr>
                         
                          <logic:present parameter="useLdap">
                          <tr><td height="1" colspan="2"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5" border="0"/></td></tr>                          
                         
                          <tr>
                            <td><b><vkc:message key="vkc.ldap.server"/>:&nbsp;&nbsp;</b></td>
                            <td> 
                              <bean:define id="ldapServers" name="form" property="ldapServerList" type="java.util.List"/>
                              <html:select name="form" property="selectedLdapServerId" size="1" style="width:300px;" onchange="javascript:changeLdapServer();">
                                <vkc:options collection="ldapServers" property="ldapServerId" labelProperty="displayName"/>
                             </html:select>
                            </td> 
                          </tr>

                          <tr><td height="1" colspan="2"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5" border="0"/></td></tr>                          

                          <tr>
                            <td><b><vkc:message key="vkc.ldap.baseDN"/>:&nbsp;&nbsp;</b></td>
                            <td><vkc:write name="form" property="ldapServerBaseDN"/></td> 
                          </tr>
                          </logic:present>
                          </logic:notEmpty>
                          </vkc:ldapEnabled>

						  <tr><td height="1" colspan="2"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5" border="0"/></td></tr>
					
                          <tr>
                            <td align="center" colspan="2"><vkc:submit property="action.login" tabindex="3" ><vkc:message key="button.login"/></vkc:submit></td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr><td align="center" class="loginMiddle"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="20" border="0"/></td></tr>
  <logic:equal name="form" property="useLdap" value="false">
  <tr>
    <td align="center" class="loginMiddle">
      <table border="0">
        <tr>
          <td><b><vkc:message key="login.guest.hint"/></b></td>
          <logic:equal name="form" property="enableGuestLogin" value="true">
          <logic:equal name="form" property="enableUserRegistration" value="false">
          <td align="left" nowrap="nowrap"><vkc:message key="login.guest.info1"/>&nbsp;<vkc:link page="/guestLogin.do" name="form" property="guestLoginLinkParams" styleClass="none" tabindex="4"><vkc:message key="login.as.guest" /></vkc:link>&nbsp;</td>
          </logic:equal>
          <logic:notEqual name="form" property="enableUserRegistration" value="false">          
          <td align="left" nowrap="nowrap"><vkc:message key="login.guest.info1"/>&nbsp;<vkc:link page="/guestLogin.do" name="form" property="guestLoginLinkParams" styleClass="none" tabindex="4"><vkc:message key="login.as.guest" /></vkc:link>&nbsp;<vkc:message key="login.guest.info2"/>&nbsp;<vkc:link page="/registerNewUser.do" styleClass="none" tabindex="5"><vkc:message key="login.register" /></vkc:link>&nbsp;</td>
          </logic:notEqual>
          </logic:equal>

          <logic:equal name="form" property="enableGuestLogin" value="false">
          <logic:equal name="form" property="enableUserRegistration" value="false">
          <td align="left" nowrap="nowrap"><vkc:message key="login.forgot.password"/>&nbsp;<vkc:link page="/forgotPassword.do" styleClass="none" tabindex="6"><vkc:message key="login.forgot.password.dialog" /></vkc:link>&nbsp;</td>
          </logic:equal>
          <logic:notEqual name="form" property="enableUserRegistration" value="false">          
          <td align="left" nowrap="nowrap"><vkc:message key="login.guest.info1"/>&nbsp;<vkc:link page="/registerNewUser.do" styleClass="none"  tabindex="5"><vkc:message key="login.register" /></vkc:link>&nbsp;</td>
          </logic:notEqual>
          </logic:equal>
        </tr>
        
        <logic:equal name="form" property="enableGuestLogin" value="false">
        <logic:equal name="form" property="enableUserRegistration" value="true">
        <tr>
          <td>&nbsp;</td>
          <td align="left" nowrap="nowrap"><vkc:message key="login.forgot.password"/>&nbsp;<vkc:link page="/forgotPassword.do" styleClass="none" tabindex="6"><vkc:message key="login.forgot.password.dialog" /></vkc:link>&nbsp;</td>
        </tr>    
        </logic:equal>
        </logic:equal>
        
        <logic:equal name="form" property="enableGuestLogin" value="true">
        <logic:equal name="form" property="enableUserRegistration" value="false">
        <tr>
          <td>&nbsp;</td>
          <td align="left" nowrap="nowrap"><vkc:message key="login.forgot.password"/>&nbsp;<vkc:link page="/forgotPassword.do" styleClass="none" tabindex="6"><vkc:message key="login.forgot.password.dialog" /></vkc:link>&nbsp;</td>
        </tr>    
        </logic:equal>
        </logic:equal>
        
        <logic:equal name="form" property="enableGuestLogin" value="true">
        <logic:equal name="form" property="enableUserRegistration" value="true">
        <tr>
          <td>&nbsp;</td>
          <td align="left" nowrap="nowrap"><vkc:message key="login.forgot.password"/>&nbsp;<vkc:link page="/forgotPassword.do" styleClass="none" tabindex="6"><vkc:message key="login.forgot.password.dialog" /></vkc:link>&nbsp;</td>
        </tr>    
        </logic:equal>
        </logic:equal>
      </table>
    </td>
  </tr>
  </logic:equal>

  <tr><td align="center" class="loginMiddle"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="20" border="0"/></td></tr>
  <vkc:hline lineHeight="1" lineClass="hline" colspan="1" bottomSpace="0" topSpace="0" />
  </html:form>
</table>
</body>
</html:html>
