<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>  	
  	<script>

		function validateFormData(){
		
			var form = $("#suggestForm");
			
			if(form.find("input[name='title']").val().length <= 0 ){
				form.find("td[name='form_title_msg']").attr("class","popu_error_msgcolor");
				return false;
			}else{
				form.find("td[name='form_title_msg']").attr("class","popu_msgcolor");
			}

			if(form.find("textarea[name='content']").val().length <= 0 ){
				form.find("td[name='form_content_msg']").attr("class","popu_error_msgcolor");
				return false;
			}else{
				form.find("td[name='form_content_msg']").attr("class","popu_msgcolor");
			}
			
			if(form.find("input[name='phone']").val().length <= 0 ){
				form.find("td[name='form_phone_msg']").attr("class","popu_error_msgcolor");
				form.find("td[name='form_phone_msg']").text("*不能为空");
				return false;
			}else{
				form.find("td[name='form_phone_msg']").attr("class","popu_msgcolor");
			}
			
			if(!checktelephone(form.find("input[name='phone']").val())){
				form.find("td[name='form_phone_msg']").attr("class","popu_error_msgcolor");
				form.find("td[name='form_phone_msg']").text("*格式错误");
				return false;
			}else{
				form.find("td[name='form_phone_msg']").text("*不能为空");
				form.find("td[name='form_phone_msg']").attr("class","popu_msgcolor");
			}
			
			if(form.find("input[name='qq']").val().length <= 0 ){
				form.find("td[name='form_qq_msg']").attr("class","popu_error_msgcolor");
				form.find("td[name='form_qq_msg']").text("*不能为空");
				return false;
			}else{
				form.find("td[name='form_qq_msg']").attr("class","popu_msgcolor");
			}
			
			if(!isQQ(form.find("input[name='qq']").val())){
				form.find("td[name='form_qq_msg']").attr("class","popu_error_msgcolor");
				form.find("td[name='form_qq_msg']").text("*格式错误");
				return false;
			}else{
				form.find("td[name='form_qq_msg']").text("*不能为空");
				form.find("td[name='form_qq_msg']").attr("class","popu_msgcolor");
			}
			
			return true;
			
		}
		
		function submitSuggestSuccessFun(json){
			
			if(json.flag) {
				$("#closePopuWin").click();
				return;			
			}
			
			$("#suggestMsg").html("*"+json.msg);
			$("#saveSuggest").attr("disable","");
			$("#saveSuggest").val("提交");
			
		}
		
		function submitSuggest(){
	
			if(!validateFormData()){
				return;
			}
			
			$("#saveSuggest").attr("disable","disable");
			$("#saveSuggest").val("正在提交...");
			$("#suggestMsg").html("&nbsp");
			
			submitForm("suggestForm");

		}
	
		function submitForm(formId){
				
				var form =  $("#"+formId);
							
				$.ajax({
                    type: "POST",
                    dataType: "json",
                    url: form.attr("action"),
                    data: form.serialize(),
                    success: function (json) {
                        submitSuggestSuccessFun(json);
                    },
                    error: function(data) {
                     		$("#suggestMsg").html("*提交失败请稍后重试");
							$("#saveSuggest").attr("disable","");
							$("#saveSuggest").val("提交");
                     }

                });       
			
		}
		
		/*
		 *验证手机号码是否合法
		 */
		function checktelephone(value) {
		
		    var RegCellPhone = /^([0-9]{11})?$/;
		    
		    var RegCellPhone2 = /^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$/; 
		    
		    var falg=value.search(RegCellPhone2);
		    
		    if (falg==-1){
		      
				return false;
		    
		    }else{
		    
		    	return true;
		    	
		    }
		} 
		
		//验证QQ

	   function isQQ(qq)        
	   {        
	
	      if (qq.search(/^[1-9]\d{4,9}$/) !=-1){  
		      return true;   
	      }else{   
	      	  return false;
	      }
	
	   }
				  		
  	</script>
  </head>
  <body>
			<div class="top"></div>
			<div class="center">
		  		<h3 id="movePopuWin">
		        	<a href="javascript:;" title="关闭" class="message_close" id="closePopuWin"></a>
		        	<span>意见反馈</span>
		        </h3>
		        <div class="popuWinMessage_main">
		        	<ul><li style="text-align:center;"><span id="suggestMsg" style="color:red;">&nbsp;</span></li></ul>
		        	<form id="suggestForm" action="<%=path %>/pub/suggestAction_saveSuggest.action" method="POST">
			        	<table width="100%" border="0" style="line-height:35px;">
			        		<tr>
			        			<td><span style="height: 25px;">标题：</span></td>
			        			<td>	
			        				<input name="title" class="popu_input"></input>				        			        				
			        			</td>
			        			<td class="popu_msgcolor" name="form_title_msg">*不能为空</td>
			        		</tr>
			        		<tr>
			        			<td><span style="height: 25px;">内容：</span></td>
			        			<td>	
			        				<textarea name="content" class="popu_textarea" rows="5" cols="5"></textarea>				        			        				
			        			</td>
			        			<td class="popu_msgcolor" name="form_content_msg">*不能为空</td>
			        		</tr>		        	
			        		<tr>
			        			<td><span style="height: 25px;">手机号：</span></td>
			        			<td>	
			        				<input name="phone" class="popu_input"></input>				        			        				
			        			</td>
			        			<td class="popu_msgcolor"  name="form_phone_msg">*不能为空</td>
			        		</tr>
			        		<tr>
			        			<td><span style="height: 25px;">QQ号码：</span></td>
			        			<td>	
			        				<input name="qq" class="popu_input"></input>				        			        				
			        			</td>
			        			<td class="popu_msgcolor"  name="form_qq_msg">*不能为空</td>
			        		</tr>
			        	</table>        	
						<input id="saveSuggest" type="button" value="提交" onclick="submitSuggest();" class="yijian_fankui_button" />					
        			</form>
		        </div>
			</div>
			<div class="bot"></div>
  </body>
</html>
