var FrontMessages_emit01={
	/**
	 * 截取电话字符串。
	 *
	 * @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 data 已经填写好的表单的数据
	 * @return
	 */

	displayInfo:function(disInfo){
		document.getElementById(disInfo).style.display="block";
		//$("#"+disInfo).css({display:"block"});
	},
	/**
	 * 隐藏相应的提示信息。
	 *
	 * @param data 已经填写好的表单的数据
	 * @return
	 */
	
	hideInfo:function(hideInfo){ 	
		document.getElementById(hideInfo).style.display="none";
		//$("#"+hideInfo).css({display:"none"});
	},
	/**
	 * 显示相应的提示信息。
	 *
	 * @param flag 
	 * @return
	 */
	showinfo:function(flag){
		strarr=flag.split("_")
		laststr=strarr[strarr.length-1];
		strinfo="";
		strno="";
		strerr="";
		strpast="";
		for(i=0;i<strarr.length-1;i++){
			if(i==0){
				strinfo=strinfo+strarr[i];
				strno=strno+strarr[i];
				strerr=strerr+strarr[i];
				strpast=strpast+strarr[i];
			}else{
				strinfo=strinfo+"_"+strarr[i];
				strno=strno+"_"+strarr[i];
				strerr=strerr+"_"+strarr[i];
				strpast=strpast+"_"+strarr[i];
			}
		}
		strinfor=strinfo+"_info"+laststr
		strinfo_black=strinfo+"_info"+laststr+"_black";
		strno=strno+"_no"+laststr;
		strerr=strerr+"_err"+laststr;
		strpast=strpast+"_past"+laststr;
		if(document.getElementById(strinfor))
		{document.getElementById(strinfor).style.display="none";}
		if(document.getElementById(strno))
		{document.getElementById(strno).style.display="none";}
		if(document.getElementById(strerr))
		{document.getElementById(strerr).style.display="none";}
		if(document.getElementById(strinfo_black))
		{document.getElementById(strinfo_black).style.display="block";}
		if(document.getElementById(strpast))
		{document.getElementById(strpast).style.display="none";}
		//$("span[@flag="+flag+"w]").css({display:"none"});
		//$("span[@flag="+flag+"r]").css({display:"none"});
		//$("span[@flag="+flag+"m]").css({display:"block"});
	},
	/**
	 * 表单验证
	 *
	 * @param form 页面提交的表单
	 * @return
	 */
    checkForm:function(form,item,compid){
    	var isSub=true;
    	//验证邮件
    	if((item=="all"||item=="mail")&&form.mail){
    		form.mail.value = form.mail.value.replace(/^\s+|\s+$/g, "");
    		//如果后台选择必填，或前台勾选邮件联系，那么邮件为必填，且必须正确
    		if(form.isByMail_chk||form.isDisplayMail.value=='2'){
	    		if(form.isDisplayMail.value=='2'||form.isByMail_chk.checked){
	    		    if(!isEmail(form.mail.value)){
						FrontMessages_emit01.hideInfo(compid+"_infomail");
						FrontMessages_emit01.hideInfo(compid+"_infomail_black");
				 		FrontMessages_emit01.hideInfo(compid+"_nomail");
						FrontMessages_emit01.displayInfo(compid+"_errmail");
						isSub=false;
					}
				 	if (/^\s*$/.test(form.mail.value)) {
				 		FrontMessages_emit01.hideInfo(compid+"_infomail");
				 		FrontMessages_emit01.hideInfo(compid+"_infomail_black");
				 		FrontMessages_emit01.hideInfo(compid+"_errmail");
						FrontMessages_emit01.displayInfo(compid+"_nomail");
						isSub=false;
				 	}
		    	}
	    	}
	    	if(form.isDisplayMail.value=='1'){
	    	  	if(!isEmail(form.mail.value)&&!/^\s*$/.test(form.mail.value)){
					FrontMessages_emit01.hideInfo(compid+"_infomail");
					FrontMessages_emit01.hideInfo(compid+"_infomail_black");
			 		FrontMessages_emit01.hideInfo(compid+"_nomail");
					FrontMessages_emit01.displayInfo(compid+"_errmail");
					isSub=false;
				}
	    	}
			if(isSub==true){
				FrontMessages_emit01.hideInfo(compid+"_infomail_black");
				FrontMessages_emit01.displayInfo(compid+"_infomail");
			}
		}
		if((item=="all"||item=="author")&&form.author){
		 	form.author.value = form.author.value.replace(/^\s+|\s+$/g, "");
		 	if(form.isDisplayAuthor.value=='2'||form.isDisplayAuthor.value=='1'){
			 	if(specialCharactersCheck(form.author.value)){
			 	    FrontMessages_emit01.hideInfo(compid+"_infoauthor");
			 	    FrontMessages_emit01.hideInfo(compid+"_infoauthor_black");
			 		FrontMessages_emit01.hideInfo(compid+"_noauthor");
					FrontMessages_emit01.displayInfo(compid+"_errauthor");
					isSub=false;
			 	}
		 	}
		 	if(form.isDisplayAuthor.value=='2'){
			 	if (/^\s*$/.test(form.author.value)) {
					FrontMessages_emit01.hideInfo(compid+"_infoauthor");
					FrontMessages_emit01.hideInfo(compid+"_infoauthor_black");
			 		FrontMessages_emit01.hideInfo(compid+"_errauthor");
					FrontMessages_emit01.displayInfo(compid+"_noauthor");
					isSub=false;
			 	}
		 	}
		 	if(isSub==true){
				FrontMessages_emit01.hideInfo(compid+"_infoauthor_black");
				FrontMessages_emit01.displayInfo(compid+"_infoauthor");
			}
	    }
	    //手机验证
	    if((item=="all"||item=="mobile")&&form.mobile){
	    	form.mobile.value = form.mobile.value.replace(/^\s+|\s+$/g, "");
	    	var mobile =  trim(form.mobile.value);
	    	if(form.isByNote_chk||form.isDisplayMobile.value=='2'){
		    	if(form.isDisplayMobile.value=='2'||form.isByNote_chk.checked){
			    	if (/^\s*$/.test(form.mobile.value)) {
						FrontMessages_emit01.hideInfo(compid+"_infomobile");
						FrontMessages_emit01.hideInfo(compid+"_infomobile_black");
				 		FrontMessages_emit01.hideInfo(compid+"_errmobile");
						FrontMessages_emit01.displayInfo(compid+"_nomobile");
						isSub=false;
				 	}else if(!isMobileNumber(mobile)){
						FrontMessages_emit01.hideInfo(compid+"_infomobile");
						FrontMessages_emit01.hideInfo(compid+"_infomobile_black");
				 		FrontMessages_emit01.hideInfo(compid+"_nomobile");
						FrontMessages_emit01.displayInfo(compid+"_errmobile");
						isSub=false;
					}
				}
			}
			if(form.isDisplayMobile.value=='1'){
				if (!/^\s*$/.test(form.mobile.value)) {
					if(!isMobileNumber(mobile)){
						FrontMessages_emit01.hideInfo(compid+"_infomobile");
						FrontMessages_emit01.hideInfo(compid+"_infomobile_black");
				 		FrontMessages_emit01.hideInfo(compid+"_nomobile");
						FrontMessages_emit01.displayInfo(compid+"_errmobile");
						isSub=false;
					}
				}
			}
		
			if(isSub==true){
				FrontMessages_emit01.hideInfo(compid+"_infomobile_black");
				FrontMessages_emit01.displayInfo(compid+"_infomobile");
			}
	    }
	    
	    if((item=="all"||item=="phone")&&form.phone){
	    	form.phone.value = form.phone.value.replace(/^\s+|\s+$/g, "");
	    	if(form.isDisplayPhone.value=='2'||form.isDisplayPhone.value=='1'){
	    		//首先判断是否为空，如果为空则不判断了，如果不为空则判断一下是否合理。
		    	if (!/^\s*$/.test(form.phone.value)) {
			    	if (!FrontMessages_emit01.isValidPhone(form.phone.value)) {
			    		FrontMessages_emit01.hideInfo(compid+"_infophone");
			    		FrontMessages_emit01.hideInfo(compid+"_infophone_black");
				 		FrontMessages_emit01.hideInfo(compid+"_nophone");
						FrontMessages_emit01.displayInfo(compid+"_errphone");
						isSub=false;
			    	}
		    	}
	    	}
	    	if(form.isDisplayPhone.value=='2'){
		    	if (/^\s*$/.test(form.phone.value)) {
		    		FrontMessages_emit01.hideInfo(compid+"_infophone");
		    		FrontMessages_emit01.hideInfo(compid+"_infophone_black");
			 		FrontMessages_emit01.hideInfo(compid+"_errphone");
					FrontMessages_emit01.displayInfo(compid+"_nophone");
					isSub=false;
		    	}
	    	}
			if(isSub==true){
				FrontMessages_emit01.hideInfo(compid+"_infophone_black");
				FrontMessages_emit01.displayInfo(compid+"_infophone");
			}
	    }

	    if((item=="all"||item=="address")&&form.address){  
			form.address.value = form.address.value.replace(/^\s+|\s+$/g, "");
			if(form.isDisplayAddress.value=='2'){
				if (/^\s*$/.test(form.address.value)) {
				
		    		FrontMessages_emit01.displayInfo(compid+"_noaddress");
					isSub=false;
				}
			}
		}
		if((item=="all"||item=="area")&&form.area){
			form.area.value = form.area.value.replace(/^\s+|\s+$/g, "");
			if(form.isDisplayArea.value=='2'){
				if (/^\s*$/.test(form.area.value)) {
		    	
					FrontMessages_emit01.displayInfo(compid+"_noarea");
					isSub=false;
				}
			}
		}
		if((item=="all"||item=="corpName")&&form.corpName){
			form.corpName.value = form.corpName.value.replace(/^\s+|\s+$/g, "");
			if(form.isDisplayCorpName.value=='2'){
				if (/^\s*$/.test(form.corpName.value)) {
					FrontMessages_emit01.displayInfo(compid+"_nocorpName");
					isSub=false;
				}
			}
		}	
		//选择分类
		if(item=="all"||item=="messagesCategoryId"){
			if(form.messagesCategoryId){
				FrontMessages_emit01.showinfo(compid+"_messagesCategoryId");
			    if(document.getElementById("messagesCategoryId").selectedIndex==0){
					FrontMessages_emit01.displayInfo(compid+"_errmessagesCategoryId");
					isSub=false;
			    }
			}	
			
	    }
	    if(item=="all"||item=="content"){
		    if (/^\s*$/.test(form.content.value)) {
	    			FrontMessages_emit01.hideInfo(compid+"_infocontent");
	    			FrontMessages_emit01.hideInfo(compid+"_infocontent_black");
		 			FrontMessages_emit01.hideInfo(compid+"_errcontent");
					FrontMessages_emit01.displayInfo(compid+"_nocontent");
					isSub=false;
		       }else if(form.content.value.length >form.maxContent.value){
		        	FrontMessages_emit01.hideInfo(compid+"_infocontent");
		        	FrontMessages_emit01.hideInfo(compid+"_infocontent_black");
		 			FrontMessages_emit01.hideInfo(compid+"_nocontent");
					FrontMessages_emit01.displayInfo(compid+"_errcontent");
					isSub=false;
		    }
		    if(isSub==true){
				FrontMessages_emit01.hideInfo(compid+"_infocontent_black");
				FrontMessages_emit01.displayInfo(compid+"_infocontent");
			}
	    }

		if((item=="all"||item=="messagesTitle")&&form.messagesTitle){
			form.messagesTitle.value = form.messagesTitle.value.replace(/^\s+|\s+$/g, "");
			if(form.isDisplayMessagesTitle.value=='2'){
				if (/^\s*$/.test(form.messagesTitle.value)) {
					FrontMessages_emit01.displayInfo(compid+"_nomessagesTitle");
					isSub=false;
				}
			}
		}
	    
		if((item=="all"||item=="weburl")&&form.weburl){
			if(form.isDisplayUrl.value=='2'){
		        var netStr =/^((http|https|ftp):(\/\/|\\\\))?((\w)+[.]){1,}/;
		        if(form.weburl.value==""){
		        	FrontMessages_emit01.displayInfo(compid+"_noweburl");
		            isSub=false;
		        }else if (!netStr.test(form.weburl.value)){
		            FrontMessages_emit01.displayInfo(compid+"_errweburl");
		            isSub=false;
		        }
			}else if(form.isDisplayUrl.value=='1'){
				 var netStr =/^((http|https|ftp):(\/\/|\\\\))?((\w)+[.]){1,}/;
				 if(form.weburl.value!=""&&form.weburl.value!="http://"){
					 if (!netStr.test(form.weburl.value)){
			            FrontMessages_emit01.displayInfo(compid+"_errweburl");
			            isSub=false;
			         }
		         }
			}
		}
		if(item=="all"||item=="verifyCode"){
			if (form.verifyCode.value.length ==0) {
			    FrontMessages_emit01.hideInfo(compid+"_pastverifyCode");
			 	FrontMessages_emit01.hideInfo(compid+"_errverifyCode");
				FrontMessages_emit01.displayInfo(compid+"_noverifyCode");
				isSub=false;
			}
		}
		if(isSub&&item=="all"){
			form.orignal_url.value = window.location.href;
			if(document.getElementById(compid+"_submit")){
				document.getElementById(compid+"_submit").disabled='disabled';
			}
			form.submit();
		}
	},
	
	/**
	 * 选择表情。
	 *
	 * @param e 被选择的表情
	 * @return
	 */
	selectEmotion:function(e){
		var firstSrc=e.src;
		var secondSrc=firstSrc.replace("mesa-","mes-"); 
		var eleEmotion = document.getElementById("emotion");
		var imageId = document.getElementById("imageId");
//		var imgStr = e.innerHTML;
//		//获取图像SRC
//		imgStr = imgStr.substring(imgStr.indexOf("src=")+5);
//		imgStr = imgStr.substring(0,imgStr.indexOf('"'));
//		//获取图像对象
//		var imgObj = imgStr.substring(imgStr.indexOf("id=")+4);
//		imgObj = imgObj.substring(0,imgObj.indexOf('"'));
//		imgObj = document.getElementById(imgObj);
		//先将以前选中的图片效果清除
		if(imageId.value !=null && imageId.value !=""){
			var oldimg = document.getElementById(imageId.value);

			oldimg.src=imageId.name;
			
		}
		
		//将当前选中的图片加样式效果
		//e.className="imgstyle2";
		e.src=secondSrc;
		//获取图片SRC
		var imgSrc = e.src;
		imgSrc = imgSrc.substring(imgSrc.lastIndexOf("/")+1);
		eleEmotion.value = imgSrc;
		document.getElementById("imageId").value = e.id;
		if(imageId.name.substring(imageId.name.length-6,imageId.name.length)!=e.src.substring(e.src.length-6,e.src.length)){
			document.getElementById("imageId").name = firstSrc;
		}
		document.getElementById("emotion").value = e.name;
		
	},
	/**
	 * 提取是否邮件联系。
	 *
	 * @param obj 
	 * @param compid
	 * @return
	 */
	addIsByMailValue:function(obj,compid){
		FrontMessages_emit01.hideInfo(compid+"_infomail_black");
		FrontMessages_emit01.hideInfo(compid+"_nomail");
		FrontMessages_emit01.hideInfo(compid+"_errmail");
		FrontMessages_emit01.displayInfo(compid+"_infomail");
		if(obj.checked){
			$("#isByMail").attr("value","1");
		}else{
			$("#isByMail").attr("value","0");
		}
	},
	/**
	 * 提取是否短信联系。
	 *
	 * @param obj 
	 * @param compid
	 * @return
	 */
	addIsByNoteValue:function(obj,compid){
		FrontMessages_emit01.hideInfo(compid+"_infomobile_black");
		FrontMessages_emit01.hideInfo(compid+"_nomobile");
		FrontMessages_emit01.hideInfo(compid+"_errmobile");
		FrontMessages_emit01.displayInfo(compid+"_infomobile");
		if(obj.checked){
			$("#isByNote").attr("value","1");
		}else{
			$("#isByNote").attr("value","0");
		}
	},
  
	/**
	 * 判断字符串中是否都是数字,返回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");
		}
	
	},
	/**
	* 动态显示留言字数
	* 参数 formId 表单id , obj 留言页面对象
	*/
	dynamicNum:function(formId,obj){
	  		var lBrowser = {};
			lBrowser.agt = navigator.userAgent.toLowerCase();
			lBrowser.isW3C = document.getElementById ? true:false;
			lBrowser.isIE = ((lBrowser.agt.indexOf("msie") != -1) && (lBrowser.agt.indexOf("opera") == -1) && (lBrowser.agt.indexOf("omniweb") == -1));
			lBrowser.isNS6 = lBrowser.isW3C && (navigator.appName=="Netscape") ;
			lBrowser.isOpera = lBrowser.agt.indexOf("opera") != -1;
			lBrowser.isGecko = lBrowser.agt.indexOf("gecko") != -1;
			lBrowser.ieTrueBody =function (){
			  return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
			};
		
			//为Firefox下的DOM对象增加innerText属性  ff下无innerText属性 有等同效果的textContent属性
			if(lBrowser.isNS6){ //firefox innerText define
			 HTMLElement.prototype.__defineGetter__( "innerText",
				 function(){
				 	return this.textContent;
				 }
			 );
			 HTMLElement.prototype.__defineSetter__( "innerText",
				 function(sText){
				 	this.textContent=sText;
			 	 }
			 );
			}
	
			
	  	  var formObj = document.getElementById(formId);
	  	  var dynamicNum = document.getElementById('dynamicNum');
	  	  var num = obj.value;
	  	  dynamicNum.innerText = num.length;
	  },
	/**
	 * 提取星级设置。
	 *
	 * @param parameter
	 * @return
	 */
	setStarValue:function(parameter){
		document.getElementById("star").value=parameter.innerHTML;
	},	
	/**
	 * ajax验证码替换。
	 *
	 * @return
	 */
	getajaxverifyCode:function(){
		$.get("/FrontMessages.do?method=getVerifyCode",
		 function(data){
		 if($("#ajaxverifyCode").attr("value")==data){
		 	FrontMessages_emit01.getajaxverifyCode();
		 }else{
		 	$("#ajaxverifyCode").attr("value",data);
		 }
		});
	},
	/**
	 * ajax验证码提取。
	 *
	 * @return
	 */
	getajaxverifyCodeforonblur:function(){
		$.get("/FrontMessages.do?method=getVerifyCode",
		 function(data){
		 if($("#ajaxverifyCode").attr("value")!=data){
		 	$("#ajaxverifyCode").attr("value",data);
		 }
		});
	},	
	/**
	 * 当鼠标划过显示手型。
	 *
	 * @return
	 */
	showHand:function(objthis){
		objthis.style.cursor = 'pointer';
	},
	/**
	 * 验证码校验。
	 *
	 * @return
	 */
	chkverifyCode:function(objid,compid){
		 if (objid=="0") {
			FrontMessages_emit01.hideInfo(compid+"_errverifyCode");
			FrontMessages_emit01.hideInfo(compid+"_noverifyCode");
			FrontMessages_emit01.displayInfo(compid+"_pastverifyCode");

		 }else if (objid=="1") {
			FrontMessages_emit01.hideInfo(compid+"_pastverifyCode");
			FrontMessages_emit01.hideInfo(compid+"_noverifyCode");
			FrontMessages_emit01.displayInfo(compid+"_errverifyCode");
		 }
	}
}


