﻿
if(typeof(Epoint_IE) != "boolean")
	var Epoint_IE = (document.all) ? true : false;
	
if(typeof(Epoint_TextBox) != "object")
	var Epoint_TextBox=[];

var Epoint_A_TextBox = new Array();
var Epoint_A_TextBoxCount = 0;

var Epoint_MessageDivID = "EpointMessageDiv";
var Epoint_MessageDiv;
var Epoint_MessageHasShow = false;
var Epoint_IsValidInput = false;
var Epoint_ErrorImage = "";
var Epoint_BackgroundImage = "";
var Epoint_MessageIFrame;
String.prototype.ReplaceAll  = function(s1,s2){    
    return this.replace(new RegExp(s1,"gm"),s2);    
}  

String.prototype.Trim = function(){    
    return  this.replace(/^\s*(.*?)[\s\n]*$/g,  '$1');  
}  

//获取焦点光标所在的位置，1:最后 2 最前 3 字符串全选
var SelectionFocus = 1;

function Epoint_getSrcElement(evnt)
{
	if(Epoint_IE)
		return evnt.srcElement;
	else
		return evnt.target;
}

function Epoint_getElementById(id)
{
    
	var el;
	if(Epoint_IE)
		el = document.all[id];
	else 
		el = document.getElementById(id);
	return el;
}

function Init_NormalText(id,type,selecttype,msg,allowSBCPoint,allowSBCNum,sForbiddenChar,iMaxLength,bAllowNull)
{
    var elem = Epoint_getElementById(id);
    var textbox;
    textbox = new TextBox(id,"normal",selecttype,msg,elem,allowSBCPoint,allowSBCNum,sForbiddenChar);
    textbox.MaxLength = iMaxLength;
    textbox.AllowNull = bAllowNull;
    textbox.CheckSelf = NormalTextBoxCheckSelf;
    textbox.CheckSelfOnBlur = NormalTextBoxCheckSelfOnBlur;
    EpointaddEventListener(elem,"blur",TextBlur,true);
    EpointaddEventListener(elem,"keyup",CheckIsForbiddenCharKeyUp,true);
    EpointaddEventListener(elem,"change",CheckIsForbiddenCharChange,true);
    EpointaddEventListener(elem,"keypress",CheckIsForbiddenCharKeyPress,true);
    Epoint_TextBox[id] = textbox;
    Epoint_A_TextBox[Epoint_A_TextBoxCount++] = id;
}

///初始化TextBox对象，分为nomal,numeric,int,money,rate五种类型
function Init_TextBox(id,type,selecttype,msg,ShowMoneyChar,MoneyChar,MaxValue,MinValue,ZeroValue,Precision,ShowCharact,iMaxLength,bAllowNull)
{
    var elem = Epoint_getElementById(id);
    var textbox;
    switch(type.toLowerCase())
    {
        case "numeric":
            textbox = new NumericTextBox(id,type,selecttype,msg,elem,MaxValue,MinValue,ZeroValue,Precision,ShowCharact);
            textbox.CheckSelfOnBlur = NumericTextBoxCheckSelfOnBlur;
            textbox.CheckSelf = NumericTextBoxCheckSelf;
            break;
        case "int":
            textbox = new IntTextBox(id,type,selecttype,msg,elem,MaxValue,MinValue,ZeroValue,ShowCharact);
            textbox.CheckSelfOnBlur = IntTextBoxCheckSelfOnBlur;
            textbox.CheckSelf = IntTextBoxCheckSelf;
            break;
        case "money":
            textbox = new MoneyTextBox(id,type,selecttype,msg,elem,ShowMoneyChar,MoneyChar,MaxValue,MinValue,ZeroValue,ShowCharact);
            textbox.CheckSelfOnBlur = MoneyTextBoxCheckSelfOnBlur;
            textbox.CheckSelf = MoneyTextBoxCheckSelf;
            break;
    }
    textbox.CheckInputValue = Epoint_CheckInputValue;
    Epoint_TextBox[id] = textbox;
    textbox.MaxLength = iMaxLength;
    textbox.AllowNull = bAllowNull;
    Epoint_A_TextBox[Epoint_A_TextBoxCount++] = id;

}    


function Init_SpecialTextBox(id,type,selecttype,msg,specialType,iMaxLength,bAllowNull)
{
    var elem = Epoint_getElementById(id);
    var textbox = new TextBox(id,type,selecttype,msg,elem);
    textbox.SpecialType = specialType;
    textbox.MaxLength = iMaxLength;
    textbox.AllowNull = bAllowNull;
    textbox.CheckSelf = SpecialTextBoxCheckSelf;
    EpointaddEventListener(elem,"blur",SpecialTextBlur,true);
    Epoint_TextBox[id] = textbox;
    Epoint_A_TextBox[Epoint_A_TextBoxCount++] = id;
}

///构造普通TextBox对象
function TextBox(id,type,selecttype,msg,elem,allowSBCPoint,allowSBCNum,sForbiddenChar)
{
    this.Id = id;
    this.Msg = msg;
    this.Type = type;
    this.Element = elem;
    this.SelectType = selecttype;
    this.AllowSBCPoint = allowSBCPoint;
    this.AllowSBCNum = allowSBCNum;
    this.ForbiddenChar = sForbiddenChar;
    AddEventOnfocusSelection(elem,selecttype);
    EpointaddEventListener(elem,"beforepaste",TextBeforePaste,true);
//    Epoint_CreateDivHTML(id);
}

///整型TextBox
function IntTextBox(id,type,selecttype,msg,elem,MaxValue,MinValue,ZeroValue,ShowCharact)
{
    var me = new TextBox(id,type,selecttype,msg,elem);
    //TODO:
    EpointaddEventListener(elem,"focus",TextFocus,true);
    EpointaddEventListener(elem,"blur",TextBlur,true);
    EpointaddEventListener(elem,"keydown",TextKeyDown,true);
    EpointaddEventListener(elem,"keypress",TextKeyPressForInt,true);
    EpointaddEventListener(elem,"keyup",TextKeyUp,true);
    me.FormatTextBox = FormatForNumericTextBox;
    me.MaxValue = MaxValue;
    me.MinValue = MinValue;
    me.ZeroValue = ZeroValue;
    me.ShowCharact = ShowCharact;
    //me.FormatTextBox();
    return me;
}

///数值型TextBox
function NumericTextBox(id,type,selecttype,msg,elem,MaxValue,MinValue,ZeroValue,Precision,ShowCharact)
{
    var me = new TextBox(id,type,selecttype,msg,elem);
    //TODO:
    EpointaddEventListener(elem,"focus",TextFocus,true);
    EpointaddEventListener(elem,"blur",TextBlur,true);
    EpointaddEventListener(elem,"keydown",TextKeyDown,true);
    EpointaddEventListener(elem,"keypress",TextKeyPressForNum,true);
    EpointaddEventListener(elem,"keyup",TextKeyUp,true);
    me.MaxValue = MaxValue;
    me.MinValue = MinValue;
    me.ZeroValue = ZeroValue;
    me.Precision = Precision;
    me.FormatTextBox = FormatForNumericTextBox;
    me.ShowCharact = ShowCharact;
    //onkeyup="value=value.replace(/[^\d]/g,'') " 
    //onbeforepaste=""
    return me;
}

//money型TextBox
function MoneyTextBox(id,type,selecttype,msg,elem,ShowMoneyChar,MoneyChar,MaxValue,MinValue,ZeroValue,ShowCharact)
{
    var me = new NumericTextBox(id,type,selecttype,msg,elem,MaxValue,MinValue,ZeroValue,2);
    me.ShowMoneyChar = ShowMoneyChar;
    me.MoneyChar = MoneyChar;
    me.ShowCharact = ShowCharact;
    return me;
}

//TextBox获取焦点触发的js事件
function TextFocus(evt)
{
    if(evt == null) evt = window.event;
	if(evt != null)
	{
		var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		var text = Epoint_TextBox[elem.id];
//		if(elem.value.indexOf(",")<0)
//		    return;
		var str = elem.value;
        if(text.Type == "money")
            str = takeOut(str,text.MoneyChar);
        else
            str = takeOut(str,null);    
        if(str!=      elem.value)   
            elem.value = str;                
	}	
    
}

//TextBox KeyUp时触发的js事件
function TextKeyUp(evt)
{
    if(evt == null) evt = window.event;
	if(evt != null)
	{
		var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		if(evt.keyCode==13)
		    evt.keyCode=9 
	}	
}

//TextBox KeyDown时触发的js事件
function TextKeyDown(evt)
{
    if(evt == null) evt = window.event;
	if(evt != null)
	{
		var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		if(evt.keyCode==13)
		    evt.keyCode=9 
	}	
}

//整型TextBox KeyPress时触发的js事件
function TextKeyPressForInt(evt)
{
    if(evt == null) evt = window.event;
    if(evt != null)
	{
        if (evt.keyCode!=45 && (evt.keyCode<48 || evt.keyCode>57)) 
        {
            var elem = evt.srcElement;
            Epoint_ShowMessageDiv(Epoint_TextBox[elem.id],Epoint_TextBox[elem.id].Msg + "只能输入数字！");
            evt.returnValue=false;
        }
    }
}

//numericTextBox KeyPress时触发的js事件
function TextKeyPressForNum(evt)
{
    if(evt == null) evt = window.event;
    if(evt != null)
	{
        if (evt.keyCode!=46 && evt.keyCode!=45 && (evt.keyCode<48 || evt.keyCode>57)) 
        {
            var elem = evt.srcElement;
            Epoint_ShowMessageDiv(Epoint_TextBox[elem.id],Epoint_TextBox[elem.id].Msg + "只能输入数字！");
            evt.returnValue=false;
        }
    }
}

//TextBox 失去焦点时触发的js事件
function TextBlur(evt)
{
	if(evt == null) evt = window.event;
	if(evt != null)
	{
		var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		
		var text = Epoint_TextBox[elem.id];
        if(text.MaxLength != 0 && ComputeStringLength(text.Element.value) > text.MaxLength)
        {
            Epoint_ShowMessageDiv(text,text.Msg + "最多只能输入" + text.MaxLength + "个字符！");
            return;
        }
        
        if(!text.AllowNull && text.Element.value == "")
        {
            Epoint_ShowMessageDiv(text,text.Msg + "必填！");
            return;       
        } 
	    text.CheckSelfOnBlur();				
	}	
}

function TextBeforePaste(evt)
{
    if(evt == null) evt = window.event;
	if(evt != null)
	{
		var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		
		var text = Epoint_TextBox[elem.id];
		var msg = "";
		if(text.MaxLength != 0 && clipboardData.getData('text').length > text.MaxLength)
		{
		    clipboardData.setData('text',clipboardData.getData('text').substring(0,text.MaxLength));
		    msg = "最多只能输入" + text.MaxLength + "个字符！";
		}
		switch(text.Type.toLowerCase())
        {
            case "numeric":
                var regAll=/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
                if(!regAll.test(clipboardData.getData('text')))
                {
                    msg = '只能输入数字！';
                    clipboardData.setData('text','');
                }
                break;
            case "int":
                var val = clipboardData.getData('text');
                if(val != parseInt(val))
                {
                    msg = '只能输入整数！';
                    clipboardData.setData('text','');
                }
                break;
            case "money":
                var regAll =   /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/
                if(!regAll.test(clipboardData.getData('text')))
                {
                    msg = '只能输入数字！';
                    clipboardData.setData('text','');
                }
                break;
        }
        
        if(msg!="")
            Epoint_ShowMessageDiv(text,msg,'2');
	}
}


//SpecialTextBlur 失去焦点时触发的js事件
function SpecialTextBlur(evt)
{
	if(evt == null) evt = window.event;
	if(evt != null)
	{
		var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		CheckSpecialTextBox(elem.id,'0');
	}	
}

//根据精度，四舍五入,然后加分节符
function FormatForNumericTextBox()
{
    //money,numeric有效
    var elem = this.Element;
    if(this.Type =="money" || (this.Type =="numeric" && this.Precision != 0))
    {
        elem.value = adv_format(elem.value,this.Precision);
    }
    
	if(this.Type =="money")
	    elem.value = commafy(elem.value,this.MoneyChar,this.ShowMoneyChar,this.ShowCharact);
	else
	    elem.value = commafy(elem.value,'',false,this.ShowCharact);	
}

function ReplaceNotNumForPaste()
{
    clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));
}


function AddEventOnfocusSelection(elem,type)
{
    switch(type)
    {     
        case "CaretToBeginning":
            EpointaddEventListener(elem,"focus",eventOnfocusSelectionFirst,true);
            break;
        case "SelectAll":
            EpointaddEventListener(elem,"focus",eventOnfocusSelectionFull,true);
            break;
        case "CaretToEnd":
            EpointaddEventListener(elem,"focus",eventOnfocusSelectionEnd,true);
            break;
        case "Normal":
            break;
    }
}


function eventOnfocusSelectionFirst(evt)
{
	// find source element
	if(evt == null) evt = window.event;
	if(evt != null)
	{
		var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		
        var r =elem.createTextRange();
        r.moveEnd("character",elem.value.length);
        r.collapse(true);
        r.select();
	}	
}

function eventOnfocusSelectionEnd(evt)
{
	// find source element
	if(evt == null) evt = window.event;
	if(evt != null)
	{
		var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		
        var r =elem.createTextRange();
        r.moveStart("character",elem.value.length);
        r.collapse(true);
        r.select();
	}	
}

function eventOnfocusSelectionFull(evt)
{
	// find source element
	if(evt == null) evt = window.event;
	if(evt != null)
	{
		var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;		        
		if(elem.type=="text")
	    {
		    elem.select();
	    }
	}	
}

/*可以是通用函数，将来统一整合*/
function EpointremoveEventListener(elem, evt, fn)
{ 
	try
	{
		if(elem && elem.EpointremoveEventListener)
		{
			elem.EpointremoveEventListener(evt, fn);
			return;
		}
	}catch(ex){}
	try
	{
		if(elem && elem.detachEvent)
			elem.detachEvent('on' + evt, fn);
	}catch(ex){}
}
	
	
function EpointaddEventListener(elem,evtName,fn,flag)
{ 
	
	try{if(elem.addEventListener){elem.addEventListener(evtName,fn,flag==true); return;}}catch(ex){}
	try{if(elem.attachEvent){elem.attachEvent("on"+evtName,fn); return;}}catch(ex){}
	var old;	
	eval("old = elem.on"+evtName);
	var sF=fn.toString();
	var i=sF.indexOf("(")+1;
	try
	{
	if((typeof old =="function") && i>10)
	{
		old=old.toString();
		
		var args=old.substring(old.indexOf("(")+1,old.indexOf(")"));
		args=replace(args," ","");
		if(args.length>0) args=args.split(",");
		
		old=old.substring(old.indexOf("{")+1,old.lastIndexOf("}"));
		
		sF=sF.substring(9,i);
		if(old.indexOf(sF)>=0)return;
		var s="fn=new Function(";
		for(i=0;i<args.length;i++)
		{
			if(i>0)sF+=",";
			s+="\""+args[i]+"\",";
			sF+=args[i];
		}
		sF+=");"+old;
		eval(s+"sF)");
	}
	eval("elem.on"+evtName+"=fn");
	}catch(ex){}
}
/*可以是通用函数，将来统一整合*/


function Epoint_CheckInput(textbox,obj,type,strErrInfo,MaxValue,MinValue,ZeroValue,MsgType)
{
    if(!CheckInput(textbox,obj,type,strErrInfo,MsgType)) 
    {
        obj.value = '';
        return false;
    }
    if(MaxValue!=null && (parseFloat(obj.value) - MaxValue) > ZeroValue)
    {
        Epoint_ShowMessageDiv(textbox,strErrInfo + '请输入小于等于' + MaxValue + '的数值！',MsgType);
        obj.value=MaxValue;
        return false;
    }
    if(MinValue!=null && (parseFloat(obj.value) - MinValue) < ZeroValue)
    {
        Epoint_ShowMessageDiv(textbox,strErrInfo + '请输入大于等于' + MinValue + '的数值！',MsgType);
        obj.value=MinValue;
        return false;
    }
    
    return true;
}

function CheckInput(textbox,obj,type,strErrInfo,MsgType)
{
    //为空，不做判断
    if(obj.value=="") return true;
    switch(type)
    {
        case 'int':// 整数Integer            
            if(parseInt(obj.value) != obj.value)
            {
                if(strErrInfo=='')
                    Epoint_ShowMessageDiv(textbox,'请输入整数！',MsgType);
                else
                    Epoint_ShowMessageDiv(textbox,strErrInfo + '：请输入整数！',MsgType);
                return false;
            }
            break;
        case "numeric":
        case "money":
            var regExp =   /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/
            if(!obj.value.match(regExp))      
            {
                if(strErrInfo=='')
                    Epoint_ShowMessageDiv(textbox,'请输入数值！',MsgType);
                else
                    Epoint_ShowMessageDiv(textbox,strErrInfo + '：请输入数值！',MsgType);                                    
                return false;
            }
            break;
        case 'Rate'://百分比
            var regExp = /^\d+(\.\d+)?$/
            if(obj.value.match(regExp))
            {
                if(obj.value<0 || obj.value>100)
                {
                    if(strErrInfo=='')
                        Epoint_ShowMessageDiv(textbox,'介于0-100之间！',MsgType)
                    else
                        Epoint_ShowMessageDiv(textbox,strErrInfo + '：介于0-100之间！',MsgType)
                    obj.value=0.00;
                    return false;
                }
            }
            else
            {
                if(strErrInfo=='')
                    Epoint_ShowMessageDiv(textbox,'介于0-100之间！',MsgType)
                else
                    Epoint_ShowMessageDiv(textbox,strErrInfo + '：介于0-100之间！',MsgType)
                obj.value=0.00;
                return false;
            }
            break;
    }
    return true;
}

//为数值增加分节符函数
function commafy(num,charactor,bShow,bShowCharact)
{  
    if(!bShowCharact)
        return num;
	num  =  num+""; 
	var  re=/(-?\d+)(\d{3})/  
	var indexPoint = num.indexOf(".");
	if(indexPoint >= 0)
	{
		var numB = num.split(".")[0];
		var numE = num.split(".")[1];
		while(re.test(numB)){  
			numB=numB.replace(re,"$1,$2")  
		}
		
		num = numB + "." + numE;
	}
	else
	{
		while(re.test(num)){  
			num=num.replace(re,"$1,$2")  
		} 
	}	
	if(bShow && num != "")
	    return charactor + num;  
	else
	    return num;  
} 

//删除数值型字符串中的逗号分隔符
function takeOut(val,charactor)
{
	var i;
	var j;
	j=parseInt(val.length/3) +1;
	if(charactor != null)
	    val = val.replace(charactor,"");
	for (i=0;i<=j;i++)
	{
		val=val.replace(',',"");
	}
	return val
}

///第一个参数是待格式化的数值，第二个是保留小数位数注意：返回的是字符串类型
function adv_format(value,num) //四舍五入
{
	//先判断是否需要四舍五入
	if(num>0)
	{
		var value1 = value + "";
		var dotIndex = value.indexOf(".");
		if(dotIndex==-1)
			return value;
		else
		{
			if(dotIndex + num + 1 == value.length)
				return value;
			else
				return Math.round(value*Math.pow(10,num))/Math.pow(10,num);
		}
	}
	else
		return Math.round(value);
} 

///id:文本框ID
///type 0：Div显示消息，1：alert
function CheckSpecialTextBox(id,type) 
{ 
    var text = Epoint_TextBox[id];
    var elem = text.Element;
    if(elem.value=="") return true;
    elem.value = elem.value.Trim(); 
    var regExp;
    switch(text.SpecialType)
    {
        case "Email":
            regExp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/
            if(!elem.value.match(regExp))
            {
                if(text.Msg=='')
                    Epoint_ShowMessageDiv(text,'请输入准确的Email地址！',type);
                else
                    Epoint_ShowMessageDiv(text,text.Msg + '：请输入准确的Email地址！',type);
                return false;
            }
            break;
        case "IdentityCard":
            var info = checkIdcard(elem.value);
            if(info != "")
            {
                if(text.Msg=='')
                    Epoint_ShowMessageDiv(text,info,type);
                else
                    Epoint_ShowMessageDiv(text,text.Msg + info,type);
                return false;
            }
            break;
        case "PostCode":
            regExp =  /^[1-9]\d{5}$/
            if(!elem.value.match(regExp))
            {
                if(text.Msg=='')
                    Epoint_ShowMessageDiv(text,'请输入准确的邮编！',type);
                else
                    Epoint_ShowMessageDiv(text,text.Msg + '：请输入准确的邮编！',type);
                return false;
            }
            break;
        case "Mobile":
            var reg0 = /^13\d{5,9}$/;
            var reg1 = /^153\d{4,8}$/;
            var reg2 = /^159\d{4,8}$/;
            var reg3 = /^0\d{10,11}$/;
            var my = false;
            if (reg0.test(elem.value))my=true;
            if (reg1.test(elem.value))my=true;
            if (reg2.test(elem.value))my=true;
            if (reg3.test(elem.value))my=true;
            if(!my)
            {
                if(text.Msg=='')
                    Epoint_ShowMessageDiv(text,'请输入准确的手机号码！',type);
                else
                    Epoint_ShowMessageDiv(text,text.Msg + '：请输入准确的手机号码！',type);
                return false;
            }
            break;
    }
    return true;
} 

///验证身份证是否有效
function checkIdcard(idcard)
{
    idcard = idcard.Trim(); 
    var Errors=new Array(
    "",
    "身份证号码位数不对!",
    "身份证号码出生日期超出范围或含有非法字符!",
    "身份证号码校验错误!",
    "身份证地区非法!"
    );
    var area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"} 

    var Y,JYM;
    var S,M;
    var idcard_array = new Array();
    idcard_array = idcard.split("");
    //地区检验
    if(area[parseInt(idcard.substr(0,2))]==null) return Errors[4];
    //身份号码位数及格式检验
    switch(idcard.length)
    {
        case 15:
            if ( (parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 ))
            {
                ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性
            } 
            else 
            {
                ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性
            }
            if(ereg.test(idcard)) 
                return Errors[0];
            else
                return Errors[2];
            break;
        case 18:
            //18位身份号码检测
            //出生日期的合法性检查 
            //闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
            //平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
            if(parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt(idcard.substr(6,4))%4 == 0 ))
            {
                ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式
            } 
            else 
            {
                ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式
            }
            if(ereg.test(idcard))
            {
                //测试出生日期的合法性
                //计算校验位
                S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
                + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
                + (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
                + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
                + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
                + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
                + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
                + parseInt(idcard_array[7]) * 1 
                + parseInt(idcard_array[8]) * 6
                + parseInt(idcard_array[9]) * 3 ;
                Y = S % 11;
                M = "F";
                JYM = "10X98765432";
                M = JYM.substr(Y,1).toLowerCase();//判断校验位
                if(M == idcard_array[17].toLowerCase()) 
                    return Errors[0]; //检测ID的校验位
                else 
                    return Errors[3];
            }
            else 
                return Errors[2];
            break;
        default:
            return Errors[1];
    }

}



/////UpDown使用的函数
var bRun = false;
function stop(id)
{
    bRun = false;
    var text = Epoint_TextBox[id]; 
    if(typeof(text.Element.onchange)=="function")
        text.Element.onchange();
}

function onUpArrowClick(id,increment)
{
    if(bRun)
    {
        var text = Epoint_TextBox[id]; 
        if(text.Element.value== "")
        {
            if (0 < text.MaxValue )
                text.Element.value = increment;
            else
            {
                text.Element.value = text.MaxValue;
            }
        }
        else
        {
            if ( parseInt(text.Element.value) < text.MaxValue )
                text.Element.value = parseInt(takeOut(text.Element.value,null)) + increment;
        }
        
        text.Element.value = commafy(text.Element.value,'',false,text.ShowCharact)
        
        window.setTimeout("onUpArrowClick('" + id + "'," + increment + ")",200);
    }
    
    
    
}

function onDownArrowClick(id,increment)
{  
    if(bRun)
    {
         var text = Epoint_TextBox[id]; 
        if(text.Element.value== "")
        {
            if (0 > text.MinValue )
                text.Element.value = 0 - increment;
            else
            {
                text.Element.value = text.MinValue;
            }
        }
        else
        {
            if (parseInt(text.Element.value) > text.MinValue )
                text.Element.value = parseInt(takeOut(text.Element.value,null)) - increment;
        }
        
        text.Element.value = commafy(text.Element.value,'',false,text.ShowCharact)
        
        window.setTimeout("onUpArrowClick('" + id + "'," + increment + ")",200);
    }
    
}
	
	
/////UpDown使用的函数
function onUpArrowMouseDown(id,increment)
{
        bRun = true;
        onUpArrowClick(id,increment)
}

function onDownArrowMouseDown(id,increment)
{
    bRun = true;
    onDownArrowClick(id,increment);
}			



//DropDownText使用的函数
function Epoint_HighLight(id,e)
{
    var textbox = Epoint_TextBox[id];
	var li=textbox.getAllLI();
    for(var i=0;i<li.length;i++)
    {
	    li[i].className="moff";
    }
    e.className="mon";
    textbox.CurIndex = parseInt(e.Seq);
	
}

function Epoint_LowLight(id,e)
{
	e.className="moff";
}

function Init_DropDownTextBox(id,type,selecttype,msg,callbackfun,valueList)
{
    var elem = Epoint_getElementById(id);
    var textbox = new TextBox(id,type,selecttype,msg,elem);
    textbox.TipDiv = Epoint_getElementById("tip" + id);
    textbox.Hidden = Epoint_getElementById("hid" + id);
    textbox.IFrame = Epoint_getElementById("iframe" + id);
    textbox.ShowDiv = ShowHideDropDownDiv;
    textbox.getAllLI = getAllLI;
    textbox.CallBackFun = callbackfun;
    textbox.LoadItem = LoadItem;
    textbox.getHtmlFromItems = getHtmlFromItems;
    textbox.items    = {};
    textbox.CurIndex = -1;
    textbox.MaxIndex = 0;
    textbox.CurInputValue = "";
    textbox.ValueList = valueList;
    textbox.MouseWheel = MouseWheel;
    Epoint_TextBox[id] = textbox;
    EpointaddEventListener(elem,"blur",DropDownTextBlur,true);
    EpointaddEventListener(elem,"mousewheel",DropDownTextMuseWheel,true);
    
}

//DropDownText 失去焦点时触发的js事件
function DropDownTextBlur(evt)
{
	if(evt == null) evt = window.event;
	if(evt != null)
	{
		var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		
		var text = Epoint_TextBox[elem.id];
		text.TipDiv.style.display = 'none';
	    text.IFrame.style.display = 'none';
	}	
}
//DropDownText 滚动滚轮时触发的js事件，鼠标在Text上面
function DropDownTextMuseWheel(evt)
{
	if(evt == null) evt = window.event;
	if(evt != null)
	{
		var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		        
		var delta = 0; 

        if (evt.wheelDelta) { 
            delta = evt.wheelDelta/120;  
            if (window.opera) delta = -delta; 
        } else if (event.detail) { 
            delta = -event.detail/3; 
        } 
        var text = Epoint_TextBox[elem.id];
        text.MouseWheel(delta);
	}	
}



//DropDownText 滚动滚轮时触发触发的js事件，鼠标在Div上面
function DropDownDivMuseWheel(id)
{
	var evt = window.event;
	var delta = 0; 
    if (evt.wheelDelta) { 
        delta = evt.wheelDelta/120;  
        if (window.opera) delta = -delta; 
    } else if (event.detail) { 
        delta = -event.detail/3; 
    } 
    var text = Epoint_TextBox[id];
    text.MouseWheel(delta);
	
}

function MouseWheel(delta)
{
    if(delta<0)
    {
        this.CurIndex = (this.CurIndex+1)%this.MaxIndex;
        var li = Epoint_getElementById("LI" + this.Id + "_" + this.CurIndex);
        Epoint_HighLight(this.Id,li);
    }
    else
    {
        this.CurIndex = (this.CurIndex + this.MaxIndex -1)%this.MaxIndex;
        var li = Epoint_getElementById("LI" + this.Id + "_" + this.CurIndex);
        Epoint_HighLight(this.Id,li);
    }
}

function getAllLI()
{
    //清除选择的节点
    var li = this.TipDiv.getElementsByTagName('LI');
    return li;
}

function SelectDropDiv(id)
{
    //alert(event.keyCode);
    var text = Epoint_TextBox[id];
    if(text.TipDiv.style.display=='none')
    {
        var pos = Epoint_CalculatePosition(text.Element,text.TipDiv);
        text.TipDiv.style.display='block';
        if(text.TipDiv.style.width == null)
            text.TipDiv.style.width = text.Element.offsetWidth
        
        text.CurIndex=-1;
        
	    text.TipDiv.style.top   =   pos.Top;
	    text.TipDiv.style.left   =   pos.Left;
	    
    }
    //alert(event.keyCode);
    
    //press Down button
    if(event.keyCode==40)
    {
        text.CurIndex = (text.CurIndex+1)%text.MaxIndex;
        var li = Epoint_getElementById("LI" + text.Id + "_" + text.CurIndex);
        Epoint_HighLight(text.Id,li);
        //alert(text.CurIndex);
        return;
    }
    
    //press Up button
    if(event.keyCode==38)
    {
        text.CurIndex = (text.CurIndex + text.MaxIndex -1)%text.MaxIndex;
        var li = Epoint_getElementById("LI" + text.Id + "_" + text.CurIndex);
        Epoint_HighLight(text.Id,li);
        return;
    }
    
    //press Enter button
    if(event.keyCode==13)
    {
        
        var li = Epoint_getElementById("LI" + text.Id + "_" + text.CurIndex);
        if(li==null) return;
        li.onmousedown();
        return;
    }
   
    //如果文本框值没有发生变化，则不重新生成Div内容
    if(text.CurInputValue != text.Element.value)
    {
        text.TipDiv.innerHTML = text.getHtmlFromItems();
        text.CurInputValue = text.Element.value;
    }
    text.IFrame.style.width   =   text.TipDiv.offsetWidth;
    text.IFrame.style.height   =   text.TipDiv.offsetHeight;
    text.IFrame.style.top   =   text.TipDiv.style.top;
    text.IFrame.style.left   =   text.TipDiv.style.left;
    text.IFrame.style.zIndex   =   text.TipDiv.style.zIndex   -   1;
    text.IFrame.style.display   =   "block";
   
    
    
}

function ShowHideDropDownDivEvent(id)
{
	var text = Epoint_TextBox[id];
    text.ShowDiv();
}

function ShowHideDropDownDiv()
{
    if(this.TipDiv.style.display=='none')
    {
        var pos = Epoint_CalculatePosition(this.Element,this.TipDiv);
        this.TipDiv.style.display='block';
        if(this.TipDiv.style.width == null)
            this.TipDiv.style.width = this.Element.offsetWidth;
         
	    this.TipDiv.style.top   =   pos.Top;
	    this.TipDiv.style.left   =   pos.Left;
	    this.IFrame.style.width   =   this.TipDiv.offsetWidth;
	    this.IFrame.style.height   =   this.TipDiv.offsetHeight;
	    this.IFrame.style.top   =   this.TipDiv.style.top;
	    this.IFrame.style.left   =   this.TipDiv.style.left;
	    this.IFrame.style.zIndex   =   this.TipDiv.style.zIndex   -   1;
	    this.IFrame.style.display   =   "block";
	    this.CurInputValue = this.Element.value;
	    this.CurIndex=-1;
        this.TipDiv.innerHTML = "加载中...";
        this.LoadItem();
	}
	else
	{
	    this.TipDiv.style.display = 'none';
	    this.IFrame.style.display = 'none';
	}
}

function getHtmlFromItems()
{
    if(this.ValueList=="") return "";
    var avalueList = this.ValueList.split(';');
    var html = "<UL>";
    var aitem;
    
    var seq =0;
    for(var i=0;i<avalueList.length;i++)
    {
        aitem = this.items[avalueList[i]].split(';');
        if(aitem[1].indexOf(this.Element.value) > -1 || aitem[0].indexOf(this.Element.value) > -1)
        {
            html += "<LI Value=\"" + aitem[1] + "\" Seq=\"" + seq + "\" + id=\"LI" + this.Id + "_" + seq + "\" onmouseover=\"Epoint_HighLight('" + this.Id + "',this)\" onmousedown=\"Epoint_SelectValue('" + this.Id + "','" + aitem[0] + "','" + aitem[1] + "')\" onmouseout=\"Epoint_LowLight('" + this.Id + "',this)\">"
            html += aitem[1] + "</LI>";
            seq++;
        }
    }
    html += "</UL>";
    this.MaxIndex = seq;
    return html;
}

function LoadItem()
{
    var args = this.Element.value;
    var textid = this.Id;
    eval(this.CallBackFun);

}

function EpointText_ReceiveServerData(result,textid)
{
    var text = Epoint_TextBox[textid];
    if(result != "")
    {
        eval(result.split("\b")[0]);
        eval(result.split("\b")[1]);
    }
    
    text.TipDiv.innerHTML = text.getHtmlFromItems();
    text.IFrame.style.width   =   text.TipDiv.offsetWidth;
    text.IFrame.style.height   =   text.TipDiv.offsetHeight;
    text.IFrame.style.top   =   text.TipDiv.style.top;
    text.IFrame.style.left   =   text.TipDiv.style.left;
    text.IFrame.style.zIndex   =   text.TipDiv.style.zIndex   -   1;
}

function OnError()
{
    alert('动态获取选择项失败！');
}

function Epoint_SelectValue(id,val,txt)
{
    var text = Epoint_TextBox[id];
    text.Element.value = txt;
    text.Hidden.value = val;
    text.CurInputValue = text.Element.value;
    text.TipDiv.style.display = 'none';
	text.IFrame.style.display = 'none';
}

function Epoint_CalculatePosition(edit,pan)
{
    var panH=pan.offsetHeight,panW=pan.offsetWidth;
    var e=edit,body=window.document.body;
    var editH=e.offsetHeight,editW=e.offsetWidth;
    if(editH==null) editH=0;
    var f,z,ok=0,x=0,y=0,pe=e,bp=body.parentNode;
    while(e!=null)
    {
        if(ok<1||e==body)
        {
            if((z=e.offsetLeft)!=null)
                x+=z;
            if((z=e.offsetTop)!=null)
                y+=z;
        }
        if(e.nodeName=="HTML")
            body=e;
        if(e==body)
            break;
        z=e.scrollLeft;
        if(z==null||z==0)
            z=pe.scrollLeft;
        if(z!=null&&z>0)
            x-=z;
        z=e.scrollTop;
        if(z==null||z==0)
            z=pe.scrollTop;
        if(z!=null&&z>0)
            y-=z;
        pe=e.parentNode;
        e=e.offsetParent;
        if(pe.tagName=="TR")
            pe=e;
        if(e==body&&pe.tagName=="DIV")
        {
            e=pe;
            ok++;
        }
    }
    if(document.elementFromPoint)
    {
        var xOld=x,yOld=y;ok=true;
        var i=1,x0=body.scrollLeft,y0=body.scrollTop,ed=this.Element;
        while(++i<16)
        {
            z=(i>2)?((i&2)-1)*(i&14)/2*5:2;
            e=document.elementFromPoint(x+z-x0,y+z-y0);
            if(!e||e==ed||e==edit)break;
        }
        if(i>15||!e)ok=false;
        x+=z;y+=z;i=0;z=0;
        while(ok&&++i<22)
        {
            if(z==0)x--;else y--;
            e=document.elementFromPoint(x-x0,y-y0);
            if(!e||i>20)ok=false;
            if(e!=ed&&e!=edit)if(z>0)break;else{i=z=1;x++;}
        }
        if(ok){x--;y--;}else{x=xOld;y=yOld;}
    }
    y+=editH;
    z=body.clientHeight;
    if(z==null||z<20)
    {
        z=pe.offsetHeight;
        f=body.offsetHeight;
        if(f>z) z=f;
    }
    else
    {
        if(bp&&(f=bp.offsetHeight)!=null)
            if(f>panH&&f<z)
                z=f-10;
    }
    if((f=body.scrollTop)==null)
        f=0;
    if(f==0&&bp)
        if((f=bp.scrollTop)==null)
            f=0;
	        
    if(z<y-f+panH)
    {
        if(y-f-3>panH+editH)
            y-=panH+editH;
        else 
            y=z+f-panH;
    }
    if(y<f)
        y=f;
    z=body.clientWidth;
    if(z==null||z<20)
    {
        z=pe.offsetWidth;
        f=body.offsetWidth;
        if(f>z)z=f;
    }
    else
    {
        if(bp&&(f=bp.offsetWidth)!=null)
            if(f>panW&&f<z)
                z=f-20;
    }
    if((f=body.scrollLeft)==null)
        f=0;
    if(f==0&&bp)
        if((f=bp.scrollLeft)==null)
            f=0;
    if(x+panW>z+f)
        x=z+f-panW;
    if(x<f)
        x=f;	
    y += edit.offsetHeight;   
    return new Epoint_Position(x,y);
}

///构造普通Epoint_Position对象
function Epoint_Position(x,y)
{
    this.Left = x;
    this.Top = y;
}
 
function FormatFullToHalfPoint(strOld)
{
    strOld=strOld.ReplaceAll("－","-");
    strOld=strOld.ReplaceAll("—","-");   
    strOld=strOld.ReplaceAll("（","(");
    strOld=strOld.ReplaceAll("）",")");
    strOld=strOld.ReplaceAll("［","[");
    strOld=strOld.ReplaceAll("］","]");
    strOld=strOld.ReplaceAll("【","[");
    strOld=strOld.ReplaceAll("】","]");
    return strOld;
}

function FormatFullToHalfNum(strOld)
{
    strOld=strOld.ReplaceAll("１","1");
    strOld=strOld.ReplaceAll("２","2");   
    strOld=strOld.ReplaceAll("３","3");
    strOld=strOld.ReplaceAll("４","4");
    strOld=strOld.ReplaceAll("５","5");
    strOld=strOld.ReplaceAll("６","6");
    strOld=strOld.ReplaceAll("７","7");
    strOld=strOld.ReplaceAll("８","8");
    strOld=strOld.ReplaceAll("９","9");   
    strOld=strOld.ReplaceAll("０","0"); 
    return strOld;
}

function CheckIsForbiddenCharKeyPress(evt)
{
    if(evt == null) evt = window.event;
	if(evt != null)
	{
	    var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		var text = Epoint_TextBox[elem.id];
        var aForbidden = text.ForbiddenChar.split(';');
        if(event.keyCode==32){return;}
        if(event.keyCode==13){return;}
        if(event.keyCode==27){return;}
        if(event.keyCode==16){return;}
        if(event.keyCode==17){return;}
        if(event.keyCode==18){return;}
        var realkey=String.fromCharCode(event.keyCode);
        for(var i=0;i<aForbidden.length;i++)
        {
            if(aForbidden[i]==realkey)
            {
                event.returnValue=false;
            }
        }  
        var  val = elem.value;
        var  val1 = elem.value;
        if(!text.AllowSBCPoint)
            val = FormatFullToHalfPoint(val);
        if(!text.AllowSBCNum)
            val = FormatFullToHalfNum(val);
        if(val1 != val)
            elem.value = val;                         
	}	
	
}

function CheckIsForbiddenCharKeyUp(evt)
{
    if(evt == null) evt = window.event;
	if(evt != null)
	{
	    var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		var text = Epoint_TextBox[elem.id];
        var aForbidden = text.ForbiddenChar.split(';');
        var  val = elem.value;
        var  val1 = elem.value;
        for(var i=0;i<aForbidden.length;i++)
        {
            val = val.ReplaceAll(aForbidden[i],'');
        }
        
        if(!text.AllowSBCPoint)
            val = FormatFullToHalfPoint(val);
        if(!text.AllowSBCNum)
            val = FormatFullToHalfNum(val);
            
        if(val1 != val)
            elem.value = val;                       
	}	
	
	
}

function CheckIsForbiddenCharChange(evt)
{
    if(evt == null) evt = window.event;
	if(evt != null)
	{
	    var elem = evt.srcElement;
		if(elem == null) 
		    if((elem = evt.target) == null) 
		        elem = this;
		var text = Epoint_TextBox[elem.id];
        var aForbidden = text.ForbiddenChar.split(';');
        var  val = elem.value;
        var  val1 = elem.value;
        for(var i=0;i<aForbidden.length;i++)
        {
            val = val.ReplaceAll(aForbidden[i],'');
        }
        if(val1 != val)
            elem.value = val;                 
	}	
}




//普通文本框的失去焦点的验证函数
function NormalTextBoxCheckSelfOnBlur()
{
    this.Element.value = this.Element.value.Trim();   
    if(!this.AllowSBCPoint)
        this.Element.value = FormatFullToHalfPoint(this.Element.value);
    if(!this.AllowSBCNum)
        this.Element.value = FormatFullToHalfNum(this.Element.value);     
}

//数值文本框的失去焦点的验证函数
function NumericTextBoxCheckSelfOnBlur()
{
    this.Element.value = takeOut(this.Element.value,null);
    
    this.CheckInputValue();
}

//整数文本框的失去焦点的验证函数
function IntTextBoxCheckSelfOnBlur()
{
    this.Element.value = takeOut(this.Element.value,null);
    this.CheckInputValue();
}

//Money文本框的失去焦点的验证函数
function MoneyTextBoxCheckSelfOnBlur()
{
    this.Element.value = takeOut(this.Element.value,this.MoneyChar);
    this.CheckInputValue();
}

function Epoint_CheckInputValue()
{
    if(!Epoint_CheckInput(this,this.Element,this.Type,this.Msg,this.MaxValue,this.MinValue,this.ZeroValue,'0'))
	    return;
	this.FormatTextBox();
}

//普通文本框的失去焦点的验证函数
function NormalTextBoxCheckSelf()
{
    this.Element.value = this.Element.value.Trim();
    if(this.MaxLength != 0 && ComputeStringLength(this.Element.value) > this.MaxLength)
    {
        alert(this.Msg + "最多只能输入" + this.MaxLength + "个字符！") ;
        this.Element.focus;
        this.Element.select();
        return false;
    }
    
    if(!this.AllowNull && this.Element.value == "")
    {
        alert(this.Msg + "必填！") ;
        this.Element.focus;
        this.Element.select();
        return false;
    } 
    return true; 
}

//Numeric文本框的失去焦点的验证函数
function NumericTextBoxCheckSelf()
{
    this.Element.value = this.Element.value.Trim();
    if(this.MaxLength != 0 && ComputeStringLength(this.Element.value) > this.MaxLength)
    {
        alert(this.Msg + "最多只能输入" + this.MaxLength + "个字符！") ;
        this.Element.focus;
        this.Element.select();
        return false;
    }
    
    if(!this.AllowNull && this.Element.value == "")
    {
        alert(this.Msg + "必填！") ;
        this.Element.focus;
        this.Element.select();
        return false;
    } 
    return Epoint_CheckInput(this,this.Element,this.Type,this.Msg,this.MaxValue,this.MinValue,this.ZeroValue,'1'); 
}


//Int文本框的失去焦点的验证函数
function IntTextBoxCheckSelf()
{
    this.Element.value = this.Element.value.Trim();
    if(this.MaxLength != 0 && ComputeStringLength(this.Element.value) > this.MaxLength)
    {
        alert(this.Msg + "最多只能输入" + this.MaxLength + "个字符！") ;
        this.Element.focus;
        this.Element.select();
        return false;
    }
    
    if(!this.AllowNull && this.Element.value == "")
    {
        alert(this.Msg + "必填！") ;
        this.Element.focus;
        this.Element.select();
        return false;
    } 
    return Epoint_CheckInput(this,this.Element,this.Type,this.Msg,this.MaxValue,this.MinValue,this.ZeroValue,'1'); 
}

//Money文本框的失去焦点的验证函数
function MoneyTextBoxCheckSelf()
{
    this.Element.value = this.Element.value.Trim();
    if(this.MaxLength != 0 && ComputeStringLength(this.Element.value) > this.MaxLength)
    {
        alert(this.Msg + "最多只能输入" + this.MaxLength + "个字符！") ;
        this.Element.focus;
        this.Element.select();
        return false;
    }
    
    if(!this.AllowNull && this.Element.value == "")
    {
        alert(this.Msg + "必填！") ;
        this.Element.focus;
        this.Element.select();
        return false;
    } 
    return Epoint_CheckInput(this,this.Element,this.Type,this.Msg,this.MaxValue,this.MinValue,this.ZeroValue,'1'); 
}


//Special文本框的失去焦点的验证函数
function SpecialTextBoxCheckSelf()
{
    this.Element.value = this.Element.value.Trim();
    if(this.MaxLength != 0 && ComputeStringLength(this.Element.value) > this.MaxLength)
    {
        alert(this.Msg + "最多只能输入" + this.MaxLength + "个字符！") ;
        this.Element.focus;
        this.Element.select();
        return false;
    }
    
    if(!this.AllowNull && this.Element.value == "")
    {
        alert(this.Msg + "必填！") ;
        this.Element.focus;
        this.Element.select();
        return false;
    } 
    return CheckSpecialTextBox(this.Id,'1'); 
}


//提交前的统一验证函数,用来控制合法性输入
function Epoint_ValidTextBox()
{
    //alert(Epoint_IsValidInput);
    if(!Epoint_IsValidInput)
        return true;
        
    try
    {
        if(typeof(Epoint_getElementById(Epoint_MessageDivID))!="undefined")
        {
            Epoint_MessageHasShow = false;
            Epoint_getElementById(Epoint_MessageDivID).style.display = "none";
            Epoint_getElementById("IFrame" + Epoint_MessageDivID).style.display = "none";
        }
    }
    catch(ex){}
    try
    {
        
        for(var i=0;i<Epoint_A_TextBoxCount;i++)
        {
            var textbox = Epoint_TextBox[Epoint_A_TextBox[i]];
            if(!textbox.CheckSelf())
            {
                return false;
            }        
        }  
    }
    catch(ex)
    {
        alert(ex);
        return false;
    }
    return true;    
}

/* 实现了中英文混合字符串取长度*/
/* 取得字符串的字节长度        */
function ComputeStringLength(str)
{
    if(str==null) return 0;
    var i;
    var len;
    var strTmp;
    strTmp=str;
    len = 0;
    for (i=0;i<strTmp.length;i++)
    {
        if (strTmp.charCodeAt(i)>255) len+=2; 
        else len++;
    }
    return len;
}

function Epoint_ShowMessageDivID(id,Msg)
{
    Epoint_ShowMessageDiv(Epoint_TextBox[id],Msg);
}

function Epoint_ShowMessageDiv(obj,Msg,type)
{
    if(type=='1')
    {
        alert(Msg);
        obj.Element.focus;
        obj.Element.select();
        return;
    }
    
    if(typeof(Epoint_getElementById("IFrame" + Epoint_MessageDivID))=="undefined")
    {
        Epoint_MessageIFrame = document.createElement("iframe");
        Epoint_MessageIFrame.id = "IFrame" + Epoint_MessageDivID;
        //Epoint_MessageIFrame.src = "javascript:false;";
        Epoint_MessageIFrame.scrolling = "no";
        Epoint_MessageIFrame.frameborder = "no";
        Epoint_MessageIFrame.style.position = "absolute";
        Epoint_MessageIFrame.style.top = "0px";
        Epoint_MessageIFrame.style.left = "0px";
        Epoint_MessageIFrame.style.display = "none";
        Epoint_MessageIFrame.style.filter = "Alpha(Opacity=100)";
        obj.Element.parentNode.insertAdjacentElement("beforeEnd", Epoint_MessageIFrame)

    }
	if(typeof(Epoint_getElementById(Epoint_MessageDivID))=="undefined")
    {
        Epoint_MessageDiv=document.createElement("div");
        Epoint_MessageDiv.id=Epoint_MessageDivID;
        Epoint_MessageDiv.style.color = "#000";
        Epoint_MessageDiv.style.paddingBottom = "4px";
        Epoint_MessageDiv.style.position = "absolute";
        Epoint_MessageDiv.style.zIndex = 10;
        Epoint_MessageDiv.style.fontSize = "9pt";
        Epoint_MessageDiv.style.background = "url(" + Epoint_BackgroundImage + ") no-repeat left bottom";
        obj.Element.parentNode.insertAdjacentElement("beforeEnd", Epoint_MessageDiv)
    }
    
    
    Epoint_MessageDiv.innerHTML = "";
    
    if(Epoint_MessageHasShow)
    {
        Epoint_MessageDiv.filters.Alpha.opacity = 100;
        Epoint_MessageIFrame.filters.Alpha.opacity = 100;
        Epoint_MessageDiv.insertAdjacentHTML("beforeEnd", "<div style=\"background:#ffc;border-left:1px solid #000; border-right:1px solid #000; border-top:1px solid #000; padding:2px 3px 0;white-space:nowrap;\"><img src='" + Epoint_ErrorImage + "'/> " + Msg.ReplaceAll("\n","<br>") + "</div>");
        
        var pos = EpointGetAbsoluteLocation1(obj.Element);
//        alert(pos.absoluteTop);
//        alert(Epoint_MessageDiv.offsetHeight);
	    Epoint_MessageDiv.style.top   =   pos.absoluteTop - Epoint_MessageDiv.offsetHeight-2;
	    Epoint_MessageDiv.style.left   =   pos.absoluteLeft;
        
        
        pos = EpointGetAbsoluteLocation1(Epoint_getElementById(Epoint_MessageDivID));
        Epoint_MessageIFrame.style.width   =   pos.offsetWidth;
        //alert(pos.offsetHeight);
        Epoint_MessageIFrame.style.height   =   parseInt(pos.offsetHeight) - 2;
        Epoint_MessageIFrame.style.top   =   Epoint_MessageDiv.style.top;
        Epoint_MessageIFrame.style.left   =   Epoint_MessageDiv.style.left;
        Epoint_MessageIFrame.style.zIndex   =   Epoint_MessageDiv.style.zIndex   -   1;
        Epoint_MessageIFrame.style.display = "";
        
	    
    }
    else
    {       
        Epoint_MessageHasShow = true;
        Epoint_MessageDiv.style.display = "";
        Epoint_MessageDiv.style.filter = "Alpha(Opacity=100)";
        Epoint_MessageIFrame.style.filter = "Alpha(Opacity=100)";
        Epoint_MessageDiv.insertAdjacentHTML("beforeEnd", "<div style=\"background:#ffc;border-left:1px solid #000; border-right:1px solid #000; border-top:1px solid #000; padding:2px 3px 0;white-space:nowrap;\"><img src='" + Epoint_ErrorImage + "'/> " + Msg.ReplaceAll("\n","<br>") + "</div>");
        
        var pos = EpointGetAbsoluteLocation1(obj.Element);
	    Epoint_MessageDiv.style.top   =   pos.absoluteTop - Epoint_MessageDiv.offsetHeight-2;
	    Epoint_MessageDiv.style.left   =   pos.absoluteLeft;
        pos = EpointGetAbsoluteLocation1(Epoint_getElementById(Epoint_MessageDivID));
        
        Epoint_MessageIFrame.style.width   =   pos.offsetWidth;
        Epoint_MessageIFrame.style.height   =   parseInt(pos.offsetHeight) - 2;
//        alert(Epoint_MessageDiv.offsetHeight);
//        alert(Epoint_MessageIFrame.style.height);
//        alert(parseInt(pos.offsetHeight) - 2);
        Epoint_MessageIFrame.style.top   =   Epoint_MessageDiv.style.top;
        Epoint_MessageIFrame.style.left   =   Epoint_MessageDiv.style.left;
        Epoint_MessageIFrame.style.zIndex   =   Epoint_MessageDiv.style.zIndex   -   1;
        Epoint_MessageIFrame.style.display = "";
        Epoint_RemoveMessageDiv();
    }
	

//	obj.setAttribute("show","true");
}


//渐渐隐藏错误信息提示
function Epoint_RemoveMessageDiv()
{
    if(Epoint_MessageHasShow && Epoint_MessageDiv.style.display == "")
    {
        try
        {
            if(Epoint_MessageDiv.filters.Alpha.opacity>1)
            {
                Epoint_MessageDiv.filters.Alpha.opacity--;
                Epoint_MessageIFrame.filters.Alpha.opacity--;
                window.setTimeout("Epoint_RemoveMessageDiv()",5);
            }
            else
            {
                Epoint_MessageDiv.style.display = "none";
                Epoint_MessageDiv.style.filter = "";
                Epoint_MessageHasShow = false;
                Epoint_MessageIFrame.style.display = "none";
            }
        }
        catch(ex)
        {
            Epoint_MessageHasShow = false;
        }
    }
}


function EpointGetAbsoluteLocation(element) 
{ 
    if ( arguments.length != 1 || element == null ) 
    { 
        return null; 
    } 
    var offsetTop = element.offsetTop; 
    var offsetLeft = element.offsetLeft; 
    var offsetWidth = element.offsetWidth; 
    var offsetHeight = element.offsetHeight; 
    while( element = element.offsetParent ) 
    { 
        offsetTop += element.offsetTop; 
        offsetLeft += element.offsetLeft; 
    } 
    return { absoluteTop: offsetTop, absoluteLeft: offsetLeft, 
        offsetWidth: offsetWidth, offsetHeight: offsetHeight }; 
}

var w3c=(document.getElementById)? true:false;
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
var ie5=(w3c && ie)? true : false;
var ns6=(w3c && (navigator.appName=="Netscape"))? true: false;

function EpointGetAbsoluteLocation1(o)
{
    var nLt=0;
    var nTp=0;
    var offsetParent = o;
    while (offsetParent!=null && offsetParent!=document.body) 
    {
        nLt+=offsetParent.offsetLeft;
        nTp+=offsetParent.offsetTop;
        if(!ns6)
        {
            parseInt(offsetParent.currentStyle.borderLeftWidth)>0?nLt+=parseInt(offsetParent.currentStyle.borderLeftWidth):"";
            parseInt(offsetParent.currentStyle.borderTopWidth)>0?nTp+=parseInt(offsetParent.currentStyle.borderTopWidth):"";
        }
        offsetParent=offsetParent.offsetParent;
    //alert(offsetParent.tagName);
    }
    return { absoluteTop: nTp, absoluteLeft: nLt, 
        offsetWidth: o.offsetWidth, offsetHeight: o.offsetHeight }; 
}


