﻿// JScript 文件
//---------------------------------begin

Validate=new function()
{
}
Validate.Submit=function(pParam1)
{

    var rtnValue=true;
    var e;
    if(arguments.length==1)
    {
        e=document.getElementById(pParam1).getElementsByTagName('input');
    }
    else
    {
        e=document.forms[0].elements;
    }
    var propertyCount=0;
     for(var i=0;i<e.length;i++)
    {
        if(rtnValue==false) break;//如果发现返回值是假直接中断
        switch(e[i].type.toLowerCase())
        {
            case 'text':
                if(e[i].isnull!=null)
                {
                        if(e[i].isnull.toLowerCase()=='false')
                        {
                            if(e[i].value=='')
                            {
                            
                                alert(e[i].alerttext+"不能为空");
                                e[i].focus();
                                rtnValue=false;
                            }
                        }
               } 
                if(rtnValue==true){
                 if(e[i].isnum!=null)
                {
                    if(e[i].isnum=='true')
                    {
                            if(isNaN(e[i].value))
                            {//不是数字
                                alert(e[i].alerttext+'只能为数字!');
                                e[i].select();
                                e[i].focus();    
                                rtnValue=false;
                            }
                            else
                            {//是数字
                                if(e[i].minvalue!=null)
								{
									propertyCount+=1;
								}
                                if(e[i].maxvalue!=null)
								{
									propertyCount+=1;
								}
                                if(propertyCount==2)
                                {
                                    if(parseFloat(e[i].value)<parseFloat(e[i].minvalue) || parseFloat(e[i].value)>parseFloat(e[i].maxvalue))
                                    {
                                        alert(e[i].alerttext+'应在 '+e[i].minvalue+' 和 '+e[i].maxvalue+' 之间');
                                        e[i].select();
                                        e[i].focus();    
                                        rtnValue=false;
                                    }
                                }
                                else if(e[i].minvalue!=null)
                                {
                                    if(parseFloat(e[i].value)<parseFloat(e[i].minvalue))
                                    {
                                        alert(e[i].alerttext+'不能小于 '+e[i].minvalue);
                                        e[i].select();
                                        e[i].focus();    
                                        rtnValue=false;
                                    }
                                }
                                else if(e[i].maxvalue!=null)
                                {
                                    if(parseFloat(e[i].value)>parseFloat(e[i].maxvalue))
                                    {
                                        alert(e[i].alerttext+'不能大于 '+e[i].maxvalue);
                                        e[i].select();
                                        e[i].focus();    
                                        rtnValue=false;
                                    }
                                }
                            }
                        }
                    }
                }
                break;
        }
    }
    return rtnValue;
}
