<script language="JavaScript" type="text/javascript">
<!--
function setFocus()
{
    if (document.horde_login.horde_user.value == "") {
        document.horde_login.horde_user.focus();
    } else {
        document.horde_login.horde_pass.focus();
    }
}
function checkLoginForm()
{
    if (document.horde_login.horde_user.value == "") {
        alert("<?php echo addslashes(_("Please provide your username and password")) ?>");
        document.horde_login.horde_user.focus();
        return false;
    } else if (document.horde_login.horde_pass.value == "") {
        alert("<?php echo addslashes(_("Please provide your username and password")) ?>");
        document.horde_login.horde_pass.focus();
        return false;
    } else {
        document.horde_login.loginButton.disabled = true;
        document.horde_login.submit();
        return true;
    }
}
//-->
</script>

<script language="JavaScript1.2" type="text/javascript">
<!--
function enter_key_trap(e)
{
    var keyPressed;

    if (document.layers) {
        keyPressed = String.fromCharCode(e.which);
    } else if (document.all) {
        keyPressed = String.fromCharCode(window.event.keyCode);
    } else if (document.getElementById) {
        keyPressed = String.fromCharCode(e.keyCode);
    }

    if ((keyPressed == "\r" || keyPressed == "\n") && (checkLoginForm())) {
        document.horde_login.submit();
    }
}

// Setup the enter keytrap code
if (window.document.captureEvents != null) {
    window.document.captureEvents(Event.KEYPRESS);
    window.document.onkeypress = enter_key_trap;
}
//-->
</script>

<form name="horde_login" method="post" action="<?php echo Horde::selfURL() ?>">
<input type="hidden" name="url" value="<?php echo Horde::getFormData('url') ?>" />
<table align="center">
<tr>
  <td align="center" colspan="2" class="header"><b>Welcome to the Kolab WebClient</b></td>
</tr>
<?php if (!empty($reason)): ?>
<tr>
  <td align="center" colspan="2" class="light"><p class="light"><?php echo $reason ?></p></td>
</tr>
<?php endif; ?>
<?php if ((count($guestapps) || $problem)): ?>
<tr>
  <td align="center" colspan="2" class="light">
    <?php if (count($guestapps)) echo sprintf(_("%s%s Guest Services</a>"), Horde::link(Horde::url($registry->getParam('webroot', 'horde') . '/guest.php'), _("Guest Services"), 'menuitem'), Horde::img('guest.gif', _("Guest Services"), null, $registry->getParam('graphics', 'horde'))) ?>
    <?php if ($problem) echo sprintf('%s%s%s</a>', Horde::link(Horde::url($registry->getParam('webroot', 'horde') . '/problem.php'), $registry->getParam('name', 'problem'), 'menuitem'), Horde::img($registry->getParam('icon', 'problem'), $registry->getParam('name', 'problem'), null, ''), $registry->getParam('name', 'problem')) ?>
  </td>
</tr>
<?php endif; ?>
<tr>
  <td align="right" class="light"><b><?php echo _("Username") ?></b>&nbsp;</td>
  <td><input class="fixed" type="text" name="horde_user" value="<?php echo Horde::getFormData('horde_user') ?>" /></td>
</tr>
<tr>
  <td align="right" class="light"><b><?php echo _("Password") ?></b>&nbsp;</td>
  <td><input class="fixed" type="password" name="horde_pass" value="" /></td>
</tr>

<?php if (!$prefs->isLocked('language')): ?>
<tr>
  <td align="right" class="light"><b><?php echo _("Language") ?></b></td>
  <td align="left" class="light"><?php echo $langs ?></td>
</tr>
<?php endif; ?>

<tr>
  <td></td>
  <td class="light"><input name="loginButton" class="button" value="<?php echo _("Log in") ?>" type="submit" onclick="return checkLoginForm();" /></td>
</tr>
<?php if ($conf['signup']['allow'] && $auth->hasCapability('add')): ?>
<tr>
  <td></td>
  <td class="light"><?php echo Horde::link(Horde::addParameter(Horde::url($registry->getParam('webroot', 'horde') . '/signup.php'), 'url', Horde::getFormData('url')), _("Sign up if not registered"), 'menuitem') . _("Sign up if not registered") ?></a></td>
</tr>
<?php endif; ?>
</table>
</form>

<?php if (@is_readable(HORDE_BASE . '/config/motd.php')) require HORDE_BASE . '/config/motd.php'; ?>

<?php if (!$prefs->isLocked('language')):
    $lang_url = Horde::applicationUrl('login.php');
    if (($url = Horde::getFormData('url'))) {
        $lang_url = Horde::addParameter($lang_url, 'url', $url);
    }
    $lang_url = Horde::addParameter($lang_url, 'new_lang', '');
?>
<script language="JavaScript" type="text/javascript">
<!--
function selectLang()
{
    // We need to reload the login page here, but only if the user
    // hasn't already entered a username and password.
    if (document.horde_login.horde_user.value == '' &&
        document.horde_login.horde_pass.value == '') {
        var lang_page = '<?php echo $lang_url ?>' + document.horde_login.new_lang[document.horde_login.new_lang.selectedIndex].value;
        self.location = lang_page;
    }
}
//-->
</script>
<?php endif; ?>
