userinfo.js 8.94 KB

function createDay(year,month, day){
	var monthArray=new Array(4,6,9,11);
	var html='';
	var dayNum = 31;
	if(jQuery.inArray(month,monthArray) != -1){
		dayNum = 30;
	}else if(month == 2 && 0 == year % 4 && (year % 100 !=0 || year % 400 == 0)){
		dayNum = 29;
	}else{
		dayNum = 28;
	}
	var select = '';
	for(var i = 1; i <= dayNum; i++){
		if(day == i){
			select = 'selected';
		}
		html += '<option value="'+i+'" '+ select +'>'+i+'日</option>';
	}
	return html;
}
function fillBirth(year, month, day){
	if(typeof(year) == 'undefined' || typeof(month) == 'undefined')
	{
		year = jQuery('#year').val();
		month = jQuery('#month').val();
	}
	jQuery("#month option[value='"+month+"']").attr("selected", true);
	jQuery('#day').html(createDay(year,month, day));
}

var edui=com=ii=1001;
var yearstring='';
var industry='';
var position='';

$().ready(function() {
	$('#updateForm input').focus(function(){
		var cls = $('#'+this.id).attr('class');
		if(cls != 'input_1 error'){
			$("#"+this.id+"_dl").attr('class','tips-box-text');
		}
	}); 
	$('#updateForm input').blur(function() {
		var cls = $('#'+this.id).attr('class');
		if(cls != 'input_1 error'){
			$("#"+this.id+"_dl").removeClass();
		}
	});
	$("#updateForm").validate({
		rules : {
			email : {
				required : true,
				minlength : 6,
				email : true,
			},
			nickname : {
				minlength : 2,
				required:true,
				maxlength : 15
			},
			name: {
				required : true,
				minlength : 2,
				maxlength : 5
			},
			char_id : {
				required : false,
				minlength : 15,
				maxlength : 18
			}
		},
		messages : {
			email : {
				required : function(val, obj){
					return validateRight( "此邮箱将作为您的登录邮箱!" ,obj.id); 
				},
				minlength : function(val, obj){
					return validateRight( "Email地址太短,最少6位!" ,obj.id);
				},
				email : function(val, obj){
					return validateRight("请填写正确的格式" ,obj.id); 
				}
			},
			nickname: {
				minlength : function(val, obj){
					return validateRight( "您的昵称太短,最少1位!" ,obj.id);
				},
				required : function(val, obj){
					return validateRight( "请输入昵称!" ,obj.id); 
				},
				maxlength : function(val, obj){
					return validateRight( "您的昵称太长,最长30位!" ,obj.id);
				}
			},
			name : {
				required : function(val, obj){
					return validateRight( "请输入真实姓名!" ,obj.id); 
				},
				minlength : function(val, obj){
					return validateRight( "真实姓名太短,最少2位!" ,obj.id);
				},
				maxlength : function(val, obj){
					return validateRight( "真实姓名最长5位!" ,obj.id);
				}
			},
			char_id : {
				minlength : function(val, obj){
					return validateRight( "身份证最短15位!" ,obj.id);
				},
				maxlength : function(val, obj){
					return validateRight( "身份证最长18位!" ,obj.id);
				}
			}
		},
		success:function(label){
			var htmlfor = label.attr('for');
			var cls = $('#'+htmlfor).attr('class');
			if(cls != 'input_1 valid'){
				$("#"+htmlfor+"_dl").attr('class','tips-box-text');
				$("#c_"+htmlfor).attr('class','tips-right').html('&nbsp;');
			}
		}
	});
	
	$("#form3").validate({
		debug:false,
		rules : {
			phone:{
				required:function(){
					if( !$('#mobile').val() ){
						return true;
					}
					return false;
				}
			},
			mobile:{
				required:function(){
					if( !$('#phone').val() ){
						return true;
					}
					return false;
				},
				number:true
			},
			msn : {
				email : true
			},
			qq : {
				number:true
			},
			zip_code : {
				zipCode : true
			}
		},
		messages : {
			phone:{
				required : function(val, obj){
					return validateRight( "固定电话和手机必填一个" ,obj.id);
				},
				number : function(val, obj){
					return validateRight( "固定电话必须是数字" ,obj.id); 
				}
			},
			mobile:{
				required:function(val, obj){
					return validateRight("固定电话和手机必填一个" ,obj.id);
				},
				number : function(val, obj){
					return validateRight( "手机必须是数字" ,obj.id); 
				}
			},
			msn : {
				email : function(val,obj){
					return validateRight('您输入的MSN地址有误,请重新输入',obj.id);
				}
			},
			qq : {
				number: function(val, obj){
					return validateRight( "QQ号码必须是数字" ,obj.id); 
				}
			},
			zip_code : {
				zipCode : function(val, obj){
					return validateRight('您输入的邮编号有误,请重新输入',obj.id);
				}
			}
			
		},
		success:function(label){
			var htmlfor = label.attr('for');
			var cls = $('#'+htmlfor).attr('class');
			if(cls != 'input_1 valid'){
				$("#c_"+htmlfor).show('fast',function(){
					if( htmlfor == 'phone'){
						$("#mobile_dl").removeClass();
						$("#error_mobile").empty();
					}else if(htmlfor == 'mobile'){
						$("#phone_dl").removeClass();
						$("#error_phone").empty();
					}
					$("#"+htmlfor+"_dl").removeClass();
					$("#c_"+htmlfor).attr('class','tips-p');
				});
			}
		}
	});
	
	
	
	jQuery("#box2").hide();jQuery("#box3").hide();jQuery("#box4").hide();
	jQuery("#box2").hide();
	jQuery("#box3").hide();
	jQuery("#box4").hide();
	jQuery('#year').change(function(){
		fillBirth();
	});
    jQuery('#month').change(function(){
		fillBirth();
	});
	var area_code = jQuery("#contacts_area").val();
	if(typeof(area_code) != 'undefined'){
		var province_code = area_code.substr(0,2);
		var city_code = area_code.substr(0,4);
	}
	getarea(0, $("#province"), '请选择省',area_code);
	getarea(province_code, $("#city"), '请选择市',area_code);
	getarea(city_code, $("#area_code"), '请选择区县',area_code);
	
    jQuery("#province").change(function(){ jQuery("#area_code").empty();jQuery("#area_code").hide(); getarea(jQuery(this).val(), jQuery("#city"), '请选择市',''); });
    jQuery("#city").change(function(){jQuery("#area_code").show();  getarea(jQuery(this).val(), jQuery("#area_code"), '请选择区县',''); });
	
    yearstring=jQuery('#education_time').html();
    industry=jQuery('#industry_parent').html();
    position=jQuery('#position_parent').html();
    var html=jQuery('#EDUCATION_temp').html();
	jQuery('#add_universty').click(function(){
		var temp=html.replace(/EDUCATION/g,'universty');
		temp=temp.replace(/EDU_TYPE/,'4');
		temp=replace_string(temp,edui,yearstring);
		jQuery('#universty').append(temp);
		edui++;
	});
	jQuery('#add_highschool').click(function(){
		var temp=html.replace(/EDUCATION/g,'highschool');
		temp=temp.replace(/EDU_TYPE/,'3');
		temp=replace_string(temp,edui,yearstring);
		jQuery('#highschool').append(temp);
		edui++;
	});
	jQuery('#add_juniorschool').click(function(){
		var temp=html.replace(/EDUCATION/g,'juniorschool');
		temp=temp.replace(/EDU_TYPE/,'2');
		temp=replace_string(temp,edui,yearstring);
		jQuery('#juniorschool').append(temp);
		edui++;
	});
	jQuery('#add_gradeschool').click(function(){
		var temp=html.replace(/EDUCATION/g,'gradeschool');
		temp=temp.replace(/EDU_TYPE/,'1');
		temp=replace_string(temp,edui,yearstring);
		jQuery('#gradeschool').append(temp);
		edui++;
	});
	jQuery('#add_company').click(function(){
		var html=jQuery('#company_temp').html();
		html=html.replace(/PID/g,com);
		html=html.replace(/YEAR_STRING/g,yearstring);
		html=html.replace(/INDUSTRY_STRING/,industry);
		html=html.replace(/POSITION_STRING/,position);
		jQuery('#company').append(html);
		fillBlank('company_add_industry1_'+com,'company_add_industry2_'+com,'industry');
		fillBlank('company_add_position1_'+com,'company_add_position2_'+com,'position');
		com++;
	});
	jQuery('#add_hobby').click(function(){
		var html=jQuery('#hobby_temp').html();
		html=html.replace(/PID/g,ii);
		jQuery('#hobby').append(html);
		ii++;
	});
	
	jQuery(".tt").click(function(){
		var temp=jQuery(this).attr('lin');
		jQuery("#"+temp).toggle('slow');
	});    
});


function replace_string(html,num,yearstring){
	html=html.replace(/PID/g,num);
	html=html.replace(/YEAR_STRING/,yearstring);
	return html;
}


function fillBlank(pos1,pos2,type){
	var pid=jQuery("#"+pos1).val();
	jQuery("#"+pos1+" option[value='"+pid+"']").attr("selected", true);
	jQuery("#"+pos2).empty();
	var dataSub = positionSub[pid];
	if(type == 'industry'){
		dataSub = industrySub[pid];
	}
	for(var i in dataSub){
    	var val = dataSub[i];
    	var value = '';
    	if(type == 'industry')
    	{
    		value = val.industry_name;
    	}else
		{
    		value = val.position_name;
		}
    	jQuery("#"+pos2).append("<option value='"+val.id+"'>"+value+"</option>");
    }
}

function ajax_delete(pre, id, url){
	if(confirm('确定要删除这条记录?')){
		jQuery.ajax({
	    	type: "GET",
	        url: "/home/userinfo/"+url,
	        data: 'id=' + id,
	        dataType:'json',
	        cache:false,
	        success: function(jsonData)
            {
            	if(jsonData.code == 200){
            		if(url=='dethobby'){
              		  jQuery('#'+pre+id+' input').val('');
      	        	  return;
              		}
	        		delete_all(pre+id);
            		return;
                }
            	alert(jsonData.message);
            	return false;
            }
	  });
	}
}

function delete_all(id){
	jQuery('#'+id).hide('slow');
	jQuery('#'+id).remove();
}