function PM_Register(containerName, element, nullMessage, regex, notMatchMessage, isAutoCheck, posAlign){
    this.containerName = containerName;
    this.container = (this.containerName == null) ? document.body : document.getElementById(this.containerName);
    this.elem = document.getElementById(element);
    this.nullMessage = nullMessage;
    this.regex = regex;
    this.notMatchMessage = notMatchMessage;
    this.posAlign = posAlign;
    var pm = this;
    
    //setup message layer
    this.MsgDiv = document.getElementById('divPopMsg'+ this.containerName);
    if(this.MsgDiv == null){
        this.MsgDiv = document.createElement("div");
        this.MsgDiv.id = 'divPopMsg'+ this.containerName;
        this.MsgDiv.style.position = "absolute";
        this.MsgDiv.style.visibility = 'hidden';//visible
    }
    
    //append child
    var parent = this.elem.parentNode;
    parent.appendChild(this.MsgDiv);
    
    if(isAutoCheck){
        this.elem.onfocus = function(){
            pm.Check(0);
        }
        
        this.elem.onblur = function(){
            pm.MsgDiv.style.visibility = 'hidden';
        }
        
        this.elem.onkeyup = function(){
            pm.Check(0);
        }
    }
}
PM_Register.prototype.Check = function(t){
	if(this.elem){
	    var val = this.elem.value;
	    if(val == '' && this.nullMessage != null){
	            try{
	                this.elem.focus();
	            }catch(e){
	                
	            }
	        this.PopupMessageLayer(this.nullMessage);
	        return false;
	    }else if(this.regex != null){
			if(!(val == '' && this.nullMessage == null)){
				var re = new RegExp(this.regex, 'ig');
				if(!re.test(val)){
					try{
						this.elem.focus();
					}catch(e){
		                
					}
					this.PopupMessageLayer(this.notMatchMessage);
					return false;
				}
			}
	    }
	}
	this.SetBackgroudColor('#FFFFFF');
	this.MsgDiv.style.visibility = 'hidden';
    this.MsgDiv.style.left = '0px';
    this.MsgDiv.style.top = '0px';
    this.MsgDiv.style.width = '0px';
    this.MsgDiv.style.height = '0px';
    this.AutoHideSelect();
	return true;
}
PM_Register.prototype.SetBackgroudColor = function(color){
    //this.elem.style.backgroundColor = color;
}
PM_Register.prototype.AbsPos = function (el){
	for (var lx=0,ly=0;el!=null;lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
	return {x:lx,y:ly}
}
PM_Register.prototype.HtmlControlBody = function(){
    var html = '<table border="0" cellspacing="0" cellpadding="0"><tr>'+
    '<td valign="top" width="14"><img width="14" height="1" />'+
        '<table border="0" cellspacing="0" cellpadding="0">'+
        '<tr><td height="10"></td></tr>'+
        '<tr><td valign="top"><img src="/images/system/pm.nav.gif" align="absmiddle" style="position:absolute;z-index:9000" /></td></tr>'+
        '</table>'+
    '</td>'+
    '<td style="border:1px solid #333333;background-color:#FFFACD;">'+
        '<table border="0" cellspacing="0" cellpadding="4"><tr>'+
        '<td valign="top"><img src="/images/system/pm.alert.gif" align="absmiddle" /></td>'+
        '<td valign="top" style="line-height:18px;padding-top:15px;padding-bottom:15px;" nowrap>{$Message}</td>'+
        '<td valign="top"><img src="/images/system/pm.close.gif" align="absmiddle" style="cursor:pointer" onclick="document.getElementById(\'divPopMsg'+ this.containerName +'\').style.visibility=\'hidden\'" /></td>'+
        '</tr></table>'+
    '</td></tr></table>';
    
    return html;
}
PM_Register.prototype.PopupMessageLayer = function(msg){
    this.SetBackgroudColor('#FFFACD');
    
    var outstr = this.HtmlControlBody();
    outstr = outstr.replace(/\{\$Message\}/ig, msg);
    
    var pos_elem = this.AbsPos(this.elem);
    var pos_cntr = this.AbsPos(this.container);
    var width = this.elem.clientWidth;
    
    if(this.posAlign == 'left'){
        width = 0;
    }else if(this.posAlign == 'middle'){
        width = width / 2;
    }
    
    this.MsgDiv.style.left = (pos_elem.x + width - pos_cntr.x) +'px';
    this.MsgDiv.style.top = (pos_elem.y - 5 - pos_cntr.y) +'px';
    this.MsgDiv.style.visibility = 'visible';
    this.MsgDiv.innerHTML = outstr;
    this.AutoHideSelect();
}
PM_Register.prototype.Popup = function(e, m){
    var outstr = this.HtmlControlBody();
    outstr = outstr.replace(/\{\$Message\}/ig, m);
    
    var elem = document.getElementById(e);
    var pos_elem = this.AbsPos(elem);
    var pos_cntr = this.AbsPos(this.container);
    var width = this.elem.clientWidth;
    this.MsgDiv.style.left = (pos_elem.x + width - pos_cntr.x) +'px';
    this.MsgDiv.style.top = (pos_elem.y - 5 - pos_cntr.y) +'px';
    this.MsgDiv.style.visibility = 'visible';
    this.MsgDiv.innerHTML = outstr;
}
PM_Register.prototype.AutoHideSelect = function(){
    var x_top = parseInt(this.MsgDiv.style.left, 10);
    var y_top = parseInt(this.MsgDiv.style.top, 10);
    var n_width = this.MsgDiv.clientWidth;
    var n_height = this.MsgDiv.clientHeight;
    this.HiddenSelector(x_top, y_top, n_width, n_height);
}
PM_Register.prototype.HiddenSelector = function(x_top, y_top, width, height){
	var x_bt = x_top + width;
	var y_bt = y_top + height;
	var sl_pos,sl_x_top, sl_y_top, sl_x_bt, sl_y_bt, dsrcid;
	var sls = document.getElementsByTagName('SELECT');
	for(i=0; i<sls.length; i++){
		sl_pos = this.AbsPos(sls[i]);
		sl_x_top = sl_pos.x;
		sl_y_top = sl_pos.y;
		sl_x_bt = sl_x_top + sls[i].clientWidth;
		sl_y_bt = sl_y_top + sls[i].clientHeight;
		
		if(((sl_x_bt > x_top) && (sl_x_top < x_bt)) && ((sl_y_bt > y_top) && (sl_y_top < y_bt))){
		    dsrcid = sls[i].parentNode;
		    if(dsrcid){
		        if(dsrcid.id.indexOf('nohidden') == -1){
		            sls[i].style.visibility = 'hidden';
		        }
		    }else{
		        sls[i].style.visibility = 'hidden';
		    }
		}else{
		    sls[i].style.visibility = 'visible';
		}
	}
}