/*
 * jQuery Tools 1.2.3 - The missing UI library for the Web
 * 
 * [tooltip, tooltip.slide, tooltip.dynamic]
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/
 * 
 * File generated: Sat Jul 03 10:58:08 GMT 2010
 */
(function(f){function p(a,b,c){var h=c.relative?a.position().top:a.offset().top,e=c.relative?a.position().left:a.offset().left,i=c.position[0];h-=b.outerHeight()-c.offset[0];e+=a.outerWidth()+c.offset[1];var j=b.outerHeight()+a.outerHeight();if(i=="center")h+=j/2;if(i=="bottom")h+=j;i=c.position[1];a=b.outerWidth()+a.outerWidth();if(i=="center")e-=a/2;if(i=="left")e-=a;return{top:h,left:e}}function t(a,b){var c=this,h=a.add(c),e,i=0,j=0,m=a.attr("title"),q=n[b.effect],k,r=a.is(":input"),u=r&&a.is(":checkbox, :radio, select, :button, :submit"),
s=a.attr("type"),l=b.events[s]||b.events[r?u?"widget":"input":"def"];if(!q)throw'Nonexistent effect "'+b.effect+'"';l=l.split(/,\s*/);if(l.length!=2)throw"Tooltip: bad events configuration for "+s;a.bind(l[0],function(d){clearTimeout(i);if(b.predelay)j=setTimeout(function(){c.show(d)},b.predelay);else c.show(d)}).bind(l[1],function(d){clearTimeout(j);if(b.delay)i=setTimeout(function(){c.hide(d)},b.delay);else c.hide(d)});if(m&&b.cancelDefault){a.removeAttr("title");a.data("title",m)}f.extend(c,{show:function(d){if(!e){if(m)e=
f(b.layout).addClass(b.tipClass).appendTo(document.body).hide().append(m);else if(b.tip)e=f(b.tip).eq(0);else{e=a.next();e.length||(e=a.parent().next())}if(!e.length)throw"Cannot find tooltip for "+a;}if(c.isShown())return c;e.stop(true,true);var g=p(a,e,b);d=d||f.Event();d.type="onBeforeShow";h.trigger(d,[g]);if(d.isDefaultPrevented())return c;g=p(a,e,b);e.css({position:"absolute",top:g.top,left:g.left});k=true;q[0].call(c,function(){d.type="onShow";k="full";h.trigger(d)});g=b.events.tooltip.split(/,\s*/);
e.bind(g[0],function(){clearTimeout(i);clearTimeout(j)});g[1]&&!a.is("input:not(:checkbox, :radio), textarea")&&e.bind(g[1],function(o){o.relatedTarget!=a[0]&&a.trigger(l[1].split(" ")[0])});return c},hide:function(d){if(!e||!c.isShown())return c;d=d||f.Event();d.type="onBeforeHide";h.trigger(d);if(!d.isDefaultPrevented()){k=false;n[b.effect][1].call(c,function(){d.type="onHide";k=false;h.trigger(d)});return c}},isShown:function(d){return d?k=="full":k},getConf:function(){return b},getTip:function(){return e},
getTrigger:function(){return a}});f.each("onHide,onBeforeShow,onShow,onBeforeHide".split(","),function(d,g){f.isFunction(b[g])&&f(c).bind(g,b[g]);c[g]=function(o){f(c).bind(g,o);return c}})}f.tools=f.tools||{version:"1.2.3"};f.tools.tooltip={conf:{effect:"toggle",fadeOutSpeed:"fast",predelay:0,delay:30,opacity:1,tip:0,position:["top","center"],offset:[0,0],relative:false,cancelDefault:true,events:{def:"mouseenter,mouseleave",input:"focus,blur",widget:"focus mouseenter,blur mouseleave",tooltip:"mouseenter,mouseleave"},
layout:"<div/>",tipClass:"tooltip"},addEffect:function(a,b,c){n[a]=[b,c]}};var n={toggle:[function(a){var b=this.getConf(),c=this.getTip();b=b.opacity;b<1&&c.css({opacity:b});c.show();a.call()},function(a){this.getTip().hide();a.call()}],fade:[function(a){var b=this.getConf();this.getTip().fadeTo(b.fadeInSpeed,b.opacity,a)},function(a){this.getTip().fadeOut(this.getConf().fadeOutSpeed,a)}]};f.fn.tooltip=function(a){var b=this.data("tooltip");if(b)return b;a=f.extend(true,{},f.tools.tooltip.conf,a);
if(typeof a.position=="string")a.position=a.position.split(/,?\s/);this.each(function(){b=new t(f(this),a);f(this).data("tooltip",b)});return a.api?b:this}})(jQuery);
(function(d){var i=d.tools.tooltip;d.extend(i.conf,{direction:"up",bounce:false,slideOffset:10,slideInSpeed:200,slideOutSpeed:200,slideFade:!d.browser.msie});var e={up:["-","top"],down:["+","top"],left:["-","left"],right:["+","left"]};i.addEffect("slide",function(g){var a=this.getConf(),f=this.getTip(),b=a.slideFade?{opacity:a.opacity}:{},c=e[a.direction]||e.up;b[c[1]]=c[0]+"="+a.slideOffset;a.slideFade&&f.css({opacity:0});f.show().animate(b,a.slideInSpeed,g)},function(g){var a=this.getConf(),f=a.slideOffset,
b=a.slideFade?{opacity:0}:{},c=e[a.direction]||e.up,h=""+c[0];if(a.bounce)h=h=="+"?"-":"+";b[c[1]]=h+"="+f;this.getTip().animate(b,a.slideOutSpeed,function(){d(this).hide();g.call()})})})(jQuery);
(function(g){function j(a){var c=g(window),d=c.width()+c.scrollLeft(),h=c.height()+c.scrollTop();return[a.offset().top<=c.scrollTop(),d<=a.offset().left+a.width(),h<=a.offset().top+a.height(),c.scrollLeft()>=a.offset().left]}function k(a){for(var c=a.length;c--;)if(a[c])return false;return true}var i=g.tools.tooltip;i.dynamic={conf:{classNames:"top right bottom left"}};g.fn.dynamic=function(a){if(typeof a=="number")a={speed:a};a=g.extend({},i.dynamic.conf,a);var c=a.classNames.split(/\s/),d;this.each(function(){var h=
g(this).tooltip().onBeforeShow(function(e,f){e=this.getTip();var b=this.getConf();d||(d=[b.position[0],b.position[1],b.offset[0],b.offset[1],g.extend({},b)]);g.extend(b,d[4]);b.position=[d[0],d[1]];b.offset=[d[2],d[3]];e.css({visibility:"hidden",position:"absolute",top:f.top,left:f.left}).show();f=j(e);if(!k(f)){if(f[2]){g.extend(b,a.top);b.position[0]="top";e.addClass(c[0])}if(f[3]){g.extend(b,a.right);b.position[1]="right";e.addClass(c[1])}if(f[0]){g.extend(b,a.bottom);b.position[0]="bottom";e.addClass(c[2])}if(f[1]){g.extend(b,
a.left);b.position[1]="left";e.addClass(c[3])}if(f[0]||f[2])b.offset[0]*=-1;if(f[1]||f[3])b.offset[1]*=-1}e.css({visibility:"visible"}).hide()});h.onBeforeShow(function(){var e=this.getConf();this.getTip();setTimeout(function(){e.position=[d[0],d[1]];e.offset=[d[2],d[3]]},0)});h.onHide(function(){var e=this.getTip();e.removeClass(a.classNames)});ret=h});return a.api?ret:this}})(jQuery);
;
if(jQuery.validator){
	jQuery.validator.addMethod("idcard", function(value, element,param) {
		return this.optional(element) || /^\d{15}$/.test(value) || /^\d{18}$/.test(value);
	});
}

var Match={
	//登入
	loginReady:function(){
		jQuery(document).ready(function(){
			jQuery('#loginForm').validate();
			jQuery('#login_btn').click(function(){
				jQuery('#loginForm').ajaxSubmit({
					beforeSubmit:function(){
						if(!jQuery('#loginForm').valid()){
							return false;
						}
						showMsg('waitVerify',matchLang.SIGNINING,'notice');
					},
					dataType:'json',
					url:'/index/ajax-login',
					success:function(data){
						if(data){
							if(data.error){
								alert(data.msg);
								showMsg('waitVerify',data.msg,'error');
							}else{
								if(data.signInHtml!=''){
									jQuery('body').append(data.signInHtml);
								}
								if(data.url){
									jumpUrl=data.url;
								}else{
									jumpUrl='/';
								}
								setTimeout("window.location.href ='"+jumpUrl+"';", 1000);
							}
						}
					}
				});//end ajaxsubmit
			});//end click
		});
		//end document ready
	},//end loginReady
	//选择是个人还是团队注册
	selectIsTeamRegReady:function(){
		jQuery('#gotoReg').click(function(){
			e = jQuery('input[type=radio][name=isTeam]:checked').get(0);
			if(jQuery(e).val()==0){
				location.href='/index/reg-personal';
			}else{
				location.href='/index/reg-team';
			}
		});
	},
	//个人注册
	regPersonalReady:function(){

		jQuery('#birthday').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		var container = jQuery('div.error_container');
		$("#regForm :input[title!='']").tooltip({

			// place tooltip on the right edge
			position: "center right",

			// a little tweaking of the position
			offset: [-2, 10],

			// use the built-in fadeIn/fadeOut effect
			effect: "fade",

			onBeforeShow:function(){
				if($(this.getTrigger()).is('.error')){
					return false;
				}
			}

		});
		var validator = jQuery("#regForm").validate({
			errorPlacement: function(label, element) {
				if(element.is('#password,#realname,#cernum,#address,#code,#cernum')){
					element.parent().append('<br/>');
					element.parent().append(label);
					if(element.is('#cernum')){
						label.css('background','none');
						label.css('paddig-left','0');
						label.css('margin-left','0');
					}
				}else if (element.is("textarea")) {
					label.insertAfter(element.next());
				} else if (element.is("select")){
					element.parent().append(label);
				} else {
					label.insertAfter(element)
				}
			},
			//errorContainer: container,
			//errorLabelContainer: jQuery("ol", container),
			//wrapper: 'li',
			rules:{
				username:{
					required:true,
					remote:'/index/ajax-test-user'
				},
				password:{
					required:true,
					minlength:6
				},
				repassword:{
					required:true,
					minlength:6,
					equalTo: "#password"
				},
				email:{
					required:true,
					email: true,
					remote:'/index/ajax-test-email'
				},
				realname:{
					required:true
				},
				birthday:{
					required:true
				},
				cernum:{required:true,remote:{
					url: "/index/ajax-test-credential",
			        type: "post",
			        data: {
						certype: function() {
			            	return jQuery('#certype').val();
			        	}
					}
					
				}},
				unit:{required:true},
				job:{required:true},
				address:{required:true},
				code:{required:true,digits:true},
				tel:{digits:true},
				mobile:{digits:true},
				agree:{required:true}
			},
			messages:{
				username:{
					required:matchLang.USERNAME_REQUIRED,
					remote:matchLang.USERNAME_VALID_RULE
				},
				password:matchLang.PASSWORD_VALID_RULE,
				repassword:{
					required:matchLang.CONFIRM_PASSWORD_REQUIRED,
					minlength:matchLang.CONFIRM_PASSWORD_INVALID,
					equalTo:matchLang.PASSWORD_CONFIRM
				},
				email:{required:matchLang.EMAIL_REQUIRED,email:matchLang.INVALID_EMAIL,remote:matchLang.INVALID_EMAIL},
				
				realname:matchLang.REALNAME_REQUIRED,
				birthday:matchLang.BIRTHDATE_REQUIRED,
				cernum:{
					required:matchLang.IDCARD_REQUIRED,
					
					remote:matchLang.CREDENTIALNUM_REPEAT
				},
				unit:matchLang.ORGANISE_REQUIRED,
				job:matchLang.JOB_SELECT_REQUIRED,
				address:matchLang.ADDRESS_REQUIRED,
				code:{required:matchLang.POSTCODE_REQUIRED,digits:matchLang.REQUIRED_DIGITS},
				tel:{digits:matchLang.REQUIRED_DIGITS},
				mobile:{digits:matchLang.REQUIRED_DIGITS},
				agree:matchLang.ONLY_AGREE
			}
		});
		//$('#certype').change(function(){
		//	validator.element('#cernum');
		//});
		jQuery('#btnReg').click(function(){
//			if($('#certype').val()=='身份证'){
//				jQuery('#cernum').rules('add',{
//					idcard:true,
//					messages:{idcard:matchLang.INVALID_IDCARD}
//				});
//			}else{
//				jQuery('#cernum').rules('remove','idcard');
//			}
			if($('#tel').val()=='' && $('#mobile').val()==''){
				$('#tel').rules('add',{
					required:true,
					messages:{required:matchLang.MOBILE_OR_TEL_REQUIRED}
				});
			}else{
				$('#tel').rules('remove');
			}
			jQuery('#regForm').ajaxSubmit({
				dataType:'json',
				url:'/index/ajax-reg-personal',
				beforeSubmit:function(){
					if(!jQuery('#regForm').valid()){
						return false;
					}
					jQuery('#btnReg').attr('disabled',true);
				},
				error:function(){
					jQuery('#btnReg').attr('disabled',false);
				},
				success:function(data){
					jQuery('#btnReg').attr('disabled',false);
					if(data){
						if(data.error){
							showMsg('noticeMsg',data.msg,'error');
						}else{
							jQuery('#signup-btn').attr('disabled',true);
							showMsg('noticeMsg',data.msg,'success');
							if(data.signInHtml!=''){
								jQuery('body').append(data.signInHtml);
							}
							alert(data.msg);
							jumpUrl='/index/upload/';
							//注册成功后，自动登陆到上传页面
							setTimeout("window.location.href ='"+jumpUrl+"';", 1000);
						}
					}
				}
			});
		});
	},
	//团队注册
	regTeamReady:function(){
		$('#tabs').tabs();
		$('#birthday').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		$('#birthday1').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		$('#birthday2').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		$('#birthday3').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		$('#birthday4').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		$("#regForm :input[title!='']").tooltip({

			// place tooltip on the right edge
			position: "center right",

			// a little tweaking of the position
			offset: [-2, 10],

			// use the built-in fadeIn/fadeOut effect
			effect: "fade",

			onBeforeShow:function(){
				if($(this.getTrigger()).is('.error')){
					return false;
				}
			}

		});
		var container = jQuery('div.error_container');
		var errorUserIndex = new Array();
		var validator = jQuery("#regForm").validate({
			//errorContainer: container,
			//errorLabelContainer: jQuery("ol", container),
			//wrapper: 'li',
			errorPlacement: function(label, element) {
				if(element.is('#password')){
					element.parent().append('<br/>');
					element.parent().append(label);
				}else if (element.is("textarea")) {
					label.insertAfter(element.next());
				} else if (element.is("select")){
					element.parent().append(label);
				} else {
					label.insertAfter(element)
				}
				

			},
			rules:{
				username:{
					required:true,
					remote:'/index/ajax-test-user'
				},
				password:{
					required:true,
					minlength:6
				},
				repassword:{
					required:true,
					minlength:6,
					equalTo: "#password"
				},
				email:{
					required:true,
					email: true,
					remote:'/index/ajax-test-email'
				},
				teamname:{
					required:true,
					remote:'/index/ajax-test-team'
				},
				realname:{
					required:true
				},
				realname1:{
					required:true
				},
				birthday:{
					required:true
				},
				cernum:{required:true},
				unit:{required:true},
				job:{required:true},
				address:{required:true},
				code:{required:true,digits:true},
				tel:{digits:true},
				mobile:{digits:true},
				agree:{required:true}
			},
			messages:{
				username:{
					required:matchLang.USERNAME_REQUIRED,
					remote:matchLang.USERNAME_VALID_RULE
				},
				password:matchLang.PASSWORD_VALID_RULE,
				repassword:{
					required:matchLang.CONFIRM_PASSWORD_REQUIRED,
					minlength:matchLang.CONFIRM_PASSWORD_INVALID,
					equalTo:matchLang.PASSWORD_CONFIRM
				},
				email:{required:matchLang.EMAIL_REQUIRED,email:matchLang.INVALID_EMAIL,remote:matchLang.INVALID_EMAIL},
				
				realname:matchLang.TEAM_LEADER_REALNAME_REQUIRED,
				birthday:matchLang.TEAM_LEADER_BIRTHDATE_REQUIRED,
				cernum:{required:matchLang.IDCARD_REQUIRED},
				unit:matchLang.ORGANISE_REQUIRED,
				job:matchLang.TEAM_LEADER_JOB_REQUIRED,
				address:matchLang.TEAM_LEADER_ADDRESS_REQUIRED,
				code:matchLang.TEAM_LEADER_ZIPCODE_REQUIRED,
				code:{required:matchLang.POSTCODE_REQUIRED,digits:matchLang.REQUIRED_DIGITS},
				tel:{digits:matchLang.REQUIRED_DIGITS},
				mobile:{digits:matchLang.REQUIRED_DIGITS},
				agree:matchLang.ONLY_AGREE,
				teamname:{
					required:matchLang.TEAMNAME_REQUIRED,
					remote:matchLang.TEAM_EXIST
				}
			}
		});
		jQuery('#certype').change(function(){
//			if(this.value=='身份证'){
//				jQuery('#cernum').rules('add',{
//					idcard:true,
//					messages:{idcard:matchLang.INVALID_IDCARD}
//				});
//			}else{
//				jQuery('#cernum').rules('remove','idcard');
//			}
		});
		//成员一必填
		addUserValidate(1);
		jQuery('#realname2,#realname3,#realname4').keyup(function(){
			num = $(this).attr('id').replace('realname','');
			this.value = $.trim(this.value);
			if(this.value!=''){
				addUserValidate(num);
			}else{
				removeUserValidate(num);
			}
		});
		
		jQuery('#signup_btn').click(function(){
			errorUserIndex = new Array();
//			if($('#certype').val()=='身份证'){
//				jQuery('#cernum').rules('add',{
//					idcard:true,
//					messages:{idcard:matchLang.INVALID_IDCARD}
//				});
//			}else{
//				jQuery('#cernum').rules('remove','idcard');
//			}
			if($('#tel').val()=='' && $('#mobile').val()==''){
				$('#tel').rules('add',{
					required:true,
					messages:{required:matchLang.TEAM_LEADER_TELMOBILE_REQUIRED}
				});
			}else{
				$('#tel').rules('remove');
			}
			testUserContact(1);
			testUserContact(2);
			testUserContact(3);
			testUserContact(4);

			
			jQuery('#regForm').ajaxSubmit({
				dataType:'json',
				url:'/index/ajax-reg-team',
				beforeSubmit:function(data){
				    if(!jQuery('#regForm').valid()){
				    	alert(matchLang.FORM_INVALID_TEAM);
				    	for(z=1;z<=5;z++){
				    		if($('#team_user'+z+' input.error').length>0||$('#team_user'+z+' select.error').length>0){
				    			$('a[href=#team_user'+z+']').css('color','red');
				    		}else{
				    			$('a[href=#team_user'+z+']').css('color','');
				    		}
			    		}
				    	return false;
					}
				},
				success:function(data){
					
					if(data){
						if(data.error){
							showMsg('noticeMsg',data.msg,'error');
						}else{
							jQuery('#signup-btn').attr('disabled',true);
							showMsg('noticeMsg',data.msg,'success');
							if(data.signInHtml!=''){
								jQuery('body').append(data.signInHtml);
							}
							alert(data.msg);
							jumpUrl='/index/upload/';
							//注册成功后，自动登陆到上传页面
							setTimeout("window.location.href ='"+jumpUrl+"';", 1000);
						}
					}
					
//					if(data.error){
//						alert(data.msg);
//					}else{
//						location.href='/index/login';
//					}
				}
			});
		});
	},
	//个人修改
	updateProfileReady:function(){
		jQuery('#birthday').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		var container = jQuery('div.error_container');
		
		var validator = jQuery("#regForm").validate({
			//errorContainer: container,
			//errorLabelContainer: jQuery("ol", container),
			//wrapper: 'li',
			errorPlacement: function(label, element) {
				if(element.is('#password,#realname,#cernum,#address')){
					element.parent().append('<br/>');
					element.parent().append(label);
					if(element.is('#cernum')){
						label.css('background','none');
						label.css('paddig-left','0');
						label.css('margin-left','0');
					}
				}else if (element.is("textarea")) {
					label.insertAfter(element.next());
				} else if (element.is("select")){
					element.parent().append(label);
				} else {
					label.insertAfter(element)
				}
			},
			rules:{
				password:{
					minlength:6
				},
				repassword:{
					minlength:6,
					equalTo: "#password"
				},
				email:{
					required:true,
					email: true,
					remote:'/index/ajax-test-email'
				},
				birthday:{
					required:true
				},
				cernum:{required:true,remote:{
					url: "/index/ajax-test-credential",
			        type: "post",
			        data: {
						certype: function() {
			            	return jQuery('#certype').val();
			        	}
					}
					
				}},
				unit:{required:true},
				job:{required:true},
				address:{required:true},
				code:{required:true}
			},
			messages:{
				
				password:matchLang.PASSWORD_VALID_RULE,
				repassword:{
					required:matchLang.CONFIRM_PASSWORD_REQUIRED,
					minlength:matchLang.CONFIRM_PASSWORD_INVALID,
					equalTo:matchLang.PASSWORD_CONFIRM
				},
				email:{required:matchLang.EMAIL_REQUIRED,email:matchLang.INVALID_EMAIL,remote:matchLang.INVALID_EMAIL},
				
				birthday:matchLang.BIRTHDATE_REQUIRED,
				cernum:{required:matchLang.IDCARD_REQUIRED,remote:matchLang.CREDENTIALNUM_REPEAT},
				unit:matchLang.ORGANISE_REQUIRED,
				job:matchLang.JOB_SELECT_REQUIRED,
				address:matchLang.ADDRESS_REQUIRED,
				code:matchLang.POSTCODE_REQUIRED
			}
		});
		//$('#certype').change(function(){
		//	validator.element('#cernum');
		//});
		jQuery('#btnReg').click(function(){
//			if($('#certype').val()=='身份证'){
//				jQuery('#cernum').rules('add',{
//					idcard:true,
//					messages:{idcard:matchLang.INVALID_IDCARD}
//				});
//			}else{
//				jQuery('#cernum').rules('remove','idcard');
//			}
			if($('#tel').val()=='' && $('#mobile').val()==''){
				$('#tel').rules('add',{
					required:true,
					messages:{required:matchLang.MOBILE_OR_TEL_REQUIRED}
				});
			}else{
				$('#tel').rules('remove');
			}
			jQuery('#regForm').ajaxSubmit({
				dataType:'json',
				url:'ajax-update-profile',
				beforeSubmit:function(){
					jQuery('#noticeMsg').hide();
					if(!jQuery('#regForm').valid()){
						return false;
					}
					jQuery('#btnReg').attr('disabled',true);
				},
				error:function(){
					jQuery('#btnReg').attr('disabled',false);
				},
				success:function(data){
					jQuery('#btnReg').attr('disabled',false);
					if(data){
						if(data.error){
							showMsg('noticeMsg',data.msg,'error');
						}else{
							jQuery('#signup-btn').attr('disabled',true);
							showMsg('noticeMsg',data.msg,'success');
							
						}
					}
				}
			});
		});
	},
	//团队修改
	updateProfileTeamReady:function(){
		$('#tabs').tabs();
		$('#birthday').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		$('#birthday1').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		$('#birthday2').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		$('#birthday3').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		$('#birthday4').datepick({dateFormat: 'yy-mm-dd',yearRange:'1910:2010'});
		var container = jQuery('div.error_container');
		var validator = jQuery("#regForm").validate({
			//errorContainer: container,
			//errorLabelContainer: jQuery("ol", container),
			//wrapper: 'li',
			errorPlacement: function(label, element) {
				if(element.is('#password')){
					element.parent().append('<br/>');
					element.parent().append(label);
				}else if (element.is("textarea")) {
					label.insertAfter(element.next());
				} else if (element.is("select")){
					element.parent().append(label);
				} else {
					label.insertAfter(element)
				}
			},
			rules:{
				password:{
					minlength:6
				},
				repassword:{
					minlength:6,
					equalTo: "#password"
				},
				email:{
					required:true,
					email: true,
					remote:'/index/ajax-test-email'
				},
				teamname:{
					required:true,
					remote:'/index/ajax-test-team'
				},
				realname:{
					required:true
				},
				birthday:{
					required:true
				},
				cernum:{required:true},
				unit:{required:true},
				job:{required:true},
				address:{required:true},
				code:{required:true}
			},
			messages:{
				password:matchLang.PASSWORD_VALID_RULE,
				repassword:{
					minlength:matchLang.CONFIRM_PASSWORD_INVALID,
					equalTo:matchLang.PASSWORD_CONFIRM
				},
				email:{required:matchLang.EMAIL_REQUIRED,email:matchLang.INVALID_EMAIL,remote:matchLang.INVALID_EMAIL},
				
				realname:matchLang.TEAM_LEADER_REALNAME_REQUIRED,
				birthday:matchLang.TEAM_LEADER_BIRTHDATE_REQUIRED,
				cernum:{required:matchLang.IDCARD_REQUIRED,remote:matchLang.CREDENTIALNUM_REPEAT},
				unit:matchLang.ORGANISE_REQUIRED,
				job:matchLang.TEAM_LEADER_JOB_REQUIRED,
				address:matchLang.TEAM_LEADER_ADDRESS_REQUIRED,
				code:matchLang.TEAM_LEADER_ZIPCODE_REQUIRED,
				teamname:{
					required:matchLang.TEAMNAME_REQUIRED,
					remote:matchLang.TEAM_EXIST
				}
			}
		});
		//成员一必填
		addUserValidate(1);
		jQuery('#realname2,#realname3,#realname4').keyup(function(){
			num = $(this).attr('id').replace('realname','');
			this.value = $.trim(this.value);
			if(this.value!=''){
				addUserValidate(num);
			}else{
				removeUserValidate(num);
			}
		})
		jQuery('#signup_btn').click(function(){
//			if($('#certype').val()=='身份证'){
//				jQuery('#cernum').rules('add',{
//					idcard:true,
//					messages:{idcard:matchLang.INVALID_IDCARD}
//				});
//			}else{
//				jQuery('#cernum').rules('remove','idcard');
//			}
			if($('#tel').val()=='' && $('#mobile').val()==''){
				$('#tel').rules('add',{
					required:true,
					messages:{required:matchLang.TEAM_LEADER_TELMOBILE_REQUIRED}
				});
			}else{
				$('#tel').rules('remove');
			}
			testUserContact(1);
			testUserContact(2);
			testUserContact(3);
			testUserContact(4);

			
			jQuery('#regForm').ajaxSubmit({
				dataType:'json',
				url:'/index/ajax-update-teamprofile',
				beforeSubmit:function(data){
				    if(!jQuery('#regForm').valid()){
				    	alert(matchLang.FORM_INVALID_TEAM);
				    	for(z=1;z<=5;z++){
				    		if($('#team_user'+z+' input.error').length>0||$('#team_user'+z+' select.error').length>0){
				    			$('a[href=#team_user'+z+']').css('color','red');
				    		}else{
				    			$('a[href=#team_user'+z+']').css('color','');
				    		}
			    		}
					    return false;
					}
				},
				success:function(data){
					alert(data.msg);
					if(data.error){
						showMsg('noticeMsg',data.msg,'error');
					}else{
						showMsg('noticeMsg',data.msg,'success');
					}
					
				}
			});
		});
	},
	//myworks
	myWorksReady:function(){
		//showUploadFile();
	},
	//上传表单
	uploadReady:function(){
		jQuery(document).ready(function(){
			addJpgFormatMethod();
			jQuery('#parti').click(function(){
				if(this.checked){
					jQuery('#category').show();
				}else{
					jQuery('#category').hide();
				}
			})
			jQuery('#uploadFrm').validate({
				rules:{
					soft:{required:true,minlength:1},
					fileField1:{required:true,jpgFormat:true}
				},
				messages:{
					fileField1:{
						jpgFormat:matchLang.JPGFORMAT_REQUIRED
					}
				}
			});
			jQuery('#uploadWorks').click(function(){
				tmpArray = new Array();
				jQuery('input[name=soft][type=checkbox]').each(function(){
					if(this.checked)
						tmpArray.push(this.value);
					else
						tmpArray.push('');
				});
				jQuery('#hidSofts').val(tmpArray.join(','));
				jQuery('#uploadFrm').ajaxSubmit({
					url:'/index/ajax-upload',
					dataType:'json',
					beforeSubmit:function(){
						if(!jQuery('#uploadFrm').valid()){
							return false;
						}
						
						showMsg('waitVerify',matchLang.UPLOADING_WORK,'notice');
						jQuery('#uploadWorks').attr('disabled',true);
					},
					error:function(){
						jQuery('#uploadWorks').attr('disabled',false);
					},
					success:function(data){
						jQuery('#uploadWorks').attr('disabled',false);
						if(data){
							if(data.error){
								showMsg('waitVerify',data.msg,'error');
								alert(data.msg);
							}else{
								setTimeout("window.location.href ='/index/show';", 1000);
							}
						}
					}
				});
			});
		});
	},
	//修改作品
	editWorksReady:function(){
		addJpgFormatMethod();
		jQuery('#parti').click(function(){
			if(this.checked){
				jQuery('#category').show();
			}else{
				jQuery('#category').hide();
			}
		})
		jQuery('#editForm').validate({
			rules:{
				soft:{required:true,minlength:1},
				fileField1:{required:true,jpgFormat:true}
			},
			messages:{
				fileField1:{
					jpgFormat:matchLang.JPGFORMAT_REQUIRED
				}
			}
		});
		jQuery('#button').click(function(){
			tmpArray = new Array();
			jQuery('input[name=soft][type=checkbox]').each(function(){
				
				if(this.checked)
					tmpArray.push(this.value);
				else
					tmpArray.push('');
			});
			jQuery('#hidSofts').val(tmpArray.join(','));
			
			jQuery('#editForm').ajaxSubmit({
				url:'/index/ajax-edit',
				dataType:'json',
				beforeSubmit:function(){
					if(!jQuery('#editForm').valid()){
						return false;
					}
					showMsg('showMsgList',matchLang.UPLOADING_WORK,'notice');
					jQuery('#button').attr('disabled',true);
				},
				error:function(){
					jQuery('#button').attr('disabled',false);
				},
				success:function(data){
					jQuery('#button').attr('disabled',false);
					if(data){
						if(data.error){
							showMsg('showMsgList',data.msg,'error');
							alert(data.msg);
						}else{
							alert(data.msg);
							parent.tb_remove();
							parent.location.href = parent.location.href;
						}
					}
				}
			});
		});
	},
	//投票
	voteReady:function(){
		jQuery('#voteForm').validate({
			rules:{
				pid:{required:true,minlength:1}
			}
		});
		jQuery('#btnVote').click(function(){
			tmpArray = new Array();
			jQuery('input[name=pid][type=checkbox]:checked').each(function(){
				tmpArray.push(this.value);
			});
			jQuery('#pids').val(tmpArray.join(','));
			
			jQuery('#voteForm').ajaxSubmit({
				url:'/index/ajaxvote',
				dataType:'json',
				beforeSubmit:function(){
					
					if(!jQuery("#voteForm").valid()){
				    	return false;
				    }
					jQuery('#btnVote').attr('disabled',true);
				},
				error:function(){
					jQuery('#btnVote').attr('disabled',false);
				},
				success:function(data){
					jQuery('#btnVote').attr('disabled',false);
					if(data){
						if(data.error){
							//showMsg('waitVerify',data.msg,'error');
							alert(data.msg);
						}else{
							alert(data.msg);
							//showMsg('waitVerify',data.msg,'error');
						}
					}
				}
			});
		});
	}
}
function addUserValidate(num){
	$('#realname'+num).rules('add',{
		required:true,
		messages:{required:jQuery.format(matchLang.TEAM_MEMBER_NAME_REQUIRED,num)}
	});
	$('#birthday'+num).rules('add',{
		required:true,
		messages:{required:jQuery.format(matchLang.TEAM_MEMBER_BIRTHDAY_REQUIRED,num)}
	});
	$('#cernum'+num).rules('add',{
		required:true,
		
		messages:{required:matchLang.IDCARD_REQUIRED}
	});
//	$('#certype'+num).change(function(){
//		if(this.value=='身份证'){
//			$('#cernum'+num).rules('add',{
//				idcard:true,
//				messages:{idcard:matchLang.INVALID_IDCARD}
//			});
//		}else{
//			$('#cernum'+num).rules('remove','idcard');
//		}
//	});	
	
	$('#job'+num).rules('add',{
		required:true,
		messages:{required:jQuery.format(matchLang.TEAM_MEMBER_JOB_REQUIRED,num)}
	});
	$('#unit'+num).rules('add',{
		required:true,
		messages:{required:jQuery.format(matchLang.TEAM_MEMBER_ORGANISE_REQUIRED,num)}
	});
	$('#address'+num).rules('add',{
		required:true,
		messages:{required:jQuery.format(matchLang.TEAM_MEMBER_ADDRESS_REQUIRED,num)}
	});
	$('#code'+num).rules('add',{
		required:true,
		messages:{required:jQuery.format(matchLang.TEAM_MEMBER_ZIPCODE_REQUIRED,num)}
	});
	$('#tel'+num).rules('add',{
		digits:true,
		messages:{digits:matchLang.REQUIRED_DIGITS}
	});
	$('#mobile'+num).rules('add',{
		digits:true,
		messages:{digits:matchLang.REQUIRED_DIGITS}
	});
}
function removeUserValidate(num){
	$('#birthday'+num).rules('remove');
	$('#cernum'+num).rules('remove');
	$('#job'+num).rules('remove');
	$('#unit'+num).rules('remove');
	$('#address'+num).rules('remove');
	$('#code'+num).rules('remove');
	$('#tel'+num).rules('remove');
	$('#mobile'+num).rules('remove');
}
function testUserContact(num){
	if($('#realname'+num).val()!='' && $('#tel'+num).val()=='' && $('#mobile'+num).val()==''){
		$('#tel'+num).rules('add',{
			required:true,
			digits:true,
			messages:{required:jQuery.format(matchLang.TEAM_MEMBER_TELMOBILE_REQUIRED,num),digits:matchLang.REQUIRED_DIGITS}
		});
	}else{
		$('#tel'+num).rules('remove');
	}
}


function upLoadFile(type){
	id = 'upload'+type;
	upid = 'uploadFile'+type;
	jQuery('#'+id).css("display","none");
	jQuery('#'+upid).css("display","block");

}
function unUpload(type){
	id = 'upload'+type;
	upid = 'uploadFile'+type;
	jQuery('#'+id).css("display","block");
	jQuery('#'+upid).css("display","none");

}
function showUploadFile(){
	var i; 
	for(i=1;i<=3;i++){
		if(jQuery('#sumCount'+i).val()<8){
			jQuery('#showUploadFile'+i).css("display","block");
		}
		if(jQuery('#sumCount'+i).val()>=8){
			jQuery('#showUploadFile'+i).css("display","none");
		}
	}
}
function editInfo(id){
	if(id>0){
		tb_show('修改作品信息','/index/ajax-editinfo?pid='+id+'&KeepThis=true&TB_iframe=true&height=360&width=430&modal=true',false);
	}
}
function addJpgFormatMethod(){
	jQuery.validator.addMethod("jpgFormat", function(value, element,param) {
		fileExtList = 'jpg';
		checkValue      = value.toLowerCase();
	    fileExtList     = fileExtList.toLowerCase();
	    extListArray    = fileExtList.split(",");
	    checkValueArray = checkValue.split(".");
	    flag            = 0;
	    if (checkValueArray.length<=1)
	        return false;
	    valueExt        = checkValueArray[checkValueArray.length-1];

	    for(i=0;i<extListArray.length;i++){
	    	strExt = extListArray[i].length;
	    	if (valueExt==extListArray[i]){
	    		flag=1
	    		break;
	    	}
	    }
	    if (flag!=1){
	        return false;
	    }
	    return true;
	});
}
function deleUploadFile(n,id,pid){
	if(confirm('确定删除?'))
	jQuery('#showPic'+n).load("/index/ajaxupload-file",{delId:id,isn:n,pid:pid});
}
function deleFileRar(fileid,id,n){
	
	if(confirm('确定删除?'))
	jQuery('#showPic'+n).load("/index/ajaxupload-file",{delId:fileid,isn:n,pid:id});
}
function uploadFileAgain(n,id,nums){
	
	jQuery('#button'+n).attr('disabled',true);
	jQuery('#showLog'+n).html('waiting....');
	jQuery('#uploadForm'+n).ajaxSubmit({
		url:'/index/ajaxupload-again/nums/'+nums+'/shown/'+n,
		dataType:'json',
		beforeSubmit:function(){
			
			if(!jQuery('#uploadForm'+n).valid()){
				jQuery('#showPic'+n).load("/index/ajaxupload-file",{pid:id,isn:n});
				return false;
			}
		},
		success:function(data){
			if(data){
				if(data.error){
					alert(data.msg);
					jQuery('#button'+n).attr('disabled',false);
				}else{
					jQuery('#showPic'+n).load("/index/ajaxupload-file",{pid:id,isn:n});
				}
			}
		}
	});
}
function uploadFileRar(id,n){

	jQuery('#buttonFile'+n).attr('disabled',true);
	jQuery('#showLogRar'+n).html('waiting....');
	jQuery('#uploadFormFileRar'+n).ajaxSubmit({
		url:'/index/ajaxupload-again/uploadRarId/'+id+'/shown/'+n,
		dataType:'json',
		beforeSubmit:function(){
			if(!jQuery('#uploadFormFileRar'+n).valid()){
				jQuery('#buttonFile'+n).attr('disabled',false);
				//jQuery('#showPic'+n).load("/index/ajaxupload-file",{pid:id,isn:n});
				return false;
			}
		},
		success:function(data){
			if(data){
				if(data.error){
					alert(data.msg);
					jQuery('#buttonFile'+n).attr('disabled',false);
				}else{
					jQuery('#showPic'+n).load("/index/ajaxupload-file",{pid:id,isn:n});
				}
			}
		}
	});
}
function reuploadFile(type,id,n){
	jQuery('#reUpload'+type).attr('disabled',true);
	jQuery('#showMsgs'+type).html('waiting....');
	jQuery('#uploadForm'+type).ajaxSubmit({
		url:'/index/ajax-reupload/shown/'+type,
		dataType:'json',
		beforeSubmit:function(){
			
			if(!jQuery('#uploadForm'+type).valid()){
				jQuery('#showPic'+n).load("/index/ajaxupload-file",{pid:id,isn:n});
				return false;
			}
		},
		success:function(data){
			if(data){
				if(data.error){
					alert(data.msg);
					jQuery('#reUpload'+type).attr('disabled',false);
				}else{
					location.reload();
					//jQuery('#showPic'+n).load("/index/ajaxupload-file",{pid:id,isn:n});
				}
			}
		}
	});
}