var FrontMessage_showForm={
	 /**
	 * 当提交留言列表后根据返回的参数弹出相应错误的对话框
	 *
	 * @param str 提交留言后的返回值
	 * @return
	 */
	verifycode:function(str){
		var mode = str;
		if (mode == 1) {
		    alert(i18n_FrontMessage_showForm_verifycode_error);
			history.go(-1);
		   }else if(mode == 3) {
		    alert(i18n_FrontMessage_showForm_content_error);
			history.go(-1);
		   }
	},
	/**
	 * 截取电话字符串。
	 *
	 * @param s 
	 * @return
	 */
	isValidPhone:function(s) {
		if (!/^[\d\-()、]{7,32}$/.test(s)) return false;
		var stack = [];
		for (var i=0,c; c=s.charAt(i); i++) {
			if (c == '(') {
				stack.push(c);
			} else if (c == ')') {
				if (stack.pop() != '(') return false;
			}
		}
		return !stack.length;
	},
	/**
	 * 表单验证
	 *
	 * @param form 页面提交的表单
	 * @return
	 */
    	checkForm:function(form){
		   	form.mail.value = form.mail.value.replace(/^\s+|\s+$/g, "");
		 	if (/^\s*$/.test(form.mail.value)) {
				alert(i18n_FrontMessage_showForm_mail_not_null);
				form.mail.focus();
				return false;
		 	}
	 	
		 	 if(!isEmail(form.mail.value)){
				alert(i18n_FrontMessage_showForm_mail_error);
				form.mail.focus();
				return false;
			}
	 
		 	  form.author.value = form.author.value.replace(/^\s+|\s+$/g, "");
		 	  if(specialCharactersCheck(form.author.value)){
		 	     alert(i18n_FrontMessage_showForm_author_error);
				   form.author.focus();
				   return false;
		 	    }
	    
	    	form.phone.value = form.phone.value.replace(/^\s+|\s+$/g, "");
	    	if (form.phone.value.length > 0) {
				if (!FrontMessage_showForm.isValidPhone(form.phone.value)) {
	    			alert(i18n_FrontMessage_showForm_phone_number_error);
	             	form.phone.focus();
	             	return false;
	    		}
	    	}
			form.address.value = trim(form.address.value);
			if (specialCharactersCheck(form.address.value)) {
				alert(i18n_FrontMessage_showForm_address_error);
				form.address.focus();
				return false;
			}
			
			// validate mobile number;
	       	var mobile =  trim(form.mobile.value);
			//var mobilePattern = /^(86)?(13|15)\d{9}$/;
			var mobilePattern = /^(\d{11})$/;
			if (form.isByNote[0].checked && !mobile) {
				alert(i18n_FrontMessage_showForm_mobile_not_null);
				form.mobile.focus();
				return false;
			}
			if (mobile || form.isByNote[0].checked) {
				if (!mobilePattern.test(mobile)) {
					alert(i18n_FrontMessage_showForm_mobile_number_error);
					form.mobile.focus();
					return false;
				}
			}
			
			//if (mobile || form.isByNote[0].checked) {
			//	if (!isMobileNumber(mobile)) {
			//		alert(i18n_FrontMessage_showForm_mobile_number_error);
			//		form.mobile.focus();
			//		return false;
			//	}
			//}
			
			//form.mobile.value = form.mobile.value.replace(/^\+?86/, "");

		    if((form.categoryId)&&(form.categoryId.value =="")){
				alert(i18n_FrontMessage_showForm_category_not_null);
				try {form.categoryId.focus()}catch(e) {};
				return false;
		    }
	    
		    if (/^\s*$/.test(form.content.value)) {
				alert(i18n_FrontMessage_showForm_content_not_null);
				form.content.focus();
				return false;
		       }else if(form.content.value.length >800){
		          alert(i18n_FrontMessage_showForm_content_over);
				form.content.focus();
				return false;
		    }
	    
		    if (form.verifyCode.value.length ==0) {
				alert(i18n_FrontMessage_showForm_verifycode_not_null);
				form.verifyCode.focus();
				return false;
		       }
	   
		   
			return true;
		},
    /**
	 * 表单验证样式004
	 *
	 * @param form 页面提交的表单
	 * @return
	 */
		 checkFormEx:function(form){
		   	form.mail.value = form.mail.value.replace(/^\s+|\s+$/g, "");
		 	if (/^\s*$/.test(form.mail.value)) {
				alert(i18n_FrontMessage_showForm_mail_not_null);
				form.mail.focus();
				return false;
		 	}
	 	
		 	 if(!isEmail(form.mail.value)){
				alert(i18n_FrontMessage_showForm_mail_error);
				form.mail.focus();
				return false;
			}
	 
		 	  form.author.value = form.author.value.replace(/^\s+|\s+$/g, "");
		 	  if(specialCharactersCheck(form.author.value)){
		 	     alert(i18n_FrontMessage_showForm_author_error);
				   form.author.focus();
				   return false;
		 	    }
	        
	        
	        var phone =  trim(form.phone.value);
	        if(phone==null||phone==''){
	                alert(i18n_FrontMessage_showForm_phone_not_null);
	             	form.phone.focus();
	             	return false;
	        }
	        
	    	form.phone.value = form.phone.value.replace(/^\s+|\s+$/g, "");
	    	if (form.phone.value.length > 0) {
				if (!FrontMessage_showForm.isValidPhone(form.phone.value)) {
	    			alert(i18n_FrontMessage_showForm_phone_number_error);
	             	form.phone.focus();
	             	return false;
	    		}
	    	}
			form.address.value = trim(form.address.value);
			if (specialCharactersCheck(form.address.value)) {
				alert(i18n_FrontMessage_showForm_address_error);
				form.address.focus();
				return false;
			}
			
			// validate mobile number;
	       	var mobile =  trim(form.mobile.value);
			var mobilePattern =/^(\d{11})$/;
			if (form.isByNote[0].checked && !mobile) {
				alert(i18n_FrontMessage_showForm_mobile_not_null);
				form.mobile.focus();
				return false;
			}
			if (mobile || form.isByNote[0].checked) {
				if (!mobilePattern.test(mobile)) {
					alert(i18n_FrontMessage_showForm_mobile_number_error);
					form.mobile.focus();
					return false;
				}
			}
			//form.mobile.value = form.mobile.value.replace(/^\+?86/, "");

		    if((form.categoryId)&&(form.categoryId.value =="")){
				alert(i18n_FrontMessage_showForm_category_not_null);
				try {form.categoryId.focus()}catch(e) {};
				return false;
		    }
	    
		    if (/^\s*$/.test(form.content.value)) {
				alert(i18n_FrontMessage_showForm_content_not_null);
				form.content.focus();
				return false;
		       }else if(form.content.value.length >800){
		          alert(i18n_FrontMessage_showForm_content_over);
				form.content.focus();
				return false;
		    }
	    
		    if (form.verifyCode.value.length ==0) {
				alert(i18n_FrontMessage_showForm_verifycode_not_null);
				form.verifyCode.focus();
				return false;
		       }
	   
		   
			return true;
		},
		
		/**
		 * 表单验证
		 *
		 * @param form 页面提交的表单
		 * @return
		 */
		checkSimpleForm:function(form){
		   	form.mail.value = form.mail.value.replace(/^\s+|\s+$/g, "");
		 	if (/^\s*$/.test(form.mail.value)) {
				alert(i18n_FrontMessage_showForm_mail_not_null);
				form.mail.focus();
				return false;
		 	}
	 	
		 	 if(!isEmail(form.mail.value)){
				alert(i18n_FrontMessage_showForm_mail_error);
				form.mail.focus();
				return false;
			}
	 
		    if (/^\s*$/.test(form.content.value)) {
				alert(i18n_FrontMessage_showForm_content_not_null);
				form.content.focus();
				return false;
		       }else if(form.content.value.length >800){
		          alert(i18n_FrontMessage_showForm_content_over);
				form.content.focus();
				return false;
		    }
	    
		    if (form.verifyCode.value.length ==0) {
				alert(i18n_FrontMessage_showForm_verifycode_not_null);
				form.verifyCode.focus();
				return false;
		       }
	   
		   
			return true;
		},
  
	/**
	 * 判断字符串中是否都是数字,返回true则不全是数字，返回false 则全是数字。
	 *
	 * @param String 字符串
	 * @return 
	 */
	checknumber:function(String){ 
		var Letters = "1234567890"; 
		var i; 
		var c; 
		for( i = 0; i < String.length; i ++ ){ 
			c = String.charAt( i ); 
			if (Letters.indexOf( c ) ==-1){ 
				return true; 
			} 
		} 
		return false; 
	},
	/**
	 * 当提交失败后返回提交时的页面，页面中初始化已经填写的表单。
	 *
	 * @param data 已经填写好的表单的数据
	 * @return
	 */
	callback:function(data)
	{
		arrsp=data.split("***");
	 	authorarr=arrsp[0].split(":");
	 	authorarr[1]=authorarr[1].substr(1, authorarr[1].length-2); 
		$("#mail").attr("value",authorarr[1]==null?'': authorarr[1]);
		if(data['mail'] != null)
		{
			$('#mail').attr("readonly","true");
		}
		authorarr=arrsp[1].split(":");
		authorarr[1]=authorarr[1].substr(1, authorarr[1].length-2); 
		$("#author").attr("value",authorarr[1]==null?'': authorarr[1]);
		authorarr=arrsp[3].split(":");
		authorarr[1]=authorarr[1].substr(1, authorarr[1].length-2); 
		$("#phone").attr("value",authorarr[1]==null?'': authorarr[1]);
		authorarr=arrsp[4].split(":");
		authorarr[1]=authorarr[1].substr(1, authorarr[1].length-2); 
		$("#mobile").attr("value",authorarr[1]==null?'': authorarr[1]);
		authorarr=arrsp[7].split(":");
		authorarr[1]=authorarr[1].substr(1, authorarr[1].length-2); 
		$("#address").attr("value",authorarr[1]==null?'': authorarr[1]);
		authorarr=arrsp[8].split(":");
		authorarr[1]=authorarr[1].substr(1, authorarr[1].length-2); 
		$("#corpName").attr("value",authorarr[1]==null?'': authorarr[1]);
	
		authorarr=arrsp[2].split(":");
		authorarr[1]=authorarr[1].substr(1, authorarr[1].length-2); 
		if(authorarr[1] != null && authorarr[1] == '0')
			$('#sex1').attr("checked","checked");
	
		else if (authorarr[1] != null && authorarr[1] == '1')
		{
			$('#sex2').attr("checked","checked");
		}
	
		if(data['isByMail'] != null && data['isByMail'] == '0')
			$('#isByMail2').attr("checked","checked");
		else if (data['isByMail'] != null && data['isByMail'] == '1')
		{
			$('#isByMail1').attr("checked","checked");
		}
		if(data['isByNote'] != null && data['isByNote'] == '0')
				$('#isByNote2').attr("checked","checked");
		else if (data['isByNote'] != null && data['isByNote'] == '1')
		{
			$('#isByNote1').attr("checked","checked");
		}
	
	},
	setStarValue:function(parameter){
		document.getElementById("star").value=parameter.innerHTML;
	}	
	
}
$(document).ready(function(){
	$(".star a").mousedown(function(){
		i=$(this).text();
		$(".FrontMessage_showForm-05 .message .content .star .current").css("width",i*20);
	})
})
