<%@page language="java" import="java.util.*,java.sql.*" contentType="text/html"%>
<%
         String k="";
           try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           
            Connection con=DriverManager.getConnection("jdbc:odbc:letter");
           
            PreparedStatement pstmt = con.prepareStatement("select max(sno) from tappal_number");
                      
           ResultSet rs= pstmt.executeQuery();
           while(rs.next())
            {
               int  i=rs.getInt(1);
               int l=i+1;
               k=String.valueOf(l);
              } 
             }
        
		catch(ClassNotFoundException s)
        { 
	out.println("loaderror");
   	}
		catch(SQLException e)
        { 
	out.println("sqlerror "+e);
   }
                       
           %>

<HTML>
 <HEAD>
<link href="css/sty.css" rel="stylesheet" type="text/css"></link>        
  <script src="js/timer.js">  </script>
<script src="js/datepicker.js">  </script>
<script>

		  function validate1()
			  {
            	
         var a=incomingform.letterno.value;
         var b=incomingform.letterdate.value;
         var c=incomingform.receivedfrom.value;
         var d=incomingform.subject.value;
         var e=incomingform.markedto.value;
       	var username=incomingform.uname.value;
		var password=incomingform.pword.value;
		if(document.incomingform.action[0].checked)
        var f=document.incomingform.action[0].value;
		 if(document.incomingform.action[1].checked)
        var f=document.incomingform.action[1].value;
		 if(document.letter.lettertype[0].checked)
        var g=document.letter.lettertype[0].value;
       if(document.letter.lettertype[1].checked)
        var g=document.letter.lettertype[1].value;
     if(document.incomingform.lettername[0].checked)
        var h=document.incomingform.lettername[0].value;
     if(document.incomingform.lettername[1].checked)
        var h=document.incomingform.lettername[1].value;
   if(document.incomingform.lettername[2].checked)
        var h=document.incomingform.lettername[2].value;

		if(g=="" || g==null)
		window.alert("please select lettertype");
else if(h=="" || h==null)
		window.alert("please select lettername");
 	else if(a=="" || a==null)
	window.alert("please enter letternumber");
        else  if(b=="" || b==null)
	window.alert("please pick letterdate");
        else if(c=="" || c==null)
	window.alert("please enter received from");
         else if(d=="" || d==null)
	window.alert("please enter subject");
         else if(e=="" || e==null)
	window.alert("please enter marked to");
		 else if(f=="" || f==null)
		window.alert("please select action taken");
	else 	if(username!="letter")
		window.alert("please enter valid username");
		else if(password!="tracker")
		window.alert("please enter valid password");
      
     else
                   incomingform.submit();
				  
   
  }
   
   
   
   function show(z)
{

document.getElementById("f"+z).style.display="block"
}
function hide(z)
{
document.getElementById("f"+z).style.display="none"
}

 
 
 function validate2()
			  {
            	
         var a=outgoingform.letterno.value;
         var b=outgoingform.subject.value;
         var c=outgoingform.sendto.value;
 if(document.letter.lettertype[0].checked)
        var g=document.letter.lettertype[0].value;
       if(document.letter.lettertype[1].checked)
        var g=document.letter.lettertype[1].value;
     if(document.outgoingform.lettername[0].checked)
        var h=document.outgoingform.lettername[0].value;
     if(document.outgoingform.lettername[1].checked)
        var h=document.outgoingform.lettername[1].value;
   if(document.outgoingform.lettername[2].checked)
        var h=document.outgoingform.lettername[2].value;

		if(g=="" || g==null)
		window.alert("please select lettertype");
       else if(h=="" || h==null)
		window.alert("please select lettername");
        else	if(a=="" || a==null)
	window.alert("please enter letternumber");
        else  if(b=="" || b==null)
	window.alert("please enter subject");
        else if(c=="" || c==null)
window.alert("please enter sendto");
		else
				
                   outgoingform.submit();

				  
			  }

</script>
 </HEAD>




<BODY onload="ftime()">

<CENTER>
	 <% if(request.getAttribute("insert")!=null){%>
   <b><h1> <font color="green"><%=(String) request.getAttribute("insert")%></font></h1></b>
    <%}%>

        <% if(request.getAttribute("error")!=null){%>
   <b><h1> <font color="red"><%=(String) request.getAttribute("error")%></font></h1></b>
    <%}%>

 
 
<FORM METHOD=POST name="letter" id="letter">
<TABLE  cellspacing=2 cellpadding=2>

<TR>
	<TD>Letter Type:</TD>
	<TD><INPUT TYPE="radio" NAME="lettertype" value="incoming" onclick="show(1),hide(2)">Incoming</TD>
	<TD><INPUT TYPE="radio" NAME="lettertype" value="outgoing" onclick="show(2),hide(1)">Outgoing</TD>
</TR>
</table>
</FORM>

 <hr> 

<FORM METHOD=POST style="display:none" name="incomingform" id="f1" ACTION="LetterProcess">

<TABLE  cellspacing=5 cellpadding=5>
<TR>
	<TD>LetterName:</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="local">Local</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="headquarters">HeadQuarters</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="others">Others</TD>
</TR>
<tr>
<TD><INPUT TYPE="checkbox" NAME="demiofficial" value="yes">Demiofficial</TD>
</tr>
</table>

<TABLE cellspacing=5 cellpadding=5 >
<TR>
	<TD>SNO</TD>
	<TD><INPUT TYPE="text" value='<%=k%>' NAME="serial" id="serial" readonly></TD>
</TR>
<TR>
	<TD>LETTER NO</TD>
	<TD><INPUT TYPE="text" NAME="letterno"></TD>
</TR>
<TR>
	<TD>LETTER DATE</TD>
	<TD><input type="TEXT" name='letterdate' readonly>
        <img alt="pickdate"src="images/cal.gif" onclick="displayDatePicker('letterdate')"></td>
</TR>

<TR>
	<TD>RECEIVED FROM</TD>
	<TD><INPUT TYPE="text" NAME="receivedfrom">
		</TD>
</TR>

<TR>
	<TD>SUBJECT</TD>
	<TD><TEXTAREA NAME="subject" ROWS="3" COLS="25"></TEXTAREA></TD>
</TR>

<TR>
	<TD>MARKED TO</TD>
	<TD><INPUT TYPE="text" NAME="markedto"></TD>
</TR>
<tr>
<td style="display:none">
<input type="text" name="lettertype" VALUE="incoming" readonly>
<input type="text" name="entrydate" id="t2" readonly>
<input type="text" name="entrytime" id="t3" readonly>
</td>
</tr>
</table>
<hr>
 <table cellspacing=5 cellpadding=5>

<TR>
<TD>Username:</TD>
 <TD><INPUT TYPE="text" NAME="uname"></TD>
 </tr>
 <tr>
<TD>Password:</TD>
<TD><INPUT TYPE="password" NAME="pword"></TD>
 </TR>
<TR>
 <td><INPUT TYPE="radio" NAME="action" value="closed">CLOSED
<td> <INPUT TYPE="radio"NAME="action" value="pending">PENDING</td>			
</tr>
<tr>
<TD><INPUT TYPE="button" VALUE="submit" onclick="validate1()"></TD>
<TD align="center"><INPUT TYPE="RESET" VALUE="RESET"></TD>
</TR>
</TABLE>
  </FORM>
 
 
  <FORM METHOD=POST style="display:none" name="outgoingform" id="f2" ACTION="LetterProcess">

	<TABLE  cellspacing=5 cellpadding=5>
<TR>
	<TD>LetterName:</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="local">Local</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="headquarters">HeadQuarters</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="others">Others</TD>
</TR>
<tr>
<TD><INPUT TYPE="checkbox" NAME="demiofficial" value="yes">Demiofficial</TD>
</tr>
</table>

<TABLE cellspacing=5 cellpadding=5>
<TR>
	<TD>SNO</TD>
	<TD><INPUT TYPE="text" NAME="serial" value='<%=k%>'  readonly></TD>
</TR>
<TR>
	<TD>LETTER NO</TD>
	<TD><INPUT TYPE="text" NAME="letterno"></TD>
</TR>
<TR>
	<TD>DATE</TD>
	<TD><input type="text" name="entrydate" id="t2" readonly ></TD>
	
</TR>
<TR>
	<TD>TIME</TD>
	<TD><input type="text" name="entrytime" id="t3" readonly></TD>
</TR>

<TR>
	<TD>SUBJECT</TD>
	<TD><TEXTAREA NAME="subject" ROWS="3" COLS="25"></TEXTAREA></TD>
</TR>
<TR>
	<TD>SEND TO</TD>
	<TD><INPUT TYPE="text" NAME="sendto"></TD>
</TR>


<TR>
	<TD><INPUT TYPE="button" VALUE="submit" onclick="validate2()"></TD>
	<TD align="center"><INPUT TYPE="RESET"></TD>
</TR>
	<tr><td><input type="hidden" name="lettertype"  VALUE="outgoing" readonly></td></tr>
	

</TABLE>
  
</FORM>
</CENTER>
 </BODY>
</HTML>
