<html>
<head>
<title><?php echo $lang->welcome_to_imp; ?></title>

<?php

$help->print_help_js(); /* Setup a help instance */

?>
<script language="JavaScript">
<!--
if (parent.impmenu)     { parent.impmenu.location="menu.php3"; }
if (parent.impfolder)   { parent.impfolder.location="menu.php3?menu=<?php echo IMPMENU_BLANK; ?>"; }

function submit_login() {
   if (document.login.user.value == "" || document.login.pass.value == "" ) {
       alert( "Please provide your username and password." );
   } else {
       document.login.submit();
   }
}

//-->
</script>
<script language="JavaScript1.2">
<!--
var IE4 = document.all;
var NS4 = document.layers;
function enter_key_trap( e ) {
   var keyPressed;
   if ( NS4 )
       keyPressed = String.fromCharCode( e.which );
   else if ( IE4 )
       keyPressed = String.fromCharCode( window.event.keyCode );

   if ( keyPressed == "\r" || keyPressed == "\n" ) {
       submit_login();
       //return true;
       //alert( keyPressed );
   } else {
       // - Debug keypress code -
       // alert( keyPressed );
   }
}
//-->
</script>

</head>

<?php $default->body->generate_body(); ?>

<noscript>
<p><b><?php echo $lang->javascript_needed; ?></b></p>
</noscript>

<center>
<form action="<?php echo $default->root_url ?>/mailbox.php3" method="post" name="login">
<input type="hidden" notab name="actionID" value="<?php echo IMP_LOGIN ?>">
<input type="hidden" notab name="mailbox" value="INBOX">

<table border="0" width="300">
<tr>
  <td align="center" colspan="3">
  <p><font size="+1" face="<?php echo $default->font->face; ?>"><b>IMP</b></font></p>
  <p><font size="2" face="<?php echo $default->font->face; ?>">
  <?php echo $lang->$reason ?>
  </font></p>
  </td>
</tr>

<tr>
   <td align="right"><font size="2" face="<?php echo $default->font->face; ?>"><b><?php echo $lang->user_name ?></b></font></td>
   <td><input type="text" tabindex="1" name="user"></td>
   <td align="left"><?php $help->link(LOGIN_HELP_USERNAME, $help_file, 'imp') ?></td>
</tr>

<tr>
   <td align="right"><font size="2" face="<?php echo $default->font->face; ?>"><b><?php echo $lang->password ?></font></td>
   <td><input type="password" tabindex="2" name="pass"></td>
   <td align="left"><?php $help->link(LOGIN_HELP_PASSWORD, $help_file, 'imp') ?></td>
</tr>


<?php if ($default->user_change_server): ?>
<tr>
  <td align="right"><font size="2" face="<?php echo $default->font->face; ?>"><b><?php echo $lang->server ?></b></font></td>
  <td><input type="text" tabindex="3" name="server" value="<?php echo $default->server ?>"> <?php $lang->server_port; ?> <input type="text" size=4 name="port" tabindex="3" value="<?php echo $default->port ?>"></td>
  <td align="left"><?php $help->link(LOGIN_HELP_SERVER, $help_file, 'imp') ?></td>
</tr>
<?php elseif ($default->use_server_list): ?>
<tr>
  <td align="right"><font size="2" face="<?php echo $default->font->face; ?>"><b><?php echo $lang->server ?></b></font></td>
  <td><select name="server" onchange="setFields()">
      <?php
include ('./config/servers.php3');
$option = '';
while (list($key, $iserver) = each($IMAPServers)) {
   if (gettype($iserver->preferred) == 'array') {
      while (list($pkey, $pref) = each($iserver->preferred)) {
         if ($pref == $default->localhost) {
	    $option = ' selected';
	    $defaultport = $iserver->port;
	 }
      }
   } else {
      if ($iserver->preferred == $default->localhost) {
	 $option = ' selected';
	 $defaultport = $iserver->port;
	 $defaultfldr = $iserver->folders;
      }
   }
   echo "<option value=\"$iserver->server\"$option>$iserver->name\n";
   $option = '';
}

if (!isset($defaultport)) {
   reset($IMAPServers);
   list ($key, $iserver) = each($IMAPServers);
   $defaultport = $iserver->port;
   $defaultfldr = $iserver->folders;
}
      ?>
      </select>
      <input type="hidden" name="port" value="<?php echo $defaultport ?>">
  </td>
  <td align="left"><?php $help->link(LOGIN_HELP_SERVER, $help_file, 'imp') ?></td>
</tr>
<?php else: ?>
<input type="hidden" name="server" notab value="<?php echo $default->server ?>">
<input type="hidden" name="port" notab value="<?php echo $default->port ?>">
<?php endif; ?>

<?php if ($default->user_change_folder): ?>
<tr>
  <td align="right"><font size="2" face="<?php echo $default->font->face; ?>"><b><?php echo $lang->folders ?></b></font></td>
  <td><input type=text tabindex="3" name="folders" value="<?php echo $default->folders ?>"></td>
  <td align="left"><?php $help->link(LOGIN_HELP_FOLDERS, $help_file, 'imp') ?></td>
</tr>
<?php elseif ($default->use_server_list): ?>
<input type="hidden" notab name="folders" value="<?php echo $defaultfldr ?>">
<?php else: ?>
<input type="hidden" notab name="folders" value="<?php echo $default->folders ?>">
<?php endif; ?>

<tr>
  <td align="right"><font size="2" face="<?php echo $default->font->face; ?>"><b><?php echo $lang->language ?></b></font></td>
  <td><?php echo $langs ?>
  </td>
<td align="left"><?php $help->link(LOGIN_HELP_LANGUAGE, $help_file, 'imp') ?></td>
</tr>

<tr><td>&nbsp;</td><td align="center"><?php
echo( '<input type="button" name="button" tabindex="4" value="' . $lang->log_in . '" onClick="submit_login();return(false);">' );
?></td></tr>

</table>
</form>
</center>

<?php if ($default->use_server_list ): ?>
<script language="Javascript">
<!--

var Ports = new Array ();
var Folders = new Array ();

<?php
reset($IMAPServers);
$i = 0;
while (list($key, $iserver) = each($IMAPServers)) {
   echo "Ports[$i] = '$iserver->port';\n";
   echo "Folders[$i] = '$iserver->folders';\n";
   $i++;
}
?>

function setFields () {
   document.login.port.value = Ports[document.login.server.selectedIndex];
   document.login.folders.value = Folders[document.login.server.selectedIndex];
}

//-->
</script>
<?php endif; ?>

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

// grab the focus right from the start
// onLoad = focusform();
// function focusform() {
//     document.login.user.focus();
// }

// when one loses the focus, pass it on
// document.login.user.onblur=new Function("document.login.pass.focus()");

<?php if($default->user_change_server): ?>
// document.login.pass.onblur=new Function("document.login.server.focus()");
// document.login.server.onblur=new Function("document.login.port.focus()");
<?php endif; ?>
    
<?php if(($default->user_change_folder) && ($default->user_change_server)): ?>
// document.login.port.onblur=new Function("document.login.folders.focus()");
// document.login.folders.onblur=new Function("document.login.button.focus()");
<?php elseif($default->user_change_folder): ?>
// document.login.pass.onblur=new Function("document.login.folders.focus()");
// document.login.folders.onblur=new Function("document.login.button.focus()");
<?php endif; ?>

// document.login.button.onblur=new Function("document.login.user.focus()");

//-->
</script>
                    
</body>
</html>
