<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@ page language="java" session = "false" %>



<%@ page import="gov.va.med.authentication.kernel.ConfigurationVO,

  gov.va.med.authentication.kernel.LoginController,

  weblogic.servlet.security.ServletAuthentication;"%>

  

<%

// Turn off cache so that a user cannot navigate back to the login page after post-login

response.setHeader("Cache-Control","no-store, no-cache, must-revalidate"); //HTTP 1.1

response.setHeader("Pragma","no-cache"); //HTTP 1.0

response.setDateHeader ("Expires", 0); //prevents caching at the proxy server

%>





<HTML>

<HEAD>

<!--

 * 

 * @author Infrastructure & Security Service

 * @version 1.0.1.002

 * -->

<STYLE type="text/css">

.scrollPane { height:18em; overflow: auto; }

</STYLE>

<TITLE>Login Page</TITLE>

<script type="text/javascript" src="<%= request.getContextPath()%>/login/javascript/login.js"></script>





</HEAD>

<BODY onload="javascript:checkHF(document.LoginForm,document.LoginForm.institution,document.LoginForm.sortInstBy,document.LoginForm.disableInstitutionObjHF,document.LoginForm.disableSortByObjHF,document.LoginForm.sortByObjHF);document.LoginForm.access.focus();">

  <a href="#skip" title="Skip to login fields"></a>



<% 

/*

It could be argued that using code within JSP is not a good thing, but for such a small app it's 

completely acceptable.  If we were working with an HTML designer, the separation would be good. But then

JSTL would be needed and with that we'd introduce some version of that as a dependency, which is preferably

avoided given because we're embedded, we force these dependencies on the containing application as well.

*/

ConfigurationVO kaajeeEnv = ConfigurationVO.getInstance();



/*

Here if the protocol is 'http', I redirected the user to the same page using 'https' protocol. 

*/

        if(request.getParameter("relogin")!=null){

        HttpSession hSess = request.getSession(false);

		if(hSess == null) {

			StringBuffer sbsession = new StringBuffer(request.getContextPath());

			sbsession.append("/login/SessionTimeout.jsp");

			response.sendRedirect(sbsession.toString());

			return;

		  } 

		 }

		 

HttpSession hSess = request.getSession(true);

		

String desiredSchema = "https"; //or http

String usingSchema = request.getScheme();

if(kaajeeEnv.getHTTPSPortLis() != null ) {

if(!desiredSchema.equals(usingSchema)) {

   

	StringBuffer sburl = request.getRequestURL();

	java.net.URL url = new java.net.URL(sburl.toString());

	hSess = request.getSession(true);

	Integer portValue = new Integer(url.getPort());

	hSess.setAttribute("portnumber",portValue);



	String urlString = desiredSchema+"://"+ url.getHost() +":"+kaajeeEnv.getHTTPSPortLis()+url.getPath();

    response.sendRedirect(response.encodeRedirectURL(urlString));

    return;

   }

}



%>



<FORM name="LoginForm" method="post" action="<%= request.getContextPath() %>/LoginController" onSubmit="javascript:enableInstitutionObj(document.LoginForm,document.LoginForm.institution,document.LoginForm.sortInstBy,document.LoginForm.disableInstitutionObjHF,document.LoginForm.disableSortByObjHF)">

<table align="center" summary="This table is for formatting purposes only">

  <tr>

    <td>

	<table width="75%" border="0" align="center" cellpadding="4" cellspacing="4" bgcolor="#eeeeee">

	    <caption align="left"><strong>System Announcements:</strong></caption>

        <tr><td><div class="scrollPane"><%= kaajeeEnv.getIntroductoryText() %></div></td></tr></table>



      <table border="0" align="center" cellpadding="3" cellspacing="3" summary="This table is for formatting purposes only">

        <tr align="center"> 

          <td colspan="2" nowrap><h3>Login: <%= kaajeeEnv.getHostApplicationName() %></h3></td>

        </tr>

        <tr> 

          <td><img src="<%= request.getContextPath() %>/login/images/HealtheVetVistaSmallBlue.jpg" alt="Health e Vet Vista logo" width="120" height="60"></td>

          <td><table border="0" align="center" cellpadding="3" cellspacing="3" summary="This table is for formatting purposes only">

              <tr> 

                <th align="right" nowrap><a name="skip"></a>Access Code:</th>

                <td><input type="password" name="access" value="" size=16 maxlength=20></td>

                <td>&nbsp;</td>

              </tr>

              <tr> 

                <th align="right" nowrap>Verify Code:</th>

                <td><input type="password" name="verify" value="" size=16 maxlength=20></td>

              </tr>

              </table></td></tr>

              <tr>

              <%

              //1. Initialize values

              String kaajeeDefaultInstitutionValue = "";

              String kaajeeDisableInstitutionComponentsValue = "";

              String kaajeeSortStationByValue = "";

              String kaajeeDisableSortStationByValue = "";

              boolean kaajeeDefaultInstitutionParamFound = false;

              boolean kaajeeDisableInstitutionParamFound = false;

              boolean kaajeeSortStationByParamFound = false;

              boolean kaajeeDisableSortStationByParamFound = false;

              //2. Get targetURL and parse out parameters

              String targetURL = ServletAuthentication.getTargetURLForFormAuthentication(request.getSession());

              if (targetURL == null) {

                  StringBuffer sbNavErrorPg = new StringBuffer(request.getContextPath());

                  sbNavErrorPg.append("/login/navigationerror.jsp");

                  response.sendRedirect(sbNavErrorPg.toString());

                  return;

              } 

              int paramPos = targetURL.indexOf('?');

              String paramList = (paramPos > -1) ? targetURL.substring(paramPos + 1, targetURL.length()) : "";

              String[] paramArray = paramList.split("\u0026"); //split on '&' char

              for (int i=0; i < paramArray.length; i++) {

                  String[] tempArray=paramArray[i].split("\u003D"); //split on '=' char

                  if (tempArray[0].indexOf("kaajeeDefaultInstitution") != -1) {

                  kaajeeDefaultInstitutionValue = tempArray[1];

                  kaajeeDefaultInstitutionParamFound = true;

                  } else {

                  	if (tempArray[0].indexOf("kaajeeDisableInstitutionComponents") != -1) {

                  	kaajeeDisableInstitutionComponentsValue = tempArray[1];

                  	kaajeeDisableInstitutionParamFound = true;

                  	} else {

                  		if (tempArray[0].indexOf("kaajeeSortStationBy") != -1) {

                  		kaajeeSortStationByValue = tempArray[1];

                  		kaajeeSortStationByParamFound = true;

                  		} else {

                  			if (tempArray[0].indexOf("kaajeeDisableSortStationBy") != -1) {

                  			kaajeeDisableSortStationByValue = tempArray[1];

                  			kaajeeDisableSortStationByParamFound = true;

                  			}

                  		}

                  	}

                  }

                  if ((kaajeeDefaultInstitutionParamFound) && (kaajeeDisableInstitutionParamFound) && (kaajeeSortStationByParamFound) && (kaajeeDisableSortStationByParamFound)) break;

              }

              //

                  //3. Get default login institution and sorting preference if any from cookies

                  boolean sortCookieFound = false;

                  boolean instCookieFound = false;

                  String defaultSortInstBy="";

                  String defaultInst="";

                  String cookieDefaultSortInstitutionByString = LoginController.COOKIE_DEFAULT_SORT_INSTITUTION_BY_STRING;

                  String cookieDefaultDivisionString = LoginController.COOKIE_DEFAULT_DIVISION_STRING;

                  Cookie[] cookies = request.getCookies();

                  if (cookies != null) {

                    for (int i=0;i<cookies.length;i++) {

                      if (cookies[i].getName().equals(cookieDefaultSortInstitutionByString)) {

                        defaultSortInstBy=cookies[i].getValue();

                        // store in session for LoginController, post-submit

                        hSess.setAttribute(LoginController.SESSION_KEY_COOKIE_DEFAULT_SORT_INSTITUTION_BY, defaultSortInstBy);

                        sortCookieFound = true;

                      } else {

                      		if (cookies[i].getName().equals(cookieDefaultDivisionString)) {

                        	defaultInst=cookies[i].getValue(); 

                        	// store in session for LoginController, post-submit

                        	hSess.setAttribute(LoginController.SESSION_KEY_COOKIE_DEFAULT_DIVISION, defaultInst);

                        	instCookieFound = true;

                        	}

                      }

                      if ((sortCookieFound) && (instCookieFound)) break;

                    }

                  }

                  String radioButton1CheckValue = ((kaajeeSortStationByValue.trim().length() > 0) ?

                  	(kaajeeSortStationByValue.equals("number") ? "checked" : "") :

                  	((defaultSortInstBy.equals("")) ||

                  	(defaultSortInstBy.equals("number")) ? "checked" : ""));

                  String radioButton2CheckValue = ((kaajeeSortStationByValue.trim().length() > 0) ?

                  	(kaajeeSortStationByValue.equals("name") ? "checked" : "") :

                  	((defaultSortInstBy.equals("name")) ? "checked" : ""));

              %>

                <td>

                  <input type=radio <%= radioButton1CheckValue %> name=sortInstBy value="number" onclick="reSortSelectOptions(this.form,this.form.institution,'value')">Sort by Station Number *</td>

                <td> <input type=radio <%= radioButton2CheckValue %> name=sortInstBy value="name" onclick="reSortSelectOptions(this.form,this.form.institution,'text')">Sort by Station Name *

                </td>

              </tr>

              <tr> <td > <input type=hidden name="disableInstitutionObjHF" value=<%= kaajeeDisableInstitutionComponentsValue %> ></td></tr>

              <tr> <td > <input type=hidden name="disableSortByObjHF" value=<%= kaajeeDisableSortStationByValue %> ></td></tr>

              <tr> <td > <input type=hidden name="sortByObjHF" value=<%= kaajeeSortStationByValue %> ></td></tr>

              <tr align="center"> 

                <th colspan="2" nowrap>Institution: 

                  <select name="institution" size="1">

                    <%

                  //4. Initialize and Create Option List

                  String imOptionList = "";

                  if (defaultSortInstBy.equals("name")) {

                    imOptionList = kaajeeEnv.getJspDropDownListLoginOptionsByName();

                  }	else {

                    imOptionList = kaajeeEnv.getJspDropDownListLoginOptions();

                  }

                  // TODO: if string is "", show error message?



                  //5. Set the selected institution in the list based on the cookie value

                  if ((defaultInst != null) || ((kaajeeDefaultInstitutionValue != null) && (kaajeeDefaultInstitutionValue.trim().length() > 0))) {

					// int indexDefaultInst = imOptionList.indexOf("value="+defaultInst+">");

					StringBuffer sbInst = new StringBuffer();

					sbInst.append(((kaajeeDefaultInstitutionValue != null) && (kaajeeDefaultInstitutionValue.trim().length() > 0)) ? kaajeeDefaultInstitutionValue : defaultInst);

					int indexDefaultInst = imOptionList.indexOf("value="+ sbInst.toString() +">");

					if (indexDefaultInst > -1) {

						StringBuffer sb = new StringBuffer();

						sb.append(imOptionList.substring(0, indexDefaultInst -1));

						sb.append(" selected ");

						sb.append(imOptionList.substring(indexDefaultInst, imOptionList.length()-1));

						imOptionList = sb.toString();

					}

                  }

                  %>

                    <%= imOptionList %> 

                  </select>

                  * </th>

                <td>&nbsp;</td>

              </tr>

              <tr> 

                <td align="right" nowrap>&nbsp;</td>

                <!-- <td><input type="checkbox" name="changeverify" value="yes" /><strong>Change Verify Code (Not yet implemented)</strong></td> -->

              </tr>

              <tr> 

                <!-- Relocate Login button here!!! -->

                <td align="right" nowrap>&nbsp;</td>

                <td><input name="submit" type="submit" value="Login"></td>

              </tr>

                <tr align="center">

                <td colspan="2" nowrap>&nbsp;</td>

                <td>&nbsp;</td>

              </tr>

              <tr align="center"> 

                <td colspan="2" nowrap>* Persistent Cookie Used (<a href="<%= request.getContextPath() %>/login/loginCookieInfo.htm" 

          onClick='window.open("<%= request.getContextPath() %>/login/loginCookieInfo.htm","new_win","status=no,scrollbars=yes,toolbar=no,location=no,width=400,height=450,resizable"); return false;'>more 

                  information</a>).</td>

                <td>&nbsp;</td>

              </tr>

            </table></td>

        </tr>    

        <tr> 

          <td colspan="2"><div align="center"></div></td>

        </tr>

      </table>

    </FORM>

</BODY>

</HTML>