<%@ page language="java"  pageEncoding="UTF-8"%>
<%@page import="com.myoa.common.util.EscapeUtil"%>
<%@page import="com.myoa.common.util.ValidateUtil"%>
<%@page import="com.stfoa.dao.hibernate.CompanyDAO"%>
<%@page import="com.myoa.common.util.SysConfUtil"%>
<%@page import="com.sysadmin.domain.System"%>
<%@page import="java.util.Locale"%>
<%@page import="com.myoa.common.util.ConfigUtil"%>
<%@include file="/common/include/taglibs.jsp"%>
<%
 String loginId = request.getParameter("loginId");
 SystemDAO sysdao = new SystemDAO();
 System sys =  sysdao.findById(1);
 
 String Cookie_Lang_OA = request.getParameter("langPara");
 String[] sysLang = sys.getLanguage().split(",");
 if(sysLang.length==1){
	 Cookie_Lang_OA = sysLang[0]; 
 }else{
	 if(ValidateUtil.isNull(Cookie_Lang_OA)){
		 Cookie[] cookies = request.getCookies();	 
		 if(cookies!=null)
		 {    
		    for (int i = 0; i < cookies.length; i++) 
		    {
		       Cookie c = cookies[i];     
		       if(c.getName().equalsIgnoreCase("Cookie_Lang_OA")){
		    	   Cookie_Lang_OA = c.getValue() ;
		       }  
		    } 
		 }		
	 } 
 }
 
 Locale locale = request.getLocale();
 if("zh_CN".equals(Cookie_Lang_OA)){
	locale = Locale.CHINA; 
 }else if("en".equals(Cookie_Lang_OA)){
	locale = Locale.ENGLISH;  
 }else if("zh_TW".equals(Cookie_Lang_OA)){
	locale = Locale.TAIWAN;
 }
%>
<fmt:setLocale value="<%=locale%>"/>
<fmt:setBundle basename="/conf/i18n"/>
<html>
<head>
<%if(ValidateUtil.isNull(sys.getSystemTitle())){ %>
<title><fmt:message key="login.Title"/></title>
<%}else{%>
<title><%=sys.getSystemTitle()%></title>
<%}%>
<%@include file="/common/include/meta.jsp"%>
<%@include file="/common/include/jquery.jsp"%>
<link href="${ctx}/common/css/login.css" rel="stylesheet" type="text/css">

<logic:present name="validuser" scope="request">
 <SCRIPT type="text/javascript">
   <%
     out.print("alert('"+(String)request.getAttribute("validuser")+"');");
   %>
  </SCRIPT>
</logic:present>  
<%
 Cookie[] cookies = request.getCookies();
 String LoginId_OA = "";
 if(cookies!=null){    
    for (int i = 0; i < cookies.length; i++) 
    {
       Cookie c = cookies[i];     
       if(c.getName().equalsIgnoreCase("LoginId_OA")){
          LoginId_OA = EscapeUtil.unescape(c.getValue()) ;
       }  
    } 
 }
 
%>
<script language="javascript" event="onkeydown" for="document">  
if(event.keyCode==13){  
  document.all('button_submit').click();  
} 
</script> 
<style type="text/css">
 .maindiv{
  width:60%;border:1px solid #000000;top:15%;left:20%;right:20%; position:absolute;padding:10px;
 }
 .maindiv800{
  width:80%;border:1px solid #000000;top:2%;left:10%;right:10%; position:absolute;padding:10px;
 }
</style>
<script type="text/javascript">
$(document).ready(function(){
 if(window.screen.width<1000){
  document.all.div_main.className='maindiv800';
 }
});
</script>
<script type="text/javascript">
function login(){
 $('#button_submit').attr("disabled", true); 
 if(!$.browser.msie){
	alert('<fmt:message key="login.PleaseUseIE"/>');
	return;
 }	 
 if(loginform.loginId.value==''){
  alert('<fmt:message key="login.PleaseInputUserName"/>');
  $('#button_submit').attr("disabled", false); 
  loginform.loginId.focus();
  return;
 }
 if(loginform.password.value==''){
  alert('<fmt:message key="login.PleaseInputPassword"/>');
  $('#button_submit').attr("disabled", false); 
  loginform.password.focus();
  return;
 }
 <%if(sys.getSecurityStatus()==1){ %>
  if(loginform.validata.value==''){
	$('#button_submit').attr("disabled", false); 
	alert('<fmt:message key="login.PleaseInputSecurityCode"/>');
	loginform.validata.focus();
	return;
  }
 <%}%>
 loginform.submit();
}
function changeImage(obj){
 obj.src="image.jsp?"+Math.random();
}
function changeLang(lang){
 location.href="${ctx}/login.jsp?langPara="+lang;
}
</script>

</head>

<body style="background-color:white;" onload="if(loginform.loginId.value==''){document.all.loginId.focus()}else{document.all.password.focus()};" onkeydown=return(!(event.keyCode==78&&event.ctrlKey)) oncontextmenu="return false">
<div align=center id=div_main class="maindiv">
<!--header-->
<table width="100%" height="15%" border="0" cellpadding="0" cellspacing="0">
 <tr>
  <td valign="middle"><%@ include file="login_header.jsp" %></td>
 </tr>
</table>
<!--分割线 -->
<hr color="brown" width="100%">
<!--login界面-->
<table width="100%" height="40%" border="0" cellpadding="0" cellspacing="0" class="login_table">
 <tr>
  <!--登录左侧图-->
  <td width="55%">
    <table width="300" height="232" border="0" align="center" cellpadding="0" cellspacing="4" style="background-repeat:no-repeat"
   <%
   String imageURL = new CompanyDAO().findById(9).getImageURL();
   if(ValidateUtil.isNull(imageURL)){ %>
   background="<%=SysConfUtil.getInstance().getDeployType()==1?(WebUtil.getRootPath(request)+"/help"):(sysdao.findById(7).getSystemUrl())%>/common/images/<%=new CompanyDAO().findById(9).getLogo()%>"
   <%}else{%> 
   background="${ctx}/common/images/customer/showImage.jsp?page=login"
   <%}%>
   >
    <tr>
      <td></td>
    </tr>
   </table>
  </td>
  <!--用户名密码输入 -->
  <td width="35%">
   <form name="loginform" action="${ctx}/login.do" method="post"> 
    <table width="250" align="center" cellpadding="0" cellspacing="0"  style="background-color:white;border:1px solid gray;margin-top:16px;">
     <tr>
       <td>
        <table width="250" height="32" border="0" align="center" cellpadding="0" cellspacing="0">
         <tr>
         <td  style="FILTER: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=ghostwhite,endColorStr=silver">
         <img src="${ctx}/common/images/loginkey.gif"></td>
         <td style="FILTER: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=ghostwhite,endColorStr=silver"><span style="color:#CF2029;font-weight:bold;font-size: 14px;">用户登录</span></td>
        </tr>
       </table>
       <table width="250" height="20" border="0" align="center" cellpadding="0">
         <tr>
         <td></td>
        </tr>
       </table>
       <table width="250" border="0" cellpadding="0" cellspacing="4">
       <%if(sysLang.length==1){ %>
    	   <input type="hidden" name="lang" value="<%=Cookie_Lang_OA%>"/>
       <%}else{%>
        <tr>
           <td width="34%" align="right" class="gray"><fmt:message key="login.Lang"/></td>
           <td width="66%" colspan='2'>
            <select name="lang" style="line-height:19px;FONT-SIZE: 13px; FONT-FAMILY: simsun, serif;height:21;width:180;" onchange="changeLang(this.value)">
            <%for(int i=0;i<sysLang.length;i++){ %>
             <option value="<%=sysLang[i]%>" <%=sysLang[i].equals(Cookie_Lang_OA)?"selected":""%>><%=ConfigUtil.getInstance().getLangName(sysLang[i])%></option>
             <%}%>
            </select>
            </td>
          </tr>
          <%} %>
         <tr>
           <td align="right" class="gray"><fmt:message key="login.UserName"/></td>
           <td colspan='2'>
            <div style="line-height:19px; text-align:left; word-break:break-all; word-wrap:break-word;">
              <input class="it1" type="text" name="loginId" value="<%=ValidateUtil.isNull(loginId)?LoginId_OA:loginId %>"
               style="FONT-SIZE: 15px; FONT-FAMILY: simsun, serif;height:21;font-weight:bold;width:180;" tabindex="1"
               onfocus="this.className='it2';" 
               onblur="this.className='it1';"
              />
             </div>
            </td>
          </tr>
          <tr>
            <td align="right" class="gray"><fmt:message key="login.Password"/></td>
            <td colspan='2'>
            <input class="it1" type="password" name="password" tabindex="2" 
             style="FONT-SIZE: 15px; FONT-FAMILY: simsun, serif;height:21;font-weight:bold;width:180;" 
             onfocus="this.className='it2';" 
             onblur="this.className='it1';"/>
            </td>
          </tr>
          <%if(sys.getAuthorizeType()==1){ %>
          <tr>
            <td align="right" class="gray"><fmt:message key="login.AuthorizeCode"/></td>
            <td colspan='2'>
            <input class="it1" type="password" name="authorizeKey" tabindex="3" 
             style="FONT-SIZE: 15px; FONT-FAMILY: simsun, serif;height:21;font-weight:bold;width:180;" 
             onfocus="this.className='it2';" 
             onblur="this.className='it1';"/>
            </td>
          </tr>
          <%}%>
           <%if(sys.getSecurityStatus()==1){ %>
          <tr>
            <td align="right" class="gray"><fmt:message key="login.SecurityCode"/></td>
            <td colspan='2'>
            <input class="it1" type="text" name="validata" tabindex="4" 
             style="FONT-SIZE: 15px; FONT-FAMILY: simsun, serif;height:21;font-weight:bold;width:45;" 
             onfocus="this.className='it2';" 
             onblur="this.className='it1';"/>
            <img id="random" border=0 src="image.jsp" width="44" height="18"><a class="blue" href="javascript:changeImage(document.getElementById('random'))">看不清，换一个</a>
            </td>
          </tr>
          <%}%>
          <tr>
            <td align="center"></td>
            <td>
            <img id="button_submit" style="CURSOR: hand" src="${ctx}/common/images/loginsubmit.gif" border="0" onclick="login();"></td>
          </tr>
        </table>
         <table width="250" height="20" border="0" align="center" cellpadding="0">
         <tr>
         <td></td>
        </tr>
        </table>
        </td>
      </tr>
     </table>
   </form>
  </td>
  <td width="10%">
  </td>
 </tr>
</table>
<!--分割线 -->
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="line_table">
  <tr>
    <td></td>
  </tr>
</table>
<!--footer-->
<table width="100%" valign="bottom" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="bottom"><%@ include file="login_footer.jsp"%></td>
  </tr>
</table>
</div>
</body>
</html>
