<%@ page import="java.util.*, com.example.model.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Find Free Times</title>
<script language='javascript' src='genvalidationv5.js'></script> 
<script type="text/javascript">
function setFlagFindFreeTimes()
{
var flag = document.getElementById("formflag");
flag.value=11;
}
function setFlagToMain()
{
var flag = document.getElementById("formflag");
flag.value=9;
}
function setFlagLogOut()
{
var flag = document.getElementById("formflag");
flag.value=4;
}
</script>
</head>
<body>
<h1 align="center">Find Free Times</h1>
<form method="POST" action="Schedule.do" name="find_free">
<br/><br/>
<input type="hidden" name="formflag" value="-1" id="formflag">
User Name:
<br/><select name="username" size="5" multiple="multiple">
<%
  int first = 1;
  List users = (List)request.getAttribute("users");
  Iterator it = users.iterator();
  while(it.hasNext()) {
        String user = (String)it.next();
        if(first == 1) 
                out.print("<option value='" + user + "' selected=selected>" + user + " </option>");
        else
                out.print("<option value='" + user + "'>" + user + "</option>");
        first = 0;
  }
  out.println("</select>");
  String user = (String)request.getAttribute("user");
  out.println("<input type=hidden name=user value=" + user + " id=user>");
%>
<br/><br/>
<input type="submit" name="get_schedule" value="Find Free Times for Selected Users" onclick="setFlagFindFreeTimes()">
<input type="submit" name="back" value="Back" onclick="setFlagToMain()">
<input type="submit" name="logout" value="Log Out" onclick="setFlagLogOut()">
<br/><br/><hr>
<p>Free Times for Users: <font color=red>
<%
  String user1 = (String)request.getAttribute("user");
  users = (List)request.getAttribute("selected");
  out.println("<input type=hidden name=user value='" + user1 + "'>");
  Iterator it2 = users.iterator();
  while(it2.hasNext()){
	String username = (String)it2.next();
  	out.println(username + ", ");
  }
  out.println("</font><br/>");
  List freeTimes = (List)request.getAttribute("freetimes");
  Iterator it3 = freeTimes.iterator();
  if(it3.hasNext()){
  	  out.print("Sunday: " + it3.next() + "<br />");
          out.print("Monday: " + it3.next() + "<br />");
          out.print("Tuesday: " + it3.next() + "<br />");
          out.print("Wednesday: " + it3.next() + "<br />");
          out.print("Thursday: " + it3.next() + "<br />");
          out.print("Friday: " + it3.next() + "<br />");
          out.print("Saturday: " + it3.next() + "<br />");
  }
%>
<script language='JavaScript'>
var loginValidator = new Validator("find_free");
loginValidator.addValidation("username","req","Please select at least one user.");
</script> 
<p>
    <br/>
        Created By Team F: Brian Hermann, Brian Johnson, Bill Meehan, Brian Sheehan, Graham Becker
  </p>

</form>
</body>
</html>
