/**
 * 电子邮件组件校验
 * 属性：
 *       
 * 说明：1、必须只含有数字。
 			2、有且只有6位。
 * @author  zhaosh
 */
 
function PostCodeObj(editerObj){
	//定义输入对象
	this.edtObj = editerObj;
    	//公共方法
	this.onvalidate = PSTC_onvalidate;
	this.checkvalidate = PSTC_checkvalidate;
	this.getParentObj = PSTC_getParentObj;
	this.getBaseObj = PSTC_getBaseObj;
	this.OnlyNumber = PSTC_OnlyNumber;
	//行为方法
	this.onReady = PSTC_onReady;
	this.eventBand = PSTC_eventBand;
	//私有方法

	//私有对象
	var ParObj=null;
	var BasObj=null;
}

function PSTC_checkvalidate() {
	var chkValue = this.edtObj.value;
	if(chkValue.length!=6 && chkValue!=""){
		return false;
	}
	var result=chkValue.replace(/\d+/g,"");
	if(result==""){
		return true;
	}
	
	return false;
}

function PSTC_OnlyNumber(){
	//只允许输入数字
	if ( !(((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) 
				|| (window.event.keyCode == 13))){
		window.event.keyCode = 0 ;
	}
}

function PSTC_getParentObj(){
	if(this.BasObj==null){
		this.BasObj = new BaseObj(this.edtObj);
	}
	return this.BasObj;
}

function PSTC_getBaseObj(){
	if(this.BasObj==null){
		this.BasObj = new BaseObj(this.edtObj);
	}
	return this.BasObj;
}

function PSTC_onvalidate() {
	var checkStr = this.edtObj.value;
	
	//调用BaseObject中的公用函数检查数据合法性
	if(!this.getBaseObj().commonCheck())	return false;

	if(!this.checkvalidate()){
		alert("["+this.edtObj.prompt + "]输入不合法！\r\n[邮政编码必须为6位数字。]");
		return false;
	}

	return true;
}

function PSTC_onReady(){
	//调用ParentObj 的初始化方法
	this.getParentObj().onReady();
	this.edtObj.maxLength="6";
};
function PSTC_eventBand(){

}

PostCodeObj.prototype.beforeSubmit = function(){
	this.getParentObj().beforeSubmit();
}
