﻿// JavaScript Document
$(document).ready(function(){
	
	/*初始化其它联系方式，与密码状态*/
	if($('#other').attr('checked')){
				$('#conOther').show();
				}else{
				$('#conOther').hide()	
					}
	if($('#secrecy').attr('checked')){
				$('#conPwd').show();
				}else{
				$('#conPwd').hide()	
					}
					
					
	/*当前*/
	//$('.conForm input,.conForm textarea').focus(function(){$(this).addClass('current');});
	//$('.conForm input,.conForm textarea').blur(function(){$(this).removeClass('current');});
	
	
					
	/*姓名*/
	
	$('#name').focus(function(){
			$(this).addClass('current');			  
			
			showTips($(this), nameTxt[0], 'blue', true, false);
//				if($(this).data('qtip')){$(this).qtip('destroy');}
//				$(this).qtip({
//					 content:nameTxt[0],
//					 show:{when:false},
//					 hide:false,
//					 style: {
//						name: 'blue',
//						width: { max: 200 }, // Set a high max width so the text doesn't wrap
//						tip: true // Give them tips with auto corner detection
//					 },
//					 position: {
//					  	 corner: {
//						 target: 'rightTop',
//						 tooltip: 'leftTop'
//					 	 }
//					 }
//							 });
//				$(this).qtip("show");
							  })
			.blur(function(){
			$(this).removeClass('current');
			$(this).removeClass('error');
			var ck = nameCheck();
			showTips($(this), nameTxt[ck], 'red', ck, true); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}	
//			if(ck){
//				$(this).addClass('error');
//				$(this).qtip({
//					 content:nameTxt[ck],
//					 show:{when:false},
//					 hide:false,
//					 style: {
//						name: 'red',
//						width: { max: 200 }, // Set a high max width so the text doesn't wrap
//						tip: true // Give them tips with auto corner detection
//					 },
//					 position: {
//					  	 corner: {
//						 target: 'rightTop',
//						 tooltip: 'leftTop'
//					 	 }
//					 }
//							 });
//				$(this).qtip("show");
//				}
							 });
	
	
	
	
	/*电话*/
	
	$('#phone').focus(function(){
		$(this).addClass('current');	
		showTips($(this), phoneTxt[0], 'blue', true, false); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}
//				$(this).qtip({
//					 content:phoneTxt[0],
//					 show:{when:false},
//					 hide:false,
//					 style: {
//						name: 'blue',
//						width: { max: 200 }, // Set a high max width so the text doesn't wrap
//						tip: true // Give them tips with auto corner detection
//					 },
//					 position: {
//					  	 corner: {
//						 target: 'rightTop',
//						 tooltip: 'leftTop'
//					 	 }
//					 }
//							 });
//				$(this).qtip("show");
							  })
			.blur(function(){
			$(this).removeClass('current');
			$(this).removeClass('error');
			var ck = phoneCheck();
			showTips($(this), phoneTxt[ck], 'red', ck, true); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}
//			if(ck){
//				$(this).addClass('error');
//				$(this).qtip({
//					 content:phoneTxt[ck],
//					 show:{when:false},
//					 hide:false,
//					 style: {
//						name: 'red',
//						width: { max: 200 }, // Set a high max width so the text doesn't wrap
//						tip: true // Give them tips with auto corner detection
//					 },
//					 position: {
//					  	 corner: {
//						 target: 'rightTop',
//						 tooltip: 'leftTop'
//					 	 }
//					 }
//							 });
//				$(this).qtip("show");
//				}
							 });
	
	
	/*EMAIL*/
	
	$('#email').focus(function(){
			$(this).addClass('current');
			showTips($(this), emailTxt[0], 'blue', true, false); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}
//				$(this).qtip({
//					 content:emailTxt[0],
//					 show:{when:false},
//					 hide:false,
//					 style: {
//						name: 'blue',
//						width: { max: 200 }, // Set a high max width so the text doesn't wrap
//						tip: true // Give them tips with auto corner detection
//					 },
//					 position: {
//					  	 corner: {
//						 target: 'rightTop',
//						 tooltip: 'leftTop'
//					 	 }
//					 }
//							 });
//				$(this).qtip("show");
							  })
			.blur(function(){
						   $(this).removeClass('current');
			$(this).removeClass('error');
			var ck = emailCheck();
			showTips($(this), emailTxt[ck], 'red', ck, true); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}	
//			if(ck){
//				$(this).addClass('error');
//				$(this).qtip({
//					 content:emailTxt[ck],
//					 show:{when:false},
//					 hide:false,
//					 style: {
//						name: 'red',
//						width: { max: 200 }, // Set a high max width so the text doesn't wrap
//						tip: true // Give them tips with auto corner detection
//					 },
//					 position: {
//					  	 corner: {
//						 target: 'rightTop',
//						 tooltip: 'leftTop'
//					 	 }
//					 }
//							 });
//				$(this).qtip("show");
//				}
							 });
	
			
	
	/*地址或其它联系方式*/
	$('#other').click(function(){
			if($(this).attr('checked')){
				$('#conOther').show();
				}else{
				if($('#address').data('qtip')){$('#address').qtip('destroy');}
				$('#conOther').hide();
					}
						   });		
	
	
	$('#address').focus(function(){
			$(this).addClass('current'); 
			showTips($(this), addressTxt[0], 'blue', true, false); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}
//				$(this).qtip({
//					 content:addressTxt[0],
//					 show:{when:false},
//					 hide:false,
//					 style: {
//						name: 'blue',
//						width: { max: 200 }, // Set a high max width so the text doesn't wrap
//						tip: true // Give them tips with auto corner detection
//					 },
//					 position: {
//					  	 corner: {
//						 target: 'rightTop',
//						 tooltip: 'leftTop'
//					 	 }
//					 }
//							 });
//				$(this).qtip("show");
							  })
			.blur(function(){
						   $(this).removeClass('current');
			$(this).removeClass('error');
			showTips($(this), addressTxt[0], 'red', false, true); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}	
							 });
			
	/*主题*/
	
	$('#title').focus(function(){
							   $(this).addClass('current');
			showTips($(this), phoneTxt[0], 'blue', false, false); //showTips(obj, contents, style, chenked, focused)
							  })
			.blur(function(){
						   $(this).removeClass('current');
			$(this).removeClass('error');
			var ck = titleCheck();
			showTips($(this), titleTxt[ck], 'red', ck, true); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}	
//			if(ck){
//				$(this).addClass('error');
//				$(this).qtip({
//					 content:titleTxt[ck],
//					 show:{when:false},
//					 hide:false,
//					 style: {
//						name: 'red',
//						width: { max: 200 }, // Set a high max width so the text doesn't wrap
//						tip: true // Give them tips with auto corner detection
//					 },
//					 position: {
//					  	 corner: {
//						 target: 'rightTop',
//						 tooltip: 'leftTop'
//					 	 }
//					 }
//							 });
//				$(this).qtip("show");
//				}
							 });
	
	
	
	
	/*内容*/
	
	$('#consultationCon').focus(function(){
										 $(this).addClass('current');
			showTips($(this), consultationConTxt[0], 'blue', false, false); //showTips(obj, contents, style, chenked, focused)
							  })
			.blur(function(){
						   $(this).removeClass('current');
			$(this).removeClass('error');
			var ck = consultationConCheck();
			showTips($(this), consultationConTxt[ck], 'red', ck, true); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}	
//			if(ck){
//				$(this).addClass('error');
//				$(this).qtip({
//					 content:titleTxt[ck],
//					 show:{when:false},
//					 hide:false,
//					 style: {
//						name: 'red',
//						width: { max: 200 }, // Set a high max width so the text doesn't wrap
//						tip: true // Give them tips with auto corner detection
//					 },
//					 position: {
//					  	 corner: {
//						 target: 'rightTop',
//						 tooltip: 'leftTop'
//					 	 }
//					 }
//							 });
//				$(this).qtip("show");
//				}
							 });
	
	


	/*内容自动扩展
	$('#consultationCon').elastic();
	*/
	
	/*密码显示*/
	//$('input:password').dPassword();	
	/*公开与否*/
	$('#secrecy').click(function(){
			if($(this).attr('checked')){
				$('#conPwd').show();
				}else{
				if($('#pwd').data('qtip')){$('#pwd').qtip('destroy');};
				if($('#comfirmPwd').data('qtip')){$('#comfirmPwd').qtip('destroy');};
				$('#pwd').removeClass('error');
				$('#comfirmPwd').removeClass('error');
				$('#conPwd').hide();
					}
						   });
	
	/*密码*/
	
	$('#pwd').focus(function(){
							 $(this).addClass('current');
			showTips($(this), pwdTxt[0], 'blue', true, false); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}
//				$(this).qtip({
//					 content:pwdTxt[0],
//					 show:{when:false},
//					 hide:false,
//					 style: {
//						name: 'blue',
//						width: { max: 200 }, // Set a high max width so the text doesn't wrap
//						tip: true // Give them tips with auto corner detection
//					 },
//					 position: {
//					  	 corner: {
//						 target: 'rightTop',
//						 tooltip: 'leftTop'
//					 	 }
//					 }
//							 });
//				$(this).qtip("show");
							  })
			.blur(function(){
						   $(this).removeClass('current');
			$(this).removeClass('error');
			var ck = pwdCheck();
			showTips($(this), pwdTxt[ck], 'red', ck, true); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}	
//			if(ck){
//					$(this).addClass('error');
//					$(this).qtip({
//						 content:pwdTxt[ck],
//						 show:{when:false},
//						 hide:false,
//						 style: {
//							name: 'red',
//							width: { max: 200 }, // Set a high max width so the text doesn't wrap
//							tip: true // Give them tips with auto corner detection
//						 },
//						 position: {
//							 corner: {
//							 target: 'rightTop',
//							 tooltip: 'leftTop'
//							 }
//						 }
//								 });
//					$(this).qtip("show");
//				}
							 });
	
	
	/*确认密码*/
	
	$('#comfirmPwd').focus(function(){
									$(this).addClass('current');
			showTips($(this), comfirmPwdTxt[0], 'blue', true, false); //showTips(obj, contents, style, chenked, focused)								 
//			if($(this).data('qtip')){$(this).qtip('destroy');}
//				$(this).qtip({
//					 content:comfirmPwdTxt[0],
//					 show:{when:false},
//					 hide:false,
//					 style: {
//						name: 'blue',
//						width: { max: 200 }, // Set a high max width so the text doesn't wrap
//						tip: true // Give them tips with auto corner detection
//					 },
//					 position: {
//					  	 corner: {
//						 target: 'rightTop',
//						 tooltip: 'leftTop'
//					 	 }
//					 }
//							 });
//				$(this).qtip("show");
							  })
			.blur(function(){
						   $(this).removeClass('current');
			$(this).removeClass('error');
			var ck = comfirmPwdCheck();
			showTips($(this), comfirmPwdTxt[ck], 'red', ck, true); //showTips(obj, contents, style, chenked, focused)
//			if($(this).data('qtip')){$(this).qtip('destroy');}	
//			if(ck){
//					$(this).addClass('error');
//					$(this).qtip({
//						 content:comfirmPwdTxt[ck],
//						 show:{when:false},
//						 hide:false,
//						 style: {
//							name: 'red',
//							width: { max: 200 }, // Set a high max width so the text doesn't wrap
//							tip: true // Give them tips with auto corner detection
//						 },
//						 position: {
//							 corner: {
//							 target: 'rightTop',
//							 tooltip: 'leftTop'
//							 }
//						 }
//								 });
//					$(this).qtip("show");
//				}
							 });
	
						
	/*验证码*/
	
	$('#vcode').focus(function(){
			$(this).addClass('current');			  
			showTips($(this), vcodeTxt[0], 'blue', true, false);})
			.blur(function(){
			$(this).removeClass('current');
			$(this).removeClass('error');
			var ck = vcodeCheck();
			showTips($(this), vcodeTxt[ck], 'red', ck, true);});
	

	
	
	/*获得焦点*/
	$('#name').focus();
	

	
	
	
	
	});

	/*表单检验*/
	function frConsultationCheck(){
		var ck1 = nameCheck();
		if(ck1){
			showTips($('#name'), nameTxt[ck1], 'red', ck1, true);
		}
		var ck2 = phoneCheck();
		if(ck2){
			showTips($('#phone'), phoneTxt[ck2], 'red', ck2, true); 
		}
		var ck3 = emailCheck();
		if(ck3){
			showTips($('#email'), emailTxt[ck3], 'red', ck3, true);
		}
		var ck4 = titleCheck();
		if(ck4){
			showTips($('#title'), titleTxt[ck4], 'red', ck4, true);
		}
		var ck5 = consultationConCheck();
		if(ck5){
			showTips($('#consultationCon'), consultationConTxt[ck5], 'red', ck5, true);
		}
		var ck6 = pwdCheck();
		if(ck6){
			showTips($('#pwd'), pwdTxt[ck6], 'red', ck6, true);
		}
		var ck7 = comfirmPwdCheck();
		if(ck7){
			showTips($('#comfirmPwd'), comfirmPwdTxt[ck7], 'red', ck7, true);
		}
		var ck8 = vcodeCheck();
		if(ck8){
			showTips($('#vcode'), vcodeTxt[ck8], 'red', ck8, true);
		}
		if(ck1||ck2||ck3||ck4||ck5||ck6||ck7||ck8){
			return false;
			}else{
			return true;
			}
		}
		
		

		
		
	/*显示提示&删除提示*/
	function showTips(obj, contents, style, chenked, focused){
		if($(obj).data('qtip')){$(obj).qtip('destroy');}
		if(chenked){
			if(focused){
				$(obj).addClass('error');
			}
				$(obj).qtip({
					 content:contents,
					 show:{when:false},
					 hide:false,
					 style: {
						name: style,
						width: { max: 200 }, // Set a high max width so the text doesn't wrap
						tip: true // Give them tips with auto corner detection
					 },
					 position: {
					  	 corner: {
						 target: 'rightTop',
						 tooltip: 'leftTop'
					 	 }
					 }
							 });
				$(obj).qtip("show");
				}
		}
		
	/*检查名字*/
	var nameTxt = ["必填项<br />建议您填写真实姓名以便联系，<br>您所提供的信息我们会保密","*姓名不能为空"];
	function nameCheck(){
		if($('#name').val().replace(/\s/g,'')==''){
			return 1;
		}else{
			return false;
			}
					 
	}
	/*检查电话*/
	var phoneTxt = ["电话格式如下<br />020-12345678 或<br />13800138000","*电话号码不正确"];
	function phoneCheck(){
		var regex = new RegExp(/^[0-9\-\(\)\ ]+$/g);
		var txt = $('#phone').val();
		if(txt.replace(/\s/g,'')!=''){
		if(regex.test(txt)){
			return false;
		}else{
			return 1;
			}}else{
				return false;
				}
					 
	}
	/*检查email*/
	var emailTxt = ["正确的email格式如下<br />info@gdga.gov.cn","*请填写正确的email格式<br />info@gdga.gov.cn"];
	function emailCheck(){
		var regex = new RegExp(/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/g);
		var txt = $('#email').val();
		if(txt.replace(/\s/g,'')!=''){
		if(regex.test(txt)){
			return false;
		}else{
			return 1;
			}}else{
				return false;
				}
					 
	}
	var addressTxt = ["填写地址或其它联系方式，如QQ等"];
	/*检查主题*/
	var titleTxt = ["","*主题不能为空"];
	function titleCheck(){
		if($('#title').val().replace(/\s/g,'')==''){
			return 1;
		}else{
			return false;
			}
					 
	}
	/*检查内容*/
	var consultationConTxt = ["","*内容不能为空"];
	function consultationConCheck(){
		if($('#consultationCon').val().replace(/\s/g,'')==''){
			return 1;
		}else{
			return false;
			}
					 
	}
	/*检查密码*/
	var pwdTxt = ["请输入6-11位的密码<br />密码不能不空","*密码不能为空","*请输入6-11位的密码"];
	function pwdCheck(){
		var txt = $('#pwd').val();
		if($('#secrecy').attr('checked')){
		if(txt.replace(/\s/g,'')!=''){
			var pwdLength =txt.length;
			if(pwdLength<6||pwdLength>12){
				return 2;
				}else{
				return false;	
					}
			}else{
				return 1;
				}}else{
					return false;
					}
					 
	}
	/*确认密码*/
	var comfirmPwdTxt = ["请再次输入6-11位的密码","*确认密码不能为空","*两次输入的密码不一致"];
	function comfirmPwdCheck(){
		var txt = $('#comfirmPwd').val();
		if($('#secrecy').attr('checked')){
		if(txt.replace(/\s/g,'')!=''){
			var txt1 = $('#pwd').val();
			if(txt != txt1){
				return 2;
				}else{
				return false;	
					}
			}else{
				return 1;
				}}else{
					return false;
					}
					 
	}
		
		
		
	/*检查验证码*/
	 var code ; //在全局 定义验证码   
     $(document).ready(function createCode()   
     {    
       code = "";   
       var codeLength = 4;//验证码的长度   
       var checkCode = document.getElementById("checkCode");    
       var selectChar = new Array(0,1,2,3,4,5,6,7,8,9);//所有候选组成验证码的字符，当然也可以用中文的   
          
      for(var i=0;i<codeLength;i++)   
      {   
   
       var charIndex = Math.floor(Math.random()*10);   
       code +=selectChar[charIndex];   
 
       }   
      if(checkCode)   
      {   
         checkCode.className="code";   
         checkCode.value = code;   
       }   
          
     });
	

	var vcodeTxt = ["必填项<br />请输入验证码，点击刷新验证码","*验证码不能为空","*验证码不正确"];
	function vcodeCheck(){
		var txt = $('#vcode').val();
		if(txt.length <=0){
			return 1;
		}else if(txt != code){
			return 2;
			}else{
			return false;
			}
					 
	}
	
	

