

function funRetoreTutor(){
	$("#mydiv").remove();
	$("#tutorform").show();
	
		$(".form_top_text").show();
		$(".form_top_text").next().remove();
		document.title='檸檬教育導師登記表格';
	
	/*$("#tutorform input, #tutorform textarea , #tutorform select").each(function(){
	
		if($(this).attr('type')!='image'){
			$(this).show();
		
		}

	});
	
	$("#tutorform .confirm").remove();

	$(" input[type='checkbox'][checked=false] ").each(function(){

		$(this).parent().show();
	});
	
	$(" input[type='checkbox'][checked=true] ").each(function(){
		$(this).show();
	});
	
	$(" input#subject_43[type='checkbox'][checked=false] ").each(function(){
		$("#subject_text").parent().show();
	});*/
	
	 confrim=false;

}

function funConfirmTutor(){
	
	/*$("#tutorform input, #tutorform textarea , #tutorform select").each(function(){
	
		if($(this).attr('type')!='image' 		&& 	$(this).attr('type')!='hidden'		&& 	$(this).attr('type')!='checkbox'		&& 	$(this).attr('id')!='subject_43'		){
			$(this).hide();
			var temp=$(document.createElement("strong")); 
			temp.addClass("confirm");
			temp.html($(this).val());
			//var str='<strong class="confirm">'+$(this).val()+'</strong>';
			$(this).after(temp);
		}
		
		
		$(" input[type='checkbox'][checked=false] ").each(function(){

			$(this).parent().hide();
		});
		$(" input[type='checkbox'][checked=true] ").each(function(){
			$(this).hide();
		});
		
		$(" input#subject_43[type='checkbox'][checked=false] ").each(function(){
			$("#subject_text").parent().hide();
		});
		
	});*/
	
	//$('#tutorform').submit();
	



	$.ajax({
		type: "POST",
		url: "ajax_tutorform.php",
		data: $('#tutorform').serialize(),
		success: function(msg){
			var mydiv=$(document.createElement("div"));
			mydiv.attr("id","mydiv");
			mydiv.html(msg);
			
			$('#tutorform').hide();
			/*alert("run");*/
			$('#tutorform').after(mydiv);
			
			$(".form_top_text").hide();
			$(".form_top_text").after('<div>以下是閣下剛剛提交的表單資料，請確保有關資料正確無誤。<BR>如有關資料正確無誤，請按“確認提交”鍵，如需更改請按“修改表單”鍵。');	
			document.title='檸檬教育導師登記表格確認'; /* 檸檬教育導師確認表單資料*/


		}
	});	


	 confrim=true;

}

var confrim=false;
$.validator.setDefaults({

});



$(document).ready(function(){


	$(" #tutorform input, #tutorform textarea").each(function(){
			
		/*$(this).val($(this).attr("id"));
		if($(this).attr("name").indexOf("[]")>0){
			$(this).attr("checked",true);
			
		}*/
	});





	$('#subject_0').bind("click",function(){
		/*var value=$(this).attr("checked");
		$("#subject_list input").each(function(){
			$(this).attr("checked",value);
		});		*/
	});	
	
	$('#area_0_0').bind("click",function(){
		var value=$(this).attr("checked");
		$("#area_list0 input").each(function(){
			$(this).attr("checked",value);
		});		
	});
				
	$('#area_1_0').bind("click",function(){
		var value=$(this).attr("checked");
		$("#area_list1 input").each(function(){
			$(this).attr("checked",value);
		});		
	});

	$('#area_2_0').bind("click",function(){
		var value=$(this).attr("checked");
		$("#area_list2 input").each(function(){
			$(this).attr("checked",value);
		});		
	});
	
	

/**/
		
});





/* ======================================== */
jQuery.extend(jQuery.validator.messages, {
        required: "必填",
                remote: "請修正此欄位",
                email: "請輸入正確的電子信箱",
                url: "請輸入合法的URL",
                date: "請輸入合法的日期",
                dateISO: "請輸入合法的日期 (ISO).",
                number: "請輸入數字",
                digits: "請輸入整數",
                creditcard: "請輸入合法的信用卡號碼",
                equalTo: "請重複輸入一次",
                accept: "請輸入有效的後缀字串",
                maxlength: jQuery.format("請輸入長度不大於{0} 的字串"),
                minlength: jQuery.format("請輸入長度不小於 {0} 的字串"),
                rangelength: jQuery.format("請輸入長度介於 {0} 和 {1} 之間的字串"),
                range: jQuery.format("請輸入介於 {0} 和 {1} 之間的數值"),
                max: jQuery.format("請輸入不大於 {0} 的數值"),
                min: jQuery.format("請輸入不小於 {0} 的數值")
});
/* ======================================== */
/*
$.validator.setDefaults({
	submitHandler: function() { 
	alert("submitted!, ajax ");
	//$('#tutorform').submit();
	 }
});
*/

$().ready(function() {
	// validate the comment form when it is submitted




$("#bank").validate({
		rules: {
			lemon_id:{
				required: true,
				minlength: 6
			},
			
		
			name:{
				required: true,
				minlength: 2
			},
					
			gender : "required",
		
			
			phone:{
				required: true,
				minlength: 8
			},
			
			birth_month : "required",
			birth_day : "required",
			payment_type : "required",
			payment_method : "required",
			amount:{
				required: true,
				minlength: 2
			},
			payment_date:{
				required: true,
				minlength: 4
			},

			payment_time:{
				required: true,
				minlength: 4
			},
		
			phone:{
				required: true,
				minlength: 8
			},
		
			
			payment_ref:{
				required: true,
				minlength: 4
			},
			
			email:{
				required: true,
				email: true,
				minlength: 10
			}
			
		},
		
		submitHandler: function(form) {
			if( window.confirm('確定提交？')){
					form.submit();
			}else{
				return false;
			}
				
		}	 		
});
	
	
	
/*

			*/
$("#tutorform").validate({
		
		rules: {
		
			chinese_full_name : {
			    required:true,
				minlength: 2,
				maxlength: 4
			},
			
			english_full_name : {
			    required:true,
				minlength: 5
			},
			
						
			gender : "required",
			birth_year : "required",
			birth_month : "required",
			birth_day : "required",
			id_card_no : {
			    required:true,
				minlength: 8
			},
		
			home_phone : {
			    required:true,
				minlength: 8
			},
			
			mobile_phone : {
			    required:true,
				minlength: 8
			},
			
			
			address : {
			    required:true,
				minlength: 8
			},
			
			region : "required",
			from_method : "required",
			pass : {
			    required:true,
				minlength: 6
			},
			pass2: {
				required: true,
				minlength: 6,
				equalTo: "#pass"
			},

			email:{
				required: true,
				email: true,
				minlength: 10
			},
			
			
		
			
			teaching_fee: "required",
			teaching_per_week: "required",
			
			
			
			
			lang_english_overall: "required",
			lang_mandarin_overall: "required",
			lang_english_conversation: "required",
			lang_mandarin_conversation: "required",
			lang_english_writing: "required",
			lang_mandarin_writing: "required",
			
	
			teaching_total_year: "required",
			
			
			
			
			
			
			job: "required",
			level_of_education: "required",
			
			
			
			introduction_title : {
			    required:true,
				minlength: 6,
				maxlength: 10
			},
			
			introduction_content : {
			    required:true,
				minlength: 50,
				maxlength: 80
			},
			
					
					
					
					
			"subject[]":{required:true,	minlength:1	},
			"teaching[]":{required:true,	minlength:1	},
			"area[]":{required:true,	minlength:1	}
			
		},
		messages: {
			Xenglish_full_name: "Please enter your lastname"
			
		},
		submitHandler: function(form) {
	
			if (confrim){
				
				
				if( 1){
					/* window.confirm('確定提交？')*/
					form.submit();
				}else{
					funRetoreTutor();
				}
			
			}else{
			
				funConfirmTutor();
			}		
		}	 		
});
	



$("#contactus").validate({
		rules: {
		
			chinese_full_name:{
				required: true,
				minlength: 2
			},
			
		
			message:{
				required: true,
				minlength: 10
			},		
			gender : "required",
			birth_year : "required",
			birth_month : "required",
			birth_day : "required",
			id_card_no : {
			    required:true,
				minlength: 7
			},
			
			mobile_phone : {
			    required:true,
				minlength: 8
			},
			address : "required",
			region : "required",
			from_method : "required",
			pass : {
			    required:true,
				minlength: 6
			},
			pass2: {
				required: true,
				minlength: 6,
				equalTo: "#pass"
			},

			email:{
				required: true,
				email: true
			},
			
			
			job: "required",
			level_of_education: "required",
			
			
			introduction_title: "required",
			introduction_content: "required",
					
					
					
					
			"subject[]":{required:true,	minlength:1	},
			"teaching[]":{required:true,	minlength:1	},
			"area[]":{required:true,	minlength:1	}
		},
		messages: {
			Xenglish_full_name: "Please enter your lastname"
			
		},
		submitHandler: function(form) {
			if( window.confirm('確定提交？')){
					form.submit();
			}else{
				return false;
			}
				
		}	 		
});
	


$("#forget_pass").validate({
		rules: {
		
			
			email:{
				required: true,
				email: true
			}
		},
		
		submitHandler: function(form) {
	
	
					form.submit();
					
		}	 		
});
	



$("#tutorform_update").validate({
		rules:  {
		
			chinese_full_name : {
			    required:true,
				minlength: 2,
				maxlength: 4
			},
			
			english_full_name : {
			    required:true,
				minlength: 5
			},
			
						
			gender : "required",
			birth_year : "required",
			birth_month : "required",
			birth_day : "required",
			id_card_no : {
			    required:true,
				minlength: 8
			},
		
			home_phone : {
			    required:true,
				minlength: 8
			},
			
			mobile_phone : {
			    required:true,
				minlength: 8
			},
			
			
			address : {
			    required:true,
				minlength: 8
			},
			
			region : "required",
			from_method : "required",
			pass : {
			    required:true,
				minlength: 6
			},
			pass2: {
				required: true,
				minlength: 6,
				equalTo: "#pass"
			},

			email:{
				required: true,
				email: true,
				minlength: 10
			},
			
			
			
			teaching_fee: "required",
			teaching_per_week: "required",
			
			
			
			
			lang_english_overall: "required",
			lang_mandarin_overall: "required",
			lang_english_conversation: "required",
			lang_mandarin_conversation: "required",
			lang_english_writing: "required",
			lang_mandarin_writing: "required",
			
	
			teaching_total_year: "required",
			
			
			
			
			
			
			job: "required",
			level_of_education: "required",
			
			
			
			introduction_title : {
			    required:true,
				minlength: 6,
				maxlength: 10
			},
			
			introduction_content : {
			    required:true,
				minlength: 50,
				maxlength: 80
			},
			
					
					
					
					
			"subject[]":{required:true,	minlength:1	},
			"teaching[]":{required:true,	minlength:1	},
			"area[]":{required:true,	minlength:1	}
			
		},
		messages: {
			Xenglish_full_name: "Please enter your lastname"
			
		},
		submitHandler: function(form) {
			if ( window.confirm('確定提交？')){
			
				form.submit();
			}else{
				
			}
		}	 		
});


	
});


