﻿/*培训学员查询配置文件*/
var filterFormElementsValidationConfig = {
	trainingName:{/*培训名称*/
		required:false,
		id:'training-name',
		tipId:'',
		type:'input',
		txt:{
			normal:'',
			notValid:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	studentName:{/*姓名*/
		required:false,
		id:'student-name',
		tipId:'',
		type:'input',
		txt:{
			normal:'',
			notValid:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	trainingAddress:{/*培训地点*/
		required:false,
		id:'training-address',
		tipId:'',
		type:'input',
		txt:{
			normal:'',
			notValid:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	channelFrom:{/*渠道来源*/
		required:false,
		id:'channel-from',
		tipId:'',
		type:'input',
		txt:{
			normal:'',
			notValid:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	trainingState:{/*状态*/
		required:false,
		id:'training-state',
		tipId:'',
		type:'input',
		txt:{
			normal:'',
			notValid:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	trainingTimeStart:{/*开始时间*/
		required:false,
		id:'training-time-start',
		tipId:'',
		type:'input',
		txt:{
			normal:'',
			notValid:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	trainingTimeEnd:{/*结束时间*/
		required:false,
		id:'training-time-end',
		tipId:'',
		type:'input',
		txt:{
			normal:'',
			notValid:'',
			exist:'。'
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	}
};
var addStudentFormElementsValidationConfig ={
	loginId:{/*用户ID*/
		required:false,
		id:'login-id',
		tipId:'v-login-id',
		type:'input',
		txt:{
			normal:'请输入您的用户名。',
			notValid:'请您输入由英文字母开头的4-20字母和数字，不支持中文和特殊字符。',
			exist:'您输入的登录名已经存在，请重新填写。'
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			if(!(/^[a-z][a-z0-9]{3,19}$/i.test(v))) return 'notValid';
		}
	},
	studentName:{/*姓名*/
		required:false,
		id:'student-name',
		tipId:'v-student-name',
		type:'input',
		txt:{
			normal:'请填写您的姓名。',
			notValid:'您的姓名含有特殊字符（@、#、$、%等），请重新填写。',
			exist:''
		},
		cls:{
			normal:'normal',
			notValid:'error',
			correct:'correct'
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			if(v.indexOf('@') > -1 || v.indexOf('#') > -1 || v.indexOf('$') > -1 || v.indexOf('%') > -1) return 'notValid';
		}
	},
	idCard:{/*身份证*/
		required:false,
		id:'id-card',
		tipId:'v-id-card',
		type:'input',
		txt:{
			normal:'请填写您的身份证号码。',
			notValid:'不符合规定！15位号码应全为数字，18位号码末位可以为数字或X。',
			exist:''
		},
		cls:{
			normal:'normal',
			notValid:'error',
			correct:'correct'
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			if(!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(v))) return 'notValid';
		}
	},
	phoneNumber:{/*固定电话*/
		required:false,
		id:'phone-number',
		tipId:'v-phone-number',
		type:'input',
		txt:{
			normal:'请填写真实的电话号码，以保证我们的服务人员能够联系上您。',
			notValid:'请您输入数字。',
			lessLength:'您输入的电话号码少于7位，请重新填写。',
			sameNumber:'请您不要输入相同的数字。',	
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			if(!(/^[\d\/\-]+$/.test(v)) || !(/\d/.test(v))) return 'notValid';
			if(v.length < 7) return 'lessLength';
			if(/^(\d)\1+$/.test(v)) return 'sameNumber';
		}
	},
	mobile:{/*手机*/
		required:false,
		id:'mobile',
		tipId:'v-mobile',
		type:'input',
		txt:{
			normal:'请填写真实的电话号码，以保证我们的服务人员能够联系上您。',
			notNumbers:'手机号码只能是数字，请重新填写。',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			if(!(/^\d+$/.test(v))) return 'notNumbers';
		}
	},
	email:{/*email*/
		required:false,
		id:'email',
		tipId:'v-email',
		type:'input',
		txt:{
			normal:'请填写有效的电子邮箱。',
			notValid:'您输入的电子邮箱格式不正确，请重新填写。如：abc@yahoo.cn',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			if(!(/^[\w\-]+(\.[\w\-]*)*@[\w\-]+([\.][\w\-]+)+$/.test(v))) return 'notValid';
		}
	},
	areaProvince:{/*省份*/
		required:false,
		id:'area-province',
		tipId:'',
		type:'select',
		txt:{
			normal:'',
			notValid:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	areaCity:{/*地级市*/
		required:false,
		id:'area-city',
		tipId:'',
		type:'select',
		txt:{
			normal:'',
			notValid:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	address:{/*具体地址*/
		required:false,
		id:'address',
		tipId:'v-address',
		type:'input',
		txt:{
			normal:'请填写具体地址。',
			notValid:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	postCode:{/*邮编*/
		required:false,
		id:'post-code',
		tipId:'v-post-code',
		type:'input',
		txt:{
			normal:'请输入邮编号码',
			notValid:'邮编号码应为6位数字。',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			if(!(/^\d+$/.test(v))) return 'notValid';
			if(v.length > 6) return 'notValid';
		}
	},
	schoolAge:{/*学历*/
		required:false,
		id:'school-age',
		tipId:'',
		type:'select',
		txt:{
			normal:'',
			denyWords:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	englishLevel:{/*英语水平*/
		required:false,
		id:'english-level',
		tipId:'',
		type:'select',
		txt:{
			normal:'',
			denyWords:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	expectedAddress:{/*期望培训地点*/
		required:false,
		id:'expected-address',
		tipId:'',
		type:'select',
		txt:{
			normal:'',
			denyWords:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	},
	remark:{
		required:false,
		id:'remark',
		tipId:'',
		type:'textarea',
		txt:{
			normal:'',
			denyWords:'',
			exist:''
		},
		cls:{
			normal:'',
			notValid:''
		},
		tracelog:{
			change:'',
			isNull:'',
			exist:'',
			notValid:''
		},
		check:function(v,lv,uv){
			//校验
		}
	}
};
!function(){
	var Y = YAHOO.util,
		D = Y.Dom,
		E = Y.Event,
		get = D.get;
	YAHOO.namespace("StudentManage");
	YAHOO.StudentManage={
		studentlistMouseEvent:function(){
			var TRS = D.getElementsBy(function(){return true;},"tr","result");
			for(var i=1,l = TRS.length;i<l;i++){
				(function(){
    				var TR = TRS[i];
    				E.on(TR,"mouseover",function(){
    					D.setStyle(TR,"background-color","#F8FCFF");
    				});
    				E.on(TR,"mouseout",function(){
    					D.setStyle(TR,"background-color","#fff");
    				});
				})();
			}
		},
		initFilterForm:function(){
			for(var i in filterFormElementsValidationConfig){
				if(!get(filterFormElementsValidationConfig[i]['id']))continue;
				if(filterFormElementsValidationConfig[i]['type']=='input'){
					if(get(filterFormElementsValidationConfig[i]['id'])){
						E.on(filterFormElementsValidationConfig[i]['id'],'focus',function(e){
							if(this.className.indexOf("i-error")>-1){
								this.select();
							}else{
								D.addClass(this,"i-text");
							}
						});
						E.on(filterFormElementsValidationConfig[i]['id'],'blur',function(e){
							D.removeClass(this,"i-text");
						});
					}
				}else if(filterFormElementsValidationConfig[i]['type']=='select'){
					E.on(filterFormElementsValidationConfig[i]['id'],'change',function(e){
						//do something
					});
				}
			}
		}
	};
	YAHOO.namespace('addStudentManage');
	YAHOO.addStudentManage={
		initAddStudentForm:function(){
			var elementsGroup = addStudentFormElementsValidationConfig;
			for(var i in elementsGroup){
				if(!get(elementsGroup[i]['id'])) continue;
				if(elementsGroup[i]['type']=='input'){
					/*input值初始化,如果有设定初始值(约定放在data中),则置为这个初始值*/
					setTimeout(function(){
						get(elementsGroup[i]['id']).value=get(elementsGroup[i]['id']).getAttribute('data')?get(elementsGroup[i]['id']).getAttribute('data'):'';
					},0);
					E.on(elementsGroup[i]['id'],'focus',function(e){
						var obj = elementsGroup[D._toCamel(this.id)];
						var tipId = obj['tipId'];
						if(this.className.indexOf("i-error")>-1){
							this.select();
						}else{
							D.addClass(this,"i-text");
							if(get(tipId)){
								if(get(tipId).className.indexOf('correct')==-1){
									D.addClass(tipId,'normal');
									get(tipId).innerHTML = obj['txt']['normal'];
								}
							}
						}
					});
					E.on(elementsGroup[i]['id'],'blur',function(e){
						D.removeClass(this,"i-text");
						var obj = elementsGroup[D._toCamel(this.id)];
						var tipId = obj['tipId'];
						var check = obj.check;
						if(this.value!=''){
							var returnV  = check(this.value);
							if(!returnV){
								if(get(tipId)){
									get(tipId).innerHTML = "正确";
									D.removeClass(tipId,'normal');
									D.removeClass(tipId,'error');
									D.addClass(tipId,'correct');
									D.removeClass(obj['id'],'i-error');
								}
							}else{
								D.removeClass(tipId,'normal');
								D.removeClass(tipId,'correct');
								D.addClass(tipId,'error');
								get(tipId).innerHTML = obj['txt'][returnV];
								D.addClass(obj['id'],'i-error');
							}
						}else{
							D.removeClass(tipId,'normal');
							D.removeClass(tipId,'correct');
							D.removeClass(tipId,'error');
							
							get(tipId).innerHTML = "";
							D.removeClass(this,"i-error");
						}

					});
				}else if(elementsGroup[i]['type']=='select'){
					E.on(elementsGroup[i]['id'],'change',function(e){
						if(this.options[0].className=='default'){
							if(this.value!=''){
								D.removeClass(this,'default');
							}else{
								D.addClass(this,'default');
							}
						}
					});
				}else if(elementsGroup[i]['type']=='textarea'){
					E.on(elementsGroup[i]['id'],'focus',function(e){
						var obj = elementsGroup[D._toCamel(this.id)];
						D.addClass(this,'i-text');
					});
					E.on(elementsGroup[i]['id'],'blur',function(e){
						var obj = elementsGroup[D._toCamel(this.id)];
						D.removeClass(this,'i-text');
					});
				}
			}
		}	
	};
	YAHOO.namespace('countryAreaManage');
	YAHOO.countryAreaManage={
		initCountryArea:function(province,city){
			if(typeof conturyAreaData!='undefined'){
				var docFlagment = YAHOO.countryAreaManage.createFlagMent('','省份');
				var defaultValue = get(province).getAttribute("dd");
				var defaultText = "";
				get(city).options.length = 0;
				var i = 0,pos = 0;
				for(var name in conturyAreaData[0]){
					name = name.split('_');
					var opt = document.createElement('option');
					opt.value = name[1];
					opt.text = opt.innerText = name[0];
					if(defaultValue == name[1]){
						pos = i;
						defaultText = name[0];
					} 
					i++;
					docFlagment.appendChild(opt);
				}
				get(province).appendChild(docFlagment);
				setTimeout(function(){
					get(province).selectedIndex = (defaultValue==""?0:pos+1);
				},0);
				
				if(defaultValue!=""){
					YAHOO.countryAreaManage.createCitySelect(defaultText,defaultValue,city);	
				}else{
					var docFlagmentCity = YAHOO.countryAreaManage.createFlagMent('','地级市');
					get(city).appendChild(docFlagmentCity);
				}
				YAHOO.countryAreaManage.provinceSelectChangeEvent(province,city);
			}
		},
		createFlagMent:function(v,t){
			var docFlagment = document.createDocumentFragment(),
			opt = document.createElement('option');
			opt.value = v;
			opt.text = opt.innerText = t;
			docFlagment.appendChild(opt);
			return docFlagment;
		},
		provinceSelectChangeEvent:function(provinceId,cityId){
			E.on(provinceId,'change',function(){
					var t = this.options[this.selectedIndex].text;
					var v = this.options[this.selectedIndex].value;
				YAHOO.countryAreaManage.createCitySelect(t,v,cityId);
			});
		},
		createCitySelect:function(t,v,cityId){
			var docFlagment = YAHOO.countryAreaManage.createFlagMent('','地级市');
			var defaultValue = get(cityId).getAttribute("dd");
				get(cityId).options.length = 0;
				if(v==''){
				}else{
					var key = t+"_"+v;
					var cityStr="";
					var i = 0,pos = 0;
					var cityArray = (conturyAreaData[0][key]);
					get(cityId).options.length = 0;
					for(var j=0;j<cityArray.length;j++){
						cityStr = cityArray[j].split('_');
						var opt = document.createElement('option');
						opt.value = cityStr[1];
						
						opt.text = opt.innerText = cityStr[0];
						if(defaultValue==cityStr[1]){
							pos = i+1;
						}
						i++;
						docFlagment.appendChild(opt);
					}
				}
				get(cityId).appendChild(docFlagment);
				setTimeout(function(){
					get(cityId).selectedIndex = pos?(pos):0;
				},0);
		}
	}
}();
