/**
 * 对象管理器，负责根据类型获取对应的对象
 */
var itownObjsMgr = new ItownObjsMgr();
function ItownObjsMgr(){
	this.getEAPObj = ITOWN_OM_getEAPObj;
	this.onReady = ITOWN_OM_onReady;
	this.validateAll=ITOWN_OM_onValidateAll;
}
function ITOWN_OM_getEAPObj(editerObj){
	var objName = editerObj.JSObjName;
	var obj=null;
	switch(objName){
		case "Text": 					obj = new TextObj(editerObj);
			break;
		case "Number": 				obj = new NumberObj(editerObj);
			break;
		case "Integer":				obj = new IntegerObj(editerObj);
			break;
		case "PositiveInteger": 	obj = new PosIntegerObj(editerObj);
			break;
		case "Double": 				obj = new DoubleObj(editerObj);
			break;
		case "Money": 					obj = new MoneyObj(editerObj);
			break;
		case "Date": 					obj = new DateObj(editerObj);
			break;
		case "IDCard": 				obj = new IDCardObj(editerObj);
			break;
		case "Password": 				obj = new PasswordObj(editerObj);
			break;
		case "PasswordConfirm": 	obj = new PasswordConfirmObj(editerObj);
			break;
		case "TextArea": 				obj = new TextAreaObj(editerObj);
			break;
		case "ReadOnly": 				obj = new ReadOnlyObj(editerObj);
			break;
		case "QuickSelect": 			obj = new QuickSelectObj(editerObj);
			break;
		case "Select": 				obj = new SelectObj(editerObj);
			break;
		case "ListSelect": 			obj = new MultiSelectObj(editerObj);
			break;
		case "Email":  				obj = new EmailObj(editerObj);
			break;
		case "PostCode":  			obj = new PostCodeObj(editerObj);
			break;
		case "Radio":					obj = new RadioObj(editerObj);
			break;
		case "CheckBox":				obj = new CheckBoxObj(editerObj);
			break;
		case "PopSelect":				obj = new PopWindowSelectObj(editerObj);
			break;
		case "SelectOrInput":		obj = new SelectOrInputObj(editerObj);
			break;
		case "Telephone":				obj = new TelephoneObj(editerObj);
			break;
		case "IP":				obj = new IPObj(editerObj);
		    break;
		case "TextAutoComplete": 
		 
		 new TextAutoCompleteObj('./controller?SERVICE_ID=FRAMEWORK_AUTO_COMPLETE_SERVICE',editerObj.name,{searchFldName:'autoSearchFldName',returnFldNames:'autoReturnFldNames',writeFldNames:'autoWriteFldNames'});
			break;
		default:		//alert("配置文件中没有此种类型为'"+objName+"'的JS对象！");
		}

	return obj;
}
function ITOWN_OM_onReady(formObj){
	var obj,eapObj;
	//formObj为空即代表使用默认的 form1
	var form = formObj == null ? findObj(ItownGlobals.FORM_NAME): formObj;
	for(var i=0;i<form.elements.length; i++){
			obj=form[i];
			if( obj.JSObjName != null){
				eapObj = this.getEAPObj(obj);
				if(eapObj != null) {
					eapObj.onReady();      //初始化
				}
		}
	}
}

/**
 * 验证域的输入。
 		如果checkGroup为空或没有传入，则只验证没有checkGroup属性的域。
 * @param formObj 表单对象
 * @param checkGroup 检查域所属的组
 */
function ITOWN_OM_onValidateAll(formObj,checkGroup){
	var boolRtn = true;
	var form = formObj == null ? findObj(ItownGlobals.FORM_NAME): formObj;
	for(var i=0;i<form.elements.length; i++){
		var obj=form.elements[i];
		//检查是否是属于要验证的组
		if(checkGroup==undefined || checkGroup==null || checkGroup==""){
			if(obj.checkGroup && obj.checkGroup!=""){
				continue;
			}
		}else{
			if(!obj.checkGroup || obj.checkGroup!=checkGroup){
				continue;
			}
		}
		if( obj.JSObjName != null){
			var eapObj = this.getEAPObj(obj);
			if(eapObj != null) {
				try{
					var aRtn = eapObj.onvalidate();      //校验
					if(aRtn == false){
						obj.focus();
						boolRtn = aRtn;
						break;
					}
				}catch(e){
					if(ItownGlobals.DEBUG){
						alert("调用：IEVP.IEVP_ValidateAllObj()；出错");
					}
				}
			}
		}
	}
  return boolRtn;
}


/**
 * 在提交前要作的处理，目前主要是对货币型的数据进行处理。
 		如果checkGroup为空或没有传入，则只验证没有checkGroup属性的域。
 * @param formObj 表单对象
 * @param checkGroup 检查域所属的组
 */
ItownObjsMgr.prototype.beforeSubmit = function(formObj,checkGroup){
	var form = formObj == null ? findObj(ItownGlobals.FORM_NAME): formObj;
	for(var i=0;i<form.elements.length; i++){
		var obj=form.elements[i];
		//检查是否是属于要验证的组
		if(checkGroup==undefined || checkGroup==null || checkGroup==""){
			if(obj.checkGroup && obj.checkGroup!=""){
				continue;
			}
		}else{
			if(!obj.checkGroup || obj.checkGroup!=checkGroup){
				continue;
			}
		}
		
		if( obj.JSObjName != null){
			var eapObj = this.getEAPObj(obj);
			if(eapObj != null) {
				try{
					eapObj.beforeSubmit();
				}catch(e){
					if(ItownGlobals.DEBUG){
						alert("调用：IEVP.IEVP_ValidateAllObj()；出错");
					}
				}
			}
		}
	}
}
