// JavaScript Document
$(document).ready(function(){
		/*获得焦点*/
	$('#title').focus();				   
	
	
	/*姓名*/
	
	$('#name').focus(function(){
			$(this).addClass('current');			  
			
			showTips($(this), nameTxt[0], 'blue', true, false);
							  })
			.blur(function(){
			$(this).removeClass('current');
			$(this).removeClass('error');
			var ck = nameCheck();
			showTips($(this), nameTxt[ck], 'red', ck, true); //showTips(obj, contents, style, chenked, focused)
							 });
	
	/*EMAIL*/
	
	$('#email').focus(function(){
			$(this).addClass('current');
			showTips($(this), emailTxt[0], 'blue', true, false); //showTips(obj, contents, style, chenked, focused)
							  })
			.blur(function(){
						   $(this).removeClass('current');
			$(this).removeClass('error');
			var ck = emailCheck();
			showTips($(this), emailTxt[ck], 'red', ck, true); //showTips(obj, contents, style, chenked, focused)
							 });
	
	/*主题*/
	
	$('#title').focus(function(){
							   $(this).addClass('current');
			showTips($(this), titleTxt[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)
							 });
	
	/*内容*/
	
	$('#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)
							 });
			
						   });

function frConsultationCheck(){
		var ck1 = nameCheck();
		if(ck1){
			showTips($('#name'), nameTxt[ck1], 'red', ck1, 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);
		}
		if(ck1||ck3||ck4||ck5){
			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;
			}
					 
	}
	
/*检查email*/
	var emailTxt = ["正确的email格式如下<br />info@gdga.gov.cn","*请填写正确的email格式<br />info@gdga.gov.cn","*email地址不能为空"];
	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 2;
				}
					 
	}
	/*检查主题*/
	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;
			}
					 
	}
