﻿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;
//获取焦点光标所在的位置，1:最后 2 最前 3 字符串全选
var SelectionFocus = 1;

function Init_NormalText(id,type,selecttype,msg,allowSBC,allowSBCPoint,allowSBCNum,sForbiddenChar,iMaxLength,bAllowNull,iShowMessageType,bMultiLine)
{
    var elem = Epoint_getElementById(id);
    var textbox;
    textbox = new TextBox(id,"normal",selecttype,msg,elem,allowSBC,allowSBCPoint,allowSBCNum,sForbiddenChar,iShowMessageType);
    textbox.MaxLength = iMaxLength;
    textbox.AllowNull = bAllowNull;
    textbox.CheckSelf = NormalTextBoxCheckSelf;
    textbox.CheckSelfOnBlur = NormalTextBoxCheckSelfOnBlur;
    textbox.ShowMessageType = iShowMessageType;
    if(bMultiLine&&iMaxLength>0)
    {
        EpointaddEventListener(elem,"keydown",LimitMultiLineInput,true);
        EpointaddEventListener(elem,"input",LimitMultiLineInput,true);
        EpointaddEventListener(elem,"paste",LimitMultiLinePaste,true);
        EpointaddEventListener(elem,"dragenter",LimitMultiLineDrag,true);
        //EpointaddEventListener(elem,"drop","javascript:return false;",true);
        
    }
    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;
}

function LimitMultiLineInput(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 isPermittedKeystroke;
        var enteredKeystroke;
        var currentFieldLength;
        var inputAllowed = true;
        var selectionLength = parseInt(GetSelectionLength(elem),10);
        // Get the current and maximum field length
        currentFieldLength = parseInt(elem.value.length,10);

        // Allow non-printing, arrow and delete keys
        enteredKeystroke = window.event ? evt.keyCode : evt.which;
        isPermittedKeystroke = ((enteredKeystroke < 32)                                
                     ||(enteredKeystroke >= 33 && enteredKeystroke <= 40)    
                     ||(enteredKeystroke == 46))                            

        // Decide whether the keystroke is allowed to proceed
        if ( !isPermittedKeystroke )
        {
            if((currentFieldLength - selectionLength) >= text.MaxLength) 
                inputAllowed = false;
        }

        // Force a trim of the textarea contents if necessary
        if(currentFieldLength > text.MaxLength )
            elem.value = elem.value.substring(0, text.MaxLength)
		
		evt.returnValue = inputAllowed;
        return (inputAllowed);
    }

}

function LimitMultiLinePaste(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 clipboardText;
        var resultantLength;
        var currentFieldLength;
        var pasteAllowed = true;
        var selectionLength = parseInt(GetSelectionLength(elem),10);
        // Get the current and maximum field length
        currentFieldLength = parseInt(elem.value.length,10);          
        clipboardText = clipboardData.getData('text');

        //如果当前已经达到最大值，则不允许复制进入
        if(currentFieldLength==text.MaxLength)
            return false;
        
        if (clipboardText.length + currentFieldLength > text.MaxLength)
        {  
            var trunckClipboard = clipboardText.substring(0, text.MaxLength - currentFieldLength);	
            var o = elem.document.selection.createRange();
            o.text = trunckClipboard;
            pasteAllowed = false;
        }
		
		evt.returnValue = pasteAllowed;
        return (pasteAllowed);
    }

}

function LimitMultiLineDrag(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 clipboardText;
        var resultantLength;
        var currentFieldLength;
        var dragAllowed = true;
        var selectionLength = parseInt(GetSelectionLength(elem),10);
        // Get the current and maximum field length
        currentFieldLength = parseInt(elem.value.length,10);          
        dragText = evt.dataTransfer.getData('text');
        //如果当前已经达到最大值，则不允许复制进入
        if(currentFieldLength==text.MaxLength)
            return false;
        
        if (dragText.length + currentFieldLength > text.MaxLength)
        {
            evt.dataTransfer.setData('text',dragText.substring(0, text.MaxLength - currentFieldLength));
//            var trunckdragText = dragText.substring(0, text.MaxLength - currentFieldLength);	
//            var o = elem.document.selection.createRange();
//            o.text = trunckdragText;
//            dragAllowed = false;
        }
		evt.returnValue = dragAllowed;
        return (dragAllowed);
    }

}

//
// Returns the number of selected characters in 
// the specified element
//
function GetSelectionLength(elem)
{
    if (elem.selectionStart == undefined )
    {
        return document.selection.createRange().text.length;
    }
    else
    {
        return (elem.selectionEnd - elem.selectionStart);
    }
}

///初始化TextBox对象，分为numeric,int,money,rate五种类型
function Init_TextBox(id,type,selecttype,msg,ShowMoneyChar,MoneyChar,MaxValue,MinValue,ZeroValue,Precision,ShowCharact,iMaxLength,bAllowNull,iShowMessageType)
{
    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;
            textbox.ForbiddenChar="";
            break;
        case "int":
            textbox = new IntTextBox(id,type,selecttype,msg,elem,MaxValue,MinValue,ZeroValue,ShowCharact);
            textbox.CheckSelfOnBlur = IntTextBoxCheckSelfOnBlur;
            textbox.CheckSelf = IntTextBoxCheckSelf;
            textbox.ForbiddenChar="";
            break;
        case "money":
            textbox = new MoneyTextBox(id,type,selecttype,msg,elem,ShowMoneyChar,MoneyChar,MaxValue,MinValue,ZeroValue,ShowCharact);
            textbox.CheckSelfOnBlur = MoneyTextBoxCheckSelfOnBlur;
            textbox.CheckSelf = MoneyTextBoxCheckSelf;
            textbox.ForbiddenChar="";
            break;
        case "rate":
            textbox = new NumericTextBox(id,type,selecttype,msg,elem,MaxValue,MinValue,ZeroValue,Precision,ShowCharact);
            textbox.CheckSelfOnBlur = RateTextBoxCheckSelfOnBlur;
            textbox.CheckSelf = NumericTextBoxCheckSelf;
            textbox.ForbiddenChar="";
            break;
    }
    textbox.CheckInputValue = Epoint_CheckInputValue;
    Epoint_TextBox[id] = textbox;
    textbox.MaxLength = iMaxLength;
    textbox.AllowNull = bAllowNull;
    textbox.ShowMessageType = iShowMessageType;
    Epoint_A_TextBox[Epoint_A_TextBoxCount++] = id;

}    


function Init_SpecialTextBox(id,type,selecttype,msg,specialType,iMaxLength,bAllowNull,sForbiddenChar,iShowMessageType)
{
    var elem = Epoint_getElementById(id);
    var textbox = new TextBox(id,type,selecttype,msg,elem,false,false,false,sForbiddenChar);
    textbox.SpecialType = specialType;
    textbox.MaxLength = iMaxLength;
    textbox.AllowNull = bAllowNull;
    textbox.CheckSelf = SpecialTextBoxCheckSelf;
    textbox.ShowMessageType = iShowMessageType;
    
    EpointaddEventListener(elem,"blur",SpecialTextBlur,true);
    EpointaddEventListener(elem,"keypress",CheckIsForbiddenCharKeyPress,true);
    Epoint_TextBox[id] = textbox;
    Epoint_A_TextBox[Epoint_A_TextBoxCount++] = id;
}

///构造普通TextBox对象
function TextBox(id,type,selecttype,msg,elem,allowSBC,allowSBCPoint,allowSBCNum,sForbiddenChar)
{
    this.Id = id;
    this.Msg = msg;
    this.Type = type;
    this.Element = elem;
    this.SelectType = selecttype;
    this.AllowSBC = allowSBC;
    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];
		var str = elem.value;
        if(text.Type == "money")
            str = Epoint_TakeOut(str,text.MoneyChar);
        else
            str = Epoint_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.Type=="normal")
		{
		    text.Element.value = text.Element.value.Trim();
            if(!text.AllowSBC)
                text.Element.value = FormatFullToHalfChar(text.Element.value);
            else
            {
                if(!text.AllowSBCPoint)
                    text.Element.value = FormatFullToHalfPoint(text.Element.value);
                if(!text.AllowSBCNum)
                    text.Element.value = FormatFullToHalfNum(text.Element.value);     
            }
		
		}
        if(text.MaxLength != 0 && Epoint_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(clipboardData.getData('text')==null) return;
		
		
		var str1 = clipboardData.getData('text');
		
		if(text.ForbiddenChar!=null && text.ForbiddenChar!="")
		{
		    var aForbidden = text.ForbiddenChar.split(';');
		    for(var i=0;i<aForbidden.length;i++)
                str1 = str1.ReplaceAll(aForbidden[i],'');
		}
		clipboardData.setData('text',str1)
		
		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);
	}
}


//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);
	}	
}

//根据精度，四舍五入,然后加分节符
function FormatForNumericTextBox()
{
    //this.Precision!=0 有效
    var elem = this.Element;
    if(this.Precision != 0)
    {
        elem.value = Epoint_Round(elem.value,this.Precision);
    }
    switch(this.Type)
    {
        case "money":
            elem.value = Epoint_Commafy(elem.value,this.MoneyChar,this.ShowMoneyChar,this.ShowCharact);
            break;
        case "numeric":
        case "int":
            elem.value = Epoint_Commafy(elem.value,'',false,this.ShowCharact);	
            break;
        case "rate":
            elem.value = Epoint_Commafy(elem.value,'',false,this.ShowCharact)+"%";	
            break;
    }
}

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 Epoint_CheckInput(textbox,obj,type,strErrInfo,MaxValue,MinValue,ZeroValue)
{
    if(!CheckInput(textbox,obj,type,strErrInfo)) 
    {
        obj.value = '';
        return false;
    }
    if(MaxValue!=null && (parseFloat(obj.value) - MaxValue) > ZeroValue)
    {
        Epoint_ShowMessageDiv(textbox,strErrInfo + '请输入小于等于' + MaxValue + '的数值！');
        obj.value=MaxValue + (type=="rate" ? "%" : "");
        return false;
    }
    if(MinValue!=null && (parseFloat(obj.value) - MinValue) < ZeroValue)
    {
        Epoint_ShowMessageDiv(textbox,strErrInfo + '请输入大于等于' + MinValue + '的数值！');
        obj.value=MinValue  + (type=="rate" ? "%" : "");
        return false;
    }
    
    return true;
}

function CheckInput(textbox,obj,type,strErrInfo)
{
    //为空，不做判断
    if(obj.value=="") return true;
    switch(type)
    {
        case 'int':// 整数Integer            
            if(parseInt(obj.value) != obj.value)
            {
                if(strErrInfo=='')
                    Epoint_ShowMessageDiv(textbox,'请输入整数！');
                else
                    Epoint_ShowMessageDiv(textbox,strErrInfo + '：请输入整数！');
                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,'请输入数值！');
                else
                    Epoint_ShowMessageDiv(textbox,strErrInfo + '：请输入数值！');                                    
                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之间！')
                    else
                        Epoint_ShowMessageDiv(textbox,strErrInfo + '：介于0-100之间！')
                    obj.value=0.00;
                    return false;
                }
            }
            else
            {
                if(strErrInfo=='')
                    Epoint_ShowMessageDiv(textbox,'介于0-100之间！')
                else
                    Epoint_ShowMessageDiv(textbox,strErrInfo + '：介于0-100之间！')
                obj.value=0.00;
                return false;
            }
            break;
    }
    return true;
}



///id:文本框ID
function CheckSpecialTextBox(id) 
{ 
    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地址！');
                else
                    Epoint_ShowMessageDiv(text,text.Msg + '：请输入准确的Email地址！');
                return false;
            }
            break;
        case "IdentityCard":
            var info = Epoint_CheckIdcard(elem.value);
            if(info != "")
            {
                if(text.Msg=='')
                    Epoint_ShowMessageDiv(text,info);
                else
                    Epoint_ShowMessageDiv(text,text.Msg + info);
                return false;
            }
            break;
        case "PostCode":
            regExp =  /^[1-9]\d{5}$/
            if(!elem.value.match(regExp))
            {
                if(text.Msg=='')
                    Epoint_ShowMessageDiv(text,'请输入准确的邮编！');
                else
                    Epoint_ShowMessageDiv(text,text.Msg + '：请输入准确的邮编！');
                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,'请输入准确的手机号码！');
                else
                    Epoint_ShowMessageDiv(text,text.Msg + '：请输入准确的手机号码！');
                return false;
            }
            break;
    }
    return true;
} 

///验证身份证是否有效
function Epoint_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 bUpDownRun = false;
function Epoint_UpDown_Stop(id)
{
    bUpDownRun = false;
    var text = Epoint_TextBox[id]; 
    if(typeof(text.Element.onchange)=="function")
        text.Element.onchange();
}

function onUpArrowClick(id,increment)
{
    if(bUpDownRun)
    {
        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(Epoint_TakeOut(text.Element.value,null)) + increment;
        }
        
        text.Element.value = Epoint_Commafy(text.Element.value,'',false,text.ShowCharact)
        
        window.setTimeout("onUpArrowClick('" + id + "'," + increment + ")",200);
    }
    
    
    
}

function onDownArrowClick(id,increment)
{  
    if(bUpDownRun)
    {
         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(Epoint_TakeOut(text.Element.value,null)) - increment;
        }
        
        text.Element.value = Epoint_Commafy(text.Element.value,'',false,text.ShowCharact)
        
        window.setTimeout("onUpArrowClick('" + id + "'," + increment + ")",200);
    }
    
}
	
	
/////UpDown使用的函数
function onUpArrowMouseDown(id,increment)
{
    bUpDownRun = true;
    onUpArrowClick(id,increment)
}

function onDownArrowMouseDown(id,increment)
{
    bUpDownRun = true;
    onDownArrowClick(id,increment);
}			

function FormatFullToHalfChar(strOld)
{
    var DBCStr = "";  
    //alert('1111');   
    for(var i=0; i<strOld.length; i++)
    {   
        var c = strOld.charCodeAt(i);   
        if(c == 12288) {   
            DBCStr += String.fromCharCode(32);   
            continue;   
        }   
        if (c > 65280 && c < 65375) {   
            DBCStr += String.fromCharCode(c - 65248);   
            continue;   
        }   
        DBCStr += String.fromCharCode(c);   
    }   
    return DBCStr; 
    
}

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.AllowSBC)
            val = FormatFullToHalfChar(val);
        else
        {
            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.AllowSBC)
            val = FormatFullToHalfChar(val);
        else
        {
            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(!text.AllowSBC)
            val = FormatFullToHalfChar(val);
        else
        {
            if(!text.AllowSBCPoint)
                val = FormatFullToHalfPoint(val);
            if(!text.AllowSBCNum)
                val = FormatFullToHalfNum(val);     
        }
        
        if(val1 != val)
            elem.value = val;                 
	}	
}




//普通文本框的失去焦点的验证函数
function NormalTextBoxCheckSelfOnBlur()
{
    
}

//数值文本框的失去焦点的验证函数
function NumericTextBoxCheckSelfOnBlur()
{
    this.Element.value = Epoint_TakeOut(this.Element.value,null);
    
    this.CheckInputValue();
}

//数值文本框的失去焦点的验证函数
function RateTextBoxCheckSelfOnBlur()
{
    this.Element.value = Epoint_TakeOut(this.Element.value,"%");
    
    this.CheckInputValue();
}

//整数文本框的失去焦点的验证函数
function IntTextBoxCheckSelfOnBlur()
{
    this.Element.value = Epoint_TakeOut(this.Element.value,null);
    this.CheckInputValue();
}

//Money文本框的失去焦点的验证函数
function MoneyTextBoxCheckSelfOnBlur()
{
    this.Element.value = Epoint_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))
	    return;
	this.FormatTextBox();
}

//普通文本框的失去焦点的验证函数
function NormalTextBoxCheckSelf()
{
    this.Element.value = this.Element.value.Trim();
    if(this.MaxLength != 0 && Epoint_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 && Epoint_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); 
}

//Rate文本框的失去焦点的验证函数
function RateTextBoxCheckSelf()
{
    if(NumericTextBoxCheckSelf())
    {
        this.Element.value += "%";
    }
    else
        return false;
    
}
//Int文本框的失去焦点的验证函数
function IntTextBoxCheckSelf()
{
    this.Element.value = this.Element.value.Trim();
    if(this.MaxLength != 0 && Epoint_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); 
}

//Money文本框的失去焦点的验证函数
function MoneyTextBoxCheckSelf()
{
    this.Element.value = this.Element.value.Trim();
    if(this.MaxLength != 0 && Epoint_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); 
}


//Special文本框的失去焦点的验证函数
function SpecialTextBoxCheckSelf()
{
    this.Element.value = this.Element.value.Trim();
    if(this.MaxLength != 0 && Epoint_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); 
}


//提交前的统一验证函数,用来控制合法性输入
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 Epoint_ShowMessageDivID(id,Msg)
{
    Epoint_ShowMessageDiv(Epoint_TextBox[id],Msg);
}

function Epoint_ShowMessageDiv(obj,Msg)
{
    //不提示
    if(obj.ShowMessageType==0)
        return;
        
    //alert
    if(obj.ShowMessageType==1)
    {
        alert(Msg);
        obj.Element.focus;
        obj.Element.select();
        return;
    }
    //Div
    if(typeof(Epoint_getElementById("IFrame" + Epoint_MessageDivID))=="undefined")
    {
        Epoint_MessageIFrame = document.createElement("iframe");
        Epoint_MessageIFrame.id = "IFrame" + Epoint_MessageDivID;
        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 = EpointGetAbsoluteLocation(obj.Element);
	    Epoint_MessageDiv.style.top   =   pos.absoluteTop - Epoint_MessageDiv.offsetHeight-2;
	    Epoint_MessageDiv.style.left   =   pos.absoluteLeft;
        
        
        pos = EpointGetAbsoluteLocation(Epoint_getElementById(Epoint_MessageDivID));
        Epoint_MessageIFrame.style.width   =   pos.offsetWidth;
        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 = EpointGetAbsoluteLocation(obj.Element);
	    Epoint_MessageDiv.style.top   =   pos.absoluteTop - Epoint_MessageDiv.offsetHeight-2;
	    Epoint_MessageDiv.style.left   =   pos.absoluteLeft;
        pos = EpointGetAbsoluteLocation(Epoint_getElementById(Epoint_MessageDivID));
        
        Epoint_MessageIFrame.style.width   =   pos.offsetWidth;
        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 = "";
        Epoint_RemoveMessageDiv();
    }
}


//渐渐隐藏错误信息提示
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 Epoint_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 Epoint_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 Epoint_Round(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
	{
	    if(value!="")
		    return Math.round(value);
		else
		    return value;
    }
} 
