<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="cn.sendsms.jdsmsserver.web.User"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="cn.sendsms.jdsmsserver.*"%>
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0); 
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%
User user=(User)session.getAttribute("user");
%>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/autoTextarea.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_send_message")%></title>
<!-- ================================================================================== -->
<!-- 引入库文件 -->
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />

<!-- ================================================================================== -->
<!-- 控制DateTimePicker的css样式 -->
<style type="text/css">
a {
	color: #007bc4 /*#424242*/;
	text-decoration: none;
}

a:hover {
	text-decoration: underline
}

ol, ul {
	list-style: none
}

body {
	height: 100%;
	font: 12px/18px Tahoma, Helvetica, Arial, Verdana, "\5b8b\4f53",
		sans-serif;
	color: #51555C;
}

img {
	border: none
}

.demo {
	width: 500px;
	margin: 20px auto
}

.demo h4 {
	height: 32px;
	line-height: 32px;
	font-size: 14px
}

.demo h4 span {
	font-weight: 500;
	font-size: 12px
}

.demo p {
	line-height: 28px;
}

input {
	width: 200px;
	height: 20px;
	line-height: 20px;
	padding: 2px;
	border: 1px solid #d3d3d3
}

pre {
	padding: 6px 0 0 0;
	color: #666;
	line-height: 20px;
	background: #f7f7f7
}

.ui-timepicker-div .ui-widget-header {
	margin-bottom: 8px;
}

.ui-timepicker-div dl {
	text-align: left;
}

.ui-timepicker-div dl dt {
	height: 25px;
	margin-bottom: -25px;
}

.ui-timepicker-div dl dd {
	margin: 0 10px 10px 65px;
}

.ui-timepicker-div td {
	font-size: 90%;
}

.ui-tpicker-grid-label {
	background: none;
	border: none;
	margin: 0;
	padding: 0;
}

.ui_tpicker_hour_label, .ui_tpicker_minute_label,
	.ui_tpicker_second_label, .ui_tpicker_millisec_label,
	.ui_tpicker_time_label {
	padding-left: 20px
}
</style>
<!-- ================================================================================== -->
<!-- 引入js库 -->
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/jquery-ui-slide.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>

<!-- ================================================================================== -->
<!-- 调用控件 -->
<script type="text/javascript">
	$(function() {
		$('#sendDate').datetimepicker({
					dateFormat: "yy/mm/dd",
					timeFormat: "hh:mm"
		});
		// var ufile = document.getElementById('upload');
	});	
</script>


<link href="css.css" type="text/css" rel="stylesheet">
<script type="text/javascript">
var uploadBtnText="<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.send_message_filename")%>";
function upLoadDone(){
    var filePath=document.getElementById("upload").value.toLowerCase();
	var arr=filePath.split('\\');
    var fileName=arr[arr.length-1];
	if(!fileName==""){
		document.getElementById("uploadBtn").innerHTML=""+fileName;		
	}
	else{
		document.getElementById("uploadBtn").innerHTML=""+uploadBtnText;
	}
}

function getExplorerVersions(){
	var userAgent = navigator.userAgent,   
	rMsie = /(msie\s|trident.*rv:)([\w.]+)/,   
	rFirefox = /(firefox)\/([\w.]+)/,   
	rOpera = /(opera).+version\/([\w.]+)/,   
	rChrome = /(chrome)\/([\w.]+)/,   
	rSafari = /version\/([\w.]+).*(safari)/;  
	var browser;  
	var version;  
	var ua = userAgent.toLowerCase();  
function uaMatch(ua){  
	var match = rMsie.exec(ua);  
	if(match != null){  
		return { browser : "IE", version : match[2] || "0" };  
	}  
	var match = rFirefox.exec(ua);  
	if (match != null) {  
		return { browser : match[1] || "", version : match[2] || "0" };  
	}  
	var match = rOpera.exec(ua);  
	if (match != null) {  
		return { browser : match[1] || "", version : match[2] || "0" };  
	}  
	var match = rChrome.exec(ua);  
	if (match != null) {  
		return { browser : match[1] || "", version : match[2] || "0" };  
	}  
	var match = rSafari.exec(ua);  
	if (match != null) {  
		return { browser : match[2] || "", version : match[1] || "0" };  
	}  
	if (match != null) {  
		return { browser : "", version : "0" };  
	}  
}  
	var browserMatch = uaMatch(userAgent.toLowerCase());  
	if (browserMatch.browser){  
		browser = browserMatch.browser;  
		version = browserMatch.version;  
	}  
	var re = browser+version;
	return re;
}  

$(document).ready(function(){
		var smsContext = document.getElementById("content");
        autoTextarea(smsContext);// 调用自动调整文本框大小的方法
		<%
			 if(user.getSurplusNumber()==0 && (!"admin".equals(user.getUserId())) && user.getSendlimit() == 1){
		%>
	    document.getElementById('sendMessage').disabled='true';
	    
		alert('<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_no_message_is_available_please_recharge_in_time")%>');
		<%
		 }else{
		%>
	    document.getElementById('sendMessage').disabled="";
	   <%
		}
		 String telephone=(String)request.getAttribute("telephone");
		 if(telephone==null)telephone="";
		if(!"".equals(telephone)){
	   %>
		document.getElementById('mobiles').value=<%=telephone%>;
		<%}%>
});
    //删除字符串左边的空格
 function ltrim(str) { 
	if(str.length==0)
		return(str);
	else {
		var idx=0;
		while(str.charAt(idx).search(/\s/)==0)
			idx++;
		return(str.substr(idx));
	}
}

//删除字符串右边的空格
   function rtrim(str) { 
	if(str.length==0)
		return(str);
	else {
		var idx=str.length-1;
		while(str.charAt(idx).search(/\s/)==0)
			idx--;
		return(str.substring(0,idx+1));
	}
}
//打开地址本
   function showaddr(){  
	   var iWidth=900; //窗口宽度
       var iHeight=800;//窗口高度
       var iTop=(window.screen.height-iHeight)/2;
       var iLeft=(window.screen.width-iWidth)/2;
       var show_result;
	   var eee = getExplorerVersions();
   	   if(eee == 'IE8.0'){
	       show_result=window.showModalDialog("addrmain.jsp?subtype=fill&curfoldertype=personal",window,"dialogHeight: "+iHeight+"px; dialogWidth: "+iWidth+"px; dialogTop:"+iTop+" ; dialogLeft: "+iLeft+"; resizable: yes;status: no;scroll:no;location:no");
       }
   	   else{
   	       show_result = window.open("addrmain.jsp?subtype=fill&curfoldertype=personal",window,"height="+iHeight+", width="+iWidth+", top="+iTop+", left="+iLeft+", resizable=no,status=no,scroll=no,location=no");
   	   }
       //var show_result = window.open("addrmain.jsp?subtype=fill&curfoldertype=personal",window,"height="+iHeight+", width="+iWidth+", top="+iTop+", left="+iLeft+", resizable=no,status=no,scroll=no,location=no");
       //window.showModalDialog("addrmain.jsp?subtype=fill&curfoldertype=personal",window,"dialogHeight: "+iHeight+"px; dialogWidth: "+iWidth+"px; dialogTop:"+iTop+" ; dialogLeft: "+iLeft+"; resizable: yes;status: no;scroll:no;location:no");
       window.onfocus=function (){show_result.focus();}
	   window.onclick=function (){show_result.focus();}
	 }
//删除字符串左右两边的空格
   function trim(str) { 
	 return(rtrim(ltrim(str)));
    }
	function insertPushURL(){
		var msgtable = document.getElementById("msgtable");
		var row = msgtable.insertRow(msgtable.rows.length-1);
		var th = document.createElement("th");
		var td = document.createElement("td");
		th.innerHTML="PUSH URL";
		td.innerHTML="<textarea rows=\"5\" cols=\"30\" name=\"pushUrl\" id=\"url\"style=\"border:1px solid #c1c1c1\">http://</textarea>";
		row.appendChild(th);
		row.appendChild(td);	
	}
	function deletePushURL(){
		var msgtable = document.getElementById("msgtable");
		msgtable.deleteRow(msgtable.rows.length-2);
	}
	function procClick(obj){
		
		if(obj.checked==true){
			obj.value="true";
			insertPushURL();
			
		}
		if(obj.checked==false){
			obj.value="false";
			deletePushURL();
			
		}
		
	}
	function countzishu(obj){
		var value=obj.value;		
		var length= value.length;
		if(length <=70)
			document.getElementById('label1').style.color="#00ff00";
		else document.getElementById('label1').style.color="#ff0000";
		if(length==0)
			document.getElementById('label1').innerHTML="";
		else
			document.getElementById('label1').innerHTML='<%=ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_the_number_of_input_characters")%>'+length;
	}
	function validateForm(){
	     var mobiles=document.getElementById('mobiles').value;
	     var sendFile=document.getElementById('upload').value;
	     var content=document.getElementById('content').value;
	     //手机号码字段是否输入
	     var mFlag=false;
	     //文件字段是否选择
	     var sFlag=false;
	     //内容字段是否有值
	     var cFlag=false;
	     if(trim(mobiles)!="") mFlag=true;
	     if(trim(sendFile)!="")sFlag=true;
	     if(trim(content)!="") cFlag=true;
	     if(!sFlag){
	        if(!(mFlag&&cFlag)){
	           if(!mFlag){
	              alert('<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_please_fill_in_the_cell_phone_number")%>');
	              return false;
	           }
	           if(!cFlag){
	        	   alert('<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_please_fill_in_the_sms_text")%>');
	              return false;
	           }
	        }
	     }
	     var re1 = /^\+?[a-zA-Z0-9]+$/;
	     var mobileArray=mobiles.split(/[\s;,.]/);
	     if(!sFlag){
	     for(var i=0;i<mobileArray.length;i++){
	        if(!re1.test(mobileArray[i])){
	           alert('<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_invalid_cell_phone_number_format_please_check")%>');
	           return false;
	        }
	     }
	     }
	     if(sFlag){
	          var type=sendFile.substring(sendFile.lastIndexOf(".")+1,sendFile.length);
	          if(!(type=="XLS" || type=="xls" || type=="xlsx" || type=="XLSX" || type=="txt" || type=="TXT")){
	              alert('<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_sorry_only_support_files_in_txt_xls_or_xlsx_format_currently")%>');
	              return false;
	          }
	     }
		 var reg=/^(\d{12}|\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2})$/;
		 var sendDate=document.getElementById('sendDate').value;
			if(trim(sendDate)!=""){
				if(!reg.test(sendDate)){
					alert('<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_please_enter_the_correct_date_format")%>');
					return false;
				}
			}
	     return true;
	}

</script>


<style type="text/css">
/*new */
#center table{
	font-size:14px;
	margin-top:20px;
}
#center table tr th{
	background: #fff;
	text-align: right;
	vertical-align: top;
	padding-right:0px;
	padding-top:3px;
	width:10%;
}
#center table tr th a:hover{
	text-decoration: none;
}
#center table .up_file{
	display: inline-block;
	width: 360px;
	height:28px;
	background: #fff;
	border:1px solid #9cc0c1;
	border-radius: 5px;
	color:#5db3b6;
	text-align: center;
	text-decoration: none;
	float:left;		
}
#center table .up_file:hover{
	cursor: pointer;		
}
#center table .up_file input[type='file']{
	width:360px;
	height:28px;
	opacity: 0;
	filter:alpha(opacity=0);
	position: relative;
	top:-26px;
	cursor: pointer;
}
input.botton2.sbut,input.botton2.rbut{
	background:#5db3b6;
	color:#fff;
	border-radius: 5px;
	width:100px;
	margin-left:-6.5%;
	outline: none;
	line-height: 28px;
	height:30px;
}
input.botton2.rbut{
	color:#5db3b6;
	background: #fff;
	border:1px solid #5db3b6;
	margin-left:25px;
	line-height: 28px;
}
textarea#content{
    display: block;
    margin:0 auto;
    overflow: hidden;
    width: 360px;
    font-size: 14px;
    height: 100px;
    line-height: 24px; 
	border:1px solid #c1c1c1;
	background-color: #fff;   
}
textarea#mobiles{
	width: 360px;
	height: 50px;
}
#sendDate{
	width: 355px;
}
</style>

</head>
<body>

<div id="top" style="background: #dfe9ed;font-size:24px;font-weight: 540;">
<span><img src="img/tu1.jpg"></span>
<%
    User user1=(User)session.getAttribute("user");
	if(!"admin".equals(user1.getUserId()) && user1.getSendlimit() == 1){
%><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_send_sms")%><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_the_available")%>&nbsp;<%=user.getSurplusNumber()%>&nbsp;&nbsp;&nbsp;<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_the_available_on_the_gateway_channel")%>&nbsp;<%=request.getAttribute("gatewaynum")%>
<%
	}else{
%>
<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_send_sms")%>
&nbsp;&nbsp;&nbsp;<span style="display: inline-block;float:right;margin-right:10px;font-size:16px;"><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_the_available_on_the_gateway_channel")%>&nbsp;<span style="font-size:24px;float:right;"><%=request.getAttribute("gatewaynum")%></span></span>
<%
	}
%>
</div>
<div id="center">
<!--
<form action="/smsAction" method="post">
-->
<form action="/sendMessage" method="post" enctype="multipart/form-data" onsubmit="return validateForm()">
<input type="hidden" id="action" name="action" value="sendMessage">
<table cellpadding="0" cellspacing="2" border="0" id="msgtable">
<tr>
	<th width="45%"><a href="JavaScript:showaddr();"  title="点击打开地址本"><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_sending_target")%></a></th>
	<td width="55%"><textarea rows="3" cols="50" name="mobiles" id="mobiles" style="border:1px solid #c1c1c1"></textarea>
	&nbsp;&nbsp;<a href="JavaScript:showaddr();"  title="点击打开地址本"><img src="w_img/sendMessage_addr.png" width="38" height="38" border="0"></a>
	</td>
</tr>
<tr>
	<th rowspan="2"><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_sending_text")%></th>
	<td>
	<textarea name="content" id="content" onkeypress="countzishu(this)" onpropertychange="countzishu(this)"  onchange="countzishu(this)" onkeydown="countzishu(this)" onkeyup="countzishu(this)"></textarea>
</tr>
<tr>	
	<td><label id="label1" title="字数统计"></label></td>
</tr>
<tr>
	<th width="45%"><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_sending_sms_file")%>
	<br><a href="/doc/JDSMS_SMS_template.zip">(<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_template_download")%>)</a>
	</th>
	<td width="55%">
	<a href="javascript:;" class="up_file" >
		<span id="uploadBtn" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;display:inline-block;width:100%;"><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.send_message_filename")%></span>
		<input type="file" name="upload" id="upload" onchange="upLoadDone()">
	</a>&nbsp;&nbsp;&nbsp;
	
	
	<!--
	<s:file name="upload"/>
	-->
	</td>
</tr>

<tr>
	<th class="fade"><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_sending_time")%></th>
	<td>
    <input type="text" name="sendDate" id="sendDate"  value="" size="20" ></td>
</tr>

<tr>
	<th class="fade"><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_sending_port")%></th>
    <td><select name="sendport" id="sendport" >
<option value="<%= request.getAttribute("flag")%>"><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_select_automatically")%></option>
<% 
	ArrayList<String> gateways = (ArrayList<String>)request.getAttribute("gateways");
	if(gateways!=null)
	for(int i =0;i<gateways.size();i++){
		String gateway = gateways.get(i);
%>
	<option value="<%=gateway%>"><%=gateway%></option>
<%} %>
<% 
	ArrayList<String> phones = (ArrayList<String>)request.getAttribute("phones");
	if(phones!=null)
	for(int i =0;i<phones.size();i++){
		String phone = phones.get(i);
%>
	<option value="<%=phone%>"><%=phone%></option>
<%} %>
<% 
	ArrayList<String> loras = (ArrayList<String>)request.getAttribute("loralist");
	if(loras!=null)
	for(int i=0;i<loras.size();i++){
%>
	<option value="<%=loras.get(i)%>"><%=loras.get(i)%></option>
<%} %>
<% 
	ArrayList<String> nbiots = (ArrayList<String>)request.getAttribute("nbiotlist");
	if(nbiots!=null)
	for(int i=0;i<nbiots.size();i++){
%>
	<option value="<%=nbiots.get(i)%>"><%=nbiots.get(i)%></option>
<%} %>
<% 
	ArrayList<String> bigdippers = (ArrayList<String>)request.getAttribute("bdlist");
	if(bigdippers!=null)
	for(int i=0;i<bigdippers.size();i++){
%>
	<option value="<%=bigdippers.get(i)%>"><%=bigdippers.get(i)%></option>
<%} %>
</select></td>
</tr>


<tr>
<th class="fade"><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_suffix_at_the_end_of_message")%></th>
<td>
<select name="sms_suffix" id="sms_suffix" >
<option value="0"><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_null")%></option>
<option value="1"><%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_yes")%></option>
</select>
</td>
</tr>

<!--
<tr>
	<th>发送选项</th>
	<td><input type="checkbox" id="isPush" name="isPush" value="true" onclick="procClick(this)">发送Wap Push短信</td>
</tr>
-->
<tr >
	<th>&nbsp;</th>
	<td><div> 
	<input type="submit" value="<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_send_sms")%>" class="botton2 sbut" id="sendMessage"> 
	<input type="reset" onclick="document.getElementById('label1').innerHTML='';" class="botton2 rbut" value="<%= ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_empty_sms")%>"></div>
</td></tr> 
<%
ArrayList<String> err = (ArrayList<String>)request.getAttribute("errlist");
if(err!=null&&err.size()>0){
%>
<tr><td colspan="2" style="color:#ff0000">

<%
	out.print(ResourceManager.getInstance().getBykey(ResourceManager.getInstance().m_sDefault).getString("settings.sending_the_following_numbers_are_filtered_for_they_don_not_conform_to_the_rules"));
	for(int i =1;i<=err.size();i++){
		 out.print(err.get(i-1));
		 if(i%4==0)
			 out.print("<BR>");
		 else
			 out.print("   ");
	}
%>

</td></tr>
<%} %>
</table>
</form>
</div>
<%
if(request.getAttribute("error")!=null&&request.getAttribute("error")!=""){	
%>

<script type="text/javascript">

try{
	if('<%=request.getAttribute("error")%>'){
	top.window.func.window.open_modal('<%=request.getAttribute("error")%>');
}
}catch(e){
	alert('<%=request.getAttribute("error")%>')
}
</script>

<%} %>
</body>
</html>